From f924bd13247babc6e4445805b53fac92b176572b Mon Sep 17 00:00:00 2001
From: Anh <zenpoems@gmail.com>
Date: Tue, 12 Feb 2019 12:45:34 -0800
Subject: [PATCH] Update graph tests

---
 afl_transforms/tools/zax/test/test_graph.sh   | 48 +++++++++++--------
 .../tools/zax/test/test_mystrlen.cpp          | 13 +++--
 2 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/afl_transforms/tools/zax/test/test_graph.sh b/afl_transforms/tools/zax/test/test_graph.sh
index f16f05b..86d54f2 100755
--- a/afl_transforms/tools/zax/test/test_graph.sh
+++ b/afl_transforms/tools/zax/test/test_graph.sh
@@ -1,8 +1,9 @@
 cd $(dirname $(realpath $0) )
 
 PUT=test_mystrlen.exe
+MYARG="0123456789abcdef"
 PUT2=test_mystrlen2.exe
-MYARG="0123456789abcdef1"
+MYARG2="0123456789abcdef12345sdafdasjfadsjk"
 
 ZAFL_PUT="$PUT.zafl $PUT.zafl.c $PUT.zafl.g $PUT.zafl.d $PUT.zafl.d.g $PUT.zafl.c.d.g"
 ZAFL_PUT2="$PUT2.zafl $PUT2.zafl.c $PUT2.zafl.g $PUT2.zafl.d $PUT2.zafl.d.g $PUT2.zafl.c.d.g"
@@ -44,8 +45,11 @@ build_all()
 {
 	g++ test_mystrlen.cpp -o $PUT
 	g++ test_mystrlen2.cpp -o $PUT2
+}
 
-	for p in $PUT $PUT2
+zafl_all()
+{
+	for p in $*
 	do
 		build_one $p $p.zafl -v -t $p.analysis 
 		build_one $p $p.zafl.c -c -v -t $p.analysis.c
@@ -58,46 +62,41 @@ build_all()
 
 clean_all()
 {
-	rm -fr ${PUT}*  ${PUT2}*
+	rm -fr ${PUT}* ${PUT2}*
 }
 
 verify_output()
 {
-	./$PUT $MYARG > $PUT.output.orig
-	./$PUT2 $MYARG > $PUT2.output.orig
+	orig_zafl=$1
+	shift
+	all_configs=$*
 
-	for p in $ZAFL_PUT 
-	do
-		echo "Program under test: $p"
-		./${p} $MYARG > $p.output
-		diff $PUT.output.orig $p.output
-		if [ ! $? -eq 0 ]; then
-			log_error "output verification failure: $p.output"
-		fi
-	done
+	./$orig_zafl $MYARG > $orig_zafl.output.orig
 
-	for p in $ZAFL_PUT2
+	for p in $all_configs 
 	do
 		echo "Program under test: $p"
 		./${p} $MYARG > $p.output
-		diff $PUT2.output.orig $p.output
+		diff $orig_zafl.output.orig $p.output
 		if [ ! $? -eq 0 ]; then
 			log_error "output verification failure: $p.output"
 		fi
 	done
 
-	log_msg "output verified"
+	log_msg "output verified for $orig_zafl"
 }
 
 verify_afl_map()
 {
+	arg=$1
+	shift
 	orig_zafl=$1
 	shift
 	all_configs=$*
 	for p in $all_configs
 	do
 		echo "Computing trace maps for input $MYARG"
-		afl-showmap -o $p.map -- ./$p $MYARG
+		afl-showmap -o $p.map -- ./$p $arg
 		cut -d':' -f2 $p.map | sort -r | head -n 1 > $p.max_count
 	done
 
@@ -119,8 +118,15 @@ verify_afl_map()
 
 clean_all
 check_afl
+
 build_all
-verify_output
-verify_afl_map $PUT $ZAFL_PUT
-verify_afl_map $PUT2 $ZAFL_PUT2
+
+zafl_all $PUT
+verify_output $PUT $ZAFL_PUT
+verify_afl_map $MYARG $PUT $ZAFL_PUT
+
+zafl_all $PUT2
+verify_output $PUT2 $ZAFL_PUT2
+verify_afl_map $MYARG2 $PUT2 $ZAFL_PUT2
+
 clean_all
diff --git a/afl_transforms/tools/zax/test/test_mystrlen.cpp b/afl_transforms/tools/zax/test/test_mystrlen.cpp
index 389357d..5bc0f48 100644
--- a/afl_transforms/tools/zax/test/test_mystrlen.cpp
+++ b/afl_transforms/tools/zax/test/test_mystrlen.cpp
@@ -2,9 +2,15 @@
 
 using namespace std;
 
-volatile int identity(int x)
+int x = 0;
+
+volatile int identity(int y)
 {
-	return x;
+	if (y % 39 == 0)
+		x = 1;
+	else
+		x = 2;
+	return y;
 }
 
 size_t my_strlen(char *arg)
@@ -23,5 +29,6 @@ size_t my_strlen(char *arg)
 int main(int argc, char **argv)
 {
 	if (argc > 1)
-		cout << "length: " << my_strlen(argv[1]) << endl;
+		cout << "length= " << my_strlen(argv[1]) << endl;
+	cout << "x= " << x << endl;
 }
-- 
GitLab