summaryrefslogtreecommitdiff
path: root/test/example/cpp-unit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/example/cpp-unit.cpp')
-rw-r--r--test/example/cpp-unit.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/test/example/cpp-unit.cpp b/test/example/cpp-unit.cpp
index e6189d9d1..2ba4388d1 100644
--- a/test/example/cpp-unit.cpp
+++ b/test/example/cpp-unit.cpp
@@ -1,17 +1,41 @@
// test multiple uses of the threadPool
-#include <assert.h>
+#include <iostream>
-#include <wasm.h>
+#include <ir/bits.h>
#include <ir/cost.h>
+#include <wasm.h>
using namespace wasm;
-int main()
-{
+void compare(size_t x, size_t y) {
+ if (x != y) {
+ std::cout << "comparison error!\n" << x << '\n' << y << '\n';
+ abort();
+ }
+}
+
+void test_bits() {
+ Const c;
+ c.type = Type::i32;
+ c.value = Literal(int32_t(1));
+ compare(Bits::getMaxBits(&c), 1);
+ c.value = Literal(int32_t(2));
+ compare(Bits::getMaxBits(&c), 2);
+ c.value = Literal(int32_t(3));
+ compare(Bits::getMaxBits(&c), 2);
+}
+
+void test_cost() {
// Some optimizations assume that the cost of a get is zero, e.g. local-cse.
LocalGet get;
- assert(CostAnalyzer(&get).cost == 0);
+ compare(CostAnalyzer(&get).cost, 0);
+}
+
+int main() {
+ test_bits();
+
+ test_cost();
std::cout << "Success.\n";
return 0;