From nobody Wed Mar 4 14:45:07 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4fQwSN12DTz6TbgR for ; Wed, 04 Mar 2026 14:45:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fQwSN0CXWz3bC1 for ; Wed, 04 Mar 2026 14:45:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772635508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N38KcfL2BszD4bUxWpacfM6uVn5yC/zm3olGXS62+Jg=; b=fwVslxGnqw146S0CSlYUkhXvG4EN0YgNobRB7drhJD7esx83/eZ5OtFf1oUWhcsi+GItaK Syhj0VT/+g8py39N2V1L+gvPTialLhw6qPDKdXUUlkOLueA2SyXnVXMqsNxWcfiCNZeDE9 ap1x/vzq9EdfhrAOEaCov3A1qmIRFmQsAYFq+iXki3kx2tAw35u7l/JO+jsJYz8jXKIGhu 07BPHLFfYszVz4RQLXd3yEo+WyiCpoj9G16AYPm77rvdYfsHGFeoVJC+yytEBuMPpqhbnw 5Jil/ZS9UEGVexBOjLF+3NCJKguhHmINgGcSHczTjDa/JVlYmBzNn+4DZtP14g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1772635508; a=rsa-sha256; cv=none; b=G7Sxdd1fMmGSBQKlGLSzthOC3TwTE483RMb3F3ryxR/nEisGlEVdwSETksOQ6PH9D3DZUP zdctbRNOTdoMzY3mGF35KhHkpgZqjw493KLzgL27DmCeq7LwLFsbC+FxfDw35h+E+csL4J AMfyUYww4Jzg0jemgCQKmv0iEHMKCMWIHEQva7sEbUTJMkCO9R6PAIeSA/u8wGEOuu9kmp itHXnyAcSqTMQjqJ4ms0aAsFl+YTC50KfGXm0l3dVzg407ojqVUig4ubd9RYac3HOKzZ7s 8ueJ97ZY7i9St8N7fe/CFtdIw3/0UDqhJEBLFmsqiWeD6jkyKRIm0ncuAbDgvg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772635508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=N38KcfL2BszD4bUxWpacfM6uVn5yC/zm3olGXS62+Jg=; b=QlAI/ZFhEEoNxmjkuPIrxtKTyS53+GSonfwduQOs1kcDb0K2PQOxt/PDhkvo30+RhG+X+8 63t+TmUPFVFV1pm+rstNS5vSmZJjaPlAEoVOG9LRF97SXtC5PqMpa8AcYunXyK67WuD39U DIhfNRfke2H6RnCEifIsVFd2lHifRLxQtB2JFIXuVGCeOufWSno+3XOVi9HvNhGRAL1uKK ETozn4GQdipfslyDzsYaHmT7eAQR9RpncZUyojXoIm+cQYoF/PpFZ4P49ZN3fZY51qhSvc SxdWGljd6gKc/ZuzCWNFEqGsY1b721P0DOCypZ+MAbPxkLDwH8Y8klgI/iMnMA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fQwSM6sG0zvW4 for ; Wed, 04 Mar 2026 14:45:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26c19 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 04 Mar 2026 14:45:07 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 3d7774db9319 - stable/15 - system(3): Write our own tests List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 3d7774db931939f17d5ad54245735e4223061525 Auto-Submitted: auto-generated Date: Wed, 04 Mar 2026 14:45:07 +0000 Message-Id: <69a84573.26c19.1b828c6f@gitrepo.freebsd.org> The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=3d7774db931939f17d5ad54245735e4223061525 commit 3d7774db931939f17d5ad54245735e4223061525 Author: Dag-Erling Smørgrav AuthorDate: 2026-02-25 21:12:29 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-03-04 14:45:00 +0000 system(3): Write our own tests Replace the somewhat perfunctory NetBSD tests with our own. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55482 (cherry picked from commit 7a1ade5109ac57d1f59eaa75b5d0f13fabecf6ba) --- lib/libc/tests/stdlib/Makefile | 3 +- lib/libc/tests/stdlib/system_test.c | 164 ++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 1 deletion(-) diff --git a/lib/libc/tests/stdlib/Makefile b/lib/libc/tests/stdlib/Makefile index 9d84becfbd1f..a714a8cab774 100644 --- a/lib/libc/tests/stdlib/Makefile +++ b/lib/libc/tests/stdlib/Makefile @@ -17,6 +17,7 @@ ATF_TESTS_C+= qsort_s_test ATF_TESTS_C+= qsort_bench ATF_TESTS_C+= set_constraint_handler_s_test ATF_TESTS_C+= strfmon_test +ATF_TESTS_C+= system_test ATF_TESTS_C+= tsearch_test ATF_TESTS_CXX+= cxa_thread_atexit_test ATF_TESTS_CXX+= cxa_thread_atexit_nothr_test @@ -44,7 +45,6 @@ NETBSD_ATF_TESTS_C+= posix_memalign_test NETBSD_ATF_TESTS_C+= random_test NETBSD_ATF_TESTS_C+= strtod_test NETBSD_ATF_TESTS_C+= strtol_test -NETBSD_ATF_TESTS_C+= system_test # TODO: need to come up with a correct explanation of what the patch pho does # with h_atexit @@ -78,6 +78,7 @@ LIBADD.${t}+= netbsd util LIBADD.libc_exit_test+= pthread LIBADD.strtod_test+= m +LIBADD.system_test+= pthread SUBDIR+= dynthr_mod SUBDIR+= libatexit diff --git a/lib/libc/tests/stdlib/system_test.c b/lib/libc/tests/stdlib/system_test.c new file mode 100644 index 000000000000..713e4bb0f87a --- /dev/null +++ b/lib/libc/tests/stdlib/system_test.c @@ -0,0 +1,164 @@ +/*- + * Copyright (c) 2026 Klara, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +ATF_TC(system_true); +ATF_TC_HEAD(system_true, tc) +{ + atf_tc_set_md_var(tc, "descr", "system(\"true\")"); +} +ATF_TC_BODY(system_true, tc) +{ + ATF_REQUIRE_EQ(W_EXITCODE(0, 0), system("true")); +} + +ATF_TC(system_false); +ATF_TC_HEAD(system_false, tc) +{ + atf_tc_set_md_var(tc, "descr", "system(\"false\")"); +} +ATF_TC_BODY(system_false, tc) +{ + ATF_REQUIRE_EQ(W_EXITCODE(1, 0), system("false")); +} + +ATF_TC(system_touch); +ATF_TC_HEAD(system_touch, tc) +{ + atf_tc_set_md_var(tc, "descr", "system(\"touch file\")"); +} +ATF_TC_BODY(system_touch, tc) +{ + /* The file does not exist */ + ATF_CHECK_ERRNO(ENOENT, unlink("file")); + + /* Run a command that creates it */ + ATF_REQUIRE_EQ(W_EXITCODE(0, 0), system("touch file")); + + /* Now the file exists */ + ATF_CHECK_EQ(0, unlink("file")); +} + +ATF_TC(system_null); +ATF_TC_HEAD(system_null, tc) +{ + atf_tc_set_md_var(tc, "descr", "system(NULL)"); +} +ATF_TC_BODY(system_null, tc) +{ + ATF_REQUIRE_EQ(1, system(NULL)); +} + +/* + * Define PROCMASK_IS_THREADMASK if sigprocmask() gets / sets the thread + * mask in multithreaded programs, which makes it impossible to verify + * that system(3) correctly blocks and unblocks SIGCHLD. + */ +#ifdef __FreeBSD__ +#define PROCMASK_IS_THREADMASK 1 +#endif + +static void * +system_thread(void *arg) +{ + char cmd[64]; + int i = (int)(intptr_t)arg; + + snprintf(cmd, sizeof(cmd), "rm flag%d ; lockf -ns lock%d true", i, i); + return ((void *)(intptr_t)system(cmd)); +} + +ATF_TC(system_concurrent); +ATF_TC_HEAD(system_concurrent, tc) +{ + atf_tc_set_md_var(tc, "descr", "Concurrent calls"); +} +ATF_TC_BODY(system_concurrent, tc) +{ +#define N 3 + sigset_t normset, sigset; + pthread_t thr[N]; + char fn[8]; + int fd[N]; + void *arg, *ret; + + /* Create and lock the locks */ + for (int i = 0; i < N; i++) { + snprintf(fn, sizeof(fn), "lock%d", i); + fd[i] = open(fn, O_CREAT|O_EXCL|O_EXLOCK|O_CLOEXEC, 0644); + ATF_REQUIRE_MSG(fd[i] >= 0, "%s: %m", fn); + } + + /* Create the flags */ + for (int i = 0; i < N; i++) { + snprintf(fn, sizeof(fn), "flag%d", i); + ATF_REQUIRE_EQ(0, symlink(fn, fn)); + } + + /* Get the current and expected signal mask */ + sigprocmask(0, NULL, &normset); + + /* Spawn threads which block on these files */ + for (int i = 0; i < N; i++) { + arg = (void *)(intptr_t)i; + ATF_REQUIRE_INTEQ(0, + pthread_create(&thr[i], NULL, system_thread, arg)); + } + + /* Wait until the flags are gone */ + for (int i = 0; i < N; i++) { + snprintf(fn, sizeof(fn), "flag%d", i); + while (readlink(fn, fn, sizeof(fn)) > 0) + usleep(10000); + ATF_REQUIRE_EQ(ENOENT, errno); + } + + /* Release the locks */ + for (int i = 0; i < N; i++) { + /* Check the signal dispositions */ + ATF_CHECK_EQ(SIG_IGN, signal(SIGINT, SIG_IGN)); + ATF_CHECK_EQ(SIG_IGN, signal(SIGQUIT, SIG_IGN)); +#ifndef PROCMASK_IS_THREADMASK + sigprocmask(0, NULL, &sigset); + ATF_CHECK(sigismember(&sigset, SIGCHLD)); +#endif + + /* Close the file, releasing the lock */ + ATF_REQUIRE_INTEQ(0, close(fd[i])); + + /* Join the thread and check the return value */ + ATF_CHECK_INTEQ(0, pthread_join(thr[i], &ret)); + ATF_CHECK_INTEQ(W_EXITCODE(0, 0), (int)(intptr_t)ret); + } + + /* Check the signal dispositions */ + ATF_CHECK_EQ(SIG_DFL, signal(SIGINT, SIG_DFL)); + ATF_CHECK_EQ(SIG_DFL, signal(SIGQUIT, SIG_DFL)); + sigprocmask(0, NULL, &sigset); + ATF_CHECK_EQ(0, memcmp(&sigset, &normset, sizeof(sigset_t))); +#undef N +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, system_true); + ATF_TP_ADD_TC(tp, system_false); + ATF_TP_ADD_TC(tp, system_touch); + ATF_TP_ADD_TC(tp, system_null); + ATF_TP_ADD_TC(tp, system_concurrent); + return (atf_no_error()); +}