From ddb460f98ca68164ba10af8704c8d35b6b7ad30a Mon Sep 17 00:00:00 2001 From: Jason Hiser <jdhiser@gmail.com> Date: Tue, 19 Feb 2019 16:17:35 -0500 Subject: [PATCH] moving files for more clear testing --- cicd_testing/elfdep.sh | 9 +++ cicd_testing/test_fib.sh | 127 ++++++++++++++++++++++++++++++++++++++ cicd_testing/test_foo.sh | 129 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 265 insertions(+) create mode 100755 cicd_testing/elfdep.sh create mode 100755 cicd_testing/test_fib.sh create mode 100755 cicd_testing/test_foo.sh diff --git a/cicd_testing/elfdep.sh b/cicd_testing/elfdep.sh new file mode 100755 index 000000000..81c3f7840 --- /dev/null +++ b/cicd_testing/elfdep.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +set -x + +cd $CICD_MODULE_WORK_DIR/irdblibs_umbrella +source set_env_vars + +cd $SECURITY_TRANSFORMS_HOME/libIRDB-elfdep/test/ +./test-elfdep.sh diff --git a/cicd_testing/test_fib.sh b/cicd_testing/test_fib.sh new file mode 100755 index 000000000..f2e487cd7 --- /dev/null +++ b/cicd_testing/test_fib.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +set -e +trap clean EXIT + +cd $CICD_MODULE_WORK_DIR/irdblibs_umbrella +source set_env_vars +cd ./irdb-libs/tools/selective_cfi/tests/cicd_tests/fib_src + +source ../../cfi_smokescreen_configs.sh + +get_correct() +{ + cp libfib.so.orig libfib.so + cp libfib2.so.orig libfib2.so + # for fib.exe, a non-zero exit status can indicate success + set +e + ./fib.exe $1 > correct + echo $? >> correct + set -e +} + +do_test() +{ + echo running test $1 $2 $3 $4 + + n=$2 + + get_correct $n + + cp $3 libfib.so + cp $4 libfib2.so + # for fib.exe, a non-zero exit status can indicate success + set +e + ./$1 $n > out + echo $? >> out + + + cmp out correct + res=$? + if [[ $res != 0 ]]; then + echo "detected output diff:" + diff out correct + exit 1 + fi + + set -e +} + + +build() +{ + gcc -o libfib.so libfib.c -w -shared -fPIC + gcc -o libfib2.so libfib2.c -w -shared -fPIC + gcc -o fib.exe fib.c -w -L. -lfib -lfib2 + gcc -o fib.exe.pie fib.c -fPIC -fpie -pie -w -L. -lfib -lfib2 + mv libfib.so libfib.so.orig + mv libfib2.so libfib2.so.orig +} + + +protect() +{ + files=(libfib.so.orig libfib2.so.orig fib.exe fib.exe.pie) + + libfib_so_orig_varients=(libfib.so.orig) + libfib2_so_orig_varients=(libfib2.so.orig) + fib_exe_varients=(fib.exe) + fib_exe_pie_varients=(fib.exe.pie) + + for file in "${files[@]}"; do + for config in "${configs[@]}"; do + echo Protecting file "$file" with config "$config" + set +e + "$config" ./"$file" ./"$file"".""$config" > out 2>&1 + res=$? + set -e + if [[ $res == 0 ]]; then + rm -rf out peasoup* + else + echo "Failed protection!" + cat out peasoup*/logs/* + exit 1 + fi + varient_array_name="$(echo "$file" | sed -e 's/\./_/g')""_varients" + varient_file="$file"".""$config" + eval $varient_array_name+=\(\$varient_file\) + done + done +} + +clean() +{ + local ec=$? + rm -f out >> /dev/null 2>&1 + rm -f correct >> /dev/null 2>&1 + rm -Rf fib.exe* peasoup_exe* lib*.so* >> /dev/null 2>&1 + + for config in "${configs[@]}"; do + rm -f *."$config" >> /dev/null 2>&1 + done + exit $ec +} + + +main() +{ + build + protect + + fib_varients=("${fib_exe_varients[@]}" "${fib_exe_pie_varients[@]}") + + for fib_varient in "${fib_varients[@]}"; do + for libfib_varient in "${libfib_so_orig_varients[@]}"; do + for libfib2_varient in "${libfib2_so_orig_varients[@]}"; do + for i in 2 6; do + do_test "$fib_varient" $i "$libfib_varient" "$libfib2_varient" + done + done + done + done + + exit 0 +} + + +main $* diff --git a/cicd_testing/test_foo.sh b/cicd_testing/test_foo.sh new file mode 100755 index 000000000..77ae98d69 --- /dev/null +++ b/cicd_testing/test_foo.sh @@ -0,0 +1,129 @@ +#!/bin/bash + +set -e +trap clean EXIT + +cd $CICD_MODULE_WORK_DIR/irdblibs_umbrella +source set_env_vars +cd ./irdb-libs/tools/selective_cfi/tests/cicd_tests/foo_src + +source ../../cfi_smokescreen_configs.sh + +get_correct() +{ + cp libfoo.so.orig libfoo.so + ./foo.exe > correct + echo $? >> correct +} + +do_test() +{ + echo Running test: "$1" "$2" + + set +e + cp $2 libfoo.so + ./$1 > out + echo $? >> out + + cmp out correct + res=$? + if [[ $res != 0 ]]; then + echo "detected output diff:" + diff out correct + exit 1 + fi + set -e + +} + + +build() +{ + gcc -o libfoo.so libfoo.c -w -shared -fPIC + gcc -o foo.exe foo.c -w -L. -lfoo + mv libfoo.so libfoo.so.orig + + gcc -o libfoo.O.so libfoo.c -O -w -shared -fPIC + gcc -o libfoo.O2.so libfoo.c -O2 -w -shared -fPIC + gcc -o libfoo.O3.so libfoo.c -O3 -w -shared -fPIC + gcc -o libfoo.Os.so libfoo.c -Os -w -shared -fPIC + mv libfoo.O.so libfoo.O.so.orig + mv libfoo.O2.so libfoo.O2.so.orig + mv libfoo.O3.so libfoo.O3.so.orig + mv libfoo.Os.so libfoo.Os.so.orig +} + + +protect() +{ + files=(foo.exe libfoo.so.orig libfoo.O.so.orig libfoo.O2.so.orig libfoo.O3.so.orig libfoo.Os.so.orig) + + foo_exe_varients=(foo.exe) + libfoo_so_orig_varients=(libfoo.so.orig) + libfoo_O_so_orig_varients=(libfoo.O.so.orig) + libfoo_O2_so_orig_varients=(libfoo.O2.so.orig) + libfoo_O3_so_orig_varients=(libfoo.O3.so.orig) + libfoo_Os_so_orig_varients=(libfoo.Os.so.orig) + + for file in "${files[@]}"; do + for config in "${configs[@]}"; do + echo Protecting file "$file" with config "$config" + set -e + "$config" ./"$file" ./"$file"".""$config" > ps.log 2>&1 + res=$? + set +e + if [[ $res != 0 ]]; then + echo "Failed to xform!" + cat peasoup*/logs/* + exit 1 + else + rm -Rf peasoup* + fi + + varient_array_name="$(echo "$file" | sed -e 's/\./_/g')""_varients" + varient_file="$file"".""$config" + eval $varient_array_name+=\(\$varient_file\) + done + done + +} + +clean() +{ + local ec=$? + rm -f out >> /dev/null 2&>1 + rm -f correct >> /dev/null 2&>1 + rm -rf peasoup_executable_directory.* >> /dev/null 2&>1 + rm -f *.orig >> /dev/null 2&>1 + rm -f *.exe >> /dev/null 2&>1 + rm -f *.so >> /dev/null 2&>1 + + for config in "${configs[@]}"; do + rm -f *."$config" >> /dev/null 2&>1 + done + + exit $ec +} + + +main() +{ + build + protect + get_correct + + libfoo_varients=("${libfoo_so_orig_varients[@]}" "${libfoo_O_so_orig_varients[@]}" "${libfoo_O2_so_orig_varients[@]}" + "${libfoo_O3_so_orig_varients[@]}" "${libfoo_Os_so_orig_varients[@]}") + + + for foo_varient in "${foo_exe_varients[@]}"; do + for libfoo_varient in "${libfoo_varients[@]}"; do + do_test "$foo_varient" "$libfoo_varient" + done + done + + exit 0 +} + + +main $* -- GitLab