From nobody Sat Apr 26 03:21:15 2025 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 4Zkw3J1b7hz5tXwK; Sat, 26 Apr 2025 03:21:16 +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 4Zkw3H5nktz3LCN; Sat, 26 Apr 2025 03:21:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745637675; 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=79Ea9oJ+/DkutPcq12w/PCVR91oHVZ069wk6HqiEs1U=; b=nAWcNuI1dhwoUx77lMITE3pdUJpjNK8gAHdaB0xxxbZJcNWM7Icn0XX7NKds1T+aTT8NLF dg+JXFDb+cD+sZgOshJZhHNKYAX1hAXraWz6XtSh+Vz77PyONvtSFuL8xnmx5ikvLXCzU5 ELpEFa0nN5sCH5UmNVuZ122PlvY0MUBWSG+L+HxTAgzOCFXg9aqrceN7rfRSkIWO6+qcOS re/ykv5W50b+574nQY3j8kzaNbvtu1YQxd748F3Bb34yTWcpbmQNKNSrk1g5bP3O1bsZEG t/3bvLsE62Ad86yY57oWzHbtLl+Zp+T7w8kvcuTe7Kmv5NJ6hm9tW4VOcNmN6A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745637675; a=rsa-sha256; cv=none; b=EWG+4lmafmWDAlk/zdYU6aRzAyzkN3/ElR9jzEvgAJQ+pNgf6pmq8xd1N++HixnkFwxec7 qteqUpLIfTFgqDPqx59rbGwiZrvrAB1OHpDyfpmt7M7wi9RoDricpCLswaZpynWalAC45/ FIM5f8o5YIqQwOO9uXj/4i3nt3zu5UA1j3vhkcws5xS51FCbzHgtzJPcI+DamQffjkP2Lu KWS/2eyXNo825AVZrrVdFbgZzPWsURZRxEhVE/nVl6z9S8HGMRrItNMxzw36UbybRVpDtl fI+odNOx2pz76tU/aJffjBIlYDagswhRwDiGRNvDmx4sSPTW7SOrQ3Q2Reg+7w== 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=1745637675; 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=79Ea9oJ+/DkutPcq12w/PCVR91oHVZ069wk6HqiEs1U=; b=rBimoV8vk3n5c5fHLeKFmlgeInw9+4yxa/6gJm+yQaWs2tsRKyTP1W63NiIoq1JbrfJKHV ovmt3QH5GGZ9Oq00mfM0Nv4SiD3Lv61696BkhyKbN/QohvV0gtUyIOdzEt2xyGRAOjBBHg RGe/x9f6saG+xCnDeMwkUcqSXrvp9FsA4tPv/wZ5D3o74TmgY4+A8AFTo0xJgd7ysPQsQ3 CP2EN8uKrqESMBQ0yIB5xr7+WVdpxIsTblCzWiCJ0q1/zU/DdbVQKjZEsmMdI7A5AEEovy gNz1zhFC+MJP4opflZixzbYYvglIRy5h7+by6JL1Gwl6I656Xl639FxPWVmxsQ== 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 4Zkw3H4X8Jz12jL; Sat, 26 Apr 2025 03:21:15 +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 53Q3LFj6009696; Sat, 26 Apr 2025 03:21:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53Q3LFXO009693; Sat, 26 Apr 2025 03:21:15 GMT (envelope-from git) Date: Sat, 26 Apr 2025 03:21:15 GMT Message-Id: <202504260321.53Q3LFXO009693@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 00640ea3144c - stable/14 - tee: add some basic 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 00640ea3144cd6511aa05c16d20037b32e592dca Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=00640ea3144cd6511aa05c16d20037b32e592dca commit 00640ea3144cd6511aa05c16d20037b32e592dca Author: Kyle Evans AuthorDate: 2025-04-20 16:34:50 +0000 Commit: Kyle Evans CommitDate: 2025-04-26 03:19:48 +0000 tee: add some basic tests The cases are ordered in such a way that we naturally progress through the functionality, with the earliest failures perhaps shedding light on any later failures. sysutils/porch is used for one test if it's available, just to cleanly check that SIGINT is being ignored properly. Reviewed by: des, emaste (cherry picked from commit 85ff0b08ee699ff323404727998993275b4d2e2a) --- etc/mtree/BSD.tests.dist | 2 ++ usr.bin/tee/Makefile | 5 +++ usr.bin/tee/tests/Makefile | 6 ++++ usr.bin/tee/tests/sigint.orch | 14 ++++++++ usr.bin/tee/tests/tee_test.sh | 74 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index f8088894e6f4..a6b2eed725b8 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1147,6 +1147,8 @@ .. tar .. + tee + .. tftp .. touch diff --git a/usr.bin/tee/Makefile b/usr.bin/tee/Makefile index a713132df295..dab708015872 100644 --- a/usr.bin/tee/Makefile +++ b/usr.bin/tee/Makefile @@ -1,5 +1,10 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 +.include + PROG= tee +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/usr.bin/tee/tests/Makefile b/usr.bin/tee/tests/Makefile new file mode 100644 index 000000000000..acb78e671a8c --- /dev/null +++ b/usr.bin/tee/tests/Makefile @@ -0,0 +1,6 @@ +PACKAGE= tests + +ATF_TESTS_SH+= tee_test +${PACKAGE}FILES+= sigint.orch + +.include diff --git a/usr.bin/tee/tests/sigint.orch b/usr.bin/tee/tests/sigint.orch new file mode 100644 index 000000000000..2fc0b32c61fb --- /dev/null +++ b/usr.bin/tee/tests/sigint.orch @@ -0,0 +1,14 @@ +-- We expect the caller to have spawned the appropriate application +write "text\r" +match "text" + +write "^C" + +-- If SIGINT isn't being ignored, we'll bail out somewhere in the process of +-- writing to the pty or trying to read from it to perform the following match. +write "text\r" +match "text" + +-- Finally, just close it out cleanly. +write "^D" +eof() diff --git a/usr.bin/tee/tests/tee_test.sh b/usr.bin/tee/tests/tee_test.sh new file mode 100644 index 000000000000..6ac733f2e58f --- /dev/null +++ b/usr.bin/tee/tests/tee_test.sh @@ -0,0 +1,74 @@ +# +# Copyright (c) 2024 Kyle Evans +# +# SPDX-License-Identifier: BSD-2-Clause +# + +atf_test_case single_file +single_file_body() +{ + atf_check -o inline:"text\n" -x "echo text | tee file" + atf_check -o inline:"text\n" cat file +} + +atf_test_case device +device_body() +{ + atf_check -e inline:"text\n" -o inline:"text\n" -x \ + "echo text | tee /dev/stderr" +} + +atf_test_case multiple_file +multiple_file_body() +{ + atf_check -o inline:"text\n" -x "echo text | tee file1 file2" + atf_check -o inline:"text\n" cat file1 + atf_check -o inline:"text\n" cat file2 +} + +atf_test_case append +append_body() +{ + atf_check -o ignore -x "echo text | tee file" + atf_check -o inline:"text\n" cat file + + # Should overwrite if done again + atf_check -o ignore -x "echo text | tee file" + atf_check -o inline:"text\n" cat file + + # Should duplicate if we use -a + atf_check -o ignore -x "echo text | tee -a file" + atf_check -o inline:"text\ntext\n" cat file +} + +atf_test_case sigint_ignored +sigint_ignored_head() +{ + # This is most cleanly tested with interactive input, to avoid adding + # a lot of complexity in trying to manage an input and signal delivery + # dance purely in shell. + atf_set "require.progs" "porch" +} +sigint_ignored_body() +{ + + # sigint.orch will write "text" to the file twice if we're properly + # ignoring SIGINT, so we'll do one test to confirm that SIGINT is not + # being ignored by porch(1), then another to confirm that tee(1) will + # ignore SIGINT when instructed to. + atf_check -s exit:1 -e ignore \ + porch -f $(atf_get_srcdir)/sigint.orch tee file + atf_check -o inline:"text\n" cat file + + atf_check porch -f $(atf_get_srcdir)/sigint.orch tee -i file + atf_check -o inline:"text\ntext\n" cat file +} + +atf_init_test_cases() +{ + atf_add_test_case single_file + atf_add_test_case device + atf_add_test_case multiple_file + atf_add_test_case append + atf_add_test_case sigint_ignored +}