From 0554fda54f6173ec4244e8ffd2259039374161b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kadl=C4=8D=C3=ADk?= Date: Fri, 9 Jul 2021 16:24:48 +0200 Subject: [PATCH] Import RHEL's test Sanity/random-apps Note than several sub-tests (apps) had to be removed as unsuitable for publishing. --- tests/Sanity/random-apps/Makefile | 64 ++++++ tests/Sanity/random-apps/PURPOSE | 3 + tests/Sanity/random-apps/abort.c | 6 + tests/Sanity/random-apps/main.fmf | 14 ++ .../Sanity/random-apps/many_looping_threads.c | 35 +++ tests/Sanity/random-apps/mthd2.c | 43 ++++ tests/Sanity/random-apps/reproducer.c | 14 ++ tests/Sanity/random-apps/reproducer2.c | 15 ++ tests/Sanity/random-apps/reproducer3.c | 14 ++ tests/Sanity/random-apps/runtest.sh | 101 +++++++++ tests/Sanity/random-apps/say_linux.c | 8 + tests/Sanity/random-apps/sleeping-c.c | 6 + tests/Sanity/random-apps/t_thread.c | 211 ++++++++++++++++++ tests/Sanity/random-apps/test1.c | 52 +++++ tests/Sanity/random-apps/test_fork.c | 78 +++++++ tests/Sanity/random-apps/test_select.c | 70 ++++++ tests/Sanity/random-apps/thread-test2.c | 34 +++ tests/Sanity/random-apps/vfork.c | 15 ++ 18 files changed, 783 insertions(+) create mode 100644 tests/Sanity/random-apps/Makefile create mode 100644 tests/Sanity/random-apps/PURPOSE create mode 100644 tests/Sanity/random-apps/abort.c create mode 100644 tests/Sanity/random-apps/main.fmf create mode 100644 tests/Sanity/random-apps/many_looping_threads.c create mode 100644 tests/Sanity/random-apps/mthd2.c create mode 100644 tests/Sanity/random-apps/reproducer.c create mode 100644 tests/Sanity/random-apps/reproducer2.c create mode 100644 tests/Sanity/random-apps/reproducer3.c create mode 100755 tests/Sanity/random-apps/runtest.sh create mode 100644 tests/Sanity/random-apps/say_linux.c create mode 100644 tests/Sanity/random-apps/sleeping-c.c create mode 100644 tests/Sanity/random-apps/t_thread.c create mode 100644 tests/Sanity/random-apps/test1.c create mode 100644 tests/Sanity/random-apps/test_fork.c create mode 100644 tests/Sanity/random-apps/test_select.c create mode 100644 tests/Sanity/random-apps/thread-test2.c create mode 100644 tests/Sanity/random-apps/vfork.c diff --git a/tests/Sanity/random-apps/Makefile b/tests/Sanity/random-apps/Makefile new file mode 100644 index 0000000..cc7d4a8 --- /dev/null +++ b/tests/Sanity/random-apps/Makefile @@ -0,0 +1,64 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /tools/ltrace/Sanity/random-apps +# Description: Runs random app which caused strace problems in the past +# Author: Michal Nowak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/tools/ltrace/Sanity/random-apps +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE *.c + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Michal Nowak " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Runs random app which caused strace problems in the past" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 1h" >> $(METADATA) + @echo "RunFor: ltrace" >> $(METADATA) + @echo "Requires: ltrace" >> $(METADATA) + @echo "Requires: gcc glibc-devel" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: yes" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Sanity/random-apps/PURPOSE b/tests/Sanity/random-apps/PURPOSE new file mode 100644 index 0000000..49e48ae --- /dev/null +++ b/tests/Sanity/random-apps/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /tools/ltrace/Sanity/random-apps +Description: Runs random app which caused strace problems in the past +Author: Michal Nowak diff --git a/tests/Sanity/random-apps/abort.c b/tests/Sanity/random-apps/abort.c new file mode 100644 index 0000000..b1db3c3 --- /dev/null +++ b/tests/Sanity/random-apps/abort.c @@ -0,0 +1,6 @@ +#include + +int main() { + abort(); +} + diff --git a/tests/Sanity/random-apps/main.fmf b/tests/Sanity/random-apps/main.fmf new file mode 100644 index 0000000..65d54ee --- /dev/null +++ b/tests/Sanity/random-apps/main.fmf @@ -0,0 +1,14 @@ +summary: Runs random app which caused strace problems in the past +description: '' +contact: Michal Nowak +component: +- ltrace +test: ./runtest.sh +framework: beakerlib +recommend: +- ltrace +- gcc +- glibc-devel +duration: 1h +extra-summary: /tools/ltrace/Sanity/random-apps +extra-task: /tools/ltrace/Sanity/random-apps diff --git a/tests/Sanity/random-apps/many_looping_threads.c b/tests/Sanity/random-apps/many_looping_threads.c new file mode 100644 index 0000000..87d837b --- /dev/null +++ b/tests/Sanity/random-apps/many_looping_threads.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +static int thd_no; + +static void *sub_thd(void *c) +{ + fprintf(stderr, "sub-thread %d created\n", ++thd_no); + for (;;) + getuid(); + return NULL; +} + +int main(int argc, char *argv[]) +{ + int i; + pthread_t *thd; + int num_threads = 1; + + if (argv[1]) + num_threads = atoi(argv[1]); + + thd = malloc(num_threads * sizeof(thd[0])); + fprintf(stderr, "test start, num_threads:%d...\n", num_threads); + for (i = 0; i < num_threads; i++) { + pthread_create(&thd[i], NULL, sub_thd, NULL); + fprintf(stderr, "after pthread_create\n"); + } + /* Exit. This kills all threads */ + return 0; +} diff --git a/tests/Sanity/random-apps/mthd2.c b/tests/Sanity/random-apps/mthd2.c new file mode 100644 index 0000000..6c0f154 --- /dev/null +++ b/tests/Sanity/random-apps/mthd2.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +#define NTHD 60 + +int thd_no; + + +long sub_func(void) +{ + uid_t uid; + + printf("sub-thread created: %d\n", ++thd_no); + + for (;;) { + uid = getuid(); + sleep(1); + } + + return (long)uid; +} + +void *sub_thd(void *c) +{ + sub_func(); +} + +main(int argc, char *argv[]) +{ + int i; + pthread_t thd[NTHD]; + + printf("test start...\n"); + + for (i = 0; i < NTHD; i++) { + pthread_create(&thd[i], NULL, sub_thd, NULL); + } +// pause(); +} + diff --git a/tests/Sanity/random-apps/reproducer.c b/tests/Sanity/random-apps/reproducer.c new file mode 100644 index 0000000..cca818c --- /dev/null +++ b/tests/Sanity/random-apps/reproducer.c @@ -0,0 +1,14 @@ +#include + +void *start (void *arg) { + return arg; +} + +pthread_t thread1; + +int main () { + pthread_create (&thread1, NULL, start, NULL); + sleep (1); + return 0; +} + diff --git a/tests/Sanity/random-apps/reproducer2.c b/tests/Sanity/random-apps/reproducer2.c new file mode 100644 index 0000000..404e8d6 --- /dev/null +++ b/tests/Sanity/random-apps/reproducer2.c @@ -0,0 +1,15 @@ +#include +#include + +static void h(int sig) {} + +int main() +{ + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_handler = h; + sa.sa_flags = SA_RESETHAND | SA_NODEFER; + sigaction (SIGUSR1, &sa, NULL); + return 0; +} + diff --git a/tests/Sanity/random-apps/reproducer3.c b/tests/Sanity/random-apps/reproducer3.c new file mode 100644 index 0000000..cca818c --- /dev/null +++ b/tests/Sanity/random-apps/reproducer3.c @@ -0,0 +1,14 @@ +#include + +void *start (void *arg) { + return arg; +} + +pthread_t thread1; + +int main () { + pthread_create (&thread1, NULL, start, NULL); + sleep (1); + return 0; +} + diff --git a/tests/Sanity/random-apps/runtest.sh b/tests/Sanity/random-apps/runtest.sh new file mode 100755 index 0000000..99e7612 --- /dev/null +++ b/tests/Sanity/random-apps/runtest.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/ltrace/Sanity/random-apps +# Description: Runs random app which caused strace problems in the past +# Author: Michal Nowak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2011 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +CMD='ltrace' +BIN=$(which --skip-alias $CMD) +PACKAGE="$(rpm -qf --qf='%{name}\n' $BIN)" +#export MALLOC_PERTURB_=$(($RANDOM % 255 + 1)) + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory" + cp *.c $TmpDir + rlRun "pushd $TmpDir" + rlPhaseEnd + + touch FAILED PASSED + PASSED_CNT=0 + FAILED_CNT=0 + ALL_CNT=0 + for test in *.c; do + RESULT="PASS" + rlPhaseStartTest "Test ${test}" + rlRun "gcc $test -o ${test}.bin -lpthread" 0 "Compile $test" + rlAssertExists "${test}.bin" + rlRun "ltrace -o ${test}.LOG -f ./${test}.bin" 0 "Run $test under ltrace" + [ $? -ne 0 ] && RESULT=FAIL + + echo + cat ${test}.LOG + echo + + rlAssertNotGrep "\-\-\- SIGKILL" ${test}.LOG + [ $? -ne 0 ] && RESULT=FAIL + rlAssertNotGrep "\-\-\- SIGSEGV" ${test}.LOG + [ $? -ne 0 ] && RESULT=FAIL + rlAssertNotGrep "\-\-\- SIGILL" ${test}.LOG + [ $? -ne 0 ] && RESULT=FAIL + rlAssertNotGrep "\-\-\- SIGTRAP" ${test}.LOG + [ $? -ne 0 ] && RESULT=FAIL + rlAssertNotGrep "\-\-\- SIGINT" ${test}.LOG + [ $? -ne 0 ] && RESULT=FAIL + if [[ "$RESULT" == "PASS" ]]; then + let "PASSED_CNT = $PASSED_CNT + 1" + echo "$test $opt" >> PASSED + else + let "FAILED_CNT = $FAILED_CNT + 1" + echo "$test $opt" >> FAILED + fi + let "ALL_CNT = $ALL_CNT + 1" + rlPhaseEnd + done + + rlPhaseStartTest + rlLog "PASSED : $PASSED_CNT of $ALL_CNT" + cat PASSED + rlLog "FAILED : $FAILED_CNT of $ALL_CNT" + cat FAILED + if [ $FAILED_CNT -eq 0 ]; then + rlPass "All testcases passed." + else + rlFail "There are some errors." + fi + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "tar c *.LOG *.bin PASSED FAILED | gzip > logs.tar.gz" + rlFileSubmit "logs.tar.gz" + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/Sanity/random-apps/say_linux.c b/tests/Sanity/random-apps/say_linux.c new file mode 100644 index 0000000..79f2d61 --- /dev/null +++ b/tests/Sanity/random-apps/say_linux.c @@ -0,0 +1,8 @@ +#include +#include + +int main() { + printf("Linux\n"); + exit(0); +} + diff --git a/tests/Sanity/random-apps/sleeping-c.c b/tests/Sanity/random-apps/sleeping-c.c new file mode 100644 index 0000000..4739a56 --- /dev/null +++ b/tests/Sanity/random-apps/sleeping-c.c @@ -0,0 +1,6 @@ +#include + +int main() +{ + sleep (15); +} diff --git a/tests/Sanity/random-apps/t_thread.c b/tests/Sanity/random-apps/t_thread.c new file mode 100644 index 0000000..e1f24c3 --- /dev/null +++ b/tests/Sanity/random-apps/t_thread.c @@ -0,0 +1,211 @@ +#include +#include +#include +#include +#include +#include +#include +#include +//#include "trigger_error.h" +#define THREAD_NUM 100 +#define MALLOC_LEN 1024*1024*10 +#define DEFAULT_NUM 0 +#define MAXSEM 5 + +int fd[10000]; +int fullid; +int emptyid; +int mutxid; + +void *thread_handle_a(void *temp); + +int main(int argc, char *argv[]) +{ + pthread_t tid_a; + int i; + int ai[THREAD_NUM]; + int ret_a = -1; + int file_num; + char filename[10]; + char str[20]; + struct sembuf P, V;; + union semun arg; + pid_t pid; + + int *array; + int *sum; + int *set; + int *get; + + if (DEFAULT_NUM == 0) { + file_num = 10; + } + +#ifdef STS_SLEEP + sleep(10); +#endif + + for (i = 0; i < file_num; i++) { + sprintf(filename, "%d", i); + printf("open fd%d\n", i); + fd[i] = open(filename, O_RDONLY); + if (fd[i] < 0) + continue; + + if (read(fd[i], str, sizeof(str)) < 0) { + close(fd[i]); + fd[i] = -1; + continue; + } + printf("%s", str); + } + + for (i = 0; i < file_num; i++) { + if (fd[i] >= 0) { + close(fd[i]); + } + } + + for (i = 0; i < file_num; i++) { + fd[0] = open("/dev/null", O_RDONLY); + if (fd[0] < 0) { + perror("open /dev/null"); + continue; + } + close(fd[0]); + } + + for (i = 0; i < file_num; i++) { + fd[0] = open("/proc/meminfo", O_RDONLY); + if (fd[0] < 0) { + perror("open /proc/meminfo"); + continue; + } + if (read(fd[0], str, sizeof(str)) < 0) { + close(fd[0]); + continue; + } + printf("%s\n", str); + close(fd[0]); + } + for (i = 0; i < file_num; i++) { + fd[0] = open("/proc/self/maps", O_RDONLY); + if (fd[0] < 0) { + perror("open /proc/meminfo"); + continue; + } + if (read(fd[0], str, sizeof(str)) < 0) { + close(fd[0]); + continue; + } + printf("%s\n", str); + close(fd[0]); + } + + array = + (int *)mmap(NULL, sizeof(int) * 5, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); + sum = + (int *)mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); + get = + (int *)mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); + set = + (int *)mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANONYMOUS, -1, 0); + *sum = 0; + *get = 0; + *set = 0; + + fullid = semget(IPC_PRIVATE, 1, IPC_CREAT | 00666); + emptyid = semget(IPC_PRIVATE, 1, IPC_CREAT | 00666); + mutxid = semget(IPC_PRIVATE, 1, IPC_CREAT | 00666); + + arg.val = 0; + if (semctl(fullid, 0, SETVAL, arg) == -1) + perror("semctl setval error"); + + arg.val = MAXSEM; + if (semctl(emptyid, 0, SETVAL, arg) == -1) + perror("semctl setval error"); + + arg.val = 1; + if (semctl(mutxid, 0, SETVAL, arg) == -1) + perror("setctl setval error"); + + V.sem_num = 0; + V.sem_op = 1; + V.sem_flg = SEM_UNDO; + P.sem_num = 0; + P.sem_op = -1; + P.sem_flg = SEM_UNDO; + + i = 0; + while (i < 5) { + + semop(emptyid, &P, 1); + semop(mutxid, &P, 1); + + array[*(set) % MAXSEM] = i + 1; + printf("Producer %d\n", array[(*set) % MAXSEM]); + (*set)++; + fflush(NULL); + semop(mutxid, &V, 1); + semop(fullid, &V, 1); + i++; + } + semctl(fullid, 0, IPC_RMID); + semctl(emptyid, 0, IPC_RMID); + semctl(mutxid, 0, IPC_RMID); + + if ((pid = fork()) == 0) { + for (i = 0; i < THREAD_NUM; i++) { + ai[i] = i; + ret_a = pthread_create(&tid_a, NULL, thread_handle_a, &ai[i]); + printf("thread a : \n"); + + if (ret_a == 0) { + pthread_detach(tid_a); + } + } + } else if (pid > 0) { + for (i = 0; i < THREAD_NUM; i++) { + ai[i] = i; + ret_a = pthread_create(&tid_a, NULL, thread_handle_a, &ai[i]); + printf("thread a : \n"); + + if (ret_a == 0) { + pthread_detach(tid_a); + } + } + } else { + printf("fork error\n"); + } + + fflush(NULL); + write(1, "BEFORE_ERROR\n", 13); + //trigger_error(); + raise(SIGFPE); + write(1, "EXIT_FLAG\n", 10); + return 10; +} + +void *thread_handle_a(void *t) +{ + long page_size = MALLOC_LEN; + int j = *(int *)t; + char *addr; + addr = (char *)malloc(page_size); + if (addr != NULL) { + sprintf(addr, "hello"); + printf("(a) malloc %d success: %s\n", j, addr); + } else { + printf("(a)malloc %d failed\n", j); + } + + printf("thread (a) will exit\n"); + fflush(NULL); + return NULL; +} + diff --git a/tests/Sanity/random-apps/test1.c b/tests/Sanity/random-apps/test1.c new file mode 100644 index 0000000..45a43af --- /dev/null +++ b/tests/Sanity/random-apps/test1.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int pfd[2]; + pid_t pid = -1; + int rc = 0; + char buf[BUFSIZ]; + sigset_t sig_mask; + + /* + * Mask of SIGTRAP + * Initialize of the value of sig_mask + */ + sigemptyset(&sig_mask); + + /* Set of SIGTRAP in sig_mask */ + sigaddset(&sig_mask, SIGTRAP); + + /* Set of SIGTRAP */ + sigprocmask(SIG_SETMASK, &sig_mask, NULL); + + rc = pipe(pfd); + if(rc == -1){ + perror("pipe Error\n"); + exit (1); + } + pid = fork(); + if (pid == -1){ + perror("Fork Error\n"); + exit (1); + } else if (pid == 0) { + close(pfd[0]); + close(1); + dup(pfd[1]); + close(pfd[1]); + execl("./test2.sh", (char *)0); + exit(0); + } else { + close(pfd[1]); + while((read(pfd[0], buf, sizeof(buf))) > 0) { + printf("%s", buf); + } + close(pfd[0]); + wait(NULL); + exit(0); + } +} diff --git a/tests/Sanity/random-apps/test_fork.c b/tests/Sanity/random-apps/test_fork.c new file mode 100644 index 0000000..7afd110 --- /dev/null +++ b/tests/Sanity/random-apps/test_fork.c @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_NUM 0 +#define THREAD_NUM 3 +#define MALLOC_LEN 1024*1024*10 + +void *thread_handle_a(void *t) +{ + long page_size = MALLOC_LEN; + int j = *(int *)t; + char *ptr; + char *addr; + + struct stat buf; + addr = (char *)malloc(page_size); + if (addr != NULL) { + sprintf(addr, "hello"); + printf("(a) malloc %d success: %s\n", j, addr); + } else { + printf("(a)malloc %d failed\n", j); + } + + + printf("thread (a) will exit\n"); + fflush(NULL); + if(addr != NULL) + free(addr); + return NULL; +} + +int main() +{ + int i = 0; + pid_t pid; + pthread_t tid_a; + int ai[THREAD_NUM]; + int ret_a = -1; + +#ifdef STS_SLEEP + sleep(10); +#endif + + if ((pid = fork()) == 0) { + for (i = 0; i < THREAD_NUM; i++) { + ai[i] = i; + ret_a = pthread_create(&tid_a, NULL, thread_handle_a, &ai[i]); + printf("thread a : \n"); + + if (ret_a == 0) { + pthread_detach(tid_a); + } + } + } else if (pid > 0) { + for (i = 0; i < THREAD_NUM; i++) { + ai[i] = i; + ret_a = pthread_create(&tid_a, NULL, thread_handle_a, &ai[i]); + printf("thread a : \n"); + + if (ret_a == 0) { + pthread_detach(tid_a); + } + } + + waitpid(pid, NULL, 0); + fflush(NULL); + write(1, "EXIT_FLAG\n", 10); + } else { + printf("fork error\n"); + } + return 0; +} diff --git a/tests/Sanity/random-apps/test_select.c b/tests/Sanity/random-apps/test_select.c new file mode 100644 index 0000000..f13df3b --- /dev/null +++ b/tests/Sanity/random-apps/test_select.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include + +#define MAXBUF 1024 +#define THREAD_NUM 100 +#define MALLOC_LEN 1024*1024*10 + +void *thread_handle_a(void *t) +{ + long page_size = MALLOC_LEN; + int j = *(int *)t; + char *addr; + addr = (char *)malloc(page_size); + if (addr != NULL) { + sprintf(addr, "hello"); + printf("(a) malloc %d success: %s\n", j, addr); + } else { + printf("(a)malloc %d failed\n", j); + } + + printf("thread (a) will exit\n"); + fflush(NULL); + return NULL; +} + +int main(int argc, char **argv) +{ + fd_set wfds; + struct timeval tv; + int retval, maxfd = -1; + pthread_t tid_a; + int i; + int ai[THREAD_NUM]; + int ret_a = -1; + + sleep(5); + + for (i = 0; i < THREAD_NUM; i++) { + ai[i] = i; + ret_a = pthread_create(&tid_a, NULL, thread_handle_a, &ai[i]); + printf("thread a : \n"); + + if (ret_a == 0) { + pthread_detach(tid_a); + } + } + + FD_ZERO(&wfds); + FD_SET(STDOUT_FILENO, &wfds); + maxfd = STDOUT_FILENO; + tv.tv_sec = 1; + tv.tv_usec = 0; + + retval = select(maxfd+1, NULL, &wfds, NULL, &tv); + if (retval == -1) { + fprintf(stderr, "select failed\n"); + } else if (retval == 0){ + printf("Time out\n"); + } else { + printf("stdout can be write\n"); + } + + printf("EXIT_FLAG\n"); + return 0; +} diff --git a/tests/Sanity/random-apps/thread-test2.c b/tests/Sanity/random-apps/thread-test2.c new file mode 100644 index 0000000..cce490c --- /dev/null +++ b/tests/Sanity/random-apps/thread-test2.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include + +#define THREAD_NUM 32 + +void *thread_function (void *); + +int main (int argc, char *argv[]) +{ + int i =0, x = 0; + int res = 0; + pthread_t a_thread[THREAD_NUM]; + void *thread_result; + + for (i = 0; i < THREAD_NUM; i++) { + res = pthread_create (&a_thread[i], NULL, thread_function, (void *)0); + if (res != 0) { + printf("Thread create failed\n"); + return (10); + } + } + raise(SIGABRT); + return (0); +} + +void *thread_function (void *arg) +{ + sleep(1); + printf("Thread TEST\n"); +} diff --git a/tests/Sanity/random-apps/vfork.c b/tests/Sanity/random-apps/vfork.c new file mode 100644 index 0000000..a34e09f --- /dev/null +++ b/tests/Sanity/random-apps/vfork.c @@ -0,0 +1,15 @@ +#define _GNU_SOURCE +#include +#include + +int main (void) +{ + pid_t child = vfork (); + + /* PRINTF/SLEEP violate the VFORK operations restriction. */ + printf ("%d pid=%d\n", (int) child, (int) getpid ()); + sleep (1); + if (!child) + execlp ("/bin/true", "/bin/true", NULL); + return 0; +}