diff --git a/Makefile b/Makefile index 4a3f169..b1ffdef 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,11 @@ install: libhaggis.a libhaggis.so haggis.h install -m644 libhaggis.a $(libdir)/ install -m644 include/haggis.h $(includedir)/ +test: libhaggis.a + $(MAKE) -C test + clean: rm -rf *.a *.so src/*.o + $(MAKE) -C test clean .PHONY: all clean install diff --git a/include/linklist.h b/include/linklist.h index 496af30..86506b0 100644 --- a/include/linklist.h +++ b/include/linklist.h @@ -33,8 +33,8 @@ #ifndef HAGGIS_LINKLIST #define HAGGIS_LINKLIST -#include -#include +#include // ino_t +#include // pthread_mutex_t struct _haggis_hardlink { struct _haggis_hardlink *next; diff --git a/src/bytes.c b/src/bytes.c index af07dac..6c118ee 100644 --- a/src/bytes.c +++ b/src/bytes.c @@ -30,9 +30,9 @@ * other than his own. */ -#include -#include -#include +#include // __BYTE_ORDER__ / __LITTLE_ENDIAN macros +#include // FILE +#include // uint_t #include "bytes.h" #include "haggis.h" diff --git a/test/Makefile b/test/Makefile index fc90986..a0880e5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -30,4 +30,38 @@ # other than his own. # +CFLAGS += -I../include +LIBS += ../libhaggis.a +LIBS += -lmd +tests += store_device +tests += load_device +total = 2 + +.PHONY: test +test: $(tests) + @printf "\n\tRunning %i tests\n\n" $(total) + @idx=1 ; success=0 ; fail=0; for t in $(tests) ; \ + do printf "[%i/$(total)] \"$${t}\"\t" $${idx} ; \ + idx=$$(expr $${idx} + 1) ; \ + ./$${t} ; \ + if [ $$? -eq 0 ] ; \ + then echo -e '\e[0;32mSuccess\e[0m' ; \ + success=$$(expr $${success} + 1) ; \ + else echo -e '\e[0;31mFailure\e[0m' ; \ + fail=$$(expr $${fail} + 1) ; \ + fi ; done ; \ + printf "\nResults: %i succeeded, %i failed\n" $${success} $${fail} + +output: + @ [-d $@ ] 2>/dev/null || install -d $@ + +store_device: store_device.c haggis_private.h output + $(CC) $(CFLAGS) -o $@ $< $(LIBS) + +load_device: load_device.c haggis_private.h output + $(CC) $(CFLAGS) -o $@ $< $(LIBS) + +.PHONY: clean +clean: + rm -rf $(tests) output/* diff --git a/test/device.c b/test/device.c deleted file mode 100644 index e69de29..0000000 diff --git a/test/load_device.c b/test/load_device.c new file mode 100644 index 0000000..f7b9f5a --- /dev/null +++ b/test/load_device.c @@ -0,0 +1,17 @@ +#include "haggis_private.h" +#include +#include + +int main() { + haggis_device dev; + FILE *f; + int ret; + + f = fopen("output/device", "r"); + ret = haggis_load_device(f, &dev); + fclose(f); + if (ret) return ret; + assert(dev.major.val == 42); + assert(dev.minor.val == 69); + return 0; +} diff --git a/test/store_device.c b/test/store_device.c new file mode 100644 index 0000000..0406e0e --- /dev/null +++ b/test/store_device.c @@ -0,0 +1,15 @@ +#include "haggis_private.h" +#include + +int main() { + haggis_device dev; + FILE *f; + int ret; + + dev.major.val = 42; + dev.minor.val = 69; + f = fopen("output/device", "w"); + ret = haggis_store_device(f, &dev); + fclose(f); + return ret; +} diff --git a/test/store_device.core b/test/store_device.core new file mode 100644 index 0000000..d63ec75 Binary files /dev/null and b/test/store_device.core differ