diff options
Diffstat (limited to 'testsuite/ltrace.main/system_calls.exp')
-rw-r--r-- | testsuite/ltrace.main/system_calls.exp | 191 |
1 files changed, 135 insertions, 56 deletions
diff --git a/testsuite/ltrace.main/system_calls.exp b/testsuite/ltrace.main/system_calls.exp index 259ae25..1b64cb0 100644 --- a/testsuite/ltrace.main/system_calls.exp +++ b/testsuite/ltrace.main/system_calls.exp @@ -1,67 +1,146 @@ -# This file was written by Yao Qi <qiyao@cn.ibm.com>. +# This file is part of ltrace. +# Copyright (C) 2014 Petr Machata, Red Hat Inc. +# Copyright (C) 2006 Yao Qi <qiyao@cn.ibm.com>, IBM Corporation +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# 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 St, Fifth Floor, Boston, MA +# 02110-1301 USA -set testfile "system_calls" -set srcfile ${testfile}.c -set binfile ${testfile} +# Objectives: Verify that Ltrace can trace all the system calls in +# execution. Note that this test is necessarily noisy. Dynamic +# linker adds a bunch of system calls of its own. +set empty [ltraceCompile {} [ltraceSource c { + int main (void) { return 0; } +}]] -verbose "compiling source file now....." -# Build the shared libraries this test case needs. -if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${objdir}/${subdir}/${binfile}" executable {debug} ] != "" } { - send_user "Testcase compile failed, so all tests in this file will automatically fail.\n" +set bin [ltraceCompile {} [ltraceSource c { + #include <stdio.h> + #include <unistd.h> + #include <sys/syscall.h> + #include <sys/stat.h> + #include <errno.h> + #include <stdlib.h> + + int + main () + { + FILE* fp; + char s[]="system_calls"; + char buffer[1024]; + struct stat state; + + fp = fopen ("system_calls.tmp", "w"); + if (fp == NULL) + { + printf("Can not create system_calls.tmp\n"); + exit (0); + } + fwrite(s, sizeof(s), 1, fp); + fseek (fp, 0, SEEK_CUR); + fread(buffer, sizeof(s), 1, fp); + fclose(fp); + + getcwd (buffer, sizeof buffer); + chdir ("."); + symlink ("system_calls.tmp", "system_calls.link"); + remove("system_calls.link"); + rename ("system_calls.tmp", "system_calls.tmp1"); + stat ("system_calls.tmp", &state); + access ("system_calls.tmp", R_OK); + remove("system_calls.tmp1"); + + mkdir ("system_call_mkdir", 0777); + rmdir ("system_call_mkdir"); + + return 0; + } +}]] + +proc Calls {logfile} { + set fp [open $logfile] + set ret {} + + while {[gets $fp line] >= 0} { + if [regexp -- {^[a-zA-Z0-9]*@SYS} $line] { + set call [lindex [split $line @] 0] + dict incr ret $call + } + } + + close $fp + return $ret +} + +proc GetDefault {d key def} { + if {[dict exists $d $key]} { + return [dict get $d $key] + } else { + return $def + } } -# set options for ltrace. -ltrace_options "-S" +proc Diff {d1 d2} { + set keys [lsort -unique [concat [dict keys $d1] [dict keys $d2]]] + set ret {} + foreach key $keys { + set n1 [GetDefault $d1 $key 0] + set n2 [GetDefault $d2 $key 0] + set sum [expr $n1 - $n2] + if {[expr $sum != 0]} { + dict set ret $key $sum + } + } + return $ret +} + +proc Match {d patterns} { + foreach line $patterns { + set pattern [lindex $line 0] + set op [lindex $line 1] + set expect [lindex $line 2] -#Run PUT for ltarce. -set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile] + set count 0 + foreach key [dict keys $d] { + if [regexp -- $pattern $key] { + incr count [dict get $d $key] + } + } -#check the output of this program. -verbose "ltrace runtest output: $exec_output\n" + set msgMain "$pattern was recorded $count times" -if [regexp {ELF from incompatible architecture} $exec_output] { - fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!" - return -} elseif [ regexp {Couldn't get .hash data} $exec_output ] { - fail "Couldn't get .hash data!" - return + if {[eval expr $count $op $expect]} { + pass $msgMain + } else { + fail "$msgMain, expected $op $expect" + } + } } +Match [Diff [Calls [ltraceRun -L -S -- $bin]] \ + [Calls [ltraceRun -L -S -- $empty]]] { + { {^write$} == 1 } + { {^unlink(at)?$} >= 2 } + { {^open(at)?$} == 1 } + { {^(new|f)?stat(64)?$} >= 1 } + { {^close$} == 1 } + { {^getcwd$} == 1 } + { {^chdir$} == 1 } + { {^symlink(at)?$} == 1 } + { {^f?access(at)?$} == 1 } + { {^rename(at)?$} == 1 } + { {^mkdir(at)?$} == 1 } +} -set pattern "SYS_munmap" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 2 -set pattern "SYS_write" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_unlink" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 - -set pattern "SYS_brk" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_open" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_(new)?fstat" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 egrep -set pattern "SYS_(old_)?mmap" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 egrep -set pattern "SYS_close" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 - -set pattern "SYS_getcwd" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_chdir" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_symlink" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_unlink" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_(new)?stat" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 egrep -set pattern "SYS_access" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_rename" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_mkdir" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 -set pattern "SYS_rmdir" -ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 +ltraceDone |