Add test harness and tests
This commit is contained in:
parent
30395e5d7e
commit
5e3ff56921
8 changed files with 75 additions and 5 deletions
4
Makefile
4
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
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
#ifndef HAGGIS_LINKLIST
|
||||
#define HAGGIS_LINKLIST
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/stat.h> // ino_t
|
||||
#include <pthread.h> // pthread_mutex_t
|
||||
|
||||
struct _haggis_hardlink {
|
||||
struct _haggis_hardlink *next;
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
* other than his own.
|
||||
*/
|
||||
|
||||
#include <endian.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <endian.h> // __BYTE_ORDER__ / __LITTLE_ENDIAN macros
|
||||
#include <stdio.h> // FILE
|
||||
#include <stdint.h> // uint<x>_t
|
||||
|
||||
#include "bytes.h"
|
||||
#include "haggis.h"
|
||||
|
|
|
@ -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/*
|
||||
|
|
17
test/load_device.c
Normal file
17
test/load_device.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "haggis_private.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
15
test/store_device.c
Normal file
15
test/store_device.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "haggis_private.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
BIN
test/store_device.core
Normal file
BIN
test/store_device.core
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue