add strace test cases and test result

This commit is contained in:
Tomoki Shirasawa
2017-11-25 17:37:10 +09:00
parent 5cc738d6bd
commit 3b6056fb1a
7 changed files with 174 additions and 1 deletions

View File

@ -27,7 +27,6 @@
../../../../mic/mcexec ./946
#946 start
#946-1 exit after wait OK
#946-1 exit after wait OK
#946-2 exit before wait OK
#946 terminated ok=2 ng=0
../../../../mic/mcexec ./960

View File

@ -0,0 +1,11 @@
*** test1 start
test1-1 gettid OK
test1-2 syscal_9999 OK
*** test1 end ok=2 ng=0
*** test2 start
test2-1 execve OK
test2-2 fork OK
test2-3 execve OK
test2-4 SIGCHLD OK
test2-5 wait OK
*** test2 end ok=5 ng=0

4
test/strace/strace/test.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
export MCEXEC=../../../../mic/mcexec
./test1.sh
./test2.sh

View File

@ -0,0 +1,20 @@
#define __BSD_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/user.h>
#include <sys/syscall.h>
#include <fcntl.h>
#include <errno.h>
int
main(int argc, char **argv)
{
syscall(SYS_gettid);
open("/", O_WRONLY);
syscall(9999);
exit(15);
}

46
test/strace/strace/test1.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
if [ ! -f test1 ]; then
gcc -o test1 test1.c
fi
rm -f check.log
$MCEXEC strace -o check.log ./test1
awk 'BEGIN{ng=0; ok=0; print "*** test1 start"}
/^gettid/{
if ($0 ~/errno/) {
print "test1-1 gettid NG"
ng++
}
else {
print "test1-1 gettid OK"
ok++
}
test1=1
}
/^syscall_9999/{
if ($0 ~/errno 38/) {
print "test1-2 syscal_9999 OK"
ok++
}
else {
print "test1-2 syscall_9999 NG"
ng++
}
test2=1
}
END {
if (test1 != 1) {
print "test1-1 gettid NG"
ng++
}
if (test2 != 1) {
print "test1-2 syscall_9999 NG"
ng++
}
printf("*** test1 end ok=%d ng=%d\n", ok, ng)
exit(ng)
}' check.log
rm -f check.log test1

View File

@ -0,0 +1,33 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
int
main(int argc, char **argv)
{
pid_t pid;
int rc;
int st;
if (argv[1] && !strcmp(argv[1], "exec")) {
exit(1);
}
pid = fork();
if (pid == 0) {
sleep(1);
execl("test2", "test2", "exec", NULL);
exit(99);
}
sleep(2);
rc = wait(&st);
if (rc != pid) {
printf("test2 NG\n");
exit(1);
}
exit(0);
}

60
test/strace/strace/test2.sh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/sh
if [ ! -f test2 ]; then
gcc -o test2 test2.c
fi
rm -f check.log
$MCEXEC strace -e trace=process -f -o check.log ./test2
awk 'BEGIN{st=0;ng=0; ok=0; print "*** test2 start"}
/execve/{
st++
if ($0 ~/ = 0$/) {
print "test2-" st " execve OK"
ok++
}
else {
print "test2-" st " execve NG"
ng++
}
}
/clone/{
st++
if ($0 ~/ = [1-9][0-9]*$/) {
print "test2-" st " fork OK"
ok++
}
else {
print "test2-" st " fork NG"
ng++
}
}
/wait4/{
st++
if ($0 ~/ = [1-9][0-9]*$/) {
print "test2-" st " wait OK"
ok++
}
else {
print "test2-" st " wait NG"
ng++
}
}
/SIGCHLD {/{
st++
print "test2-" st " SIGCHLD OK"
ok++
sigchld = 1
}
END {
if (sigchld != 1) {
st++
print "test2-" st " SIGCHLD NG"
ng++
}
printf("*** test2 end ok=%d ng=%d\n", ok, ng)
exit(ng)
}' check.log
rm -f check.log test2