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
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
+
--- /dev/null
+
+#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
+};
+