Current location

narf Source control manager Git

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Mehani <shtrom@ssji.net>2019-07-12 17:20:11 +1000
committerOlivier Mehani <shtrom@ssji.net>2019-07-12 17:30:41 +1000
commite05e2c36e10767f530df45d338d81386b1c1b81f (patch)
treec030cde0b5c5a727b8cb6ba998f8d408286b4801
parent6b87fe78ceba6789e3da5d1fa7a4f39f4504b646 (diff)
Add some sort of integration test
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
-rw-r--r--.gitignore2
-rw-r--r--Makefile37
-rw-r--r--rfc6555_test.c28
-rw-r--r--test.c21
4 files changed, 61 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index ebf999d..f1b207d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
*.o
connect_*
-test
+rfc6555_test
diff --git a/Makefile b/Makefile
index 3cb3020..2fecbfe 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,13 @@
+CFLAGS+=-Wall
+
+TESTPORT=1025
+
TARGETS = \
connect_gai \
connect_rfc6555 \
connect_rfc6555_min \
- test \
# end
-
-CFLAGS+=-Wall
+TEST_TARGETS = $(addprefix test-,$(TARGETS))
all: $(TARGETS)
@@ -14,9 +16,34 @@ connect_%: main.o %.o
connect_rfc6555_min: rfc6555_lib.o
-test: CFLAGS+=-g
-test: rfc6555_lib.o
+rfc6555_test: CFLAGS+=-g
+rfc6555_test: rfc6555_lib.o
+
+test%: CFLAGS+=-g
+test: test-unit test-integration
+
+test-unit: rfc6555_test
+ ./rfc6555_test
+
+test-integration: test-up $(TEST_TARGETS) test-down
+test-up:
+ -sudo iptables -I INPUT -p tcp --dport $(TESTPORT) -j ACCEPT
+ -sudo ip6tables -I INPUT -p tcp --dport $(TESTPORT) -j DROP
+ yes | nc -4klp $(TESTPORT) &
+test-down:
+ killall -9 nc # XXX: dodgy
+ -sudo ip6tables -D INPUT -p tcp --dport $(TESTPORT) -j DROP
+ -sudo iptables -D INPUT -p tcp --dport $(TESTPORT) -j ACCEPT
+test-%: %
+ ./$(*) localhost $(TESTPORT)
clean:
rm -f *.o
+ rm -f rfc6555_test
rm -f $(TARGETS)
+
+.PHONY: all \
+ test test-unit \
+ test-integration test-up test-down \
+ # $(TEST_TARGETS) \ # For some reason, those don't run if PHONY
+ # end
diff --git a/rfc6555_test.c b/rfc6555_test.c
new file mode 100644
index 0000000..45ba53a
--- /dev/null
+++ b/rfc6555_test.c
@@ -0,0 +1,28 @@
+#include <assert.h>
+#include <malloc.h>
+
+#include "rfc6555.h"
+
+void test_context();
+
+int main() {
+ test_context();
+}
+
+#define MIN_CTX_LEN 4 /* Copied from the implementation */
+
+void test_context() {
+ rfc6555_ctx *ctx;
+
+ ctx = rfc6555_context_create();
+ assert(ctx != NULL);
+ assert(malloc_usable_size(ctx) >= sizeof(rfc6555_ctx));
+ assert(ctx->fds != NULL);
+ assert(malloc_usable_size(ctx->fds) >= MIN_CTX_LEN * sizeof(int));
+ assert(ctx->original_flags != NULL);
+ assert(malloc_usable_size(ctx->original_flags) >= MIN_CTX_LEN * sizeof(int));
+ assert(ctx->rps != NULL);
+ assert(malloc_usable_size(ctx->rps) >= MIN_CTX_LEN * sizeof(struct addrinfo*));
+
+ rfc6555_context_destroy(ctx);
+}
diff --git a/test.c b/test.c
deleted file mode 100644
index e1a8919..0000000
--- a/test.c
+++ /dev/null
@@ -1,21 +0,0 @@
-#include <assert.h>
-
-#include "rfc6555.h"
-
-void test_context();
-
-int main() {
- test_context();
-}
-
-void test_context() {
- rfc6555_ctx *ctx;
-
- ctx = rfc6555_context_create();
- assert(ctx != NULL);
- assert(ctx->fds != NULL);
- assert(ctx->original_flags != NULL);
- assert(ctx->rps != NULL);
-
- rfc6555_context_destroy(ctx);
-}