1 # This file is part of ltrace.
2 # Copyright (C) 2014 Petr Machata, Red Hat Inc.
3 # Copyright (C) 2006 Yao Qi <qiyao@cn.ibm.com>, IBM Corporation
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 # Objectives: Verify that Ltrace can trace all the system calls in
21 # execution. Note that this test is necessarily noisy. Dynamic
22 # linker adds a bunch of system calls of its own.
24 set empty [ltraceCompile {} [ltraceSource c {
25 int main (void) { return 0; }
28 set bin [ltraceCompile {} [ltraceSource c {
31 #include <sys/syscall.h>
40 char s[]="system_calls";
44 fp = fopen ("system_calls.tmp", "w");
47 printf("Can not create system_calls.tmp\n");
50 fwrite(s, sizeof(s), 1, fp);
51 fseek (fp, 0, SEEK_CUR);
52 fread(buffer, sizeof(s), 1, fp);
55 getcwd (buffer, sizeof buffer);
57 symlink ("system_calls.tmp", "system_calls.link");
58 remove("system_calls.link");
59 rename ("system_calls.tmp", "system_calls.tmp1");
60 stat ("system_calls.tmp", &state);
61 access ("system_calls.tmp", R_OK);
62 remove("system_calls.tmp1");
64 mkdir ("system_call_mkdir", 0777);
65 rmdir ("system_call_mkdir");
71 proc Calls {logfile} {
72 set fp [open $logfile]
75 while {[gets $fp line] >= 0} {
76 if [regexp -- {^[a-zA-Z0-9]*@SYS} $line] {
77 set call [lindex [split $line @] 0]
86 proc GetDefault {d key def} {
87 if {[dict exists $d $key]} {
88 return [dict get $d $key]
95 set keys [lsort -unique [concat [dict keys $d1] [dict keys $d2]]]
98 set n1 [GetDefault $d1 $key 0]
99 set n2 [GetDefault $d2 $key 0]
100 set sum [expr $n1 - $n2]
101 if {[expr $sum != 0]} {
102 dict set ret $key $sum
108 proc Match {d patterns} {
109 foreach line $patterns {
110 set pattern [lindex $line 0]
111 set op [lindex $line 1]
112 set expect [lindex $line 2]
115 foreach key [dict keys $d] {
116 if [regexp -- $pattern $key] {
117 incr count [dict get $d $key]
121 set msgMain "$pattern was recorded $count times"
123 if {[eval expr $count $op $expect]} {
126 fail "$msgMain, expected $op $expect"
131 Match [Diff [Calls [ltraceRun -L -S -- $bin]] \
132 [Calls [ltraceRun -L -S -- $empty]]] {
134 { {^unlink(at)?$} >= 2 }
135 { {^open(at)?$} == 1 }
136 { {^(new|f)?stat(64)?$} == 1 }
140 { {^symlink(at)?$} == 1 }
141 { {^f?access(at)?$} == 1 }
142 { {^rename(at)?$} == 1 }
143 { {^mkdir(at)?$} == 1 }