Skip to content

Commit

Permalink
tests: rewrite wait_exit() to use child-proc
Browse files Browse the repository at this point in the history
Instead of using sh to execute remote code, use child-proc to perform
the remote logic. This avoids using, on mingw platform, a binary which
is linked to msys2.dll which may alter the standard behavior of the
platform.

Change-Id: I8bc628f58f48078b8bc4fa652ac76cae496b34e8
  • Loading branch information
nbourdau committed Jan 7, 2023
1 parent be5ac9f commit b3b8a65
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 21 additions & 1 deletion tests/child-proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[])

static
int check_open_files(int argc, char* argv[])
{
int i;
int num_fd;
Expand All @@ -29,3 +31,21 @@ int main(int argc, char* argv[])

return 0;
}


int main(int argc, char* argv[])
{
if (argc < 2) {
fprintf(stderr, "child-proc: Missing argument\n");
return EXIT_FAILURE;
}

if (strcmp(argv[1], "check-open-files") == 0)
return check_open_files(argc, argv);

if (strcmp(argv[1], "check-exit") == 0)
return atoi(argv[2]);

fprintf(stderr, "child-proc: invalid argument: %s\n", argv[1]);
return EXIT_FAILURE;
}
9 changes: 4 additions & 5 deletions tests/process-api-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ struct process_test_data* create_process_test_data(const char* file)
{
int i, child_last_fd, pipe_fds[2];
char name[32];
const char* argv[] = {"opt1", "another opt2", "Whi opt3",
MM_STRINGIFY(NUM_FILE)};
const char* argv[] = {"check-open-files", MM_STRINGIFY(NUM_FILE)};
struct process_test_data* data;

data = malloc(sizeof(*data));
Expand Down Expand Up @@ -505,11 +504,11 @@ START_TEST(wait_exit)
{
int status;
mm_pid_t pid;
char script[32];
char* cmd[] = {"sh", "-c", script, NULL};
char arg[32];
char* cmd[] = {CHILDPROC_BINPATH, "check-exit", arg, NULL};
int expected_code = exit_code_cases[_i];

sprintf(script, "exit %i", expected_code);
sprintf(arg, "%i", expected_code);

ck_assert(mm_spawn(&pid, cmd[0], 0, NULL, 0, cmd, NULL) == 0);
ck_assert(mm_wait_process(pid, &status) == 0);
Expand Down

0 comments on commit b3b8a65

Please sign in to comment.