Skip to content

Commit

Permalink
Add unit tests for cfarmhash
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikwidlund committed Jan 4, 2017
1 parent c07d7f3 commit 6b8a149
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ test_maps_LDADD = $(CHECK_LDADD)
test_maps_LDFLAGS = $(CHECK_LDFLAGS_EXTRA)
test_maps_SOURCES = test/maps.c test/memory.c

check_PROGRAMS += test/cfarmhash
test_cfarmhash_CFLAGS = $(CHECK_CFLAGS)
test_cfarmhash_LDADD = $(CHECK_LDADD)
test_cfarmhash_LDFLAGS = $(CHECK_LDFLAGS_EXTRA)
test_cfarmhash_SOURCES = test/cfarmhash.c test/memory.c

dist_noinst_SCRIPTS = test/valgrind.sh test/coverage.sh

TESTS = $(check_PROGRAMS) test/coverage.sh test/valgrind.sh
Expand Down
47 changes: 47 additions & 0 deletions test/cfarmhash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <setjmp.h>
#include <cmocka.h>

#include "../src/dynamic/cfarmhash.h"

void core()
{
int i;
struct
{
const char *in;
uint64_t out;
} strings[] = {
{"", 0x9ae16a3b2f90404f},
{"1", 0x811f023a122d0be1},
{"1234", 0xc3fa0b46e8adcae},
{"12345678", 0x2f99d2664a0fb6ea},
{"1234567890123456", 0xef3d9afd22778424},
{"12345678901234567890123456789012", 0xf8317d59683e31b1},
{"1234567890123456789012345678901234567890123456789012345678901234", 0x78a95a0d9788b255},
{"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678", 0x6085a2475352e7f9},
{"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", 0xed4501398023b759},
{NULL, 0}
};

for (i = 0; strings[i].in; i ++)
{
const char *in = strings[i].in;
uint64_t out = strings[i].out;
assert_true(cfarmhash(in, strlen(in)) == out);
}
}

int main()
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(core)
};

return cmocka_run_group_tests(tests, NULL, NULL);
}
2 changes: 1 addition & 1 deletion test/coverage.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

for file in buffer vector string mapi maps
for file in buffer vector string mapi maps cfarmhash
do
echo [$file]
test=`gcov -b src/dynamic/libdynamic_test_a-$file | grep -A4 File.*$file`
Expand Down
2 changes: 1 addition & 1 deletion test/valgrind.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

if command -v valgrind; then
for file in buffer vector string mapi maps
for file in buffer vector string mapi maps cfarmhash
do
echo [$file]
if ! valgrind --error-exitcode=1 --read-var-info=yes --leak-check=full --show-leak-kinds=all test/$file; then
Expand Down

0 comments on commit 6b8a149

Please sign in to comment.