summaryrefslogtreecommitdiff
path: root/testsuite/lib/ltrace.exp
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/lib/ltrace.exp')
-rw-r--r--testsuite/lib/ltrace.exp93
1 files changed, 85 insertions, 8 deletions
diff --git a/testsuite/lib/ltrace.exp b/testsuite/lib/ltrace.exp
index cbb5602..494b3c8 100644
--- a/testsuite/lib/ltrace.exp
+++ b/testsuite/lib/ltrace.exp
@@ -1,5 +1,5 @@
# This file is part of ltrace.
-# Copyright (C) 2012 Petr Machata, Red Hat Inc.
+# Copyright (C) 2012, 2013 Petr Machata, Red Hat Inc.
# Copyright (C) 2006 Yao Qi, IBM Corporation
#
# This program is free software; you can redistribute it and/or
@@ -218,12 +218,15 @@ proc ltrace_compile_shlib {sources dest options} {
#
# Arguments:
# files List of files to delete.
+#
# Results:
-# Each of the files is deleted. Returns nothing.
+# Each of the files is deleted. Files are deleted in reverse
+# order, so that directories are emptied and can be deleted
+# without using -force. Returns nothing.
proc WipeFiles {files} {
verbose "WipeFiles: $files\n"
- foreach f $files {
+ foreach f [lreverse $files] {
file delete $f
}
}
@@ -315,6 +318,37 @@ proc LtraceTempFile {pat} {
return
}
+# ltraceNamedSource --
+#
+# Create a file named FILENAME, and prime it with TEXT. If
+# REMEMBERTEMP, add the file into LTRACE_TEMP_FILES, so that
+# ltraceDone (or rather WipeFiles) erases it later.
+#
+# Arguments:
+# filename Name of the file to create.
+#
+# text Contents of the new file.
+#
+# rememberTemp Whether to add filename to LTRACE_TEMP_FILES.
+#
+# Results:
+# Returns $filename, which now refers to a file with contents
+# given by TEXT.
+
+proc ltraceNamedSource {filename text {rememberTemp 1}} {
+ global LTRACE_TEMP_FILES
+
+ set chan [open $filename w]
+ puts $chan $text
+ close $chan
+
+ if $rememberTemp {
+ lappend LTRACE_TEMP_FILES $filename
+ }
+
+ return $filename
+}
+
# ltraceSource --
#
# Create a temporary file with a given suffix and prime it with
@@ -329,12 +363,22 @@ proc LtraceTempFile {pat} {
# Returns file name of created file.
proc ltraceSource {suffix text} {
- set ret [LtraceTempFile "lt-XXXXXXXXXX.$suffix"]
+ return [ltraceNamedSource \
+ [LtraceTempFile "lt-XXXXXXXXXX.$suffix"] $text 0]
+}
- set chan [open $ret w]
- puts $chan $text
- close $chan
+# ltraceDir --
+#
+# Create a temporary directory.
+#
+# Arguments:
+#
+# Results:
+# Returns name of created directory.
+proc ltraceDir {} {
+ set ret [LtraceTempFile "lt-XXXXXXXXXX.dir"]
+ file mkdir $ret
return $ret
}
@@ -435,7 +479,9 @@ proc ltraceCompile {dest args} {
set sources {}
set objects {}
foreach a $args {
- if {[string match "-?*" $a]} {
+ if {[string match "-l*" $a]} {
+ lappend options "shlib=$a"
+ } elseif {[string match "-?*" $a]} {
lappend options [string range $a 1 end]
} elseif {[string match "*.so" $a]} {
lappend options "shlib=$a"
@@ -620,6 +666,37 @@ proc ltraceMatch {logfile patterns} {
return
}
+# ltraceLibTest --
+#
+# Generate a binary, a library (liblib.so) and a config file.
+# Run the binary using ltraceRun, passing it -F to load the
+# config file.
+#
+# Arguments:
+# conf Contents of ltrace config file.
+#
+# cdecl Contents of header file.
+#
+# libcode Contents of library implementation file.
+#
+# maincode Contents of function "main".
+#
+# params Additional parameters to pass to ltraceRun.
+#
+# Results:
+#
+# Returns whatever ltraceRun returns.
+
+proc ltraceLibTest {conf cdecl libcode maincode {params ""}} {
+ set conffile [ltraceSource conf $conf]
+ set lib [ltraceCompile liblib.so [ltraceSource c [concat $cdecl $libcode]]]
+ set bin [ltraceCompile {} $lib \
+ [ltraceSource c \
+ [concat $cdecl "int main(void) {" $maincode "}"]]]
+
+ return [eval [concat "ltraceRun -F $conffile " $params "-- $bin"]]
+}
+
#
# ltrace_options OPTIONS_LIST
# Pass ltrace commandline options.