]> granicus.if.org Git - strace/commitdiff
tests/ipc_shm.c: use libtests
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 6 Jan 2016 11:59:58 +0000 (11:59 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 6 Jan 2016 11:59:58 +0000 (11:59 +0000)
* tests/ipc_shm.c (cleanup): New function.
(main): Use it and perror_msg_and_skip.

tests/ipc_shm.c

index 9f4771166d96fa5f184f132c117972f41a8cbfbc..54723e22ea036ab702ac8d149efa5ad3e6628884 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
  * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
+ * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <stdio.h>
+#include "tests.h"
 #include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <sys/shm.h>
 
+static int id = -1;
+
+static void
+cleanup(void)
+{
+       shmctl(id, IPC_RMID, NULL);
+       printf("shmctl\\(%d, (IPC_64\\|)?IPC_RMID, NULL\\) += 0\n", id);
+       id = -1;
+}
+
 int
 main(void)
 {
-       int rc, id;
+       int rc;
        struct shmid_ds ds;
 
        id = shmget(IPC_PRIVATE, 1, 0600);
        if (id < 0)
-               return 77;
+               perror_msg_and_skip("shmget");
        printf("shmget\\(IPC_PRIVATE, 1, 0600\\) += %d\n", id);
+       atexit(cleanup);
 
        if (shmctl(id, IPC_STAT, &ds))
-               goto fail;
+               perror_msg_and_skip("shmctl IPC_STAT");
        printf("shmctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{shm_perm=\\{uid=%u, gid=%u, "
                "mode=%#o, key=%u, cuid=%u, cgid=%u\\}, shm_segsz=%u, shm_cpid=%u, "
                "shm_lpid=%u, shm_nattch=%u, shm_atime=%u, shm_dtime=%u, "
@@ -57,7 +70,7 @@ main(void)
 
        int max = shmctl(0, SHM_INFO, &ds);
        if (max < 0)
-               goto fail;
+               perror_msg_and_skip("shmctl SHM_INFO");
        printf("shmctl\\(0, (IPC_64\\|)?SHM_INFO, %p\\) += %d\n", &ds, max);
 
        rc = shmctl(id, SHM_STAT, &ds);
@@ -67,20 +80,11 @@ main(void)
                 * an index in the kernel's internal array.
                 */
                if (-1 != rc || EINVAL != errno)
-                       goto fail;
-               printf("shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += -1 EINVAL \\(Invalid argument\\)\n", id, &ds);
+                       perror_msg_and_skip("shmctl SHM_STAT");
+               printf("shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += -1 EINVAL \\(%m\\)\n", id, &ds);
        } else {
                printf("shmctl\\(%d, (IPC_64\\|)?SHM_STAT, %p\\) += %d\n", id, &ds, id);
        }
 
-       rc = 0;
-done:
-       if (shmctl(id, IPC_RMID, NULL) < 0)
-               return 1;
-       printf("shmctl\\(%d, (IPC_64\\|)?IPC_RMID, NULL\\) += 0\n", id);
-       return rc;
-
-fail:
-       rc = 1;
-       goto done;
+       return 0;
 }