From nobody Thu Sep 19 20:07:07 2024 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 4X8mkz2RNJz5XJCF; Thu, 19 Sep 2024 20:07:07 +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 4X8mkz1t9jz4SGX; Thu, 19 Sep 2024 20:07:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726776427; 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=tW64fGPjxlHHtskdiLeQubxQyX+wW+RDf3nSDr7hW/g=; b=iFckQPPqWf4Qc1t84vfmGxAouuNmlrJZdQ0zvb3BSSFoYxrO98OXnv8VQN3ohEZhljdYvL 09PlrOXVWISS7kZXmojZFc8Mq3GW7T6wrr2Dl4xXY/obrgufD83ESAYv3vQKTFv4y/VKGw cxj/mPFXjOCz/8lhzRlMxxPENvAxuXbM1Zp2h+RmH2LA0HEMKTfuWrA+b5XhC8idYB7vg5 FsEah9RywAwIrrmusmXXhCbnrlLJPYTvVzjE6AdrLBhygNXGnrOQudHYrq54dIR7BjEJmK pPGLBWrSJ0SJ1brpCOVT2G+STqj+ion5EV1Kr5mOaQWMhL2ye/eH2l+AkkeOHA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726776427; a=rsa-sha256; cv=none; b=Vtor1X/+TeRl32S5dOu5GzaDa3QuDrMsGZ1TdQbVRWot0kSF6UMrtjcEjcD/RcT7b38QGw MoiX7b9KjEw5eQWNWWX5LA4At6UbvqZ/hA6U8tDH1Qs6AvXhysi70AdrTj2G489g6uPYMD Xi7hPAfjG+Hsz5CCHZ33VD/q9K9iwWbE9/hhJ8Y/X44VzyGMJaEZnMy4KNIjMnfI9LODlX KMyh7zruqi46lbomf0WgfjYZBPtk7/0CWmdlpal2JhEQnBIQ3jCLLfxOsG9BsJSMfpMToj I5lInfDVg1lQhEVhipkWCr8qO0Z35NZvfi5sh/FnclB1srTtYdUWfeLnO3vQlQ== 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=1726776427; 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=tW64fGPjxlHHtskdiLeQubxQyX+wW+RDf3nSDr7hW/g=; b=sb1gkMNGQ5RIgJf5FgARJ2PJBJBf0P1+Rmp25nP3Aku595ZEvj1DJdl3hCOnXj/J4aRXVg AfGts4/0+KcYCkWhOWiU7j+QK4tXSCGzRhoGoWIWjgNVrIZ848f0+lEmcPlZdjVnq5+BYF SOu+d9Uc3GqxJ6QxcLXhRk7+TkFTZkGhO6HBszwHktmarJqUJScEU7dfHD2/TLg0yTOaOb XDasCZAE/gvjWIoTjt/TPyNZULOuOXTaeit+JFBIGj2R9F6Z13hHMkfUSDM0yXG28HQ7aP Xiv4l3OuIytfqK3WZg1i42xNclGyrcEOmaVsYHMy9JcainUFFFdLL3I8r6fXbw== 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 4X8mkz1TMvzK3T; Thu, 19 Sep 2024 20:07:07 +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 48JK77GJ017725; Thu, 19 Sep 2024 20:07:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JK77cL017722; Thu, 19 Sep 2024 20:07:07 GMT (envelope-from git) Date: Thu, 19 Sep 2024 20:07:07 GMT Message-Id: <202409192007.48JK77cL017722@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: bc4240ed3b23 - stable/14 - Add some ATF tests for ctladm 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: bc4240ed3b232420f2f38b74ec1db0cb524a52c6 Auto-Submitted: auto-generated The branch stable/14 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=bc4240ed3b232420f2f38b74ec1db0cb524a52c6 commit bc4240ed3b232420f2f38b74ec1db0cb524a52c6 Author: Alan Somers AuthorDate: 2024-06-05 20:16:25 +0000 Commit: Alan Somers CommitDate: 2024-09-19 20:03:09 +0000 Add some ATF tests for ctladm So far only "ctladm port -c" and "ctladm port -r" are covered. Sponsored by: Axcient Reviewed by: mav Pull Request: https://github.com/freebsd/freebsd-src/pull/1279 (cherry picked from commit 9747d11d91642cb9b81602d88e8aebeb388543c7) Fix mtree entry for ctladm tests Sponsored by: Axcient (cherry picked from commit 81ef0a89fcc055bdf3d0f1affbadb643412ebce9) ctladm: add a copyright header to the port test [skip ci] Reported by: markj Sponsored by: Axcient (cherry picked from commit a1608e8854da7f3b5734c2fcb85dd740733a08e6) --- etc/mtree/BSD.tests.dist | 2 + usr.sbin/ctladm/Makefile | 3 + usr.sbin/ctladm/tests/Makefile | 10 +++ usr.sbin/ctladm/tests/port.sh | 180 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 9f0f59eb923d..95328d6d293f 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -1175,6 +1175,8 @@ usr.sbin chown .. + ctladm + .. daemon .. etcupdate diff --git a/usr.sbin/ctladm/Makefile b/usr.sbin/ctladm/Makefile index f9ddd251f96c..69dc727deaf4 100644 --- a/usr.sbin/ctladm/Makefile +++ b/usr.sbin/ctladm/Makefile @@ -23,4 +23,7 @@ MAN= ctladm.8 CFLAGS+= -DWANT_ISCSI .endif +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/usr.sbin/ctladm/tests/Makefile b/usr.sbin/ctladm/tests/Makefile new file mode 100644 index 000000000000..73ac94d77d21 --- /dev/null +++ b/usr.sbin/ctladm/tests/Makefile @@ -0,0 +1,10 @@ + +PACKAGE= tests + +ATF_TESTS_SH= port + +# "ctladm port" does not report the name of the port just created, so we can't +# cleanup unless we assume that no other test created a port too. +TEST_METADATA+= is_exclusive="true" + +.include diff --git a/usr.sbin/ctladm/tests/port.sh b/usr.sbin/ctladm/tests/port.sh new file mode 100644 index 000000000000..110b89bd965b --- /dev/null +++ b/usr.sbin/ctladm/tests/port.sh @@ -0,0 +1,180 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 Axcient +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS DOCUMENTATION IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Things that aren't tested due to lack of kernel support: +# * Creating camsim ports +# * Creating tpc ports +# * Creating camtgt ports +# * Creating umass ports + +# TODO +# * Creating iscsi ports +# * Creating nvmf ports +# * Creating ha ports +# * Creating fc ports + +skip_if_ctld() { + if service ctld onestatus > /dev/null; then + # If ctld is running on this server, let's not interfere. + atf_skip "Cannot run this test while ctld is running" + fi +} + +cleanup() { + driver=$1 + + if [ -e after-ports ]; then + diff before-ports after-ports | awk "/$driver/ {print \$2}" | xargs -n1 ctladm port -r -d ioctl -p + fi +} + +atf_test_case create_ioctl cleanup +create_ioctl_head() +{ + atf_set "descr" "ctladm can create a new ioctl port" + atf_set "require.user" "root" +} +create_ioctl_body() +{ + skip_if_ctld + + atf_check -o save:before-ports ctladm portlist -qf ioctl + atf_check ctladm port -c -d "ioctl" + atf_check -o save:after-ports ctladm portlist -qf ioctl + if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then + atf_fail "Did not create a new ioctl port" + fi +} +create_ioctl_cleanup() +{ + cleanup ioctl +} + +atf_test_case create_ioctl_options cleanup +create_ioctl_options_head() +{ + atf_set "descr" "ctladm can set options when creating a new ioctl port" + atf_set "require.user" "root" +} +create_ioctl_options_body() +{ + skip_if_ctld + + atf_check -o save:before-ports ctladm portlist -qf ioctl + atf_check ctladm port -c -d "ioctl" -O pp=101 -O vp=102 + atf_check -o save:after-ports ctladm portlist -qf ioctl + if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then + atf_fail "Did not create a new ioctl port" + fi + if ! egrep -q '101[[:space:]]+102' after-ports; then + ctladm portlist + atf_fail "Did not create the port with the specified options" + fi +} +create_ioctl_options_cleanup() +{ + cleanup ioctl +} + + +atf_test_case disable_ioctl cleanup +disable_ioctl_head() +{ + atf_set "descr" "ctladm can disable an ioctl port" + atf_set "require.user" "root" +} +disable_ioctl_body() +{ + skip_if_ctld + + atf_check -o save:before-ports ctladm portlist -qf ioctl + atf_check ctladm port -c -d "ioctl" + atf_check -o save:after-ports ctladm portlist -qf ioctl + if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then + atf_fail "Did not create a new ioctl port" + fi + portnum=`diff before-ports after-ports | awk '/ioctl/ {print $2}'`; + atf_check -o ignore ctladm port -o off -p $portnum + atf_check -o match:"^$portnum *NO" ctladm portlist -qf ioctl +} +disable_ioctl_cleanup() +{ + cleanup ioctl +} + +atf_test_case enable_ioctl cleanup +enable_ioctl_head() +{ + atf_set "descr" "ctladm can enable an ioctl port" + atf_set "require.user" "root" +} +enable_ioctl_body() +{ + skip_if_ctld + + atf_check -o save:before-ports ctladm portlist -qf ioctl + atf_check ctladm port -c -d "ioctl" + atf_check -o save:after-ports ctladm portlist -qf ioctl + if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then + atf_fail "Did not create a new ioctl port" + fi + portnum=`diff before-ports after-ports | awk '/ioctl/ {print $2}'`; + atf_check -o ignore ctladm port -o off -p $portnum + atf_check -o ignore ctladm port -o on -p $portnum + atf_check -o match:"^$portnum *YES" ctladm portlist -qf ioctl +} +enable_ioctl_cleanup() +{ + cleanup ioctl +} + +atf_test_case remove_ioctl +remove_ioctl_head() +{ + atf_set "descr" "ctladm can remove an ioctl port" + atf_set "require.user" "root" +} +remove_ioctl_body() +{ + skip_if_ctld + + atf_check -o save:before-ports ctladm portlist -qf ioctl + atf_check ctladm port -c -d "ioctl" + atf_check -o save:after-ports ctladm portlist -qf ioctl + if test `wc -l before-ports | cut -w -f2` -ge `wc -l after-ports | cut -w -f2`; then + atf_fail "Did not create a new ioctl port" + fi + portnum=`diff before-ports after-ports | awk '/ioctl/ {print $2}'`; + atf_check ctladm port -r -d ioctl -p $portnum +} + +atf_init_test_cases() +{ + atf_add_test_case create_ioctl + atf_add_test_case create_ioctl_options + atf_add_test_case disable_ioctl + atf_add_test_case enable_ioctl + atf_add_test_case remove_ioctl +}