script enhancements
cover script enhancements
Hi,
Some small trinity patches to enhance the scripts. Please have a look.
Cheers,
Anders
Anders Roxell (3):
scripts: TRINITY_PATH defaults to "."
scripts: change mkdir tmp to mktemp
scripts: arch dependent to get the syscall_list
scripts/analyse-dumps.sh | 4 +++- scripts/clean-cores.sh | 4 +++- scripts/find.sh | 26 +++++++++++++++++--------- scripts/test-all-syscalls-parallel.sh | 20 ++++++++++++++------ scripts/test-all-syscalls-sequentially.sh | 25 ++++++++++++++++--------- scripts/test-multi.sh | 18 +++++++++--------- scripts/test-vm.sh | 12 ++++++------ 7 files changed, 68 insertions(+), 41 deletions(-)
Signature · 1 line
1.8.1.2
PATCH 1/3 scripts: TRINITY_PATH defaults to "."
TRINITY_PATH may be changed in the enviroment
--- scripts/analyse-dumps.sh | 4 +++- scripts/clean-cores.sh | 4 +++- scripts/find.sh | 8 +++++--- scripts/test-all-syscalls-parallel.sh | 6 ++++-- scripts/test-all-syscalls-sequentially.sh | 8 +++++--- scripts/test-multi.sh | 6 ++++-- scripts/test-vm.sh | 4 +++- 7 files changed, 27 insertions(+), 13 deletions(-)
scripts/analyse-dumps.sh +3 -1
@@ -1,8 +1,10 @@ #!/bin/sh +TRINITY_PATH=${TRINITY_PATH:-.} + for core in $(find . -name "core.*") do - gdb -batch -n -ex 'bt' ./trinity $core > core.txt + gdb -batch -n -ex 'bt' $TRINITY_PATH/trinity $core > core.txt SHA=$(cat core.txt| grep -v New\ LWP | sha1sum) cat core.txt > core-$SHA.txt rm -f core.txt
scripts/clean-cores.sh +3 -1
@@ -1,8 +1,10 @@ #!/bin/sh +TRINITY_PATH=${TRINITY_PATH:-.} + # remove old cores for i in `find . -name "core.*" -exec ls -l {} \; | grep -v "$(date +%b\ %e)" | awk '{ print $9 }'`; do rm -f $i; done # Remove corrupted cores find . -empty -name "core.*" -exec rm -f {} \; -for i in $(file core.* | grep -v trinity | awk '{ print $1 }' | sed 's/://'); do rm -f $i; done +for i in $(file core.* | grep -v $TRINITY_PATH/trinity | awk '{ print $1 }' | sed 's/://'); do rm -f $i; done
scripts/find.sh +5 -3
@@ -5,6 +5,8 @@ # sendmsg that only occurred after connect was called. # +TRINITY_PATH=${TRINITY_PATH:-.} + check_tainted() { if [ "$(cat /proc/sys/kernel/tainted)" != $TAINT ]; then
@@ -27,18 +29,18 @@ while [ 1 ]; do -for sc in $(../trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) +for sc in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) do mkdir -p tmp.$i pushd tmp.$i - if [ ! -f ../../trinity ]; then + if [ ! -f $TRINITY_PATH/trinity ]; then echo lost! pwd exit fi - ../../trinity -q -l off -n -c sendmsg -c $sc -C32 -N 999999 + $TRINITY_PATH/trinity -q -l off -n -c sendmsg -c $sc -C32 -N 999999 popd
scripts/test-all-syscalls-parallel.sh +4 -2
@@ -1,5 +1,7 @@ #!/bin/bash +TRINITY_PATH=${TRINITY_PATH:-.} + if [ ! -d tmp ]; then mkdir tmp fi
@@ -8,9 +10,9 @@ cd tmp while [ 1 ]; do - for syscall in $(../trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) + for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) do - MALLOC_CHECK_=2 ../trinity -q -c $syscall -D & + MALLOC_CHECK_=2 $TRINITY_PATH/trinity -q -c $syscall -D & done wait done
scripts/test-all-syscalls-sequentially.sh +5 -3
@@ -3,6 +3,8 @@ # This is a useful test to run occasionally, to see which syscalls are # causing trinity to segfault. +TRINITY_PATH=${TRINITY_PATH:-.} + check_tainted() { if [ "$(cat /proc/sys/kernel/tainted)" != $TAINT ]; then
@@ -19,18 +21,18 @@ TAINT=$(cat /proc/sys/kernel/tainted) while [ 1 ] do -for syscall in $(./trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) +for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) do chmod 755 tmp pushd tmp - if [ ! -f ../trinity ]; then + if [ ! -f $TRINITY_PATH/trinity ]; then echo lost! pwd exit fi - MALLOC_CHECK_=2 ../trinity -q -c $syscall -N 99999 -l off -C 64 + MALLOC_CHECK_=2 $TRINITY_PATH/trinity -q -c $syscall -N 99999 -l off -C 64 popd check_tainted
scripts/test-multi.sh +4 -2
@@ -1,5 +1,7 @@ #!/bin/bash +TRINITY_PATH=${TRINITY_PATH:-.} + check_tainted() { if [ "$(cat /proc/sys/kernel/tainted)" != $TAINT ]; then
@@ -22,7 +24,7 @@ NR_PROCESSES=$(($NR_CPUS * 2)) while [ 1 ]; do rm -f trinity - cp ../trinity . + cp $TRINITY_PATH/trinity . chmod -w trinity for i in `seq 1 $NR_PROCESSES`
@@ -35,7 +37,7 @@ do mkdir -p tmp.$i pushd tmp.$i - if [ ! -f ../../trinity ]; then + if [ ! -f $TRINITY_PATH/trinity ]; then echo lost! pwd exit
scripts/test-vm.sh +3 -1
@@ -1,5 +1,7 @@ #!/bin/bash +TRINITY_PATH=${TRINITY_PATH:-.} + if [ ! -d tmp ]; then mkdir tmp fi
@@ -16,7 +18,7 @@ do cd tmp.$RND for i in `seq 1 $NR_PROCESSES` do - ../../trinity -q -g vm & + $TRINITY_PATH/trinity -q -g vm & done wait cd ..
Signature · 1 line
1.8.1.2
PATCH 2/3 scripts: change mkdir tmp to mktemp
In reply to Anders Roxell--- scripts/find.sh | 10 ++++------ scripts/test-all-syscalls-parallel.sh | 8 +++----- scripts/test-all-syscalls-sequentially.sh | 9 +++------ scripts/test-multi.sh | 12 +++++------- scripts/test-vm.sh | 8 +++----- 5 files changed, 18 insertions(+), 29 deletions(-)
scripts/find.sh +4 -6
@@ -6,6 +6,7 @@ # TRINITY_PATH=${TRINITY_PATH:-.} +TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) check_tainted() {
@@ -15,11 +16,8 @@ check_tainted() fi } -if [ ! -d tmp ]; then - mkdir tmp -fi -chmod 755 tmp -cd tmp +chmod 755 $TRINITY_TMP +cd $TRINITY_TMP TAINT=$(cat /proc/sys/kernel/tainted)
@@ -46,7 +44,7 @@ do check_tainted - chmod 755 ../tmp + chmod 755 $TRINITY_TMP done
scripts/test-all-syscalls-parallel.sh +3 -5
@@ -1,12 +1,10 @@ #!/bin/bash TRINITY_PATH=${TRINITY_PATH:-.} +TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) -if [ ! -d tmp ]; then - mkdir tmp -fi -chmod 755 tmp -cd tmp +chmod 755 $TRINITY_TMP +cd $TRINITY_TMP while [ 1 ]; do
scripts/test-all-syscalls-sequentially.sh +3 -6
@@ -4,6 +4,7 @@ # causing trinity to segfault. TRINITY_PATH=${TRINITY_PATH:-.} +TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) check_tainted() {
@@ -13,18 +14,14 @@ check_tainted() fi } -if [ ! -d tmp ]; then - mkdir tmp -fi - TAINT=$(cat /proc/sys/kernel/tainted) while [ 1 ] do for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) do - chmod 755 tmp - pushd tmp + chmod 755 $TRINITY_TMP + pushd $TRINITY_TMP if [ ! -f $TRINITY_PATH/trinity ]; then echo lost!
scripts/test-multi.sh +5 -7
@@ -1,6 +1,7 @@ #!/bin/bash TRINITY_PATH=${TRINITY_PATH:-.} +TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) check_tainted() {
@@ -10,11 +11,8 @@ check_tainted() fi } -if [ ! -d tmp ]; then - mkdir tmp -fi -chmod 755 tmp -cd tmp +chmod 755 $TRINITY_TMP +cd $TRINITY_TMP TAINT=$(cat /proc/sys/kernel/tainted)
@@ -29,7 +27,7 @@ do for i in `seq 1 $NR_PROCESSES` do - chmod 755 ../tmp + chmod 755 ../$TRINITY_TMP if [ -d tmp.$i ]; then chmod 755 tmp.$i rm -rf tmp.$i
@@ -55,7 +53,7 @@ do sleep 1 check_tainted - chmod 755 ../tmp + chmod 755 ../$TRINITY_TMP for i in `seq 1 $NR_PROCESSES` do
scripts/test-vm.sh +3 -5
@@ -1,12 +1,10 @@ #!/bin/bash TRINITY_PATH=${TRINITY_PATH:-.} +TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) -if [ ! -d tmp ]; then - mkdir tmp -fi -chmod 755 tmp -cd tmp +chmod 755 $TRINITY_TMP +cd $TRINITY_TMP NR_CPUS=`grep ^processor /proc/cpuinfo | /usr/bin/wc -l` NR_PROCESSES=$(($NR_CPUS * 2))
Signature · 1 line
1.8.1.2
PATCH 3/3 scripts: arch dependent to get the syscall_list
In reply to Anders RoxellARCH may be changed in the enviroment
--- scripts/find.sh | 10 +++++++++- scripts/test-all-syscalls-parallel.sh | 10 +++++++++- scripts/test-all-syscalls-sequentially.sh | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-)
scripts/find.sh +9 -1
@@ -8,6 +8,14 @@ TRINITY_PATH=${TRINITY_PATH:-.} TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) +if [ $ARCH = "arm" ]; then + $TRINITY_PATH/trinity -L | grep -v AVOID | \ + awk '{ print $2 }' | sort -u> $TRINITY_TMP/syscall_list +else + $TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | \ + awk '{ print $4 }' | sort -u> $TRINITY_TMP/syscall_list +fi + check_tainted() { if [ "$(cat /proc/sys/kernel/tainted)" != $TAINT ]; then
@@ -27,7 +35,7 @@ while [ 1 ]; do -for sc in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) +for sc in $(cat $TRINITY_TMP/syscall_list) do mkdir -p tmp.$i pushd tmp.$i
scripts/test-all-syscalls-parallel.sh +9 -1
@@ -3,12 +3,20 @@ TRINITY_PATH=${TRINITY_PATH:-.} TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) +if [ $ARCH = "arm" ]; then + $TRINITY_PATH/trinity -L | grep -v AVOID | \ + awk '{ print $2 }' | sort -u> $TRINITY_TMP/syscall_list +else + $TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | \ + awk '{ print $4 }' | sort -u> $TRINITY_TMP/syscall_list +fi + chmod 755 $TRINITY_TMP cd $TRINITY_TMP while [ 1 ]; do - for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) + for syscall in $(cat $TRINITY_TMP/syscall_list) do MALLOC_CHECK_=2 $TRINITY_PATH/trinity -q -c $syscall -D & done
scripts/test-all-syscalls-sequentially.sh +9 -1
@@ -6,6 +6,14 @@ TRINITY_PATH=${TRINITY_PATH:-.} TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) +if [ $ARCH = "arm" ]; then + $TRINITY_PATH/trinity -L | grep -v AVOID | \ + awk '{ print $2 }' | sort -u> $TRINITY_TMP/syscall_list +else + $TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | \ + awk '{ print $4 }' | sort -u> $TRINITY_TMP/syscall_list +fi + check_tainted() { if [ "$(cat /proc/sys/kernel/tainted)" != $TAINT ]; then
@@ -18,7 +26,7 @@ TAINT=$(cat /proc/sys/kernel/tainted) while [ 1 ] do -for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) +for syscall in $(cat $TRINITY_TMP/syscall_list) do chmod 755 $TRINITY_TMP pushd $TRINITY_TMP
Signature · 1 line
1.8.1.2
Re: [PATCH 3/3] scripts: arch dependent to get the syscall_list
Quoted 14 lines · Anders Roxell
ARCH may be changed in the enviroment
Signed-off-by Anders Roxell <[email protected]>--- scripts/find.sh | 10 +++++++++- scripts/test-all-syscalls-parallel.sh | 10 +++++++++- scripts/test-all-syscalls-sequentially.sh | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-)scripts/find.sh +0
-0
scripts/find.sh line 17
Quoted 10 lines
scripts/find.sh +7
-0@@ -8,6 +8,14 @@ TRINITY_PATH=${TRINITY_PATH:-.} TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) +if [ $ARCH = "arm" ]; then + $TRINITY_PATH/trinity -L | grep -v AVOID | \ + awk '{ print $2 }' | sort -u> $TRINITY_TMP/syscall_list +else + $TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | \ + awk '{ print $4 }' | sort -u> $TRINITY_TMP/syscall_list +fi
Ugh. How about we just change the format of the output of -L so it's more similar on both uniarch and biarch ?
Changing to to be..
on biarch=true:
entrypoint 0 restart_syscall [32-bit] : Enabled AVOID entrypoint 1 exit [32-bit] : Enabled AVOID
..
entrypoint 312 kcmp [64-bit]
entrypoint 313 finit_module [64-bit]
And then the !biarch case would just lack the *-bit tags, allowing the awk to pluck out column 2 regardless of arch.
Does that sound better ?
Dave
Re: [PATCH 3/3] scripts: arch dependent to get the syscall_list
Quoted 40 lines · Dave Jones
Quoted 14 lines · Anders Roxell
ARCH may be changed in the enviroment
Signed-off-by Anders Roxell <[email protected]>--- scripts/find.sh | 10 +++++++++- scripts/test-all-syscalls-parallel.sh | 10 +++++++++- scripts/test-all-syscalls-sequentially.sh | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-)scripts/find.sh +0
-0scripts/find.sh line 17
Quoted 10 lines
scripts/find.sh +7
-0@@ -8,6 +8,14 @@ TRINITY_PATH=${TRINITY_PATH:-.} TRINITY_TMP=$(mktemp -d /tmp/trinity.XXXXXX) +if [ $ARCH = "arm" ]; then + $TRINITY_PATH/trinity -L | grep -v AVOID | \ + awk '{ print $2 }' | sort -u> $TRINITY_TMP/syscall_list +else + $TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | \ + awk '{ print $4 }' | sort -u> $TRINITY_TMP/syscall_list +fiUgh. How about we just change the format of the output of -L so it's more similar on both uniarch and biarch ?
Changing to to be..
on biarch=true:
entrypoint 0
restart_syscall[32-bit] : Enabled AVOID entrypoint 1 exit [32-bit] : Enabled AVOID
..
entrypoint 312 kcmp [64-bit]
entrypoint 313finit_module[64-bit]
Quoted 4 lines
And then the !biarch case would just lack the *-bit tags, allowing the awk to pluck out column 2 regardless of arch.
Does that sound better ?
That sound great!
I will redo and send patchv2.
Anders
Quoted 3 lines
Dave
PATCH v2 3/3 tables.c: change the output format of -L
In reply to Anders RoxellSo the scripts can works for both biarch and !biarch
--- scripts/find.sh | 2 +- scripts/test-all-syscalls-parallel.sh | 2 +- scripts/test-all-syscalls-sequentially.sh | 2 +- tables.c | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-)
scripts/find.sh +1 -1
@@ -27,7 +27,7 @@ while [ 1 ]; do -for sc in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) +for sc in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $3 }' | sort -u) do mkdir -p tmp.$i pushd tmp.$i
scripts/test-all-syscalls-parallel.sh +1 -1
@@ -8,7 +8,7 @@ cd $TRINITY_TMP while [ 1 ]; do - for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) + for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $3 }' | sort -u) do MALLOC_CHECK_=2 $TRINITY_PATH/trinity -q -c $syscall -D & done
scripts/test-all-syscalls-sequentially.sh +1 -1
@@ -18,7 +18,7 @@ TAINT=$(cat /proc/sys/kernel/tainted) while [ 1 ] do -for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $4 }' | sort -u) +for syscall in $($TRINITY_PATH/trinity -L | grep entrypoint | grep -v AVOID | awk '{ print $3 }' | sort -u) do chmod 755 $TRINITY_TMP pushd $TRINITY_TMP
tables.c +5 -5
@@ -527,18 +527,18 @@ void dump_syscall_tables(void)unsigned int i;if (biarch == TRUE) { -printf ("32-bit syscalls: %d\n" , max_nr_32bit_syscalls); -printf ("64-bit syscalls: %d\n" , max_nr_64bit_syscalls); +printf ("syscalls: %d [32-bit] \n" , max_nr_32bit_syscalls); +printf ("syscalls: %d [64-bit] \n" , max_nr_64bit_syscalls);for_each_32bit_syscall (i) { -printf ("32-bit entrypoint %d %s : " , syscalls_32bit[i].entry->number, syscalls_32bit[i].entry->name); +printf ("entrypoint %d %s : [32-bit] " , syscalls_32bit[i].entry->number, syscalls_32bit[i].entry->name);show_state (syscalls_32bit[i].entry->flags &ACTIVE );if (syscalls_32bit[i].entry->flags &AVOID_SYSCALL )printf (" AVOID" );printf ("\n" ); }for_each_64bit_syscall (i) { -printf ("64-bit entrypoint %d %s : " , syscalls_64bit[i].entry->number, syscalls_64bit[i].entry->name); +printf ("entrypoint %d %s : [64-bit] " , syscalls_64bit[i].entry->number, syscalls_64bit[i].entry->name);show_state (syscalls_64bit[i].entry->flags &ACTIVE );if (syscalls_64bit[i].entry->flags &AVOID_SYSCALL )printf (" AVOID" );
@@ -547,7 +547,7 @@ void dump_syscall_tables(void) }else {printf ("syscalls: %d\n" , max_nr_syscalls);for_each_syscall (i) { -printf ("%d %s : " , syscalls[i].entry->number, syscalls[i].entry->name); +printf ("entrypoint %d %s : " , syscalls[i].entry->number, syscalls[i].entry->name);show_state (syscalls[i].entry->flags &ACTIVE );if (syscalls[i].entry->flags &AVOID_SYSCALL )printf (" AVOID" );
Signature · 1 line
1.8.1.2
Re: [PATCHv2 3/3] tables.c: change the output format of -L
Quoted 9 lines · Anders Roxell
So the scripts can works for both biarch and !biarch
Signed-off-by Anders Roxell <[email protected]>--- scripts/find.sh | 2 +- scripts/test-all-syscalls-parallel.sh | 2 +- scripts/test-all-syscalls-sequentially.sh | 2 +- tables.c | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-)
applied, with some tweaks to fit on top of Ildar's recent output() changes.
thanks,
Dave