Skip to content
Permalink
Browse files

New test suite for darwintrace.

git-svn-id: https://svn.macosforge.org/repository/darwinbuild/branches/PR-8817822@919 10a61168-4876-4dac-953b-31e694342555
  • Loading branch information
wsiegrist@apple.com
wsiegrist@apple.com committed Feb 8, 2011
1 parent 143ec8d commit db856016b3d53c3d97a82d0e09553bd5cca39814
Showing with 101 additions and 0 deletions.
  1. +16 −0 testing/darwintrace/close-test
  2. +3 −0 testing/darwintrace/exec
  3. +4 −0 testing/darwintrace/realpath
  4. +78 −0 testing/darwintrace/run-tests.sh
@@ -0,0 +1,16 @@
#!/usr/bin/env python
import os
for i in range(81,102):
print " ... trying to close(%s)" % i
try:
os.close(i)
print " ... closed %s" % i
exit(1)
except Exception, e:
# test for EBADF
if e.errno == 9:
print " ... got EBADF as expected"
else:
print " ... got wrong error back: %s" % e
exit(2)
exit(0)
@@ -0,0 +1,3 @@
#!/usr/bin/env python
import subprocess, sys
subprocess.call(sys.argv[1:])
@@ -0,0 +1,4 @@
#!/usr/bin/env python
import os
import sys
print os.path.realpath(sys.argv[1])
@@ -0,0 +1,78 @@
#!/bin/bash
#
# Run test suite for darwintrace
#
set -e
set -x
pushd $(dirname $0) >> /dev/null

PREFIX=/tmp/testing/darwintrace
LOGS=$PREFIX/logs
ROOT=$PREFIX/root
BIN=$PREFIX/bin

DARWINTRACE="/usr/local/share/darwinbuild/darwintrace.dylib"
export DYLD_FORCE_FLAT_NAMESPACE=1
export DYLD_INSERT_LIBRARIES=$DARWINTRACE
export DARWINTRACE_LOG="${LOGS}/trace.log"

echo "INFO: Cleaning up testing area ..."
rm -rf $PREFIX
mkdir -p $PREFIX
mkdir -p $LOGS
mkdir -p $BIN

cp realpath $BIN/realpath
REALPATH=$BIN/realpath

cp exec $BIN/exec
EXEC=$BIN/exec

cp close-test $BIN/close-test


echo "========== TEST: execve() Trace =========="
for FILE in cp echo chmod date df expr hostname ls ps pwd test;
do
# some of these commands will error out when run without arguments,
# so just ignore that since all we want is the execve() call to happen
set +e
$EXEC /bin/$FILE 2>&1 >> /dev/null
set -e
LOGPAT="Python\[[0-9]+\][[:space:]]execve[[:space:]]/bin/${FILE}"
C=$(grep -cE $LOGPAT $DARWINTRACE_LOG)
test $C -eq 1
done
set -e

echo "========== TEST: close() Safety =========="
$BIN/close-test

echo "========== TEST: open() Trace =========="
for FILE in /System/Library/LaunchDaemons/*.plist;
do
cat $FILE >> /dev/null;
RP=$($REALPATH $FILE);
LOGPAT="cat\[[0-9]+\][[:space:]]open[[:space:]]${RP}"
C=$(grep -cE $LOGPAT $DARWINTRACE_LOG)
test $C -eq 1
done

echo "========== TEST: readlink() Trace =========="
for FILE in $(find /System/Library/Frameworks/*Foundation.framework -type l | xargs);
do
readlink $FILE
LOGPAT="readlink\[[0-9]+\][[:space:]]readlink[[:space:]]${FILE}"
C=$(grep -cE $LOGPAT $DARWINTRACE_LOG)
test $C -eq 1
done


#echo "========== TEST: Redirection =========="
#cp $DARWINTRACE $ROOT/
#DARWINTRACE_REDIRECT="${ROOT}"
#DARWINTRACE_LOG="${LOGS}/Redirection.log"


popd >> /dev/null
echo "INFO: Done testing!"

0 comments on commit db85601

Please sign in to comment.
You can’t perform that action at this time.