Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110753685
D41937.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D41937.diff
View Options
diff --git a/lib/libc/tests/stdlib/Makefile b/lib/libc/tests/stdlib/Makefile
--- a/lib/libc/tests/stdlib/Makefile
+++ b/lib/libc/tests/stdlib/Makefile
@@ -12,6 +12,7 @@
ATF_TESTS_C+= qsort_r_compat_test
ATF_TESTS_C+= qsort_r_test
ATF_TESTS_C+= qsort_s_test
+ATF_TESTS_C+= quick_exit_test
ATF_TESTS_C+= set_constraint_handler_s_test
ATF_TESTS_C+= strfmon_test
ATF_TESTS_C+= tsearch_test
diff --git a/lib/libc/tests/stdlib/quick_exit_test.c b/lib/libc/tests/stdlib/quick_exit_test.c
new file mode 100644
--- /dev/null
+++ b/lib/libc/tests/stdlib/quick_exit_test.c
@@ -0,0 +1,81 @@
+/*-
+ * Copyright (c) 2023 Klara, Inc.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/wait.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static void func_a(void)
+{
+ if (write(STDOUT_FILENO, "a", 1) != 1)
+ _Exit(1);
+}
+
+static void func_b(void)
+{
+ if (write(STDOUT_FILENO, "b", 1) != 1)
+ _Exit(1);
+}
+
+static void func_c(void)
+{
+ if (write(STDOUT_FILENO, "c", 1) != 1)
+ _Exit(1);
+}
+
+static void child(void)
+{
+ // this will be received by the parent
+ printf("hello, ");
+ fflush(stdout);
+ // this won't, because quick_exit() does not flush
+ printf("world");
+ // these will be called in reverse order, producing "abc"
+ if (at_quick_exit(func_c) != 0 ||
+ at_quick_exit(func_b) != 0 ||
+ at_quick_exit(func_a) != 0)
+ _Exit(1);
+ quick_exit(0);
+}
+
+ATF_TC_WITHOUT_HEAD(quick_exit);
+ATF_TC_BODY(quick_exit, tc)
+{
+ char buf[100] = "";
+ ssize_t len;
+ int p[2], wstatus = 0;
+ pid_t pid;
+
+ ATF_REQUIRE(pipe(p) == 0);
+ pid = fork();
+ if (pid == 0) {
+ if (dup2(p[1], STDOUT_FILENO) < 0)
+ _Exit(1);
+ (void)close(p[1]);
+ (void)close(p[0]);
+ child();
+ _Exit(1);
+ }
+ ATF_REQUIRE_MSG(pid > 0,
+ "expect fork() to succeed");
+ ATF_CHECK_EQ_MSG(pid, waitpid(pid, &wstatus, 0),
+ "expect to collect child process");
+ ATF_CHECK_EQ_MSG(0, wstatus,
+ "expect child to exit cleanly");
+ ATF_CHECK_MSG((len = read(p[0], buf, sizeof(buf))) > 0,
+ "expect to receive output from child");
+ ATF_CHECK_STREQ("hello, abc", buf);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, quick_exit);
+ return (atf_no_error());
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 23, 4:20 PM (13 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16802074
Default Alt Text
D41937.diff (2 KB)
Attached To
Mode
D41937: libc: Add a rudimentary test for quick_exit(3).
Attached
Detach File
Event Timeline
Log In to Comment