Commit 67155769 authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Improve tests

parent 02fb032a
No related merge requests found
Showing with 62 additions and 8 deletions
+62 -8
CC = clang-with-asan
CFLAGS = -Wall -Wextra -Werror -MMD -fno-sanitize=integer
CFLAGS = -Wall -Wextra -Werror -MMD
ifdef NREADLINE
CFLAGS += -DNREADLINE
......@@ -16,7 +16,7 @@ TESTS_1 = simple_math simple_print algo_fizzbuzz algo_csum algo_join \
long_chain transpose ordered_fractions # champernowne bouncy_numbers
TESTS_2 = $(TESTS_1) dict_ops long_chain_dict tree dict_resize stress_struct
TESTS_3 = $(TESTS_2) self_cycle simple_recursive simple_rep long_loops \
linked_list gc_ref_counts dense_graph compacting
linked_list gc_ref_counts dense_graph compacting gc_tombstones
test: test3
test1: $(TESTS_1:=-result)
......
......@@ -88,6 +88,7 @@ void eval_close() {
free(global_vars[i].name);
}
free(global_vars);
global_vars = NULL;
}
/*!
......
......@@ -120,18 +120,23 @@ static bool integer_eq(value_t *l, value_t *r) {
return integer_cmp(l, r) == 0;
}
__attribute__((no_sanitize("integer")))
static reference_t integer_add(value_t *l, value_t *r) {
return make_reference_int(integer_coerce(l) + integer_coerce(r));
}
__attribute__((no_sanitize("integer")))
static reference_t integer_subtract(value_t *l, value_t *r) {
return make_reference_int(integer_coerce(l) - integer_coerce(r));
}
__attribute__((no_sanitize("integer")))
static reference_t integer_multiply(value_t *l, value_t *r) {
return make_reference_int(integer_coerce(l) * integer_coerce(r));
}
__attribute__((no_sanitize("integer")))
static reference_t integer_divide(value_t *l, value_t *r) {
return make_reference_int(integer_coerce(l) / integer_coerce(r));
}
__attribute__((no_sanitize("integer")))
static reference_t integer_modulo(value_t *l, value_t *r) {
return make_reference_int(integer_coerce(l) % integer_coerce(r));
}
......
......@@ -144,6 +144,8 @@ value_t *deref(reference_t ref) {
/* Make sure the reference's value is within the pool!
* Also ensure that the value is not NULL, indicating an unused reference. */
assert(pool <= (uint8_t *) value && (uint8_t *) value < pool + pool_size);
/* The value should also be aligned to an 8-byte boundary. */
assert((size_t) value % ALIGNMENT == 0);
return value;
}
......@@ -227,5 +229,7 @@ void collect_garbage() {
void refs_close() {
free(pool);
free(ref_table);
pool = NULL;
ref_table = NULL;
}
......@@ -33,7 +33,10 @@ static bool debug = false;
* completion.
*/
bool eval(Node *node) {
assert(node != NULL);
if (node == NULL) {
/* Parsed a comment; nothing to do. */
return true;
}
/* Perform the computation. */
reference_t result = eval_root(node);
......
# -m 10000
# -m 10009
node_one = {"name": "a"}
node_two = {"name": "b"}
......
# -m 10000
# -m 10008
# Simple test: one garbage value refers to non-garbage
non_garbage = 123
......
# -m 10015
d = {0: 0, 1: 1}
# output {0: 0, 1: 1}
print(d)
i = 2
while i <= 40:
d[i] = d[i - 2] + d[i - 1]
del d[i - 2]
i = i + 1
del i
# output 824 bytes in use; 10 refs in use
mem()
# output {39: 63245986, 40: 102334155}
print(d)
gc()
# output 824 bytes in use; 10 refs in use
mem()
del d
# output 72 bytes in use; 3 refs in use
mem()
a = {}
a[True] = a
b = {1: a}
del a
# output {1: {True: {True: {...: ...}}}}
print(b)
# output 584 bytes in use; 10 refs in use
mem()
del b[1]
# output {}
print(b)
# output 552 bytes in use; 9 refs in use
mem()
gc()
# output 312 bytes in use; 6 refs in use
mem()
del b
# output 72 bytes in use; 3 refs in use
mem()
# -m 10000
# -m 10004
a = {"value": 1, "prev": None, "next": None}
b = {"value": True, "prev": a, "next": None}
......
# -m 100000
# -m 100003
# Create three separate cycles
z = {"next": "i am root"}
......
# -m 10000
# -m 10001
a = [0]
a[0] = a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment