#include #include #include #include #include #include #include #include #include #include #include #include "test_assert.h" #include "llmsset.h" #include "sylvan.h" #define BLACK "\33[22;30m" #define GRAY "\33[01;30m" #define RED "\33[22;31m" #define LRED "\33[01;31m" #define GREEN "\33[22;32m" #define LGREEN "\33[01;32m" #define BLUE "\33[22;34m" #define LBLUE "\33[01;34m" #define BROWN "\33[22;33m" #define YELLOW "\33[01;33m" #define CYAN "\33[22;36m" #define LCYAN "\33[22;36m" #define MAGENTA "\33[22;35m" #define LMAGENTA "\33[01;35m" #define NC "\33[0m" #define BOLD "\33[1m" #define ULINE "\33[4m" //underline #define BLINK "\33[5m" #define INVERT "\33[7m" __thread uint64_t seed = 1; uint64_t xorshift_rand(void) { uint64_t x = seed; if (seed == 0) seed = rand(); x ^= x >> 12; x ^= x << 25; x ^= x >> 27; seed = x; return x * 2685821657736338717LL; } double uniform_deviate(uint64_t seed) { return seed * (1.0 / (0xffffffffffffffffL + 1.0)); } int rng(int low, int high) { return low + uniform_deviate(xorshift_rand()) * (high-low); } static inline BDD make_random(int i, int j) { if (i == j) return rng(0, 2) ? sylvan_true : sylvan_false; BDD yes = make_random(i+1, j); BDD no = make_random(i+1, j); BDD result = sylvan_invalid; switch(rng(0, 4)) { case 0: result = no; sylvan_deref(yes); break; case 1: result = yes; sylvan_deref(no); break; case 2: result = sylvan_ref(sylvan_makenode(i, yes, no)); sylvan_deref(no); sylvan_deref(yes); break; case 3: default: result = sylvan_ref(sylvan_makenode(i, no, yes)); sylvan_deref(no); sylvan_deref(yes); break; } return result; } /** GC testing */ VOID_TASK_2(gctest_fill, int, levels, int, width) { if (levels > 1) { int i; for (i=0; i,<2,2,3,5,4,3>,<2,2,3,5,4,2>,<2,3,3,5,4,3>,<2,3,4,4,4,3>} MDD proj = lddmc_cube((uint32_t[]){1,1,-2},3); b = lddmc_cube((uint32_t[]){1,2}, 2); b = lddmc_union_cube(b, (uint32_t[]){2,2}, 2); b = lddmc_union_cube(b, (uint32_t[]){2,3}, 2); test_assert(lddmc_project(a, proj)==b); test_assert(lddmc_project_minus(a, proj, lddmc_false)==b); test_assert(lddmc_project_minus(a, proj, b)==lddmc_false); // Test relprod a = lddmc_cube((uint32_t[]){1},1); b = lddmc_cube((uint32_t[]){1,2},2); proj = lddmc_cube((uint32_t[]){1,2,-1}, 3); test_assert(lddmc_cube((uint32_t[]){2},1) == lddmc_relprod(a, b, proj)); test_assert(lddmc_cube((uint32_t[]){3},1) == lddmc_relprod(a, lddmc_cube((uint32_t[]){1,3},2), proj)); a = lddmc_union_cube(a, (uint32_t[]){2},1); test_assert(lddmc_satcount(a) == 2); test_assert(lddmc_cube((uint32_t[]){2},1) == lddmc_relprod(a, b, proj)); b = lddmc_union_cube(b, (uint32_t[]){2,2},2); test_assert(lddmc_cube((uint32_t[]){2},1) == lddmc_relprod(a, b, proj)); b = lddmc_union_cube(b, (uint32_t[]){2,3},2); test_assert(lddmc_satcount(lddmc_relprod(a, b, proj)) == 2); test_assert(lddmc_union(lddmc_cube((uint32_t[]){2},1),lddmc_cube((uint32_t[]){3},1)) == lddmc_relprod(a, b, proj)); // Test relprev MDD universe = lddmc_union(lddmc_cube((uint32_t[]){1},1), lddmc_cube((uint32_t[]){2},1)); a = lddmc_cube((uint32_t[]){2},1); b = lddmc_cube((uint32_t[]){1,2},2); test_assert(lddmc_cube((uint32_t[]){1},1) == lddmc_relprev(a, b, proj, universe)); test_assert(lddmc_cube((uint32_t[]){1},1) == lddmc_relprev(a, b, proj, lddmc_cube((uint32_t[]){1},1))); a = lddmc_cube((uint32_t[]){1},1); MDD next = lddmc_relprod(a, b, proj); test_assert(lddmc_relprev(next, b, proj, a) == a); // Random tests MDD rnd1, rnd2; int i; for (i=0; i<200; i++) { int depth = rng(1, 20); rnd1 = CALL(random_ldd, depth, rng(0, 30)); rnd2 = CALL(random_ldd, depth, rng(0, 30)); test_assert(rnd1 != lddmc_true); test_assert(rnd2 != lddmc_true); test_assert(lddmc_intersect(rnd1,rnd2) == lddmc_intersect(rnd2,rnd1)); test_assert(lddmc_union(rnd1,rnd2) == lddmc_union(rnd2,rnd1)); MDD tmp = lddmc_union(lddmc_minus(rnd1, rnd2), lddmc_minus(rnd2, rnd1)); test_assert(lddmc_intersect(tmp, lddmc_intersect(rnd1, rnd2)) == lddmc_false); test_assert(lddmc_union(tmp, lddmc_intersect(rnd1, rnd2)) == lddmc_union(rnd1, rnd2)); test_assert(lddmc_minus(rnd1,rnd2) == lddmc_minus(rnd1, lddmc_intersect(rnd1,rnd2))); } // Test file stuff for (i=0; i<10; i++) { FILE *f = fopen("__lddmc_test_bdd", "w+"); int N = 20; MDD rnd[N]; size_t a[N]; char sha[N][65]; int j; for (j=0;j 1) sscanf(argv[1], "%d", &threads); if (runtests(threads)) exit(1); printf(NC); exit(0); }