aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/tests/sys
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/tests/sys')
-rw-r--r--lib/libc/tests/sys/Makefile6
-rw-r--r--lib/libc/tests/sys/brk_test.c1
-rw-r--r--lib/libc/tests/sys/cpuset_test.c3
-rw-r--r--lib/libc/tests/sys/errno_test.c36
-rw-r--r--lib/libc/tests/sys/mlock_helper.c1
-rw-r--r--lib/libc/tests/sys/queue_test.c1
-rw-r--r--lib/libc/tests/sys/sendfile_test.c1
-rw-r--r--lib/libc/tests/sys/swapcontext_test.c63
8 files changed, 102 insertions, 10 deletions
diff --git a/lib/libc/tests/sys/Makefile b/lib/libc/tests/sys/Makefile
index f44cec11225d..88f8191a16eb 100644
--- a/lib/libc/tests/sys/Makefile
+++ b/lib/libc/tests/sys/Makefile
@@ -1,4 +1,3 @@
-
PACKAGE= tests
.include <bsd.own.mk>
@@ -7,11 +6,12 @@ PACKAGE= tests
ATF_TESTS_C+= brk_test
.endif
ATF_TESTS_C+= cpuset_test
+ATF_TESTS_C+= errno_test
+ATF_TESTS_C+= swapcontext_test
ATF_TESTS_C+= queue_test
ATF_TESTS_C+= sendfile_test
-# TODO: clone, lwp_create, lwp_ctl, posix_fadvise, recvmmsg,
-# swapcontext
+# TODO: clone, lwp_create, lwp_ctl, posix_fadvise, recvmmsg
NETBSD_ATF_TESTS_C+= access_test
NETBSD_ATF_TESTS_C+= bind_test
NETBSD_ATF_TESTS_C+= chroot_test
diff --git a/lib/libc/tests/sys/brk_test.c b/lib/libc/tests/sys/brk_test.c
index 38093b4cbd29..2d8c7af38ff7 100644
--- a/lib/libc/tests/sys/brk_test.c
+++ b/lib/libc/tests/sys/brk_test.c
@@ -25,7 +25,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/mman.h>
diff --git a/lib/libc/tests/sys/cpuset_test.c b/lib/libc/tests/sys/cpuset_test.c
index 52c0dc877ab8..53d6a8215bbc 100644
--- a/lib/libc/tests/sys/cpuset_test.c
+++ b/lib/libc/tests/sys/cpuset_test.c
@@ -25,9 +25,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD");
-
#include <sys/param.h>
#include <sys/cpuset.h>
#include <sys/jail.h>
diff --git a/lib/libc/tests/sys/errno_test.c b/lib/libc/tests/sys/errno_test.c
new file mode 100644
index 000000000000..27d0548fc29d
--- /dev/null
+++ b/lib/libc/tests/sys/errno_test.c
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * This software were developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+ATF_TC(errno_basic);
+ATF_TC_HEAD(errno_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Verify basic functionality of errno");
+}
+
+ATF_TC_BODY(errno_basic, tc)
+{
+ int res;
+
+ res = unlink("/non/existent/file");
+ ATF_REQUIRE(res == -1);
+ ATF_REQUIRE(errno == ENOENT);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, errno_basic);
+
+ return (atf_no_error());
+}
diff --git a/lib/libc/tests/sys/mlock_helper.c b/lib/libc/tests/sys/mlock_helper.c
index 31471b2b281c..e7a3d5e39c3f 100644
--- a/lib/libc/tests/sys/mlock_helper.c
+++ b/lib/libc/tests/sys/mlock_helper.c
@@ -28,7 +28,6 @@
* Helper for mlock(3) to avoid EAGAIN errors
*/
-#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/sysctl.h>
diff --git a/lib/libc/tests/sys/queue_test.c b/lib/libc/tests/sys/queue_test.c
index 8db5b5cae7b6..cfe9ac934cbd 100644
--- a/lib/libc/tests/sys/queue_test.c
+++ b/lib/libc/tests/sys/queue_test.c
@@ -24,7 +24,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/queue.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/lib/libc/tests/sys/sendfile_test.c b/lib/libc/tests/sys/sendfile_test.c
index cfa885d1e8e3..d46e7b0cb186 100644
--- a/lib/libc/tests/sys/sendfile_test.c
+++ b/lib/libc/tests/sys/sendfile_test.c
@@ -24,7 +24,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/mman.h>
#include <sys/socket.h>
diff --git a/lib/libc/tests/sys/swapcontext_test.c b/lib/libc/tests/sys/swapcontext_test.c
new file mode 100644
index 000000000000..f341a746e515
--- /dev/null
+++ b/lib/libc/tests/sys/swapcontext_test.c
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2025 Raptor Computing Systems, LLC
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ucontext.h>
+#include <errno.h>
+
+#include <atf-c.h>
+
+#define STACK_SIZE (64ull << 10)
+
+static volatile int callback_reached = 0;
+
+static ucontext_t uctx_save, uctx_switch;
+
+static void swapcontext_callback()
+{
+ // Increment callback reached variable
+ // If this is called multiple times, we will fail the test
+ // If this is not called at all, we will fail the test
+ callback_reached++;
+}
+
+ATF_TC(swapcontext_basic);
+ATF_TC_HEAD(swapcontext_basic, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Verify basic functionality of swapcontext");
+}
+
+ATF_TC_BODY(swapcontext_basic, tc)
+{
+ char *stack;
+ int res;
+
+ stack = malloc(STACK_SIZE);
+ ATF_REQUIRE_MSG(stack != NULL, "malloc failed: %s", strerror(errno));
+ res = getcontext(&uctx_switch);
+ ATF_REQUIRE_MSG(res == 0, "getcontext failed: %s", strerror(errno));
+
+ uctx_switch.uc_stack.ss_sp = stack;
+ uctx_switch.uc_stack.ss_size = STACK_SIZE;
+ uctx_switch.uc_link = &uctx_save;
+ makecontext(&uctx_switch, swapcontext_callback, 0);
+
+ res = swapcontext(&uctx_save, &uctx_switch);
+
+ ATF_REQUIRE_MSG(res == 0, "swapcontext failed: %s", strerror(errno));
+ ATF_REQUIRE_MSG(callback_reached == 1,
+ "callback failed, reached %d times", callback_reached);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, swapcontext_basic);
+
+ return (atf_no_error());
+}
+