diff --git a/.gitignore b/.gitignore index 24c2ff2..1068a47 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ *.o *.la *.lo +*.log +*.trs .deps .libs GPATH diff --git a/README.md b/README.md index f917a46..c304024 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,8 @@ For a quick test of libmodbus, you can run the following programs in two shells: By default, all TCP unit tests will be executed (see --help for options). +It's also possible to run the unit tests with `make check`. + Report a Bug ------------ diff --git a/tests/Makefile.am b/tests/Makefile.am index 4f18f34..4d469ef 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,4 +46,7 @@ AM_CPPFLAGS = \ AM_CFLAGS = ${my_CFLAGS} -CLEANFILES = *~ +CLEANFILES = *~ *.log + +noinst_SCRIPTS=unit-tests.sh +TESTS=./unit-tests.sh diff --git a/tests/unit-test-client.c b/tests/unit-test-client.c index ad90b5e..8e42aca 100644 --- a/tests/unit-test-client.c +++ b/tests/unit-test-client.c @@ -57,6 +57,7 @@ int main(int argc, char *argv[]) uint32_t old_byte_to_sec; uint32_t old_byte_to_usec; int use_backend; + int success = FALSE; if (argc > 1) { if (strcmp(argv[1], "tcp") == 0) { @@ -600,6 +601,7 @@ int main(int argc, char *argv[]) ASSERT_TRUE(ctx == NULL && errno == EINVAL, ""); printf("\nALL TESTS PASS WITH SUCCESS.\n"); + success = TRUE; close: /* Free the memory */ @@ -610,7 +612,7 @@ close: modbus_close(ctx); modbus_free(ctx); - return 0; + return (success) ? 0 : -1; } /* Send crafted requests to test server resilience diff --git a/tests/unit-tests.sh b/tests/unit-tests.sh new file mode 100755 index 0000000..9fd387e --- /dev/null +++ b/tests/unit-tests.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +client_log=unit-test-client.log +server_log=unit-test-server.log + +rm -f $client_log $server_log + +echo "Starting server" +./unit-test-server > $server_log 2>&1 & + +echo "Starting client" +./unit-test-client > $client_log 2>&1 +rc=$? + +killall unit-test-server +exit $rc +