aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/convey.c66
-rw-r--r--tests/convey.h13
-rw-r--r--tests/inproc.c5
-rw-r--r--tests/ipc.c4
-rw-r--r--tests/tcp.c18
-rw-r--r--tests/trantest.h27
7 files changed, 123 insertions, 14 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index fe58c602..8d64796e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -46,9 +46,9 @@ if (NNG_TESTS)
target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}")
endif()
- add_test (NAME ${NAME} COMMAND ${NAME} -v ${TEST_PORT})
+ add_test (NAME ${NAME} COMMAND ${NAME} -v -p TEST_PORT=${TEST_PORT})
set_tests_properties (${NAME} PROPERTIES TIMEOUT ${TIMEOUT})
- math (EXPR TEST_PORT "${TEST_PORT}+10")
+ math (EXPR TEST_PORT "${TEST_PORT}+20")
endmacro (add_nng_test)
macro (add_nng_compat_test NAME TIMEOUT)
diff --git a/tests/convey.c b/tests/convey.c
index a4d38a85..4260a65d 100644
--- a/tests/convey.c
+++ b/tests/convey.c
@@ -973,6 +973,52 @@ convey_nextline(char **next)
return (line);
}
+static struct convey_env {
+ struct convey_env *next;
+ const char *name;
+ char *value;
+} *convey_environment;
+
+static struct convey_env *
+conveyFindEnv(const char *name)
+{
+ struct convey_env *ev;
+ for (ev = convey_environment; ev != NULL; ev = ev->next) {
+ if (strcmp(name, ev->name) == 0) {
+ return (ev);
+ }
+ }
+ return (NULL);
+}
+
+char *
+conveyGetEnv(const char *name)
+{
+ struct convey_env *ev;
+
+ if ((ev = conveyFindEnv(name)) != NULL) {
+ return (ev->value);
+ }
+ return (getenv(name));
+}
+
+int
+conveyPutEnv(const char *name, char *value)
+{
+ struct convey_env *env;
+
+ if ((env = conveyFindEnv(name)) == NULL) {
+ env = malloc(sizeof (*env));
+ if (env == NULL) {
+ return (-1);
+ }
+ env->next = convey_environment;
+ convey_environment = env;
+ }
+ env->name = name;
+ env->value = value;
+ return (0);
+}
int
conveyMain(int argc, char **argv)
@@ -982,6 +1028,7 @@ conveyMain(int argc, char **argv)
const char *prog;
struct convey_timer pc;
int secs, usecs;
+ struct convey_env *env;
if ((argc > 0) && (argv[0] != NULL)) {
prog = argv[0];
@@ -999,9 +1046,22 @@ conveyMain(int argc, char **argv)
}
if (strcmp(argv[i], "-v") == 0) {
ConveySetVerbose();
+ continue;
}
if (strcmp(argv[i], "-d") == 0) {
convey_debug++;
+ continue;
+ }
+ if ((strcmp(argv[i], "-p") == 0) && ((i + 1) < argc)) {
+ char *delim;
+ if ((delim = strchr(argv[i+1], '=')) != NULL) {
+ *delim = '\0';
+ conveyPutEnv(argv[i+1], delim+1);
+ } else {
+ conveyPutEnv(argv[i+1], "");
+ }
+ i++;
+ continue;
}
}
if (ConveyInit() != 0) {
@@ -1038,7 +1098,11 @@ conveyMain(int argc, char **argv)
break;
}
- convey_read_timer(&pc, &secs, &usecs);
(void) printf("%-8s%-52s%4d.%03ds\n", status, prog, secs, usecs / 1000);
+ while ((env = convey_environment) != NULL) {
+ convey_environment = env->next;
+ free(env);
+ }
+ convey_read_timer(&pc, &secs, &usecs);
exit(i);
}
diff --git a/tests/convey.h b/tests/convey.h
index bb52ad7d..d367cfcc 100644
--- a/tests/convey.h
+++ b/tests/convey.h
@@ -80,6 +80,8 @@ extern int conveyStart(conveyScope *, const char *);
extern int conveyLoop(conveyScope *, int);
extern void conveyFinish(conveyScope *, int *);
extern int conveyMain(int, char **);
+extern char *conveyGetEnv(const char *);
+extern int conveyPutEnv(const char *, char *);
extern void conveyAssertPass(const char *, const char *, int);
extern void conveyAssertSkip(const char *, const char *, int);
@@ -168,6 +170,17 @@ extern void conveyPrintf(const char *, int, const char *, ...);
}
/*
+ * ConveyGetEnv is used to get environment variables, which can be
+ * overridden with -p <name>=<value> on the command line.
+ */
+#define ConveyGetEnv(name) conveyGetEnv(name)
+
+/*
+ * ConveyPutEnv is used to change environment variables. This is not
+ * thread safe!
+ */
+#define ConveyPutEnv(name, value) conveyPutEnv(name, value)
+/*
* ConveyTest creates a top-level test instance, which can contain multiple
* Convey blocks.
*/
diff --git a/tests/inproc.c b/tests/inproc.c
index 2afb1ae0..3ab52639 100644
--- a/tests/inproc.c
+++ b/tests/inproc.c
@@ -1,5 +1,6 @@
//
-// Copyright 2016 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -14,6 +15,6 @@
// Inproc tests.
TestMain("Inproc Transport", {
- trantest_test_all("inproc://TEST");
+ trantest_test_all("inproc://TEST_%u");
nni_fini();
})
diff --git a/tests/ipc.c b/tests/ipc.c
index d8752a70..54996ee3 100644
--- a/tests/ipc.c
+++ b/tests/ipc.c
@@ -1,5 +1,6 @@
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -10,11 +11,10 @@
#include "convey.h"
#include "trantest.h"
-
// Inproc tests.
TestMain("IPC Transport", {
- trantest_test_all("ipc:///tmp/nng_ipc_test");
+ trantest_test_all("ipc:///tmp/nng_ipc_test_%u");
nng_fini();
})
diff --git a/tests/tcp.c b/tests/tcp.c
index 3910cb7f..58c9bca7 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -1,5 +1,6 @@
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -14,29 +15,34 @@
TestMain("TCP Transport", {
- trantest_test_all("tcp://127.0.0.1:4450");
+ trantest_test_all("tcp://127.0.0.1:%u");
Convey("We cannot connect to wild cards", {
nng_socket s;
+ char addr[NNG_MAXADDRLEN];
So(nng_pair_open(&s) == 0);
Reset({ nng_close(s); });
- So(nng_dial(s, "tcp://*:5555", NULL, NNG_FLAG_SYNCH) ==
- NNG_EADDRINVAL);
+ trantest_next_address(addr, "tcp://*:%u");
+ So(nng_dial(s, addr, NULL, NNG_FLAG_SYNCH) == NNG_EADDRINVAL);
});
Convey("We can bind to wild card", {
nng_socket s1;
nng_socket s2;
+ char addr[NNG_MAXADDRLEN];
+
So(nng_pair_open(&s1) == 0);
So(nng_pair_open(&s2) == 0);
Reset({
nng_close(s2);
nng_close(s1);
});
- So(nng_listen(s1, "tcp://*:5771", NULL, NNG_FLAG_SYNCH) == 0);
- So(nng_dial(
- s2, "tcp://127.0.0.1:5771", NULL, NNG_FLAG_SYNCH) == 0);
+ trantest_next_address(addr, "tcp://*:%u");
+ So(nng_listen(s1, addr, NULL, NNG_FLAG_SYNCH) == 0);
+ // reset port back one
+ trantest_prev_address(addr, "tcp://127.0.0.1:%u");
+ So(nng_dial(s2, addr, NULL, NNG_FLAG_SYNCH) == 0);
});
nng_fini();
diff --git a/tests/trantest.h b/tests/trantest.h
index 173c6b45..74e533bf 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -11,6 +11,7 @@
#include "convey.h"
#include "core/nng_impl.h"
#include "nng.h"
+#include <stdlib.h>
#include <string.h>
// Transport common tests. By making a common test framework for transports,
@@ -25,10 +26,34 @@ typedef struct {
nni_tran * tran;
} trantest;
+unsigned trantest_port = 0;
+
+void
+trantest_next_address(char *out, const char *template)
+{
+ if (trantest_port == 0) {
+ char *pstr;
+ trantest_port = 5555;
+ if (((pstr = ConveyGetEnv("TEST_PORT")) != NULL) &&
+ (atoi(pstr) != 0)) {
+ trantest_port = atoi(pstr);
+ }
+ }
+ (void) snprintf(out, NNG_MAXADDRLEN, template, trantest_port);
+ trantest_port++;
+}
+
+void
+trantest_prev_address(char *out, const char *template)
+{
+ trantest_port--;
+ trantest_next_address(out, template);
+}
+
void
trantest_init(trantest *tt, const char *addr)
{
- (void) snprintf(tt->addr, sizeof(tt->addr), "%s", addr);
+ trantest_next_address(tt->addr, addr);
So(nng_req_open(&tt->reqsock) == 0);
So(nng_rep_open(&tt->repsock) == 0);