From cca6f2069935ac9464bc5e5bacbacef886bfe39a Mon Sep 17 00:00:00 2001 From: adamdebek Date: Mon, 7 Oct 2024 14:22:53 +0200 Subject: [PATCH] libc: add passing custom parameter to unix-socket test Add passing custom parameter to unix-socket test on armv7a9-zynq7000-qemu since blocking interval significantly overruns timeout due to host system scheduling delays JIRA: CI-501 --- libc/socket/common.h | 3 --- libc/socket/inet-socket.c | 4 +--- libc/socket/unix-socket.c | 26 ++++++++++++++++++++------ libc/test.yaml | 6 ++++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/libc/socket/common.h b/libc/socket/common.h index cd63b8dda..a1bf0f33d 100644 --- a/libc/socket/common.h +++ b/libc/socket/common.h @@ -29,9 +29,6 @@ #define DATA_SIZE 10000 #endif -extern char data[DATA_SIZE]; -extern char buf[DATA_SIZE]; - ssize_t msg_send(int sock, void *buf, size_t len, int *fd, size_t fdcnt); ssize_t msg_recv(int sock, void *buf, size_t len, int *fd, size_t *fdcnt); diff --git a/libc/socket/inet-socket.c b/libc/socket/inet-socket.c index 967571f73..58b977b62 100644 --- a/libc/socket/inet-socket.c +++ b/libc/socket/inet-socket.c @@ -28,9 +28,7 @@ #include "common.h" #include "unity_fixture.h" -char data[DATA_SIZE]; -char buf[DATA_SIZE]; - +static char data[DATA_SIZE]; TEST_GROUP(test_inet_socket); diff --git a/libc/socket/unix-socket.c b/libc/socket/unix-socket.c index 0bd139aa4..1ba2ddf12 100644 --- a/libc/socket/unix-socket.c +++ b/libc/socket/unix-socket.c @@ -57,8 +57,9 @@ #define MS_BETWEEN(ts0, ts1) \ ((ts1).tv_sec - (ts0).tv_sec) * 1000 + ((ts1).tv_nsec - (ts0).tv_nsec) / 1000000; -char data[DATA_SIZE]; -char buf[DATA_SIZE]; +static char data[DATA_SIZE]; +static char buf[DATA_SIZE]; +static int pollTimeoutDelay = 30; static ssize_t unix_named_socket(int type, const char *name) @@ -883,7 +884,7 @@ static void unix_poll(int type) TEST_ASSERT(rv == 0); TEST_ASSERT(fds[0].revents == 0); TEST_ASSERT(fds[1].revents == 0); - TEST_ASSERT_LESS_THAN(350, ms); + TEST_ASSERT_LESS_THAN(300 + pollTimeoutDelay, ms); TEST_ASSERT_GREATER_THAN(290, ms); clock_gettime(CLOCK_REALTIME, &ts[0]); @@ -1478,8 +1479,21 @@ void runner(void) int main(int argc, char *argv[]) { - /* Assume /tmp dir is missing */ - int isMissing = 0; + /* Due to scheduling delays of host system on which emulator runs, + * add some extra value to poll timeout checks + */ + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--extra-poll-delay-ms") == 0) { + pollTimeoutDelay = atoi(argv[i + 1]); + if (pollTimeoutDelay <= 0) { + fprintf(stderr, "--extra-poll-delay-ms argument is not positive integer\n"); + exit(EXIT_FAILURE); + } + break; + } + } + + int isMissing; if (createTmpIfMissing(&isMissing) < 0) { exit(EXIT_FAILURE); @@ -1487,7 +1501,7 @@ int main(int argc, char *argv[]) int failures = UnityMain(argc, (const char **)argv, runner); - if (isMissing) { + if (isMissing != 0) { rmdir("/tmp"); } diff --git a/libc/test.yaml b/libc/test.yaml index 0f96e6766..2bc458df3 100644 --- a/libc/test.yaml +++ b/libc/test.yaml @@ -66,8 +66,14 @@ test: - name: unix-socket execute: test-libc-unix-socket targets: + exclude: [armv7a9-zynq7000-qemu] include: [host-generic-pc] + - name: unix-socket + execute: test-libc-unix-socket --extra-poll-delay-ms 150 + targets: + value: [armv7a9-zynq7000-qemu] + - name: inet-socket execute: test-libc-inet-socket targets: