Skip to content

Commit f64103c

Browse files
committed
tests/unit-test-client.c: on WIN32 replace "7ms > 5ms" test case with "33ms > 20ms"
Signed-off-by: Jim Klimov <[email protected]>
1 parent d51b7ae commit f64103c

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

tests/unit-test-client.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,11 +738,21 @@ int main(int argc, char *argv[])
738738
usleep(1000000);
739739
modbus_flush(ctx);
740740

741+
#ifdef _WIN32
742+
/* Timeout of 20ms between bytes, allow for 2*16+1
743+
* Windows sleep seems to be at least 15ms always
744+
*/
745+
TEST_TITLE("2/2 Adapted byte timeout (33ms > 20ms)");
746+
modbus_set_byte_timeout(ctx, 0, 33000);
747+
rc = modbus_read_registers(
748+
ctx, UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS, 1, tab_rp_registers);
749+
#else
741750
/* Timeout of 7ms between bytes */
742751
TEST_TITLE("2/2 Adapted byte timeout (7ms > 5ms)");
743752
modbus_set_byte_timeout(ctx, 0, 7000);
744753
rc = modbus_read_registers(
745754
ctx, UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS, 1, tab_rp_registers);
755+
#endif
746756
ASSERT_TRUE(rc == 1, "FAILED (rc: %d != 1)", rc);
747757
}
748758

tests/unit-test-server.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int main(int argc, char *argv[])
221221
} else if (address == UT_REGISTERS_ADDRESS_SLEEP_500_MS) {
222222
printf("Sleep 0.5 s before replying\n");
223223
usleep(500000);
224-
} else if (address == UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS) {
224+
} else if (address == UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS || address == UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS) {
225225
/* Test low level only available in TCP mode */
226226
/* Catch the reply and send reply byte a byte */
227227
uint8_t req[] = "\x00\x1C\x00\x00\x00\x05\xFF\x03\x02\x00\x00";
@@ -236,7 +236,11 @@ int main(int argc, char *argv[])
236236
req[1] = query[1];
237237
for (i = 0; i < req_length; i++) {
238238
printf("(%.2X)", req[i]);
239-
usleep(5000);
239+
if (address == UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS) {
240+
usleep(5000);
241+
} else if (address == UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS) {
242+
usleep(20000);
243+
}
240244
rc = send(w_s, (const char *) (req + i), 1, MSG_NOSIGNAL);
241245
if (rc == -1) {
242246
break;

tests/unit-test.h.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ const uint16_t UT_REGISTERS_ADDRESS_SPECIAL = 0x170;
4747
const uint16_t UT_REGISTERS_ADDRESS_INVALID_TID_OR_SLAVE = 0x171;
4848
/* The server will wait for 1 second before replying to test timeout */
4949
const uint16_t UT_REGISTERS_ADDRESS_SLEEP_500_MS = 0x172;
50-
/* The server will wait for 5 ms before sending each byte */
50+
/* The server will wait for 5 ms before sending each byte
51+
* WARNING: this may be too short for WIN32 */
5152
const uint16_t UT_REGISTERS_ADDRESS_BYTE_SLEEP_5_MS = 0x173;
53+
/* The server will wait for 20 ms before sending each byte */
54+
const uint16_t UT_REGISTERS_ADDRESS_BYTE_SLEEP_20_MS = 0x174;
5255

5356
/* If the following value is used, a bad response is sent.
5457
It's better to test with a lower value than

0 commit comments

Comments
 (0)