Date: Wed, 14 May 2025 19:32:11 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: a6bac0a9efa1 - main - mail: Add test cases for SIGHUP. Message-ID: <202505141932.54EJWBfc038881@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=a6bac0a9efa15275ada0f0b0ef784837929fb5c6 commit a6bac0a9efa15275ada0f0b0ef784837929fb5c6 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2025-05-14 19:31:47 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2025-05-14 19:31:47 +0000 mail: Add test cases for SIGHUP. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50296 --- ObsoleteFiles.inc | 3 ++ usr.bin/mail/tests/Makefile | 2 +- .../{mail_sigint_test.c => mailx_signal_test.c} | 58 ++++++++++++++++------ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 1793eb4ba582..589c9ce41ab7 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -51,6 +51,9 @@ # xargs -n1 | sort | uniq -d; # done +# 20250511: mailx test renamed +OLD_FILES+=usr/tests/usr.bin/mail/mail_sigint_test + # 20250505: Remove audio(8) files after rename to sndctl(8) OLD_FILES+=usr/sbin/audio OLD_FILES+=usr/share/man/man8/audio.8.gz diff --git a/usr.bin/mail/tests/Makefile b/usr.bin/mail/tests/Makefile index cb194b3da1f1..d7c1776f87fc 100644 --- a/usr.bin/mail/tests/Makefile +++ b/usr.bin/mail/tests/Makefile @@ -1,4 +1,4 @@ PACKAGE= tests -ATF_TESTS_C+= mail_sigint_test +ATF_TESTS_C+= mailx_signal_test .include <bsd.test.mk> diff --git a/usr.bin/mail/tests/mail_sigint_test.c b/usr.bin/mail/tests/mailx_signal_test.c similarity index 69% rename from usr.bin/mail/tests/mail_sigint_test.c rename to usr.bin/mail/tests/mailx_signal_test.c index ace5f714c459..d4ce1e536935 100644 --- a/usr.bin/mail/tests/mail_sigint_test.c +++ b/usr.bin/mail/tests/mailx_signal_test.c @@ -25,9 +25,11 @@ * then exit cleanly on receipt of a second. * * When not interactive, mailx(1) should terminate on receipt of SIGINT. + * + * In either case, mailx(1) should terminate on receipt of SIGHUP. */ static void -mailx_sigint(bool interactive) +mailx_signal_test(int signo, bool interactive) { char obuf[1024] = ""; char ebuf[1024] = ""; @@ -80,8 +82,8 @@ mailx_sigint(bool interactive) ATF_REQUIRE_INTEQ(BODYLEN, write(ipd[1], BODY, BODYLEN)); /* give it a chance to process */ poll(NULL, 0, 2000); - /* send first SIGINT */ - ATF_CHECK_INTEQ(0, kill(pid, SIGINT)); + /* send first signal */ + ATF_CHECK_INTEQ(0, kill(pid, signo)); kc = 1; /* receive output until child terminates */ fds[0].fd = opd[0]; @@ -103,7 +105,7 @@ mailx_sigint(bool interactive) } time(&now); if (now - start > 1 && elen > 0 && kc == 1) { - ATF_CHECK_INTEQ(0, kill(pid, SIGINT)); + ATF_CHECK_INTEQ(0, kill(pid, signo)); kc++; } if (now - start > 15 && kc > 0) { @@ -117,41 +119,67 @@ mailx_sigint(bool interactive) close(opd[0]); close(epd[0]); close(spd[0]); - if (interactive) { + /* + * In interactive mode, SIGINT results in a prompt, and a second + * SIGINT results in exit(1). In all other cases, we should see + * the signal terminate the process. + */ + if (interactive && signo == SIGINT) { ATF_CHECK(WIFEXITED(status)); if (WIFEXITED(status)) ATF_CHECK_INTEQ(1, WEXITSTATUS(status)); ATF_CHECK_INTEQ(2, kc); ATF_CHECK_STREQ("", obuf); ATF_CHECK_MATCH("Interrupt -- one more to kill letter", ebuf); - atf_utils_compare_file("dead.letter", BODY); } else { ATF_CHECK(WIFSIGNALED(status)); if (WIFSIGNALED(status)) - ATF_CHECK_INTEQ(SIGINT, WTERMSIG(status)); + ATF_CHECK_INTEQ(signo, WTERMSIG(status)); ATF_CHECK_INTEQ(1, kc); ATF_CHECK_STREQ("", obuf); ATF_CHECK_STREQ("", ebuf); + } + /* + * In interactive mode, and only in interactive mode, mailx should + * save whatever was typed before termination in ~/dead.letter. + * This is why we set HOME to "." in the child. + */ + if (interactive) { + atf_utils_compare_file("dead.letter", BODY); + } else { ATF_CHECK_INTEQ(-1, access("dead.letter", F_OK)); } } +ATF_TC_WITHOUT_HEAD(mailx_sighup_interactive); +ATF_TC_BODY(mailx_sighup_interactive, tc) +{ + mailx_signal_test(SIGHUP, true); +} + +ATF_TC_WITHOUT_HEAD(mailx_sighup_noninteractive); +ATF_TC_BODY(mailx_sighup_noninteractive, tc) +{ + mailx_signal_test(SIGHUP, false); +} -ATF_TC_WITHOUT_HEAD(mail_sigint_interactive); -ATF_TC_BODY(mail_sigint_interactive, tc) +ATF_TC_WITHOUT_HEAD(mailx_sigint_interactive); +ATF_TC_BODY(mailx_sigint_interactive, tc) { - mailx_sigint(true); + mailx_signal_test(SIGINT, true); } -ATF_TC_WITHOUT_HEAD(mail_sigint_noninteractive); -ATF_TC_BODY(mail_sigint_noninteractive, tc) +ATF_TC_WITHOUT_HEAD(mailx_sigint_noninteractive); +ATF_TC_BODY(mailx_sigint_noninteractive, tc) { - mailx_sigint(false); + mailx_signal_test(SIGINT, false); } ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, mail_sigint_interactive); - ATF_TP_ADD_TC(tp, mail_sigint_noninteractive); + ATF_TP_ADD_TC(tp, mailx_sighup_interactive); + ATF_TP_ADD_TC(tp, mailx_sighup_noninteractive); + ATF_TP_ADD_TC(tp, mailx_sigint_interactive); + ATF_TP_ADD_TC(tp, mailx_sigint_noninteractive); return (atf_no_error()); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505141932.54EJWBfc038881>