From 112693ee541356cbd2bd5b7504f244a0ed542238 Mon Sep 17 00:00:00 2001
From: Anh <zenpoems@gmail.com>
Date: Sun, 16 Sep 2018 13:26:28 -0400
Subject: [PATCH] New smoke tests

---
 test/od/test_od.sh               | 83 ++++++++++++++++++++++++++++++++
 test/sha256sum/test_sha256sum.sh | 83 ++++++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+)
 create mode 100755 test/od/test_od.sh
 create mode 100755 test/sha256sum/test_sha256sum.sh

diff --git a/test/od/test_od.sh b/test/od/test_od.sh
new file mode 100755
index 0000000..002b635
--- /dev/null
+++ b/test/od/test_od.sh
@@ -0,0 +1,83 @@
+export AFL_TIMEOUT=15
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SECURITY_TRANSFORMS_HOME/lib/:. 
+
+session=/tmp/tmp.od.$$
+
+cleanup()
+{
+	rm -fr /tmp/od.tmp* od*.zafl peasoup_exec*.od* zafl_in zafl_out $session
+}
+
+log_error()
+{
+	echo "TEST FAIL: $1"
+	exit 1
+}
+
+log_message()
+{
+	echo "TEST  MSG: $1"
+}
+
+log_success()
+{
+	echo "TEST PASS: $1"
+}
+
+fuzz_with_zafl()
+{
+	od_zafl=$1
+
+	# setup AFL directories
+	mkdir zafl_in
+	echo "1" > zafl_in/1
+
+	if [ -d zafl_out ]; then
+		rm -fr zafl_out
+	fi
+
+	# run for 30 seconds
+	timeout $AFL_TIMEOUT afl-fuzz -i zafl_in -o zafl_out -- $od_zafl @@
+	if [ $? -eq 124 ]; then
+		if [ ! -e zafl_out/fuzzer_stats ]; then
+			log_error "$od_zafl: something went wrong with afl -- no fuzzer stats file"
+		fi
+
+		cat zafl_out/fuzzer_stats
+		execs_per_sec=$( grep execs_per_sec zafl_out/fuzzer_stats )
+		log_success "$od_zafl: $execs_per_sec"
+	else
+		log_error "$od_zafl: unable to run with afl"
+	fi
+
+}
+
+mkdir $session
+pushd $session
+
+# build ZAFL version of od executable
+zafl.sh `which od` od.zafl --tempdir analysis.od.zafl
+if [ $? -eq 0 ]; then
+	log_success "build od.zafl"
+else
+	log_error "build od.zafl"
+fi
+grep ATTR analysis.od.zafl/logs/zafl.log
+
+log_message "Fuzz for $AFL_TIMEOUT secs"
+fuzz_with_zafl $(realpath ./od.zafl)
+
+# build ZAFL (no Ida) version of od executable
+zafl.sh `which od` od.rida.zafl --tempdir analysis.od.rida.zafl
+if [ $? -eq 0 ]; then
+	log_success "build od.rida.zafl"
+else
+	log_error "build od.rida.zafl"
+fi
+grep ATTR analysis.od.rida.zafl/logs/zafl.log
+
+log_message "Fuzz rida.zafl for $AFL_TIMEOUT secs"
+fuzz_with_zafl $(realpath ./od.rida.zafl)
+
+cleanup
+popd
diff --git a/test/sha256sum/test_sha256sum.sh b/test/sha256sum/test_sha256sum.sh
new file mode 100755
index 0000000..1247f83
--- /dev/null
+++ b/test/sha256sum/test_sha256sum.sh
@@ -0,0 +1,83 @@
+export AFL_TIMEOUT=15
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SECURITY_TRANSFORMS_HOME/lib/:. 
+
+session=/tmp/tmp.sha256sum.$$
+
+cleanup()
+{
+	rm -fr /tmp/sha256sum.tmp* sha256sum*.zafl peasoup_exec*.sha256sum* zafl_in zafl_out $session
+}
+
+log_error()
+{
+	echo "TEST FAIL: $1"
+	exit 1
+}
+
+log_message()
+{
+	echo "TEST  MSG: $1"
+}
+
+log_success()
+{
+	echo "TEST PASS: $1"
+}
+
+fuzz_with_zafl()
+{
+	sha256sum_zafl=$1
+
+	# setup AFL directories
+	mkdir zafl_in
+	echo "1" > zafl_in/1
+
+	if [ -d zafl_out ]; then
+		rm -fr zafl_out
+	fi
+
+	# run for 30 seconds
+	timeout $AFL_TIMEOUT afl-fuzz -i zafl_in -o zafl_out -- $sha256sum_zafl 
+	if [ $? -eq 124 ]; then
+		if [ ! -e zafl_out/fuzzer_stats ]; then
+			log_error "$sha256sum_zafl: something went wrong with afl -- no fuzzer stats file"
+		fi
+
+		cat zafl_out/fuzzer_stats
+		execs_per_sec=$( grep execs_per_sec zafl_out/fuzzer_stats )
+		log_success "$sha256sum_zafl: $execs_per_sec"
+	else
+		log_error "$sha256sum_zafl: unable to run with afl"
+	fi
+
+}
+
+mkdir $session
+pushd $session
+
+# build ZAFL version of sha256sum executable
+zafl.sh `which sha256sum` sha256sum.zafl --tempdir analysis.sha256sum.zafl
+if [ $? -eq 0 ]; then
+	log_success "build sha256sum.zafl"
+else
+	log_error "build sha256sum.zafl"
+fi
+grep ATTR analysis.sha256sum.zafl/logs/zafl.log
+
+log_message "Fuzz for $AFL_TIMEOUT secs"
+fuzz_with_zafl $(realpath ./sha256sum.zafl)
+
+# build ZAFL (no Ida) version of sha256sum executable
+zafl.sh `which sha256sum` sha256sum.rida.zafl --tempdir analysis.sha256sum.rida.zafl
+if [ $? -eq 0 ]; then
+	log_success "build sha256sum.rida.zafl"
+else
+	log_error "build sha256sum.rida.zafl"
+fi
+grep ATTR analysis.sha256sum.rida.zafl/logs/zafl.log
+
+log_message "Fuzz rida.zafl for $AFL_TIMEOUT secs"
+fuzz_with_zafl $(realpath ./sha256sum.rida.zafl)
+
+cleanup
+popd
-- 
GitLab