Skip to content

Commit

Permalink
Skip to avoid numeric values of 0 for set items. (katef#72)
Browse files Browse the repository at this point in the history
Skip tests to avoid numeric values of 0 for set items.

These are disallowed by the set API since it depends on returning `NULL` for errors.
  • Loading branch information
katef authored Sep 26, 2017
1 parent c3b295b commit f2750d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
18 changes: 14 additions & 4 deletions fuzz/fuzz_adt_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ cmp_item(const void *pa, const void *pb)
uintptr_t a = (uintptr_t) pa;
uintptr_t b = (uintptr_t) pb;

assert(pa != NULL);
assert(pb != NULL);

return a < b ? -1 : a > b ? 1 : 0;
}

Expand Down Expand Up @@ -134,8 +137,11 @@ theft_trial_res prop_set_equality(struct theft *t, void *arg1)
set_b = set_create(cmp_item);

for (i = 0; i < seq->count; i++) {
(void) set_add(&set_a, (void *) (uintptr_t) seq->values[i]); /* XXX */
(void) set_add(&set_b, (void *) (uintptr_t) permuted[i]);
assert(seq->values[i] != 0);
assert(permuted[i] != 0);

(void) set_add(&set_a, (void *) ((uintptr_t) seq->values[i])); /* XXX */
(void) set_add(&set_b, (void *) ((uintptr_t) permuted[i]));
}

if (!set_equal(set_a, set_b)) {
Expand Down Expand Up @@ -176,7 +182,9 @@ op_add(struct model *m, struct set_op *op, struct set **set)

old_s = *set;

(void) set_add(set, (void *) op->u.add.item); /* XXX */
assert(op->u.add.item != 0);

(void) set_add(set, (void *) ((uintptr_t) op->u.add.item)); /* XXX */

if (m->env->verbosity > 0) {
fprintf(stderr, "ITEM IS %zu (decimal)\n", (size_t) op->u.add.item);
Expand All @@ -200,7 +208,9 @@ op_remove(struct model *m, struct set_op *op, struct set **set)

old_s = *set;

set_remove(set, (void *) op->u.remove.item);
assert(op->u.remove.item != 0);

set_remove(set, (void *) ((uintptr_t) op->u.remove.item));

if (m->env->verbosity > 0) {
fprintf(stderr, "REMOVE 0x%" PRIxPTR " to %p => %p\n",
Expand Down
21 changes: 21 additions & 0 deletions fuzz/type_info_adt_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ alloc_scen(struct theft *t, void *type_env, void **output)
switch (op->t) {
case SET_OP_ADD:
op->u.add.item = theft_random_bits(t, env->item_bits);
if (op->u.add.item == 0) {
goto skip;
}
break;

case SET_OP_REMOVE:
op->u.remove.item = theft_random_bits(t, env->item_bits);
if (op->u.remove.item == 0) {
goto skip;
}
break;

case SET_OP_CLEAR:
Expand All @@ -63,6 +69,12 @@ alloc_scen(struct theft *t, void *type_env, void **output)
*output = res;

return THEFT_ALLOC_OK;

skip:

free(res);

return THEFT_ALLOC_SKIP;
}

static void
Expand Down Expand Up @@ -136,11 +148,20 @@ alloc_seq(struct theft *t, void *type_env, void **output)

for (size_t i = 0; i < count; i++) {
res->values[i] = theft_random_bits(t, 16);
if (res->values[i] == 0) {
goto skip;
}
}

*output = res;

return THEFT_ALLOC_OK;

skip:

free(res);

return THEFT_ALLOC_SKIP;
}

static void
Expand Down

0 comments on commit f2750d7

Please sign in to comment.