From b227e47b1f7bf4a1adcfea823e2efc7be40d171b Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Sun, 17 Dec 2017 08:42:21 +0100 Subject: rename librt test, add tst-posix_spawn --- test/.gitignore | 3 +- test/librt/Makefile | 8 ---- test/librt/Makefile.in | 8 ---- test/librt/shmtest.c | 104 ---------------------------------------------- test/rt/Makefile | 8 ++++ test/rt/Makefile.in | 7 ++++ test/rt/tst-posix_spawn.c | 48 +++++++++++++++++++++ test/rt/tst-shm.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 169 insertions(+), 121 deletions(-) delete mode 100644 test/librt/Makefile delete mode 100644 test/librt/Makefile.in delete mode 100644 test/librt/shmtest.c create mode 100644 test/rt/Makefile create mode 100644 test/rt/Makefile.in create mode 100644 test/rt/tst-posix_spawn.c create mode 100644 test/rt/tst-shm.c diff --git a/test/.gitignore b/test/.gitignore index 0d19285..b1370ac 100644 --- a/test/.gitignore +++ b/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 diff --git a/test/librt/Makefile b/test/librt/Makefile deleted file mode 100644 index 1021afe..0000000 --- a/test/librt/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# uClibc shm tests -# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - -top_builddir=../../ -top_srcdir=../../ -include ../Rules.mak --include Makefile.in -include ../Test.mak diff --git a/test/librt/Makefile.in b/test/librt/Makefile.in deleted file mode 100644 index b2a829d..0000000 --- a/test/librt/Makefile.in +++ /dev/null @@ -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 diff --git a/test/librt/shmtest.c b/test/librt/shmtest.c deleted file mode 100644 index a14302d..0000000 --- a/test/librt/shmtest.c +++ /dev/null @@ -1,104 +0,0 @@ -/* Copyright (C) 2009 Mikael Lund Jepsen - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - -char shared_name[] = "/sharetest"; -int test_data[11] = {0,1,2,3,4,5,6,7,8,9,10}; - -int main(void) { - int pfds[2]; - pid_t pid; - int fd; - int test_data_fails = 0; - char *ptest_data; - unsigned int i; - char buf[30]; - int rv; - - pipe(pfds); - - switch(pid = fork()) { - case -1: - perror("fork"); - exit(1); /* parent exits */ - - case 0: - /* Child */ - - /* wait for parent */ - read(pfds[0], buf, 5); - - fd = shm_open(shared_name, O_RDWR, DEFFILEMODE); - if (fd == -1) { - perror("CHILD - shm_open(existing):"); - exit(1); - } else { - ptest_data = mmap(0, sizeof(test_data), PROT_READ + PROT_WRITE, MAP_SHARED, fd, 0); - if (ptest_data != MAP_FAILED) { - for (i=0; i < ARRAY_SIZE(test_data); i++) { - if (ptest_data[i] != test_data[i]) { - printf("%-40s: Offset %d, local %d, shm %d\n", "Compare memory error", i, test_data[i], ptest_data[i]); - test_data_fails++; - } - } - if (test_data_fails == 0) - printf("%-40s: %s\n", "Compare memory", "Success"); - - munmap(ptest_data, sizeof(test_data)); - } - } - exit(0); - - default: - /* Parent */ - fd = shm_open(shared_name, O_RDWR+O_CREAT+O_EXCL, DEFFILEMODE ); - if (fd == -1) { - perror("PARENT - shm_open(create):"); - } else { - if ((ftruncate(fd, sizeof(test_data))) == -1) - { - printf("%-40s: %s", "ftruncate", strerror(errno)); - shm_unlink(shared_name); - return 0; - } - - ptest_data = mmap(0, sizeof(test_data), PROT_READ + PROT_WRITE, MAP_SHARED, fd, 0); - if (ptest_data == MAP_FAILED) - { - perror("PARENT - mmap:"); - if (shm_unlink(shared_name) == -1) { - perror("PARENT - shm_unlink:"); - } - return 0; - } - for (i=0; i < ARRAY_SIZE(test_data); i++) - ptest_data[i] = test_data[i]; - - /* signal child */ - write(pfds[1], "rdy", 5); - /* wait for child */ - wait(&rv); - - /* Cleanup */ - munmap(ptest_data, sizeof(test_data)); - if (shm_unlink(shared_name) == -1) { - perror("PARENT - shm_unlink:"); - } - } - } - return 0; -} diff --git a/test/rt/Makefile b/test/rt/Makefile new file mode 100644 index 0000000..1021afe --- /dev/null +++ b/test/rt/Makefile @@ -0,0 +1,8 @@ +# uClibc shm tests +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + +top_builddir=../../ +top_srcdir=../../ +include ../Rules.mak +-include Makefile.in +include ../Test.mak diff --git a/test/rt/Makefile.in b/test/rt/Makefile.in new file mode 100644 index 0000000..38a7b5a --- /dev/null +++ b/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 diff --git a/test/rt/tst-posix_spawn.c b/test/rt/tst-posix_spawn.c new file mode 100644 index 0000000..28b6500 --- /dev/null +++ b/test/rt/tst-posix_spawn.c @@ -0,0 +1,48 @@ +#include +#include +#include + +#include +#include +#include + +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; +} diff --git a/test/rt/tst-shm.c b/test/rt/tst-shm.c new file mode 100644 index 0000000..a14302d --- /dev/null +++ b/test/rt/tst-shm.c @@ -0,0 +1,104 @@ +/* Copyright (C) 2009 Mikael Lund Jepsen + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +char shared_name[] = "/sharetest"; +int test_data[11] = {0,1,2,3,4,5,6,7,8,9,10}; + +int main(void) { + int pfds[2]; + pid_t pid; + int fd; + int test_data_fails = 0; + char *ptest_data; + unsigned int i; + char buf[30]; + int rv; + + pipe(pfds); + + switch(pid = fork()) { + case -1: + perror("fork"); + exit(1); /* parent exits */ + + case 0: + /* Child */ + + /* wait for parent */ + read(pfds[0], buf, 5); + + fd = shm_open(shared_name, O_RDWR, DEFFILEMODE); + if (fd == -1) { + perror("CHILD - shm_open(existing):"); + exit(1); + } else { + ptest_data = mmap(0, sizeof(test_data), PROT_READ + PROT_WRITE, MAP_SHARED, fd, 0); + if (ptest_data != MAP_FAILED) { + for (i=0; i < ARRAY_SIZE(test_data); i++) { + if (ptest_data[i] != test_data[i]) { + printf("%-40s: Offset %d, local %d, shm %d\n", "Compare memory error", i, test_data[i], ptest_data[i]); + test_data_fails++; + } + } + if (test_data_fails == 0) + printf("%-40s: %s\n", "Compare memory", "Success"); + + munmap(ptest_data, sizeof(test_data)); + } + } + exit(0); + + default: + /* Parent */ + fd = shm_open(shared_name, O_RDWR+O_CREAT+O_EXCL, DEFFILEMODE ); + if (fd == -1) { + perror("PARENT - shm_open(create):"); + } else { + if ((ftruncate(fd, sizeof(test_data))) == -1) + { + printf("%-40s: %s", "ftruncate", strerror(errno)); + shm_unlink(shared_name); + return 0; + } + + ptest_data = mmap(0, sizeof(test_data), PROT_READ + PROT_WRITE, MAP_SHARED, fd, 0); + if (ptest_data == MAP_FAILED) + { + perror("PARENT - mmap:"); + if (shm_unlink(shared_name) == -1) { + perror("PARENT - shm_unlink:"); + } + return 0; + } + for (i=0; i < ARRAY_SIZE(test_data); i++) + ptest_data[i] = test_data[i]; + + /* signal child */ + write(pfds[1], "rdy", 5); + /* wait for child */ + wait(&rv); + + /* Cleanup */ + munmap(ptest_data, sizeof(test_data)); + if (shm_unlink(shared_name) == -1) { + perror("PARENT - shm_unlink:"); + } + } + } + return 0; +} -- cgit v1.2.3