test/: base tests, test both compat and system code
authorMarko Kreen <markokr@gmail.com>
Sat, 9 Oct 2010 12:03:44 +0000 (15:03 +0300)
committerMarko Kreen <markokr@gmail.com>
Tue, 12 Oct 2010 10:50:41 +0000 (13:50 +0300)
test/Makefile
test/attregex/Makefile
test/test_base.c [new file with mode: 0644]
test/test_common.c
test/test_common.h

index 9573811e7d81b303feb5ab1d6709c689121d3247..869b066aeee98cfc17b054896c4f8106754ebcbf 100644 (file)
@@ -12,24 +12,21 @@ override DEFS = -DUSUAL_TEST_CONFIG
 OBJS = test_string.o test_crypto.o test_aatree.o test_heap.o \
        test_common.o test_list.o tinytest.o test_cbtree.o \
        test_utf8.o test_strpool.o test_pgutil.o test_regex.o \
-       test_cxalloc.o test_bits.o
+       test_cxalloc.o test_bits.o test_base.o
 
-test-all: regtest
+test-all: test
 
 include ../Makefile
 
+hdrs += test_config.h
+
 %.o: %.c $(hdrs)
        @mkdir -p $(USUAL_OBJDIR)
        $(E) "  CC" $<
        $(Q) $(CC) -c -o $@ $(DEFS) $(CPPFLAGS) $(CFLAGS) $<
 
 
-test_config.h: ../usual/config.h force_compat.sed
-       sed -f force_compat.sed $< > $@
-
-#libusual.a: test_config.h
-
-regtest: test_config.h libusual.a $(OBJS)
+regtest: libusual.a $(OBJS)
        $(E) "  LD" $@
        $(Q) $(CC) -o $@ $(OBJS) -L. -lusual
 
@@ -38,6 +35,27 @@ clean: clean-test
 clean-test:
        rm -f libusual.a obj/* *.o regtest
        rm -f config.test usual/config.h test_config.h
+       rm -f regtest.compat regtest.system
+       rm -f libusual_compat.a libusual_system.a
 
 config.mak: ../config.mak
        cp ../config.mak .
+
+regtest.compat: ../usual/config.h force_compat.sed
+       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
+       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
+
index 6a11bf13bd14ea4df022d0fb6d7c8129bb724842..31287f67f69a2a7db79160e6e7116d8fc4d48019 100644 (file)
@@ -4,7 +4,7 @@ CFLAGS = -O -g
 CPPFLAGS = -I../..
 DEFS = -DUSUAL -DUSE_INTERNAL_REGEX
 LDFLAGS = -g
-LIBS = ../libusual.a
+LIBS = ../libusual_compat.a
 
 all: testregex.usual testregex.libc
 
diff --git a/test/test_base.c b/test/test_base.c
new file mode 100644 (file)
index 0000000..06023b7
--- /dev/null
@@ -0,0 +1,78 @@
+
+#include <usual/base.h>
+
+#include "test_common.h"
+
+#include <string.h>
+
+struct somestruct {
+       char a, b, c;
+};
+
+static void test_ptr(void *p)
+{
+       /* offsetof */
+       int_check(offsetof(struct somestruct, a), 0);
+       int_check(offsetof(struct somestruct, b), 1);
+       int_check(offsetof(struct somestruct, c), 2);
+
+       /* container_of */
+       {
+               struct somestruct s = {'a', 'b', 'c'};
+               char *pa = &s.a;
+               char *pb = &s.b;
+               char *pc = &s.c;
+               struct somestruct *sa, *sb, *sc;
+               sa = container_of(pa, struct somestruct, a);
+               sb = container_of(pb, struct somestruct, b);
+               sc = container_of(pc, struct somestruct, c);
+               int_check(sa->a, 'a');
+               int_check(sb->b, 'b');
+               int_check(sc->c, 'c');
+       }
+
+       /* alignof */
+       int_check(alignof(char), 1);
+       int_check(alignof(short), 2);
+       int_check(alignof(int), 4);
+
+       /* CUSTOM_ALIGN */
+       int_check(CUSTOM_ALIGN(1, 4), 4);
+       int_check(CUSTOM_ALIGN(2, 4), 4);
+       int_check(CUSTOM_ALIGN(3, 4), 4);
+       int_check(CUSTOM_ALIGN(4, 4), 4);
+       int_check(CUSTOM_ALIGN(5, 4), 8);
+end:;
+}
+
+struct packed {
+       char a;
+       int b;
+       char c;
+       short d;
+} _PACKED;
+
+static void test_misc(void *_p)
+{
+       int i_4[4];
+       int i_2[2];
+       short s_4[4];
+       short s_2[2];
+
+       int_check(ARRAY_NELEM(i_4), 4);
+       int_check(ARRAY_NELEM(i_2), 2);
+       int_check(ARRAY_NELEM(s_4), 4);
+       int_check(ARRAY_NELEM(s_2), 2);
+
+       int_check(strcmp(__func__, "test_misc"), 0);
+
+       int_check(sizeof(struct packed), 8);
+end:;
+}
+
+struct testcase_t base_tests[] = {
+       { "ptr", test_ptr },
+       { "misc", test_misc },
+       END_OF_TESTCASES
+};
+
index c176397d9f6cf064a7c705057243056c4cad34c5..4d48b21feaa7c35974967c05a404e97e2e71024f 100644 (file)
@@ -3,6 +3,7 @@
 #include "test_common.h"
 
 struct testgroup_t groups[] = {
+       { "base/", base_tests },
        { "aatree/", aatree_tests },
        { "bits/", bits_tests },
        { "cxalloc/", cxalloc_tests },
index 6ba09f1734b8281141ca96095dac8f15b61fd030..12144db2cb387042615c23b74f52d875830b651f 100644 (file)
@@ -20,4 +20,5 @@ extern struct testcase_t pgutil_tests[];
 extern struct testcase_t regex_tests[];
 extern struct testcase_t cxalloc_tests[];
 extern struct testcase_t bits_tests[];
+extern struct testcase_t base_tests[];