Skip to content

Commit

Permalink
Add test for malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
krtab committed Jan 25, 2024
1 parent ee66c6a commit c89c234
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/owic/stdlib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(rule
(alias runtest)
(deps
malloc_aligned.c
%{bin:owi}
(package owi)
)
(action
(run dune exec owi -- c ./malloc_aligned.c)
)
)
27 changes: 27 additions & 0 deletions test/owic/stdlib/malloc_aligned.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <owi.h>
#include <stdlib.h>

void arbitrary_pre_align() {
int s = owi_i32();
owi_assume(s >= 0);
owi_assume(s < 8);
for (int i = 0; i < s; i++) {
malloc(1);
}
}

int main() {
malloc(1024);
arbitrary_pre_align();
for (int p = 0; p < 10; p++) {
int low_pow = (1 << p);
for (int i = low_pow; i < 2*low_pow; i++) {
void * ptr = malloc(i);
if (low_pow < 16) {
owi_assert((int) ptr % low_pow == 0);
} else {
owi_assert((int) ptr % 16 == 0);
}
}
}
}

0 comments on commit c89c234

Please sign in to comment.