Skip to content

Commit 8f0ccd6

Browse files
committed
tests/unit-test-client.c: revise test case "Adapted byte timeout (Xms > Yms)" to increase the timeouts and fit all laggy systems better
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent 7d1a6dd commit 8f0ccd6

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

tests/unit-test-client.c

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -739,33 +739,42 @@ int main(int argc, char *argv[])
739739
usleep(1000000);
740740
modbus_flush(ctx);
741741

742-
#if defined(_WIN32)
743-
/* Timeout of 20ms between bytes, allow for 2*16+1
744-
* Windows sleep seems to be at least 15ms always.
745-
*/
746-
TEST_TITLE("2/2 Adapted byte timeout (33ms > 20ms)");
747-
modbus_set_byte_timeout(ctx, 0, 33000);
748-
rc = modbus_read_registers(
749-
ctx, UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS, 1, tab_rp_registers);
750-
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
751-
/* For some reason, FreeBSD 12 and OpenBSD 6.5 also
752-
* tended to fail with 7ms and even 33ms variants
753-
* as "gmake check", but passed in
754-
* gmake -j 8 && ( ./tests/unit-test-server|cat & sleep 1 ; ./tests/unit-test-client|cat )
755-
* An even longer timeout seems to satisfy all of them.
756-
*/
757-
TEST_TITLE("2/2 Adapted byte timeout (66ms > 20ms)");
758-
modbus_set_byte_timeout(ctx, 0, 66000);
759-
rc = modbus_read_registers(
760-
ctx, UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS, 1, tab_rp_registers);
761-
#else
762742
/* Timeout of 7ms between bytes */
763-
TEST_TITLE("2/2 Adapted byte timeout (7ms > 5ms)");
743+
TEST_TITLE("2/2-A Adapted byte timeout (7ms > 5ms)");
764744
modbus_set_byte_timeout(ctx, 0, 7000);
765745
rc = modbus_read_registers(
766746
ctx, UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS, 1, tab_rp_registers);
767-
#endif
768-
ASSERT_TRUE(rc == 1, "FAILED (rc: %d != 1)", rc);
747+
if (rc == 1) {
748+
ASSERT_TRUE(rc == 1, "FAILED (rc: %d != 1)", rc);
749+
} else {
750+
/* Timeout of 20ms between bytes, allow for 2*16+1
751+
* Windows sleep seems to be at least 15ms always.
752+
*/
753+
usleep(1000000);
754+
modbus_flush(ctx);
755+
TEST_TITLE("2/2-B Adapted byte timeout (33ms > 20ms)");
756+
modbus_set_byte_timeout(ctx, 0, 33000);
757+
rc = modbus_read_registers(
758+
ctx, UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS, 1, tab_rp_registers);
759+
760+
if (rc == 1) {
761+
ASSERT_TRUE(rc == 1, "FAILED (rc: %d != 1)", rc);
762+
} else {
763+
/* For some reason, FreeBSD 12 and OpenBSD 6.5 also
764+
* tended to fail with 7ms and even 33ms variants
765+
* as "gmake check", but passed in
766+
* gmake -j 8 && ( ./tests/unit-test-server|cat & sleep 1 ; ./tests/unit-test-client|cat )
767+
* An even longer timeout seems to satisfy all of them.
768+
*/
769+
usleep(1000000);
770+
modbus_flush(ctx);
771+
TEST_TITLE("2/2-C Adapted byte timeout (66ms > 20ms)");
772+
modbus_set_byte_timeout(ctx, 0, 66000);
773+
rc = modbus_read_registers(
774+
ctx, UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS, 1, tab_rp_registers);
775+
ASSERT_TRUE(rc == 1, "FAILED (rc: %d != 1)", rc);
776+
}
777+
}
769778
}
770779

771780
/* Restore original byte timeout */

0 commit comments

Comments
 (0)