|
|
5cd83f |
diff -Nrup a/testsuite/ltrace.main/system_call_params.exp b/testsuite/ltrace.main/system_call_params.exp
|
|
|
5cd83f |
--- a/testsuite/ltrace.main/system_call_params.exp 2013-10-24 06:02:24.000000000 -0600
|
|
|
5cd83f |
+++ b/testsuite/ltrace.main/system_call_params.exp 2015-06-01 12:13:04.639847059 -0600
|
|
|
5cd83f |
@@ -1,5 +1,5 @@
|
|
|
5cd83f |
# This file is part of ltrace.
|
|
|
5cd83f |
-# Copyright (C) 2013 Petr Machata, Red Hat Inc.
|
|
|
5cd83f |
+# Copyright (C) 2013, 2014, 2015 Petr Machata, Red Hat Inc.
|
|
|
5cd83f |
#
|
|
|
5cd83f |
# This program is free software; you can redistribute it and/or
|
|
|
5cd83f |
# modify it under the terms of the GNU General Public License as
|
|
|
5cd83f |
@@ -17,13 +17,31 @@
|
|
|
5cd83f |
# 02110-1301 USA
|
|
|
5cd83f |
|
|
|
5cd83f |
set bin [ltraceCompile {} [ltraceSource c {
|
|
|
5cd83f |
+ #ifndef _GNU_SOURCE
|
|
|
5cd83f |
+ #define _GNU_SOURCE
|
|
|
5cd83f |
+ #endif
|
|
|
5cd83f |
#include <sys/types.h>
|
|
|
5cd83f |
#include <sys/stat.h>
|
|
|
5cd83f |
#include <fcntl.h>
|
|
|
5cd83f |
+ #include <unistd.h>
|
|
|
5cd83f |
+ #include <sys/syscall.h> /* For SYS_xxx definitions */
|
|
|
5cd83f |
+ #include <sys/mount.h>
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ #ifndef SYS_open
|
|
|
5cd83f |
+ # if defined(__aarch64__)
|
|
|
5cd83f |
+ # /* Linux doesn't actually implement SYS_open on AArch64, but for merely
|
|
|
5cd83f |
+ # * recording the syscall, it's fine. */
|
|
|
5cd83f |
+ # define SYS_open 1024
|
|
|
5cd83f |
+ # else
|
|
|
5cd83f |
+ # error SYS_open not available.
|
|
|
5cd83f |
+ # endif
|
|
|
5cd83f |
+ #endif
|
|
|
5cd83f |
+
|
|
|
5cd83f |
int main(void) {
|
|
|
5cd83f |
- open("/some/path", O_RDONLY);
|
|
|
5cd83f |
+ syscall(SYS_open, "/some/path", O_RDONLY);
|
|
|
5cd83f |
write(1, "something", 10);
|
|
|
5cd83f |
mount("source", "target", "filesystemtype", 0, 0);
|
|
|
5cd83f |
+ return 0;
|
|
|
5cd83f |
}
|
|
|
5cd83f |
}]]
|
|
|
5cd83f |
|
|
|
5cd83f |
@@ -42,8 +60,33 @@ set conf [ltraceNamedSource "$dir/syscal
|
|
|
5cd83f |
# somelib.conf is passed, and syscalls.conf is not available, or
|
|
|
5cd83f |
# doesn't list readdir, that would be taken from somelib.conf with a
|
|
|
5cd83f |
# wrong prototype.
|
|
|
5cd83f |
+#
|
|
|
5cd83f |
+# This test relies on the fact that there is no global config file
|
|
|
5cd83f |
+# that would provide legitimate system call prototype. But that
|
|
|
5cd83f |
+# doesn't have to be true, maybe ltrace is already installed on the
|
|
|
5cd83f |
+# system with the right prefix. So first compile a wrapper that we
|
|
|
5cd83f |
+# use to redirect fopen calls.
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+set libfopen_so [ltraceCompile libfopen.so -ldl [ltraceSource c {
|
|
|
5cd83f |
+ #define _GNU_SOURCE
|
|
|
5cd83f |
+ #include <dlfcn.h>
|
|
|
5cd83f |
+ #include <stdio.h>
|
|
|
5cd83f |
+ #include <string.h>
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ FILE *
|
|
|
5cd83f |
+ fopen(const char *path, const char *mode)
|
|
|
5cd83f |
+ {
|
|
|
5cd83f |
+ if (strncmp(path, "/usr/share", 10) == 0)
|
|
|
5cd83f |
+ path = "/dev/null";
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ return ((FILE *(*)(const char *, const char *))
|
|
|
5cd83f |
+ dlsym(RTLD_NEXT, "fopen")) (path, mode);
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+}]]
|
|
|
5cd83f |
|
|
|
5cd83f |
+setenv LD_PRELOAD $libfopen_so
|
|
|
5cd83f |
ltraceMatch1 [ltraceRun -L -S -F $conf -- $bin] {^open@SYS\("/some/path"} == 0
|
|
|
5cd83f |
+unsetenv LD_PRELOAD
|
|
|
5cd83f |
|
|
|
5cd83f |
# On the other hand, if -F somedir/ is given, we want to accept
|
|
|
5cd83f |
# syscalls.conf found there.
|
|
|
5cd83f |
diff -Nrup a/testsuite/ltrace.main/system_calls.exp b/testsuite/ltrace.main/system_calls.exp
|
|
|
5cd83f |
--- a/testsuite/ltrace.main/system_calls.exp 2013-10-24 06:02:24.000000000 -0600
|
|
|
5cd83f |
+++ b/testsuite/ltrace.main/system_calls.exp 2015-06-01 12:09:11.132944455 -0600
|
|
|
5cd83f |
@@ -1,67 +1,146 @@
|
|
|
5cd83f |
-# This file was written by Yao Qi <qiyao@cn.ibm.com>.
|
|
|
5cd83f |
+# This file is part of ltrace.
|
|
|
5cd83f |
+# Copyright (C) 2014 Petr Machata, Red Hat Inc.
|
|
|
5cd83f |
+# Copyright (C) 2006 Yao Qi <qiyao@cn.ibm.com>, IBM Corporation
|
|
|
5cd83f |
+#
|
|
|
5cd83f |
+# This program is free software; you can redistribute it and/or
|
|
|
5cd83f |
+# modify it under the terms of the GNU General Public License as
|
|
|
5cd83f |
+# published by the Free Software Foundation; either version 2 of the
|
|
|
5cd83f |
+# License, or (at your option) any later version.
|
|
|
5cd83f |
+#
|
|
|
5cd83f |
+# This program is distributed in the hope that it will be useful, but
|
|
|
5cd83f |
+# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
5cd83f |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
5cd83f |
+# General Public License for more details.
|
|
|
5cd83f |
+#
|
|
|
5cd83f |
+# You should have received a copy of the GNU General Public License
|
|
|
5cd83f |
+# along with this program; if not, write to the Free Software
|
|
|
5cd83f |
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
5cd83f |
+# 02110-1301 USA
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+# Objectives: Verify that Ltrace can trace all the system calls in
|
|
|
5cd83f |
+# execution. Note that this test is necessarily noisy. Dynamic
|
|
|
5cd83f |
+# linker adds a bunch of system calls of its own.
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+set empty [ltraceCompile {} [ltraceSource c {
|
|
|
5cd83f |
+ int main (void) { return 0; }
|
|
|
5cd83f |
+}]]
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+set bin [ltraceCompile {} [ltraceSource c {
|
|
|
5cd83f |
+ #include <stdio.h>
|
|
|
5cd83f |
+ #include <unistd.h>
|
|
|
5cd83f |
+ #include <sys/syscall.h>
|
|
|
5cd83f |
+ #include <sys/stat.h>
|
|
|
5cd83f |
+ #include <errno.h>
|
|
|
5cd83f |
+ #include <stdlib.h>
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ int
|
|
|
5cd83f |
+ main ()
|
|
|
5cd83f |
+ {
|
|
|
5cd83f |
+ FILE* fp;
|
|
|
5cd83f |
+ char s[]="system_calls";
|
|
|
5cd83f |
+ char buffer[1024];
|
|
|
5cd83f |
+ struct stat state;
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ fp = fopen ("system_calls.tmp", "w");
|
|
|
5cd83f |
+ if (fp == NULL)
|
|
|
5cd83f |
+ {
|
|
|
5cd83f |
+ printf("Can not create system_calls.tmp\n");
|
|
|
5cd83f |
+ exit (0);
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+ fwrite(s, sizeof(s), 1, fp);
|
|
|
5cd83f |
+ fseek (fp, 0, SEEK_CUR);
|
|
|
5cd83f |
+ fread(buffer, sizeof(s), 1, fp);
|
|
|
5cd83f |
+ fclose(fp);
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ getcwd (buffer, sizeof buffer);
|
|
|
5cd83f |
+ chdir (".");
|
|
|
5cd83f |
+ symlink ("system_calls.tmp", "system_calls.link");
|
|
|
5cd83f |
+ remove("system_calls.link");
|
|
|
5cd83f |
+ rename ("system_calls.tmp", "system_calls.tmp1");
|
|
|
5cd83f |
+ stat ("system_calls.tmp", &state);
|
|
|
5cd83f |
+ access ("system_calls.tmp", R_OK);
|
|
|
5cd83f |
+ remove("system_calls.tmp1");
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ mkdir ("system_call_mkdir", 0777);
|
|
|
5cd83f |
+ rmdir ("system_call_mkdir");
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ return 0;
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+}]]
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+proc Calls {logfile} {
|
|
|
5cd83f |
+ set fp [open $logfile]
|
|
|
5cd83f |
+ set ret {}
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ while {[gets $fp line] >= 0} {
|
|
|
5cd83f |
+ if [regexp -- {^[a-zA-Z0-9]*@SYS} $line] {
|
|
|
5cd83f |
+ set call [lindex [split $line @] 0]
|
|
|
5cd83f |
+ dict incr ret $call
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
|
|
|
5cd83f |
-set testfile "system_calls"
|
|
|
5cd83f |
-set srcfile ${testfile}.c
|
|
|
5cd83f |
-set binfile ${testfile}
|
|
|
5cd83f |
-
|
|
|
5cd83f |
-
|
|
|
5cd83f |
-verbose "compiling source file now....."
|
|
|
5cd83f |
-# Build the shared libraries this test case needs.
|
|
|
5cd83f |
-if { [ ltrace_compile "${srcdir}/${subdir}/${testfile}.c" "${objdir}/${subdir}/${binfile}" executable {debug} ] != "" } {
|
|
|
5cd83f |
- send_user "Testcase compile failed, so all tests in this file will automatically fail.\n"
|
|
|
5cd83f |
+ close $fp
|
|
|
5cd83f |
+ return $ret
|
|
|
5cd83f |
}
|
|
|
5cd83f |
|
|
|
5cd83f |
-# set options for ltrace.
|
|
|
5cd83f |
-ltrace_options "-S"
|
|
|
5cd83f |
-
|
|
|
5cd83f |
-#Run PUT for ltarce.
|
|
|
5cd83f |
-set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
|
|
|
5cd83f |
+proc GetDefault {d key def} {
|
|
|
5cd83f |
+ if {[dict exists $d $key]} {
|
|
|
5cd83f |
+ return [dict get $d $key]
|
|
|
5cd83f |
+ } else {
|
|
|
5cd83f |
+ return $def
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+}
|
|
|
5cd83f |
|
|
|
5cd83f |
-#check the output of this program.
|
|
|
5cd83f |
-verbose "ltrace runtest output: $exec_output\n"
|
|
|
5cd83f |
+proc Diff {d1 d2} {
|
|
|
5cd83f |
+ set keys [lsort -unique [concat [dict keys $d1] [dict keys $d2]]]
|
|
|
5cd83f |
+ set ret {}
|
|
|
5cd83f |
+ foreach key $keys {
|
|
|
5cd83f |
+ set n1 [GetDefault $d1 $key 0]
|
|
|
5cd83f |
+ set n2 [GetDefault $d2 $key 0]
|
|
|
5cd83f |
+ set sum [expr $n1 - $n2]
|
|
|
5cd83f |
+ if {[expr $sum != 0]} {
|
|
|
5cd83f |
+ dict set ret $key $sum
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+ return $ret
|
|
|
5cd83f |
+}
|
|
|
5cd83f |
|
|
|
5cd83f |
-if [regexp {ELF from incompatible architecture} $exec_output] {
|
|
|
5cd83f |
- fail "32-bit ltrace can not perform on 64-bit PUTs and rebuild ltrace in 64 bit mode!"
|
|
|
5cd83f |
- return
|
|
|
5cd83f |
-} elseif [ regexp {Couldn't get .hash data} $exec_output ] {
|
|
|
5cd83f |
- fail "Couldn't get .hash data!"
|
|
|
5cd83f |
- return
|
|
|
5cd83f |
+proc Match {d patterns} {
|
|
|
5cd83f |
+ foreach line $patterns {
|
|
|
5cd83f |
+ set pattern [lindex $line 0]
|
|
|
5cd83f |
+ set op [lindex $line 1]
|
|
|
5cd83f |
+ set expect [lindex $line 2]
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ set count 0
|
|
|
5cd83f |
+ foreach key [dict keys $d] {
|
|
|
5cd83f |
+ if [regexp -- $pattern $key] {
|
|
|
5cd83f |
+ incr count [dict get $d $key]
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ set msgMain "$pattern was recorded $count times"
|
|
|
5cd83f |
+
|
|
|
5cd83f |
+ if {[eval expr $count $op $expect]} {
|
|
|
5cd83f |
+ pass $msgMain
|
|
|
5cd83f |
+ } else {
|
|
|
5cd83f |
+ fail "$msgMain, expected $op $expect"
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
+ }
|
|
|
5cd83f |
}
|
|
|
5cd83f |
|
|
|
5cd83f |
+Match [Diff [Calls [ltraceRun -L -S -- $bin]] \
|
|
|
5cd83f |
+ [Calls [ltraceRun -L -S -- $empty]]] {
|
|
|
5cd83f |
+ { {^write$} == 1 }
|
|
|
5cd83f |
+ { {^unlink(at)?$} >= 2 }
|
|
|
5cd83f |
+ { {^open(at)?$} == 1 }
|
|
|
5cd83f |
+ { {^(new|f)?stat(64)?$} >= 1 }
|
|
|
5cd83f |
+ { {^close$} == 1 }
|
|
|
5cd83f |
+ { {^getcwd$} == 1 }
|
|
|
5cd83f |
+ { {^chdir$} == 1 }
|
|
|
5cd83f |
+ { {^symlink(at)?$} == 1 }
|
|
|
5cd83f |
+ { {^f?access(at)?$} == 1 }
|
|
|
5cd83f |
+ { {^rename(at)?$} == 1 }
|
|
|
5cd83f |
+ { {^mkdir(at)?$} == 1 }
|
|
|
5cd83f |
+}
|
|
|
5cd83f |
|
|
|
5cd83f |
-set pattern "^munmap@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 2
|
|
|
5cd83f |
-set pattern "^write@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^unlink@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-
|
|
|
5cd83f |
-set pattern "^brk@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^open@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^(new)?fstat(64)?@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 egrep
|
|
|
5cd83f |
-set pattern "^(old_)?mmap2?@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 egrep
|
|
|
5cd83f |
-set pattern "^close@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-
|
|
|
5cd83f |
-set pattern "^getcwd@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^chdir@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^symlink@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^unlink@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^(new)?stat(64)?@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1 egrep
|
|
|
5cd83f |
-set pattern "^access@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^rename@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^mkdir@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
-set pattern "^rmdir@SYS"
|
|
|
5cd83f |
-ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 1
|
|
|
5cd83f |
+ltraceDone
|