From nobody Wed Aug 07 16:08:39 2024 X-Original-To: dev-commits-src-main@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 4WfFTg64pmz5SbRL; Wed, 07 Aug 2024 16:08:39 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WfFTg5Rd1z3x3L; Wed, 7 Aug 2024 16:08:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723046919; 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=pS5xo6IRe9S3SECgr33JmyZGvlbP4sYQMFJmeKBe5sE=; b=s4o6CMh4fcJwlHQqmpX8blZ4oWaowA9fx4EpDvbVicPJsQuylunYz2UPG3OG3g9zKF/eIt cglR8tTUa73HPcZlvoShAu8SNrqEymu7zSP8A4w/96CjyxQBMG9Sj7n5mm2+kuDmu4wiNE NpCKpgiVQ0CFTKC/MBXI5KcVftSdnEoneq8/lqp0mmwUsVnIm7RSWQx5JZiKM8cjKdeDFB y3lZgY1HymttsAjNfEQgEx+m3qA2DDirWm3rPA0rNIRgJwomIOTEbnSmh1mPrv89lLw5dK 3eBYZNBIjPt/QFtwxotjAtU7UOwkG2pPFSxzLUb5RA79LCqMrR5f+y2FDh3Vbg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1723046919; a=rsa-sha256; cv=none; b=Dh1RL6O3KcZPtXfWPE8kYksuKTi4/4aIuCOoo4quyanZOknc63tGHSf+JHrNupM/NnY28C hZizrq09CiLqnpFAdX2xwq6H5qzL0mdnrgi68NdYrRE2bY1C24O4j4IgDNDucmDYZrf9Lh lMGzzKILShZ4jCf0U325Esw4B88AQG83pAHdia2WLEVm/uZtOObzIOp7dzO0cpyVXgGwcw X421FcM2QyEtfRynLehDpcT50IE4usuytiPiEMeP4u1E0pe1vffrWEIXXrZUWpjyQoVs53 syZpbw30kmYWg9yusvCe00tulurPT1l92pXpQvBXW4H/riuHCybcQOhRE+9Ufg== 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=1723046919; 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=pS5xo6IRe9S3SECgr33JmyZGvlbP4sYQMFJmeKBe5sE=; b=upHW6C9QZ7zOUGrVIoyw8P//p8ay65E/YtoU3k8UvHf+32X3FXGpiathQD9NYiXWvDgQ8T MT+dnaXuh3x83mbO1jLyOq4aszxLiNj8G7wORVwFb4cuz6R/dUrPnc9T38GI8kOzlDifz1 2noOvz5477FWde47ogmJj/V74AmO7LMoB7HGfoz6bdiWvfZh8lcdHhPdiWVsuL+jcqRsaS 5Ibnsn94ILYVhs7mvAG6JkhP4ValNWMTTu+y3Z1AY3peIjx+n8aDwB4w8H+YqY52pGQh+3 Kl0m7Lyk2IrTXKzLvvrYSJdsLam4o0RwwQZ758Wrab0rEzFhsoS2ywMskqPzZQ== 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 4WfFTg4m0tzwnH; Wed, 7 Aug 2024 16:08:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 477G8dJX075571; Wed, 7 Aug 2024 16:08:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 477G8dXJ075568; Wed, 7 Aug 2024 16:08:39 GMT (envelope-from git) Date: Wed, 7 Aug 2024 16:08:39 GMT Message-Id: <202408071608.477G8dXJ075568@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c0946aee5b2a - main - libc tests: Add some test cases for recursive exiting List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c0946aee5b2ab6c9bb2e8281a1f625914ed2fec8 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c0946aee5b2ab6c9bb2e8281a1f625914ed2fec8 commit c0946aee5b2ab6c9bb2e8281a1f625914ed2fec8 Author: Mark Johnston AuthorDate: 2024-08-07 16:06:11 +0000 Commit: Mark Johnston CommitDate: 2024-08-07 16:06:11 +0000 libc tests: Add some test cases for recursive exiting Derived from tests posted by kib in D46108. I made one of them use a pthread barrier instead of sleeping. Reviewed by: kib MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D46176 --- lib/libc/tests/stdlib/Makefile | 1 + lib/libc/tests/stdlib/libc_exit_test.c | 69 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/lib/libc/tests/stdlib/Makefile b/lib/libc/tests/stdlib/Makefile index 29cf895006d1..6f57b8014a1e 100644 --- a/lib/libc/tests/stdlib/Makefile +++ b/lib/libc/tests/stdlib/Makefile @@ -75,6 +75,7 @@ LDFLAGS.$t+= -L${LIBNETBSD_OBJDIR} LIBADD.${t}+= netbsd util .endfor +LIBADD.libc_exit_test+= pthread LIBADD.strtod_test+= m SUBDIR+= dynthr_mod diff --git a/lib/libc/tests/stdlib/libc_exit_test.c b/lib/libc/tests/stdlib/libc_exit_test.c index c47d03d1d598..12965261bdb3 100644 --- a/lib/libc/tests/stdlib/libc_exit_test.c +++ b/lib/libc/tests/stdlib/libc_exit_test.c @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -78,8 +79,76 @@ ATF_TC_BODY(quick_exit, tc) ATF_CHECK_STREQ("hello, abc", buf); } +static void +myatexit1(void) +{ + exit(12); +} + +ATF_TC_WITHOUT_HEAD(recursive_exit1); +ATF_TC_BODY(recursive_exit1, tc) +{ + pid_t pid; + int wstatus; + + pid = fork(); + if (pid == 0) { + atexit(myatexit1); + 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(WIFEXITED(wstatus)); + ATF_CHECK_EQ(WEXITSTATUS(wstatus), 12); +} + +static pthread_barrier_t barrier; + +static void +myatexit2(void) +{ + pthread_barrier_wait(&barrier); + exit(12); +} + +static void * +mythreadexit(void *arg) +{ + pthread_barrier_wait(&barrier); + exit(15); +} + +ATF_TC_WITHOUT_HEAD(recursive_exit2); +ATF_TC_BODY(recursive_exit2, tc) +{ + pid_t pid; + int wstatus; + + pid = fork(); + if (pid == 0) { + pthread_t thr; + + atexit(myatexit2); + + pthread_barrier_init(&barrier, NULL, 2); + pthread_create(&thr, NULL, mythreadexit, NULL); + + 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(WIFEXITED(wstatus)); + ATF_CHECK_EQ(WEXITSTATUS(wstatus), 12); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, quick_exit); + ATF_TP_ADD_TC(tp, recursive_exit1); + ATF_TP_ADD_TC(tp, recursive_exit2); return (atf_no_error()); }