Skip to content

Commit

Permalink
darwintracelib1.0: Fix tests
Browse files Browse the repository at this point in the history
Invoking [setup] enables the tracing sandbox, which means that binaries
started after that must be started via system or must not be arm64e
system binaries (which are untraceable unmodified and will crash with
DYLD_INSERT_LIBRARIES set).

The reverse applies for [expect] in the cleanup phase.

Use system for invocations of system utilities that should be traced
when invoked after [setup]. Move invocations that don't need to be
traced after [expect] in cleanup.

Add infrastructure required to use system (e.g., allow access to the
shell and provide `ui_info` and `ui_debug`).
  • Loading branch information
neverpanic committed Nov 15, 2024
1 parent 5ccd351 commit 3eb7733
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/darwintracelib1.0/tests/darwintrace.test
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ test darwintrace_relative_symlinks "Test that resolution of relative symlinks wo
set levels [llength [regexp -all -inline -- "/" $cwd]]
set path "[string repeat "../" [expr {$levels + 2}]]$cwd//./stat"

[setup [list allow "$cwd/symlink"]]

exec -ignorestderr -- ln -s $path symlink
[setup [list allow "$cwd/symlink" allow "/private/var/select/sh" allow "/bin" allow "/usr" allow "/dev" allow $env(DARWINTRACE_SIP_WORKAROUND_PATH)]]
system "/bin/ln -s $path symlink"
} \
-cleanup {
file delete -force symlink
Expand All @@ -142,7 +141,7 @@ test darwintrace_relative_symlinks "Test that resolution of relative symlinks wo
test darwintrace_long_symlinks "Test that resolution of long symlinks does not trigger the stack canary" \
-setup {
[setup [list allow /]]
exec -- ln -s [string repeat "ab/de/ghi/" 102] longlink
system "/bin/ln -s [string repeat "ab/de/ghi/" 102] longlink"
} \
-cleanup {
[expect]
Expand Down
2 changes: 1 addition & 1 deletion src/darwintracelib1.0/tests/readdir.test
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ test darwintrace_readdir_at_maxpathlen "Test that readdir(3) with a directory at
[setup [list allow $cwd]]
} \
-cleanup {
exec -ignorestderr -- rm -rf ab
[expect]
exec -ignorestderr -- rm -rf ab
} \
-body {
set lines [split [exec -ignorestderr -- ./readdir $dirname 2>@1] "\n"]
Expand Down
7 changes: 7 additions & 0 deletions src/darwintracelib1.0/tests/testlib.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,10 @@ proc tracelib_cleanup {} {
array unset env DARWINTRACE_LOG
}

# used by the 'system' builtin in Pextlib.dylib
proc ui_info {msg} {
puts stderr "$msg"
}
proc ui_debug {msg} {
puts stderr "$msg"
}

0 comments on commit 3eb7733

Please sign in to comment.