Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: add passing custom parameter to unix-socket test #378

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions libc/socket/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions libc/socket/inet-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 20 additions & 6 deletions libc/socket/unix-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
adamgreloch marked this conversation as resolved.
Show resolved Hide resolved
TEST_ASSERT_GREATER_THAN(290, ms);

clock_gettime(CLOCK_REALTIME, &ts[0]);
Expand Down Expand Up @@ -1478,16 +1479,29 @@ 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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should pollTimeoutDelay ever be allowed to have negative value? If not, maybe it'd be good to have a simple argument value validation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is passed directly in test.yaml, but I can add it.

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);
}

int failures = UnityMain(argc, (const char **)argv, runner);

if (isMissing) {
if (isMissing != 0) {
rmdir("/tmp");
}

Expand Down
6 changes: 6 additions & 0 deletions libc/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading