From 47f6ae8c1652fa3eb8236de738bd4ee3a30257e3 Mon Sep 17 00:00:00 2001
From: Anh <zenpoems@gmail.com>
Date: Tue, 12 Feb 2019 19:50:50 -0800
Subject: [PATCH] Add more graph test

---
 afl_transforms/tools/zax/test/test_graph.sh   | 38 +++++++++++++------
 .../tools/zax/test/test_running.cpp           | 34 +++++++++++++++++
 2 files changed, 60 insertions(+), 12 deletions(-)
 create mode 100644 afl_transforms/tools/zax/test/test_running.cpp

diff --git a/afl_transforms/tools/zax/test/test_graph.sh b/afl_transforms/tools/zax/test/test_graph.sh
index eb0db25..b87836f 100755
--- a/afl_transforms/tools/zax/test/test_graph.sh
+++ b/afl_transforms/tools/zax/test/test_graph.sh
@@ -7,8 +7,13 @@ MYARG="0123456789abcdef"
 PUT2=test_mystrlen2.exe
 MYARG2="0123456789abcdefaadsf"
 
+PUT3=test_running.exe
+MYARG3="000aaaaaaaa"
+MYARG3A="000aaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+
 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"
+ZAFL_PUT3="$PUT3.zafl $PUT3.zafl.c $PUT3.zafl.g $PUT3.zafl.d $PUT3.zafl.d.g $PUT3.zafl.c.d.g"
 
 log_msg()
 {
@@ -31,8 +36,8 @@ check_afl()
 
 build_one()
 {
-	orig=$1
-	zafl=$2
+	local orig=$1
+	local zafl=$2
 	shift
 	shift
 	zafl.sh $orig $zafl $@
@@ -47,6 +52,7 @@ build_all()
 {
 	g++ test_mystrlen.cpp -o $PUT
 	g++ test_mystrlen2.cpp -o $PUT2
+	g++ test_running.cpp -o $PUT3
 }
 
 zafl_all()
@@ -64,21 +70,23 @@ zafl_all()
 
 clean_all()
 {
-	rm -fr ${PUT}* ${PUT2}*
+	rm -fr ${PUT}* ${PUT2}* ${PUT3}*
 }
 
 verify_output()
 {
-	orig_zafl=$1
+	local arg=$1
+	shift
+	local orig_zafl=$1
 	shift
-	all_configs=$*
+	local all_configs=$*
 
-	./$orig_zafl $MYARG > $orig_zafl.output.orig
+	./$orig_zafl $arg > $orig_zafl.output.orig
 
 	for p in $all_configs 
 	do
 		echo "Program under test: $p"
-		./${p} $MYARG > $p.output
+		./${p} $arg > $p.output
 		diff $orig_zafl.output.orig $p.output
 		if [ ! $? -eq 0 ]; then
 			log_error "output verification failure: $p.output"
@@ -90,11 +98,11 @@ verify_output()
 
 verify_afl_map()
 {
-	arg=$1
+	local arg=$1
 	shift
-	orig_zafl=$1
+	local orig_zafl=$1
 	shift
-	all_configs=$*
+	local all_configs=$*
 	for p in $all_configs
 	do
 		echo "Computing trace maps for input $MYARG"
@@ -124,11 +132,17 @@ check_afl
 build_all
 
 zafl_all $PUT
-verify_output $PUT $ZAFL_PUT
+verify_output $MYARG $PUT $ZAFL_PUT
 verify_afl_map $MYARG $PUT $ZAFL_PUT
 
 zafl_all $PUT2
-verify_output $PUT2 $ZAFL_PUT2
+verify_output $MYARG2 $PUT2 $ZAFL_PUT2
 verify_afl_map $MYARG2 $PUT2 $ZAFL_PUT2
 
+zafl_all $PUT3
+verify_output $MYARG3 $PUT3 $ZAFL_PUT3
+verify_afl_map $MYARG3 $PUT3 $ZAFL_PUT3
+verify_output $MYARG3A $PUT3 $ZAFL_PUT3
+verify_afl_map $MYARG3A $PUT3 $ZAFL_PUT3
+
 clean_all
diff --git a/afl_transforms/tools/zax/test/test_running.cpp b/afl_transforms/tools/zax/test/test_running.cpp
new file mode 100644
index 0000000..59d04bd
--- /dev/null
+++ b/afl_transforms/tools/zax/test/test_running.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+#include <string.h>
+
+using namespace std;
+
+int num_running_a = 0;
+
+size_t my_strlen(char *arg)
+{
+	int i = 0;
+	bool a_detected = false;
+
+	while(arg[i])
+	{
+		if (arg[i]=='a') {
+				num_running_a++;
+				a_detected = true;
+		}
+		else{
+			if (a_detected)
+				goto out;
+		}
+		i++;
+	}
+out:
+	return i;
+}
+
+int main(int argc, char **argv)
+{
+	if (argc > 1)
+		cout << "length: " << my_strlen(argv[1]) << endl;
+	cout << "num running a: " << num_running_a <<endl;
+}
-- 
GitLab