* gdb.base/info-os.c (main): Retry resource acquisition until an
authorStan Shebs <shebs@codesourcery.com>
Tue, 3 Jul 2012 23:17:13 +0000 (23:17 +0000)
committerStan Shebs <shebs@codesourcery.com>
Tue, 3 Jul 2012 23:17:13 +0000 (23:17 +0000)
available one is found.
* gdb.base/info-os.exp: Collect resource keys from the program
and use them in matching.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/info-os.c
gdb/testsuite/gdb.base/info-os.exp

index 34351ff..e993c49 100644 (file)
@@ -1,3 +1,10 @@
+2012-07-03  Stan Shebs  <stan@codesourcery.com>
+
+       * gdb.base/info-os.c (main): Retry resource acquisition until an
+       available one is found.
+       * gdb.base/info-os.exp: Collect resource keys from the program
+       and use them in matching.
+
 2012-07-02  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * gdb.threads/gcore-thread.exp: Remove variable libthread_db_seen.
index 2971671..1590a9b 100644 (file)
@@ -1,6 +1,6 @@
 /* This testcase is part of GDB, the GNU debugger.
 
-   Copyright 2011 Free Software Foundation, Inc.
+   Copyright 2011, 2012 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -36,6 +36,7 @@ int
 main (void)
 {
   const int flags = IPC_CREAT | 0666;
+  key_t shmkey = 3925, semkey = 7428, msgkey = 5294;
   int shmid, semid, msqid;
   FILE *fd;
   pthread_t thread;
@@ -43,22 +44,53 @@ main (void)
   int sock;
   unsigned short port;
   socklen_t size;
-  int status;
+  int status, try, retries = 1000;
 
-  if ((shmid = shmget (3925, 4096, flags | IPC_EXCL)) < 0)
+  for (try = 0; try < retries; ++try)
     {
-      /* Attempt to delete the existing shared-memory region, then
-        recreate it.  */
-      shmctl (shmget (3925, 4096, flags), IPC_RMID, NULL);
-      if ((shmid = shmget (3925, 4096, flags | IPC_EXCL)) < 0)
-       {
-         printf ("Cannot create shared-memory region.\n");
-         return 1;
-       }         
+      shmid = shmget (shmkey, 4096, flags | IPC_EXCL);
+      if (shmid >= 0)
+       break;
+
+      ++shmkey;
+    }
+
+  if (shmid < 0)
+    {
+      printf ("Cannot create shared-memory region after %d tries.\n", retries);
+      return 1;
+    }
+
+  for (try = 0; try < retries; ++try)
+    {
+      semid = semget (semkey, 1, flags | IPC_EXCL);
+      if (semid >= 0)
+       break;
+
+      ++semkey;
+    }
+
+  if (semid < 0)
+    {
+      printf ("Cannot create semaphore after %d tries.\n", retries);
+      return 1;
+    }
+
+  for (try = 0; try < retries; ++try)
+    {
+      msqid = msgget (msgkey, flags | IPC_EXCL);
+      if (msqid >= 0)
+       break;
+
+      ++msgkey;
+    }
+
+  if (msqid < 0)
+    {
+      printf ("Cannot create message queue after %d tries.\n", retries);
+      return 1;
     }
 
-  semid = semget (7428, 1, flags);
-  msqid = msgget (5294, flags);
   fd = fopen ("/dev/null", "r");
 
   /* Lock the mutex to prevent the new thread from finishing immediately.  */
index 5696402..541f03b 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2011 Free Software Foundation, Inc.
+# Copyright 2011, 2012 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -52,7 +52,15 @@ gdb_test_multiple "call getpid()" $test {
 gdb_breakpoint ${srcfile}:[gdb_get_line_number "Set breakpoint here"]
 gdb_continue_to_breakpoint "Set breakpoint here"
 
-# Get IDs of the IPC object instances.
+# Get keys and IDs of the IPC object instances.
+set shmkey -1
+set test "get shared memory key"
+gdb_test_multiple "print shmkey" $test {
+    -re ".* = ($decimal).*$gdb_prompt $" {
+       set shmkey $expect_out(1,string)
+       pass $test
+    }
+}
 set shmid -1
 set test "get shared memory ID"
 gdb_test_multiple "print shmid" $test {
@@ -62,6 +70,15 @@ gdb_test_multiple "print shmid" $test {
     }
 }
 
+set semkey -1
+set test "get semaphore key"
+gdb_test_multiple "print semkey" $test {
+    -re ".* = ($decimal).*$gdb_prompt $" {
+       set semkey $expect_out(1,string)
+       pass $test
+    }
+}
+
 set semid -1
 set test "get semaphore ID"
 gdb_test_multiple "print semid" $test {
@@ -71,6 +88,15 @@ gdb_test_multiple "print semid" $test {
     }
 }
 
+set msgkey -1
+set test "get message queue key"
+gdb_test_multiple "print msgkey" $test {
+    -re ".* = ($decimal).*$gdb_prompt $" {
+       set msgkey $expect_out(1,string)
+       pass $test
+    }
+}
+
 set msqid -1
 set test "get message queue ID"
 gdb_test_multiple "print msqid" $test {
@@ -138,20 +164,16 @@ expect_multiline "info os files" "$inferior_pid +info-os +\\d+ +/dev/null" "get
 expect_multiline "info os sockets" "0\\.0\\.0\\.0 +$port +0\\.0\\.0\\.0 +0 +LISTEN +\\S+ +INET +STREAM" "get internet-domain sockets"
 
 #                               key   shmid   perm size creator command last op  command  num attached  user  group  creator user  creator group  last shmat() time  last shmdt() time  last shmctl() time
-expect_multiline "info os shm" "3925 +$shmid +666 +4096 +info-os .*" "get shared-memory regions"
+expect_multiline "info os shm" "$shmkey +$shmid +666 +4096 +info-os .*" "get shared-memory regions"
 
 #                                      key   semid   perm num semaphores  user  group  creator user  creator group  last semop() time  last semctl() time
-expect_multiline "info os semaphores" "7428 +$semid +666 +1 .*" "get semaphores"
+expect_multiline "info os semaphores" "$semkey +$semid +666 +1 .*" "get semaphores"
 
 #                               key   msqid   perm  num used bytes  num messages  last msgsnd() command  last msgrcv() command  user  group  creator user  creator group  last msgsnd() time  last msgrcv() time  last msgctl() time
-expect_multiline "info os msg" "5294 +$msqid +666 .*" "get message queues"
+expect_multiline "info os msg" "$msgkey +$msqid +666 .*" "get message queues"
 
 
 # The SysV IPC primitives linger on after the creating process is killed
 # unless they are destroyed explicitly, so allow the test program to tidy
-# up after itself.  Note that the test program attempts to delete and
-# recreate the shared-memory region if it already exists, in case a
-# previous run failed before having a chance to clean up.  The tests for
-# semaphores and message queues should still work with primitives from
-# previous runs.
+# up after itself.
 send_gdb "continue\n"