Эх сурвалжийг харах

Run unit tests with standard: make check (closes #205, closes #238)

This patch has been developed by Andrey Skvortsov, Michael Heimpold
and Stéphane Raimbault.

- avoid bash'isms and use of GNU find
- terminate server after test run (ignored in TCP mode)
- add *.log, *.trs to .gitignore
- unit-test-client returns 0 on success
- save exit code of unit-test-client for make check status
- replace kill by killall
- add entry in README
Andrey Skvortsov 11 жил өмнө
parent
commit
3f96e18c09

+ 2 - 0
.gitignore

@@ -3,6 +3,8 @@
 *.o
 *.la
 *.lo
+*.log
+*.trs
 .deps
 .libs
 GPATH

+ 2 - 0
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
 ------------
 

+ 4 - 1
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

+ 3 - 1
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

+ 17 - 0
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
+