Skip to content

Commit

Permalink
tests/rtld: add stdio flush-on-exit test
Browse files Browse the repository at this point in the history
  • Loading branch information
64 committed Oct 16, 2024
1 parent 348e8a2 commit a3cabed
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
Empty file removed tests/rtld/destroy/meson.build
Empty file.
1 change: 1 addition & 0 deletions tests/rtld/destroy1/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# only the test executable is required
File renamed without changes.
1 change: 1 addition & 0 deletions tests/rtld/destroy2/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# only the test executable is required
43 changes: 43 additions & 0 deletions tests/rtld/destroy2/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>

// Make sure files are flushed on process exit.

int main() {
int pipefd[2];
if (pipe(pipefd) < 0) {
perror("pipe");
return -1;
}

pid_t child = fork();
if (child < 0) {
perror("fork");
return -1;
}

// This should sit in libc's buffer and be flushed on exit.
const char *message = "hello world";

if (child == 0) {
// Child
dup2(pipefd[1], STDOUT_FILENO);
printf("%s", message);
return 0;
}

// Parent
wait(NULL);

char buffer[64];
ssize_t len = read(pipefd[0], buffer, sizeof(buffer));
assert(len > 0);
buffer[len] = 0;

return strcmp(buffer, message) != 0;
}

3 changes: 2 additions & 1 deletion tests/rtld/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ rtld_test_cases = [
'rtld_next',
'soname',
'preinit',
'destroy',
'destroy1',
'destroy2',
'scope1',
'scope2',
'scope3',
Expand Down

0 comments on commit a3cabed

Please sign in to comment.