From nobody Tue Sep 26 20:26:34 2023 X-Original-To: dev-commits-src-all@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 4RwB970cm2z4vcKb; Tue, 26 Sep 2023 20:26:35 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RwB966vHQz3Vth; Tue, 26 Sep 2023 20:26:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1695759995; 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=EE+rAa3tRdqbNGAiInuXKOUBEYxB7eSHgRC0Bu5KU9Q=; b=q543Y5ln+WBX8+pp96hSGCFyj3TWla3TbkOSh67m08y4FrfIo1FEPfw82/+vtRA2FU0het 9qj4agKhQE2fRW4Ie20SzTI833byVM0d5lL5VgFLZTfAAYJQUDU6phHSKC1VTxVScCReIH uVHBUpTmzZupVCh/57m6YDC8iNaacYyCC87vPWta2+BjR89xCBI3NiujfqA9od56Hd+tQJ sLXGCQ0JE4jmgZhIpNnl4iaWNupnaASxFFdMH1MDve38alEN+CvrpE36pAjtu2VDja+8+9 s/svqS3QxYIkVkqeOowbj3Hoou9sYHGg1ZsuLCECeIvKPPXKuqiT2F5SimXiBw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1695759995; a=rsa-sha256; cv=none; b=UC5dncvQ/m17+ojIMzB1qz/82/3ZS6eV0KPYiF+/WED2OFwpihd3QGqO7DJd4vCXPwwUNO dX8jF2u9gn1om89DvoEMG43ij6l62CiFQhfNTWb77PCC8xemglTwVpEdtaCNR8qeGx5EMj V0fkOD2792zdJyhsb90WdJz0+5494uqoLdPBjLJKvYWi+Z5AgM5314GElqQ2tw8YChC5SK g9wHMeP6Nn06pQjDXSMCBSEjA9llQt02GmVrqKq1d1bov1Ioa9kxeNGxAnhbp6XaSmJ03t PG0mPMyHBUbMJsZ9borY+MMCsVM6340Iog2XlvcvX9mTaZZQeJC127/rSmnDbg== 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=1695759995; 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=EE+rAa3tRdqbNGAiInuXKOUBEYxB7eSHgRC0Bu5KU9Q=; b=BEEarrS9EkWO9t6lohtpIWl7vNGdPK4PUTg+xF1g8GiOZaU1Syr4Wsk6pnWXPAYuRoBQJj ak9ffJkchMUgE0d1tOWbD42Taj6X7sCxl4Y6cqOb92XJhNhX2VxvY1xYXu5MBWLq/5ls8D UgadcLZEV/103El6SXNRCD5Om66WkzSFbSlU8Yl1sdvIFJTSZcQfpquEXyNuuaOWkgfaSV tWG5cutxT4kNmbbQSEhkNmCt4IAGHHINX0469akfO6/PvZniDu3DPnW2ENoO2Nm1kjnemB 9kcf8NCMX2coIWnzofZX0XuMSxLI/dLXUfzphPYywVk8g/FTm6cNeirgEcqXqA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RwB965XfYz19X2; Tue, 26 Sep 2023 20:26:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 38QKQY15083004; Tue, 26 Sep 2023 20:26:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 38QKQY4A083001; Tue, 26 Sep 2023 20:26:34 GMT (envelope-from git) Date: Tue, 26 Sep 2023 20:26:34 GMT Message-Id: <202309262026.38QKQY4A083001@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: c7dd4601aeeb - main - libc: Add a rudimentary test for quick_exit(3). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: c7dd4601aeebbc1bbe131cbe6747476c124b47fe Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c7dd4601aeebbc1bbe131cbe6747476c124b47fe commit c7dd4601aeebbc1bbe131cbe6747476c124b47fe Author: Dag-Erling Smørgrav AuthorDate: 2023-09-26 20:07:03 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-09-26 20:07:10 +0000 libc: Add a rudimentary test for quick_exit(3). Sponsored by: Klara, Inc. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D41937 --- lib/libc/tests/stdlib/Makefile | 1 + lib/libc/tests/stdlib/quick_exit_test.c | 81 +++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/lib/libc/tests/stdlib/Makefile b/lib/libc/tests/stdlib/Makefile index a2a6420aba41..860e530389df 100644 --- a/lib/libc/tests/stdlib/Makefile +++ b/lib/libc/tests/stdlib/Makefile @@ -12,6 +12,7 @@ ATF_TESTS_C+= qsort_b_test 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 index 000000000000..9feed8a6fa63 --- /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 + +#include +#include +#include + +#include + +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()); +}