1 2 /*++ 3 Copyright (c) 2015 Microsoft Corporation 4 5 --*/ 6 7 #ifdef _WINDOWS 8 #include "api/z3.h" 9 #include "api/z3_private.h" 10 #include <iostream> 11 #include "util/util.h" 12 #include "util/trace.h" 13 14 static bool oom = false; 15 16 err_handler(Z3_context c,Z3_error_code e)17static void err_handler(Z3_context c, Z3_error_code e) { 18 oom = true; 19 throw std::bad_alloc(); 20 } 21 hit_me(char const * wm)22static void hit_me(char const* wm) { 23 Z3_config cfg; 24 Z3_context ctx; 25 26 oom = false; 27 28 cfg = Z3_mk_config(); 29 if (!cfg) { 30 return; 31 } 32 Z3_global_param_set("MEMORY_MAX_SIZE", wm); 33 ctx = Z3_mk_context(cfg); 34 if (ctx) { 35 Z3_set_error_handler(ctx, &err_handler); 36 37 unsigned i; 38 for (i = 1; !oom ; ++i) { 39 try { 40 Z3_mk_bv_sort(ctx,i); 41 42 } 43 catch (std::bad_alloc) { 44 std::cout << "caught\n"; 45 } 46 } 47 std::cout << "oom " << i << "\n"; 48 Z3_del_context(ctx); 49 } 50 Z3_del_config(cfg); 51 } 52 tst_memory()53void tst_memory() { 54 hit_me("10"); 55 Z3_reset_memory(); 56 hit_me("20"); 57 Z3_reset_memory(); 58 hit_me("30"); 59 Z3_reset_memory(); 60 61 } 62 63 #else tst_memory()64void tst_memory() { 65 } 66 #endif 67