From d273a2f58b753c61d7b0f23a18821b46d2d7ec12 Mon Sep 17 00:00:00 2001 From: Tomoki Shirasawa Date: Wed, 22 Nov 2017 10:52:30 +0900 Subject: [PATCH] add strace bundled test cases --- arch/x86_64/kernel/cpu.c | 4 +- kernel/syscall.c | 2 + test/strace/strace-bundle/init.sh | 30 +++ test/strace/strace-bundle/ptrace_setoptions | 28 +++ test/strace/strace-bundle/qual_syscall | 27 +++ test/strace/strace-bundle/stat | 37 ++++ test/strace/strace-bundle/strace-f | 13 ++ test/strace/strace-bundle/test-result.txt | 216 ++++++++++++++++++++ 8 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 test/strace/strace-bundle/init.sh create mode 100755 test/strace/strace-bundle/ptrace_setoptions create mode 100755 test/strace/strace-bundle/qual_syscall create mode 100755 test/strace/strace-bundle/stat create mode 100755 test/strace/strace-bundle/strace-f create mode 100644 test/strace/strace-bundle/test-result.txt diff --git a/arch/x86_64/kernel/cpu.c b/arch/x86_64/kernel/cpu.c index 6d9e831c..5bcad024 100644 --- a/arch/x86_64/kernel/cpu.c +++ b/arch/x86_64/kernel/cpu.c @@ -1018,7 +1018,7 @@ void gpe_handler(struct x86_user_context *regs) check_need_resched(); } set_cputime(0); - // panic("GPF"); + panic("GPF"); } void debug_handler(struct x86_user_context *regs) @@ -1582,6 +1582,8 @@ void arch_show_interrupt_context(const void *reg) __kprintf("%16lx %16lx %16lx %16lx\n", regs->cs, regs->ss, regs->rflags, regs->error); +kprintf_unlock(irqflags); +return; arch_show_extended_context(); arch_print_pre_interrupt_stack(regs); diff --git a/kernel/syscall.c b/kernel/syscall.c index 79d6021b..51ec6cbe 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -9340,6 +9340,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx) #endif // DISABLE_SCHED_YIELD set_cputime(1); +//kprintf("syscall=%d\n", num); #ifdef PROFILE_ENABLE if (thread->profile && thread->profile_start_ts) { unsigned long ts = rdtsc(); @@ -9473,6 +9474,7 @@ long syscall(int num, ihk_mc_user_context_t *ctx) if (thread->proc->nohost) { // mcexec termination was detected terminate(0, SIGKILL); } +//kprintf("syscall=%d returns %lx(%ld)\n", num, l, l); return l; } diff --git a/test/strace/strace-bundle/init.sh b/test/strace/strace-bundle/init.sh new file mode 100644 index 00000000..9017cc75 --- /dev/null +++ b/test/strace/strace-bundle/init.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +ME_="${0##*/}" + +warn_() { printf >&2 '%s\n' "$*"; } +fail_() { warn_ "$ME_: failed test: $*"; exit 1; } +skip_() { warn_ "$ME_: skipped test: $*"; exit 77; } +framework_failure_() { warn_ "$ME_: framework failure: $*"; exit 99; } +framework_skip_() { warn_ "$ME_: framework skip: $*"; exit 77; } + +check_prog() +{ + type "$@" > /dev/null 2>&1 || + framework_skip_ "$* is not available" +} + +check_strace() +{ + STRACE=${*:-strace} + $STRACE -V > /dev/null || + framework_failure_ "$STRACE is not available" +} + +timeout_duration=60 +check_timeout() +{ + TIMEOUT="timeout -s 9 $timeout_duration" + $TIMEOUT true > /dev/null 2>&1 || + TIMEOUT= +} diff --git a/test/strace/strace-bundle/ptrace_setoptions b/test/strace/strace-bundle/ptrace_setoptions new file mode 100755 index 00000000..cf51deac --- /dev/null +++ b/test/strace/strace-bundle/ptrace_setoptions @@ -0,0 +1,28 @@ +#!/bin/sh + +# Ensure that strace tests kernel PTRACE_O_TRACECLONE +# and PTRACE_O_TRACESYSGOOD support properly. + +. "${srcdir=.}/init.sh" + +[ "$(uname -s)" = Linux ] || + skip_ 'The kernel is not a Linux kernel' +case "$(uname -r)" in + 2.[6-9]*|2.[1-5][0-9]*|[3-9].*|[12][0-9]*) ;; + *) skip_ 'The kernel is not Linux 2.6.* or newer' ;; +esac + +check_strace +check_timeout + +$TIMEOUT $MCEXEC $STRACE -df -enone / 2>&1 | + grep -F -x 'ptrace_setoptions = 0xe' > /dev/null || + fail_ 'strace -f failed to recognize proper kernel PTRACE_O_TRACECLONE support' + +$TIMEOUT $MCEXEC $STRACE -df -enone / 2>&1 | + grep -F -x 'ptrace_setoptions = 0x1f' > /dev/null || + fail_ 'strace -f failed to recognize proper kernel PTRACE_O_TRACESYSGOOD support' + +$TIMEOUT $MCEXEC $STRACE -d -enone / 2>&1 | + grep -F -x 'ptrace_setoptions = 0x11' > /dev/null || + fail_ 'strace failed to recognize proper kernel PTRACE_O_TRACESYSGOOD support' diff --git a/test/strace/strace-bundle/qual_syscall b/test/strace/strace-bundle/qual_syscall new file mode 100755 index 00000000..6f93fee7 --- /dev/null +++ b/test/strace/strace-bundle/qual_syscall @@ -0,0 +1,27 @@ +#!/bin/sh + +# Ensure that strace -e trace=set works. + +. "${srcdir=.}/init.sh" + +check_strace +check_timeout +check_prog ls +check_prog grep + +$TIMEOUT $MCEXEC $STRACE -e execve ls > /dev/null 2> check.log && +grep '^execve(' check.log > /dev/null || + { cat check.log; fail_ 'strace -e execve does not work'; } + +grep -v '^execve(' check.log | +LC_ALL=C grep '^[[:alnum:]_]*(' > /dev/null && + { cat check.log; fail_ 'strace -e execve does not work properly'; } + +$TIMEOUT $MCEXEC $STRACE -e trace=process ls > /dev/null 2> check.log && +grep '^execve(' check.log > /dev/null || + { cat check.log; fail_ 'strace -e trace=process does not work'; } + +grep '^open' check.log > /dev/null && + { cat check.log; fail_ 'strace -e trace=process does not work properly'; } + +exit 0 diff --git a/test/strace/strace-bundle/stat b/test/strace/strace-bundle/stat new file mode 100755 index 00000000..34bec48a --- /dev/null +++ b/test/strace/strace-bundle/stat @@ -0,0 +1,37 @@ +#!/bin/sh + +# Check how ftruncate, lseek and stat family syscalls are traced. + +. "${srcdir=.}/init.sh" + +check_strace +check_timeout +check_prog dd +check_prog find +check_prog grep +check_prog rm + +umask 022 +truncate_cmd='dd seek=46118400000 obs=1 count=0 if=/dev/null of=sample' +$truncate_cmd > check.log 2>&1 || + { cat check.log; framework_skip_ 'failed to create a large sparse file'; } +rm -f sample + +$TIMEOUT $MCEXEC $STRACE -edesc $truncate_cmd 2>&1 > /dev/null 2> check.log && +LC_ALL=C grep -E -x 'ftruncate(64)?\(1, 46118400000\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -edesc failed to trace ftruncate/ftruncate64 properly'; } + +LC_ALL=C grep -E -x 'lseek\(1, 46118400000, SEEK_CUR\) += 46118400000|_llseek\(1, 46118400000, \[46118400000\], SEEK_CUR\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -edesc failed to trace lseek/_llseek properly'; } + +$TIMEOUT $MCEXEC $STRACE -efile find -L sample > /dev/null 2> check.log && +LC_ALL=C grep -E -x 'stat(64)?\("sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}\) += 0|(new)?fstatat(64)?\(AT_FDCWD, "sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}, 0\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -efile failed to trace stat/stat64 properly'; } + +$TIMEOUT $MCEXEC $STRACE -efile find sample > /dev/null 2> check.log && +LC_ALL=C grep -E -x 'lstat(64)?\("sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}\) += 0|(new)?fstatat(64)?\(AT_FDCWD, "sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}, AT_SYMLINK_NOFOLLOW\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -efile failed to trace fstatat/fstatat64 properly'; } + +rm -f sample + +exit 0 diff --git a/test/strace/strace-bundle/strace-f b/test/strace/strace-bundle/strace-f new file mode 100755 index 00000000..cc6a7dda --- /dev/null +++ b/test/strace/strace-bundle/strace-f @@ -0,0 +1,13 @@ +#!/bin/sh + +# Ensure that strace -f works. + +. "${srcdir=.}/init.sh" + +check_strace +check_timeout +time=/usr/bin/time +check_prog $time + +$TIMEOUT $MCEXEC $STRACE -f $time /bin/ls > check.log 2>&1 || + { cat check.log; fail_ 'strace -f does not work'; } diff --git a/test/strace/strace-bundle/test-result.txt b/test/strace/strace-bundle/test-result.txt new file mode 100644 index 00000000..d6a4dbbf --- /dev/null +++ b/test/strace/strace-bundle/test-result.txt @@ -0,0 +1,216 @@ +スクリプトは Mon Nov 20 13:34:02 2017 + に開始しました[?1034hbash-4.2$ export MCEXEC=$HOME/wallaby11-smp-x86/development/mic/mcexec +bash-4.2$ cat ptrace_setoptions +#!/bin/sh + +# Ensure that strace tests kernel PTRACE_O_TRACECLONE +# and PTRACE_O_TRACESYSGOOD support properly. + +. "${srcdir=.}/init.sh" + +[ "$(uname -s)" = Linux ] || + skip_ 'The kernel is not a Linux kernel' +case "$(uname -r)" in + 2.[6-9]*|2.[1-5][0-9]*|[3-9].*|[12][0-9]*) ;; + *) skip_ 'The kernel is not Linux 2.6.* or newer' ;; +esac + +check_strace +check_timeout + +$TIMEOUT $MCEXEC $STRACE -df -enone / 2>&1 | + grep -F -x 'ptrace_setoptions = 0xe' > /dev/null || + fail_ 'strace -f failed to recognize proper kernel PTRACE_O_TRACECLONE support' + +$TIMEOUT $MCEXEC $STRACE -df -enone / 2>&1 | + grep -F -x 'ptrace_setoptions = 0x1f' > /dev/null || + fail_ 'strace -f failed to recognize proper kernel PTRACE_O_TRACESYSGOOD support' + +$TIMEOUT $MCEXEC $STRACE -d -enone / 2>&1 | + grep -F -x 'ptrace_setoptions = 0x11' > /dev/null || + fail_ 'strace failed to recognize proper kernel PTRACE_O_TRACESYSGOOD support' +bash-4.2$ sh -x ptrace_setoptions ++ . ./init.sh +++ ME_=ptrace_setoptions +++ timeout_duration=60 +++ uname -s ++ '[' Linux = Linux ']' ++ case "$(uname -r)" in +++ uname -r ++ check_strace ++ STRACE=../strace ++ ../strace -V ++ check_timeout ++ TIMEOUT='timeout -s 9 60' ++ timeout -s 9 60 true ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -df -enone / ++ grep -F -x 'ptrace_setoptions = 0xe' ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -df -enone / ++ grep -F -x 'ptrace_setoptions = 0x1f' ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -d -enone / ++ grep -F -x 'ptrace_setoptions = 0x11' +bash-4.2$ echo $? +0 +bash-4.2$ cat strace-f +#!/bin/sh + +# Ensure that strace -f works. + +. "${srcdir=.}/init.sh" + +check_strace +check_timeout +time=/usr/bin/time +check_prog $time + +$TIMEOUT $MCEXEC $STRACE -f $time /bin/ls > check.log 2>&1 || + { cat check.log; fail_ 'strace -f does not work'; } +bash-4.2$ sh -x strace-f ++ . ./init.sh +++ ME_=strace-f +++ timeout_duration=60 ++ check_strace ++ STRACE=../strace ++ ../strace -V ++ check_timeout ++ TIMEOUT='timeout -s 9 60' ++ timeout -s 9 60 true ++ time=/usr/bin/time ++ check_prog /usr/bin/time ++ type /usr/bin/time ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -f /usr/bin/time /bin/ls +bash-4.2$ echo ?$? +0 +bash-4.2$ cat qual_syscall +#!/bin/sh + +# Ensure that strace -e trace=set works. + +. "${srcdir=.}/init.sh" + +check_strace +check_timeout +check_prog ls +check_prog grep + +$TIMEOUT $MCEXEC $STRACE -e execve ls > /dev/null 2> check.log && +grep '^execve(' check.log > /dev/null || + { cat check.log; fail_ 'strace -e execve does not work'; } + +grep -v '^execve(' check.log | +LC_ALL=C grep '^[[:alnum:]_]*(' > /dev/null && + { cat check.log; fail_ 'strace -e execve does not work properly'; } + +$TIMEOUT $MCEXEC $STRACE -e trace=process ls > /dev/null 2> check.log && +grep '^execve(' check.log > /dev/null || + { cat check.log; fail_ 'strace -e trace=process does not work'; } + +grep '^open' check.log > /dev/null && + { cat check.log; fail_ 'strace -e trace=process does not work properly'; } + +exit 0 +bash-4.2$ sh -x qual_syscall ++ . ./init.sh +++ ME_=qual_syscall +++ timeout_duration=60 ++ check_strace ++ STRACE=../strace ++ ../strace -V ++ check_timeout ++ TIMEOUT='timeout -s 9 60' ++ timeout -s 9 60 true ++ check_prog ls ++ type ls ++ check_prog grep ++ type grep ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -e execve ls ++ grep '^execve(' check.log ++ grep -v '^execve(' check.log ++ LC_ALL=C ++ grep '^[[:alnum:]_]*(' ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -e trace=process ls ++ grep '^execve(' check.log ++ grep '^open' check.log ++ exit 0 +bash-4.2$ echo $? +0 +bash-4.2$ cat stat +#!/bin/sh + +# Check how ftruncate, lseek and stat family syscalls are traced. + +. "${srcdir=.}/init.sh" + +check_strace +check_timeout +check_prog dd +check_prog find +check_prog grep +check_prog rm + +umask 022 +truncate_cmd='dd seek=46118400000 obs=1 count=0 if=/dev/null of=sample' +$truncate_cmd > check.log 2>&1 || + { cat check.log; framework_skip_ 'failed to create a large sparse file'; } +rm -f sample + +$TIMEOUT $MCEXEC $STRACE -edesc $truncate_cmd 2>&1 > /dev/null 2> check.log && +LC_ALL=C grep -E -x 'ftruncate(64)?\(1, 46118400000\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -edesc failed to trace ftruncate/ftruncate64 properly'; } + +LC_ALL=C grep -E -x 'lseek\(1, 46118400000, SEEK_CUR\) += 46118400000|_llseek\(1, 46118400000, \[46118400000\], SEEK_CUR\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -edesc failed to trace lseek/_llseek properly'; } + +$TIMEOUT $MCEXEC $STRACE -efile find -L sample > /dev/null 2> check.log && +LC_ALL=C grep -E -x 'stat(64)?\("sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}\) += 0|(new)?fstatat(64)?\(AT_FDCWD, "sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}, 0\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -efile failed to trace stat/stat64 properly'; } + +$TIMEOUT $MCEXEC $STRACE -efile find sample > /dev/null 2> check.log && +LC_ALL=C grep -E -x 'lstat(64)?\("sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}\) += 0|(new)?fstatat(64)?\(AT_FDCWD, "sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}, AT_SYMLINK_NOFOLLOW\) += 0' check.log > /dev/null || + { cat check.log; fail_ 'strace -efile failed to trace fstatat/fstatat64 properly'; } + +rm -f sample + +exit 0 +bash-4.2$ sh -x stat ++ . ./init.sh +++ ME_=stat +++ timeout_duration=60 ++ check_strace ++ STRACE=../strace ++ ../strace -V ++ check_timeout ++ TIMEOUT='timeout -s 9 60' ++ timeout -s 9 60 true ++ check_prog dd ++ type dd ++ check_prog find ++ type find ++ check_prog grep ++ type grep ++ check_prog rm ++ type rm ++ umask 022 ++ truncate_cmd='dd seek=46118400000 obs=1 count=0 if=/dev/null of=sample' ++ dd seek=46118400000 obs=1 count=0 if=/dev/null of=sample ++ rm -f sample ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -edesc dd seek=46118400000 obs=1 count=0 if=/dev/null of=sample ++ LC_ALL=C ++ grep -E -x 'ftruncate(64)?\(1, 46118400000\) += 0' check.log ++ LC_ALL=C ++ grep -E -x 'lseek\(1, 46118400000, SEEK_CUR\) += 46118400000|_llseek\(1, 46118400000, \[46118400000\], SEEK_CUR\) += 0' check.log ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -efile find -L sample ++ LC_ALL=C ++ grep -E -x 'stat(64)?\("sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}\) += 0|(new)?fstatat(64)?\(AT_FDCWD, "sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}, 0\) += 0' check.log ++ timeout -s 9 60 /home/shirasawa/wallaby11-smp-x86/development/mic/mcexec ../strace -efile find sample ++ LC_ALL=C ++ grep -E -x 'lstat(64)?\("sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}\) += 0|(new)?fstatat(64)?\(AT_FDCWD, "sample", \{st_mode=S_IFREG\|0644, st_size=46118400000, \.\.\.\}, AT_SYMLINK_NOFOLLOW\) += 0' check.log ++ rm -f sample ++ exit 0 +bash-4.2$ echo $? +0 +bash-4.2$ シェルから脱出するには "exit" を使用してください。 +bash-4.2$ exit + +スクリプトは Mon Nov 20 13:36:26 2017 + に終了しました \ No newline at end of file