Commit 3f96e18c09be604e992b640e61e4d8b9ec24e646
Committed by
Stéphane Raimbault
1 parent
e98fd68c
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
Showing
5 changed files
with
28 additions
and
2 deletions
.gitignore
README.md
| ... | ... | @@ -77,6 +77,8 @@ For a quick test of libmodbus, you can run the following programs in two shells: |
| 77 | 77 | |
| 78 | 78 | By default, all TCP unit tests will be executed (see --help for options). |
| 79 | 79 | |
| 80 | +It's also possible to run the unit tests with `make check`. | |
| 81 | + | |
| 80 | 82 | Report a Bug |
| 81 | 83 | ------------ |
| 82 | 84 | ... | ... |
tests/Makefile.am
tests/unit-test-client.c
| ... | ... | @@ -57,6 +57,7 @@ int main(int argc, char *argv[]) |
| 57 | 57 | uint32_t old_byte_to_sec; |
| 58 | 58 | uint32_t old_byte_to_usec; |
| 59 | 59 | int use_backend; |
| 60 | + int success = FALSE; | |
| 60 | 61 | |
| 61 | 62 | if (argc > 1) { |
| 62 | 63 | if (strcmp(argv[1], "tcp") == 0) { |
| ... | ... | @@ -600,6 +601,7 @@ int main(int argc, char *argv[]) |
| 600 | 601 | ASSERT_TRUE(ctx == NULL && errno == EINVAL, ""); |
| 601 | 602 | |
| 602 | 603 | printf("\nALL TESTS PASS WITH SUCCESS.\n"); |
| 604 | + success = TRUE; | |
| 603 | 605 | |
| 604 | 606 | close: |
| 605 | 607 | /* Free the memory */ |
| ... | ... | @@ -610,7 +612,7 @@ close: |
| 610 | 612 | modbus_close(ctx); |
| 611 | 613 | modbus_free(ctx); |
| 612 | 614 | |
| 613 | - return 0; | |
| 615 | + return (success) ? 0 : -1; | |
| 614 | 616 | } |
| 615 | 617 | |
| 616 | 618 | /* Send crafted requests to test server resilience | ... | ... |
tests/unit-tests.sh
0 → 100755
| 1 | +#!/bin/sh | |
| 2 | + | |
| 3 | +client_log=unit-test-client.log | |
| 4 | +server_log=unit-test-server.log | |
| 5 | + | |
| 6 | +rm -f $client_log $server_log | |
| 7 | + | |
| 8 | +echo "Starting server" | |
| 9 | +./unit-test-server > $server_log 2>&1 & | |
| 10 | + | |
| 11 | +echo "Starting client" | |
| 12 | +./unit-test-client > $client_log 2>&1 | |
| 13 | +rc=$? | |
| 14 | + | |
| 15 | +killall unit-test-server | |
| 16 | +exit $rc | |
| 17 | + | ... | ... |