diff --git a/tests/rtld/destroy/meson.build b/tests/rtld/destroy/meson.build deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/rtld/destroy1/meson.build b/tests/rtld/destroy1/meson.build new file mode 100644 index 0000000000..0e7d79e30e --- /dev/null +++ b/tests/rtld/destroy1/meson.build @@ -0,0 +1 @@ +# only the test executable is required diff --git a/tests/rtld/destroy/test.c b/tests/rtld/destroy1/test.c similarity index 100% rename from tests/rtld/destroy/test.c rename to tests/rtld/destroy1/test.c diff --git a/tests/rtld/destroy2/meson.build b/tests/rtld/destroy2/meson.build new file mode 100644 index 0000000000..0e7d79e30e --- /dev/null +++ b/tests/rtld/destroy2/meson.build @@ -0,0 +1 @@ +# only the test executable is required diff --git a/tests/rtld/destroy2/test.c b/tests/rtld/destroy2/test.c new file mode 100644 index 0000000000..53e51781dc --- /dev/null +++ b/tests/rtld/destroy2/test.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include + +// 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; +} + diff --git a/tests/rtld/meson.build b/tests/rtld/meson.build index 13f465cb2c..68c0825324 100644 --- a/tests/rtld/meson.build +++ b/tests/rtld/meson.build @@ -6,7 +6,8 @@ rtld_test_cases = [ 'rtld_next', 'soname', 'preinit', - 'destroy', + 'destroy1', + 'destroy2', 'scope1', 'scope2', 'scope3',