From 484cbc45812b1a221397eec2e99c70957738995e Mon Sep 17 00:00:00 2001
From: an7s <an7s@git.zephyr-software.com>
Date: Sun, 4 Dec 2011 15:47:39 +0000
Subject: [PATCH] Added utilities to figure out the state of Grace

Former-commit-id: ee90b63b18483c6a661790929227991a8975228b
---
 .gitattributes       |  1 +
 tools/grace_utils.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100755 tools/grace_utils.sh

diff --git a/.gitattributes b/.gitattributes
index db618a759..716645416 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1035,6 +1035,7 @@ tools/generate_exe.sh -text
 tools/generate_io_baseline.sh -text
 tools/getlibs.sh -text
 tools/getsyms.sh -text
+tools/grace_utils.sh -text
 tools/libc_functions.txt -text
 tools/manual_cover.sh -text
 tools/manual_test_import.sh -text
diff --git a/tools/grace_utils.sh b/tools/grace_utils.sh
new file mode 100755
index 000000000..9feaff40d
--- /dev/null
+++ b/tools/grace_utils.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+#
+# Utilities to assess state of Grace-produced inputs & outputs
+#
+
+#
+# Did Grace produce at least one valid baseline?
+#
+# A valid baseline is an input with a set of corresponding outputs, where
+# the original run that produces the outputs did not result in a segmentation violation
+#
+# Returns 0 if Grace did not produce any valid baseline
+# Returns 1 if Grace produced at least one valid baseline
+#
+check_grace_baseline()
+{
+	CONCOLIC_DIR=$1
+
+	baseline_flag=0
+	# do we have at least 1 Grace input that did not generate an 
+	# exit code of 139 (segmentation violation)
+
+	for i in `ls $CONCOLIC_DIR/input*.json`
+	do
+ 		input=`basename $i .json`
+		input_number=`echo $input | sed "s/input_//"`
+
+		abridged_number=`echo $input_number | sed 's/0*\(.*\)/\1/'`
+
+		#if there is no exit code for the input number, skip for now.
+		if [ ! -f "$CONCOLIC_DIR/exit_code.run_$abridged_number.log" ]; then
+			echo "do_p1transform.sh: No baseline data for input $input_number, missing exit status"
+			continue;
+		fi
+	echo "check_grace_baseline(): Exit status baseline file: $CONCOLIC_DIR/exit_code.run_$abridged_number.log"
+	#if baseline exited with 139, ignore input
+	grep 139 $CONCOLIC_DIR/exit_code.run_$abridged_number.log
+	if [ $? -eq 0 ]; then
+		echo "Baseline exit status was 139 for input $i, ignoring input"
+		continue
+	fi
+
+	echo "check_grace_baseline(): Found at least one grace produced valid baseline comparison output"
+	#at this point we know we have baseline data to compare against
+	#we assume that if exit status was produced, baseline information is available
+	#if I find one, break the loop
+	baseline_flag=`expr $baseline_flag + 1`
+	break
+	done
+
+	if [ $baseline_flag -eq 0 ]; then
+		echo "check_grace_baseline(): no valid baseline comparison output"
+	fi
+
+	return $baseline_flag
+}
-- 
GitLab