-#vpath %.mak ..
-#vpath %.mk ..
-#vpath %.c ..
-#vpath %.h ..
-
-override CPPFLAGS = -I. -I..
-override USUAL_DIR = ..
-
-override DEFS = -DUSUAL_TEST_CONFIG
SRCS = test_string.c test_crypto.c test_aatree.c test_heap.c \
test_common.c test_list.c tinytest.c test_cbtree.c \
test_utf8.c test_strpool.c test_pgutil.c test_regex.c \
test_cxalloc.c test_bits.c test_base.c test_netdb.c \
test_cfparser.c
-OBJS = $(SRCS:.c=.o)
-
-test-all: regtest.compat
-
-include ../Makefile
-
-hdrs += test_config.h
-
-%.o: %.c $(hdrs)
- @mkdir -p $(USUAL_OBJDIR)
+OBJS = $(addprefix obj/, $(SRCS:.c=.o))
+HDRS = test_common.h test_config.h tinytest.h tinytest_macros.h
+LIBS =
+
+USUAL_DIR = ..
+USUAL_OBJDIR = obj
+USUAL_LOCAL_SRCS = $(SRCS) $(HDRS)
+include $(USUAL_DIR)/Setup.mk
+include ../config.mak
+
+DEFS += -DUSUAL_TEST_CONFIG
+CPPFLAGS += -I.. -I.
+
+hdrs = $(HDRS) $(USUAL_HDRS)
+objs = $(OBJS) $(USUAL_OBJS)
+
+.SUFFIXES:
+
+# Quiet by default, 'make V=1' shows commands
+V=0
+ifeq ($(V), 0)
+Q = @
+E = @echo
+else
+Q =
+E = @true
+endif
+
+all: regtest
+
+obj/%.o: %.c $(hdrs)
+ @mkdir -p obj
$(E) " CC" $<
- $(Q) $(CC) -c -o $@ $(DEFS) $(CPPFLAGS) $(CFLAGS) $<
+ $(Q) $(CC) -c -o $@ $< $(DEFS) $(CFLAGS) $(CPPFLAGS) $(WFLAGS)
+obj/%.o: $(USUAL_DIR)/usual/%.c $(hdrs)
+ @mkdir -p obj
+ $(E) " CC" $<
+ $(Q) $(CC) -c -o $@ $< $(DEFS) $(CFLAGS) $(CPPFLAGS) $(WFLAGS)
-regtest: libusual.a $(OBJS)
+regtest: $(objs)
$(E) " LD" $@
- $(Q) $(CC) -o $@ $(OBJS) -L. -lusual
-
-clean: clean-test
+ $(Q) $(CC) -o $@ $(objs) $(LIBS)
-clean-test:
+clean:
rm -f libusual.a obj/* *.o regtest
rm -f config.test usual/config.h test_config.h
rm -f regtest.compat regtest.system
config.mak: ../config.mak
cp ../config.mak .
-regtest.compat: ../usual/config.h force_compat.sed $(SRCS)
- sed -f force_compat.sed $< > test_config.h
- make regtest
- mv regtest regtest.compat
- mv libusual.a libusual_compat.a
- rm test_config.h
-
-regtest.system: ../usual/config.h $(SRCS)
- cp $< test_config.h
- make regtest
- mv regtest regtest.system
- mv libusual.a libusual_system.a
- rm test_config.h
-
-test: regtest.compat regtest.system
- ./regtest.compat
- ./regtest.system
+test_config.h: ../usual/config.h force_compat.sed
+ $(E) " GEN-COMPAT" $<
+ $(Q) sed -f force_compat.sed $< > test_config.h
+
+sys: ../usual/config.h
+ rm -f test_config.h
+ cp ../usual/config.h test_config.h
+ make
+
+test: regtest
+ ./regtest
+
+vcheck: regtest
+ valgrind --leak-check=full ./regtest
-#include "test_common.h"
+#include <usual/cbtree.h>
-#include <usual/cbtree.c>
+#include <usual/string.h>
+#include "test_common.h"
static char *OK = "OK";
return node;
}
-static void my_node_free(struct MyNode *node)
+static bool my_node_free(void *ctx, void *obj)
{
- free(node);
+ free(obj);
+ return true;
}
/*
cbtree_delete(tree, buf, strlen(buf));
if (cbtree_lookup(tree, buf, strlen(buf)) != NULL)
return "still found";
- my_node_free(my);
return OK;
}
struct CBTree *tree;
int i;
- tree = cbtree_create(my_getkey, NULL, NULL, USUAL_ALLOC);
+ tree = cbtree_create(my_getkey, my_node_free, NULL, USUAL_ALLOC);
str_check(my_search(tree, 1), "not found");
srandom(123123);
memset(is_added, 0, sizeof(is_added));
- tree = cbtree_create(my_getkey, NULL, NULL, USUAL_ALLOC);
+ tree = cbtree_create(my_getkey, my_node_free, NULL, USUAL_ALLOC);
while (total < 100000) {
int r = random() & 15;
+
#include <usual/heap.h>
#include <stdio.h>
#include "test_common.h"
-#include <usual/heap.c>
-
struct MyNode {
int value;
unsigned heap_idx;
return n;
}
+static unsigned _heap_get_child(unsigned i, unsigned child_nr)
+{
+ return 2*i + 1 + child_nr;
+}
+
+static bool _heap_is_better(struct Heap *h, unsigned i1, unsigned i2)
+{
+ return heap_is_better(heap_get_obj(h, i1), heap_get_obj(h, i2));
+}
+
+
/*
* Test tree sanity
*/
unsigned c1 = _heap_get_child(idx, 1);
struct MyNode *n;
const char *res;
+ unsigned used = heap_size(heap);
- if (idx >= heap->used)
+ if (idx >= used)
return OK;
- n = heap->data[idx];
+ n = heap_get_obj(heap, idx);
if (n->heap_idx != idx)
return mkerr("wrong saved idx", idx, i);
- if (c0 < heap->used && _heap_is_better(heap, c0, idx))
+ if (c0 < used && _heap_is_better(heap, c0, idx))
return mkerr("c0 wrong order", idx, i);
- if (c1 < heap->used && _heap_is_better(heap, c1, idx))
+ if (c1 < used && _heap_is_better(heap, c1, idx))
return mkerr("c1 wrong order", idx, i);
res = check_sub(heap, c0, i);
return check(heap, value);
}
-static const char *my_remove(struct Heap *heap, unsigned idx)
+static const char *my_remove(struct Heap *h, unsigned idx)
{
struct MyNode *n;
- if (idx >= heap->used)
+ if (idx >= heap_size(h))
return "NEXIST";
- n = heap->data[idx];
- heap_remove(heap, idx);
+ n = heap_get_obj(h, idx);
+ heap_remove(h, idx);
free(n);
- return check(heap, 0);
+ return check(h, 0);
}
static const char *my_clean(struct Heap *heap)
{
const char *res;
- while (heap->used > 0) {
+ while (heap_size(heap) > 0) {
res = my_remove(heap, 0);
if (res != OK)
return res;
#include <usual/netdb.h>
#include <usual/string.h>
+#include <usual/time.h>
#include "test_common.h"
+static int gotres;
+
+static void cb_func(sigval_t v)
+{
+ gotres++;
+}
static void test_gai(void *p)
{
int res;
struct sigevent sev;
+ struct gaicb req;
+ struct gaicb *rlist[] = { &req };
- memset(&sev, 0, sizeof(sev));
+ memset(&req, 0, sizeof(req));
+ req.ar_name = "localhost";
+ memset(&sev, 0, sizeof(sev));
sev.sigev_notify = SIGEV_THREAD;
+ sev.sigev_notify_function = cb_func;
- res = getaddrinfo_a(GAI_NOWAIT, NULL, 0, &sev);
-
+ res = getaddrinfo_a(GAI_NOWAIT, rlist, 1, &sev);
int_check(res, 0);
+
+ while (gai_error(&req) == EAI_INPROGRESS || gotres == 0)
+ usleep(10000);
+
+ int_check(gai_error(&req), 0);
+
+ freeaddrinfo(req.ar_result);
+
+ int_check(gotres, 1);
end:;
}
static const char *run_basename(const char *path)
{
- char buf[128];
+ static char buf[128];
const char *res;
if (!path)
- return basename(path);
+ return basename(NULL);
strlcpy(buf, path, sizeof(buf));
res = basename(buf);
if (strcmp(buf, path) != 0)
static const char *run_dirname(const char *path)
{
- char buf[128];
+ static char buf[128];
const char *res;
if (!path)
- return dirname(path);
+ return dirname(NULL);
strlcpy(buf, path, sizeof(buf));
res = dirname(buf);
if (strcmp(buf, path) != 0)