Skip to content

Commit 562755a

Browse files
committed
add minimal test
1 parent 62d59d2 commit 562755a

File tree

6 files changed

+89
-24
lines changed

6 files changed

+89
-24
lines changed

Makefile.am

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
bin_PROGRAMS = hardhat mkhardhat
2-
hardhat_SOURCES = src/hardhat.c
3-
hardhat_LDADD = libhardhat.la
4-
mkhardhat_SOURCES = src/mkhardhat.c
5-
mkhardhat_LDADD = libhardhat.la
1+
bin_PROGRAMS = bin/hardhat bin/mkhardhat
2+
bin_hardhat_SOURCES = src/hardhat.c
3+
bin_hardhat_LDADD = lib/libhardhat.la
4+
bin_mkhardhat_SOURCES = src/mkhardhat.c
5+
bin_mkhardhat_LDADD = lib/libhardhat.la
66

7-
lib_LTLIBRARIES = libhardhat.la
8-
libhardhat_la_SOURCES = src/hashtable.c src/hashtable.h src/layout.h src/maker.c src/maker.h src/reader.c src/reader.h src/murmur3.c src/murmur3.h src/readerimpl.h
9-
libhardhat_la_LDFLAGS = -Wl,--version-script,$(srcdir)/libhardhat.ver
10-
libhardhat_la_LIBADD = -lrt
7+
noinst_PROGRAMS = tests/hardhat
8+
tests_hardhat_SOURCES = tests/hardhat.c
9+
tests_hardhat_LDADD = lib/libhardhat.la
10+
11+
LOG_DRIVER = AM_TAP_AWK='$(AWK)' $(top_srcdir)/tests/log-driver
12+
TESTS = tests/hardhat
13+
14+
lib_LTLIBRARIES = lib/libhardhat.la
15+
lib_libhardhat_la_SOURCES = src/hashtable.c src/hashtable.h src/layout.h src/maker.c src/maker.h src/reader.c src/reader.h src/murmur3.c src/murmur3.h src/readerimpl.h
16+
lib_libhardhat_la_LDFLAGS = -Wl,--version-script,$(srcdir)/libhardhat.ver
17+
lib_libhardhat_la_LIBADD = -lrt
1118

1219
hh_HEADERS = src/layout.h src/reader.h src/hashtable.h src/maker.h
1320
hhdir = $(pkgincludedir)

configure.ac

+3-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
AC_INIT(hardhat, 1.1.5, [email protected])
44
AM_INIT_AUTOMAKE([foreign subdir-objects dist-xz no-dist-gzip])
55

6+
AC_CONFIG_MACRO_DIR([m4])
67
AC_CONFIG_SRCDIR([src/hardhat.c])
78
AC_CONFIG_HEADERS([src/config.h])
89

@@ -37,24 +38,11 @@ AC_CHECK_LIB(rt, clock_gettime, [true], [
3738
AC_CHECK_FUNCS([fpurge __fpurge fileno], [break])
3839
AC_CHECK_HEADERS([stdio_ext.h])
3940

40-
AC_DEFUN([MY_GCC_BUILTIN], [
41-
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_builtin_$1])
42-
43-
AC_CACHE_CHECK([for __builtin_$1], [ac_var], [
44-
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [__builtin_$1($2)])],
45-
[AS_VAR_SET([ac_var], [yes])], [AS_VAR_SET([ac_var], [no])])
46-
])
47-
48-
case AS_VAR_GET([ac_var]) in yes)
49-
AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_BUILTIN_$1), 1, [has GCC __builtin_$1 function])
50-
esac
51-
52-
AS_VAR_POPDEF([ac_var])
53-
])
54-
5541
MY_GCC_BUILTIN(bswap16, 0)
5642
MY_GCC_BUILTIN(bswap32, 0)
5743
MY_GCC_BUILTIN(bswap64, 0)
5844

45+
AC_REQUIRE_AUX_FILE([tap-driver.sh])
46+
5947
AC_CONFIG_FILES([Makefile])
6048
AC_OUTPUT

m4/gcc-builtin.m4

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
AC_DEFUN([MY_GCC_BUILTIN], [
2+
AS_VAR_PUSHDEF([ac_var], [ax_cv_have_builtin_$1])
3+
4+
AC_CACHE_CHECK([for __builtin_$1], [ac_var], [
5+
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [__builtin_$1($2)])],
6+
[AS_VAR_SET([ac_var], [yes])], [AS_VAR_SET([ac_var], [no])])
7+
])
8+
9+
case AS_VAR_GET([ac_var]) in yes)
10+
AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_BUILTIN_$1), 1, [has GCC __builtin_$1 function])
11+
esac
12+
13+
AS_VAR_POPDEF([ac_var])
14+
])

src/maker.c

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static size_t pad4k(size_t x) {
231231
return -x % 4096;
232232
}
233233

234+
__attribute__((unused))
234235
static size_t adaptive_padding(size_t offset, size_t length, size_t elsize, size_t pagesize) {
235236
size_t align = -offset % elsize;
236237
offset += align;

tests/hardhat.c

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <stdio.h>
2+
#include <inttypes.h>
3+
#include <stdbool.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
7+
#include "reader.h"
8+
#include "maker.h"
9+
10+
static unsigned int testcounter;
11+
12+
static void tap(bool test, const char *description) {
13+
testcounter++;
14+
printf("%s %u - %s\n", test ? "ok" : "not ok", testcounter, description);
15+
}
16+
17+
static void bail(const char *description) {
18+
printf("Bailing out! %s\n", description);
19+
exit(1);
20+
}
21+
22+
int main(void) {
23+
char *filename;
24+
const char *tmpdir;
25+
hardhat_maker_t *hhm;
26+
27+
tmpdir = getenv("TMPDIR");
28+
if(!tmpdir) bail("no $TMPDIR set");
29+
30+
filename = malloc(strlen(tmpdir) + 20);
31+
if(!filename) bail("no memory");
32+
33+
sprintf(filename, "%s/test.hh", tmpdir);
34+
hhm = hardhat_maker_new(filename);
35+
if(!hhm) bail("no hardhat_maker object");
36+
37+
tap(true, "able to create a hardhat_maker");
38+
39+
tap(hardhat_maker_finish(hhm), "close the hardhat_maker # TODO");
40+
41+
hardhat_maker_free(hhm);
42+
43+
printf("1..%u\n", testcounter);
44+
return 0;
45+
}

tests/log-driver

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
tmp=$(mktemp -d)
6+
trap 'rm -rf -- "$tmp"' EXIT QUIT INT HUP TERM
7+
8+
export TMPDIR=$tmp
9+
10+
sh tap-driver.sh "$@"

0 commit comments

Comments
 (0)