diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-10-28 20:47:22 +0200 |
|---|---|---|
| committer | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-10-28 20:47:22 +0200 |
| commit | f36902fa3110277d93f809e04a71cc427a2c6dbc (patch) | |
| tree | ef66ae31fb7741a50fc12ff100e93371881052a4 /accel-cmd/accel_cmd_test.c | |
| parent | a9e7d43596c5d524b2fe9300102ab8fe20c987f5 (diff) | |
| download | accel-ppp-f36902fa3110277d93f809e04a71cc427a2c6dbc.tar.gz accel-ppp-f36902fa3110277d93f809e04a71cc427a2c6dbc.zip | |
accel-cmd: convert millisecond timeouts to nanoseconds correctly
The fractional part of a millisecond timeout was multiplied by 1000 instead of 1000000, so 1500ms became 1.0005 seconds. Correct the conversion and add a CTest regression covering subsecond values, second boundaries, microseconds, and invalid input. Initialize CTest before configuring the client subdirectory.
Validation: Release build and CTest pass. The regression fails against upstream master at 1ms.
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
Diffstat (limited to 'accel-cmd/accel_cmd_test.c')
| -rw-r--r-- | accel-cmd/accel_cmd_test.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/accel-cmd/accel_cmd_test.c b/accel-cmd/accel_cmd_test.c new file mode 100644 index 00000000..a127caca --- /dev/null +++ b/accel-cmd/accel_cmd_test.c @@ -0,0 +1,46 @@ +/* Exercise the production timeout parser without opening a connection. */ +#define main accel_cmd_main +#include "accel_cmd.c" +#undef main + +int main(void) +{ + static const struct { + const char *value; + time_t seconds; + long nanoseconds; + } cases[] = { + { "0", 0, 0 }, + { "2s", 2, 0 }, + { "0ms", 0, 0 }, + { "1ms", 0, 1000000 }, + { "500ms", 0, 500000000 }, + { "999ms", 0, 999000000 }, + { "1000ms", 1, 0 }, + { "1001ms", 1, 1000000 }, + { "1500ms", 1, 500000000 }, + { "1us", 0, 1000 }, + { "1500000us", 1, 500000000 }, + }; + static const char *invalid[] = { "", "-1ms", "1.5ms", "1m" }; + struct timespec timeout; + size_t i; + + for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + if (set_timespec(&timeout, cases[i].value) || + timeout.tv_sec != cases[i].seconds || + timeout.tv_nsec != cases[i].nanoseconds) { + fprintf(stderr, "incorrect timeout for %s\n", cases[i].value); + return 1; + } + } + for (i = 0; i < sizeof(invalid) / sizeof(invalid[0]); i++) { + if (!set_timespec(&timeout, invalid[i])) { + fprintf(stderr, "accepted invalid timeout %s\n", invalid[i]); + return 1; + } + } + + puts("accel-cmd timeout parsing: PASS"); + return 0; +} |
