Browse Source

rename librt test, add tst-posix_spawn

Waldemar Brodkorb 6 years ago
parent
commit
b227e47b1f
6 changed files with 57 additions and 9 deletions
  1. 2 1
      test/.gitignore
  2. 0 8
      test/librt/Makefile.in
  3. 0 0
      test/rt/Makefile
  4. 7 0
      test/rt/Makefile.in
  5. 48 0
      test/rt/tst-posix_spawn.c
  6. 0 0
      test/rt/tst-shm.c

+ 2 - 1
test/.gitignore

@@ -51,7 +51,8 @@ inet/tst-network
 inet/tst-ntoa
 inet/tst-res
 inet/tst-sock-nonblock
-librt/shmtest
+rt/tst-shm
+rt/tst-posix_spawn
 locale/bug-iconv-trans
 locale/bug-usesetlocale
 locale/C

+ 0 - 8
test/librt/Makefile.in

@@ -1,8 +0,0 @@
-# uClibc-ng shm tests
-# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
-
-LDFLAGS_shmtest := -lrt
-
-ifeq ($(ARCH_USE_MMU),)
-TESTS_DISABLED := shmtest
-endif

+ 0 - 0
test/librt/Makefile → test/rt/Makefile


+ 7 - 0
test/rt/Makefile.in

@@ -0,0 +1,7 @@
+# uClibc-ng realtime tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+LDFLAGS_tst-shm := -lrt
+TESTS_DISABLED := tst-shm
+
+OPTS_tst-posix_spawn := ls

+ 48 - 0
test/rt/tst-posix_spawn.c

@@ -0,0 +1,48 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <unistd.h>
+#include <spawn.h>
+#include <sys/wait.h>
+
+extern char **environ;
+
+void run_cmd(char *cmd)
+{
+    pid_t pid;
+    posix_spawnattr_t attrs;
+    posix_spawn_file_actions_t actions;
+    sigset_t defsignals;
+    char *argv[] = {"sh", "-c", cmd, NULL};
+    int status;
+
+    sigemptyset(&defsignals);
+    sigaddset(&defsignals, SIGTERM);
+    sigaddset(&defsignals, SIGCHLD);
+    sigaddset(&defsignals, SIGPIPE);
+
+    posix_spawnattr_init(&attrs);
+    posix_spawnattr_setflags(&attrs, POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF);
+    posix_spawnattr_setpgroup(&attrs, 0);
+    posix_spawnattr_setsigdefault(&attrs, &defsignals);
+
+    printf("Run command: %s\n", cmd);
+    status = posix_spawn(&pid, "/bin/sh", &actions, &attrs, argv, environ);
+    if (status == 0) {
+        printf("Child pid: %i\n", pid);
+        if (waitpid(pid, &status, 0) != -1) {
+            printf("Child exited with status %i\n", status);
+        } else {
+            perror("waitpid");
+        }
+    } else {
+        printf("posix_spawn: %s\n", strerror(status));
+    }
+}
+
+int main(int argc, char* argv[])
+{
+    run_cmd(argv[1]);
+    return 0;
+}

+ 0 - 0
test/librt/shmtest.c → test/rt/tst-shm.c