about summary refs log tree commit diff homepage
path: root/unittests/Assignment
diff options
context:
space:
mode:
authorDan Liew <delcypher@gmail.com>2016-09-29 21:04:27 +0100
committerGitHub <noreply@github.com>2016-09-29 21:04:27 +0100
commit96b77a4a211745cdee375b38ce4313dfc70efe8f (patch)
treec2bbce1f697a31d9b8c8716cf765b651b266185a /unittests/Assignment
parenta936dcbaefe0efa67e97f4ea14893bdae63db99b (diff)
downloadklee-96b77a4a211745cdee375b38ce4313dfc70efe8f.tar.gz
Fix bug in `AssignmentEvaluator` where NotOptimizedExpr would not (#466)
* Add unittest to check that the `Assignment` class can evaluate
expressions containing a `NotOptimizedExpr`.

* Fix the `AssignmentTest.FoldNotOptimized` unit test by
teaching the `ExprEvaluator` to fold `NotOptimizedExpr` nodes.
Diffstat (limited to 'unittests/Assignment')
-rw-r--r--unittests/Assignment/AssignmentTest.cpp35
-rw-r--r--unittests/Assignment/Makefile12
2 files changed, 47 insertions, 0 deletions
diff --git a/unittests/Assignment/AssignmentTest.cpp b/unittests/Assignment/AssignmentTest.cpp
new file mode 100644
index 00000000..0eaa28f1
--- /dev/null
+++ b/unittests/Assignment/AssignmentTest.cpp
@@ -0,0 +1,35 @@
+#include "klee/util/ArrayCache.h"
+#include "klee/util/Assignment.h"
+#include "gtest/gtest.h"
+#include <iostream>
+#include <vector>
+
+int finished = 0;
+
+using namespace klee;
+
+TEST(AssignmentTest, FoldNotOptimized)
+{
+  ArrayCache ac;
+  const Array* array = ac.CreateArray("simple_array", /*size=*/ 1);
+  // Create a simple assignment
+  std::vector<const Array*> objects;
+  std::vector<unsigned char> value;
+  std::vector< std::vector<unsigned char> > values;
+  objects.push_back(array);
+  value.push_back(128);
+  values.push_back(value);
+  // We want to simplify to a constant so allow free values so
+  // if the assignment is incomplete we don't get back a constant.
+  Assignment assignment(objects, values, /*_allowFreeValues=*/true);
+
+  // Now make an expression that reads from the array at position
+  // zero.
+  ref<Expr> read = NotOptimizedExpr::alloc(Expr::createTempRead(array, Expr::Int8));
+
+  // Now evaluate. The OptimizedExpr should be folded
+  ref<Expr> evaluated = assignment.evaluate(read);
+  const ConstantExpr* asConstant = dyn_cast<ConstantExpr>(evaluated);
+  ASSERT_TRUE(asConstant != NULL);
+  ASSERT_EQ(asConstant->getZExtValue(), (unsigned) 128);
+}
diff --git a/unittests/Assignment/Makefile b/unittests/Assignment/Makefile
new file mode 100644
index 00000000..d4110c80
--- /dev/null
+++ b/unittests/Assignment/Makefile
@@ -0,0 +1,12 @@
+##===- unittests/Assignment/Makefile -----------------------*- Makefile -*-===##
+
+LEVEL := ../..
+include $(LEVEL)/Makefile.config
+
+TESTNAME := Assignment
+USEDLIBS := kleaverExpr.a
+LINK_COMPONENTS := support
+
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
+
+CXXFLAGS += -DLLVM_29_UNITTEST