Skip to content

Commit

Permalink
Improve fuzz testing with a fake malloc and CI compat
Browse files Browse the repository at this point in the history
Debugging CI

Debugging CI #2

Debugging CI #3

Debugging CI #4

Debugging CI #5

Debugging CI #6
  • Loading branch information
PJK committed May 30, 2015
1 parent 40e71a9 commit 3371385
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ before_install:
matrix:
include:
- compiler: clang
env: CUSTOM_ALLOC=ON
- compiler: clang
env: CUSTOM_ALLOC=OFF
- compiler: gcc
env: CUSTOM_ALLOC=OFF

script:
- export SOURCE=$(pwd) && ./buildscript.sh
Expand Down
2 changes: 1 addition & 1 deletion buildscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd $SOURCE
cppcheck . --error-exitcode=1 --suppressions cppcheck_suppressions.txt --force
cd $PREVD

cmake $SOURCE -DCUSTOM_ALLOC=$CUSTOM_ALLOC -DCMAKE_BUILD_TYPE=Debug
cmake $SOURCE -DCUSTOM_ALLOC=ON -DCMAKE_BUILD_TYPE=Debug
make VERBOSE=1
ctest -V

Expand Down
14 changes: 14 additions & 0 deletions test/fuzz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ static void printmem(const unsigned char * ptr, size_t length)

unsigned seed;

#ifdef CBOR_CUSTOM_ALLOC
void *mock_malloc(size_t size)
{
if (size > (1 << 19))
return NULL;
else
return malloc(size);
}
#endif

static void run_round()
{
cbor_item_t *item;
Expand All @@ -64,6 +74,10 @@ static void run_round()

static void fuzz(void **state)
{

#ifdef CBOR_CUSTOM_ALLOC
cbor_set_allocs(mock_malloc, realloc, free);
#endif
printf(
"Fuzzing %llu rounds of up to %llu bytes with seed %u\n",
ROUNDS,
Expand Down

0 comments on commit 3371385

Please sign in to comment.