Import RHEL's test Sanity/random-apps

Note than several sub-tests (apps) had to be removed as unsuitable
for publishing.
This commit is contained in:
Václav Kadlčík 2021-07-09 16:24:48 +02:00 committed by codonell
parent c8ea90148a
commit 0554fda54f
18 changed files with 783 additions and 0 deletions

View File

@ -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 <mnowak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# 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 <mnowak@redhat.com>" > $(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)

View File

@ -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 <mnowak@redhat.com>

View File

@ -0,0 +1,6 @@
#include <stdlib.h>
int main() {
abort();
}

View File

@ -0,0 +1,14 @@
summary: Runs random app which caused strace problems in the past
description: ''
contact: Michal Nowak <mnowak@redhat.com>
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

View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <stdlib.h>
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;
}

View File

@ -0,0 +1,43 @@
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#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();
}

View File

@ -0,0 +1,14 @@
#include <pthread.h>
void *start (void *arg) {
return arg;
}
pthread_t thread1;
int main () {
pthread_create (&thread1, NULL, start, NULL);
sleep (1);
return 0;
}

View File

@ -0,0 +1,15 @@
#include <stddef.h>
#include <signal.h>
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;
}

View File

@ -0,0 +1,14 @@
#include <pthread.h>
void *start (void *arg) {
return arg;
}
pthread_t thread1;
int main () {
pthread_create (&thread1, NULL, start, NULL);
sleep (1);
return 0;
}

View File

@ -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 <mnowak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# 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

View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Linux\n");
exit(0);
}

View File

@ -0,0 +1,6 @@
#include <unistd.h>
int main()
{
sleep (15);
}

View File

@ -0,0 +1,211 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/sem.h>
#include <sys/mman.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//#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;
}

View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
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);
}
}

View File

@ -0,0 +1,78 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/wait.h>
#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;
}

View File

@ -0,0 +1,70 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#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;
}

View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <signal.h>
#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");
}

View File

@ -0,0 +1,15 @@
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
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;
}