Add test harness and tests

This commit is contained in:
Nathan Fisher 2023-08-09 11:41:06 -04:00
parent 30395e5d7e
commit 5e3ff56921
8 changed files with 75 additions and 5 deletions

View file

@ -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

View file

@ -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;

View file

@ -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"

View file

@ -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/*

View file

17
test/load_device.c Normal file
View 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
View 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

Binary file not shown.