From nobody Mon Jun 10 16:01:41 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 4Vyc4Q0hJNz5M8vy; Mon, 10 Jun 2024 16:01:42 +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 4Vyc4Q01XJz4pgm; Mon, 10 Jun 2024 16:01:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718035302; 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=6Vf277lJNZJ+GbTKdYYqxyQC4w4Y2Pk8lhI6BXUY/ak=; b=K9W4KlyeX7bDjPWOhFX/BRlCrRyd5ZemV24X48Y5CQG3VW4jth1Q8SQM33c1ksyU1sMfUK BxaUR9whCBBk1pshxyHu7WGQ+Fua6WtGXmLsfQC0WKbWWMnvbnb/vKSox1t4e2f0ijbDAQ mudpoytpcdm7MRLpHILbUGy+gJH5bIpC10hN4D9aL/adsps45x/AnwsT1bNpAJojt7XlGK RqQ1kwNO4DiuYY9PcvGbhya+N6aONif24mj4WVd1FnMPXlT9UYxtenph7nwHGrm7f/uLXz BOVPBdwQuzLEtgVgjiRS0EY0SZXnLrkJhWAeofZZVWyGFrJ0JgTsTR9X/TL/KA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718035302; a=rsa-sha256; cv=none; b=W+E0ro+/AsV6pKbz2RMJjlHBKnYr7IDKMDVFwLwvnEiRr2RRb8KDBq/AhupmNtH/pC2j7I +PJDT79t4560UU7W89joZXVLWd3DpH7qCaJTEkbE7MlgTXUb3/j68KPZy1UrfU1M6n0AHk ZfJmIwEp92GmZe4kIfpyQCY+xiCLaSIXGQF5bEscvReFVz+coQTUTFlyD2oITHFQrZRxs9 LFu0jPiv5UE0gwKC26oMrTA8qYtyInoj2/og1klIuIysWTeXIyJe7CM3TtzLJX+vcwgtkH 5Lwdf4J3MBFUkJki2YQoVU2eN5R6Q/tOhzT4d71PWePsHwYu109StXjotJWfQw== 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=1718035302; 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=6Vf277lJNZJ+GbTKdYYqxyQC4w4Y2Pk8lhI6BXUY/ak=; b=m8I9kS6wrfY6nj7bHDXFT2n6DZAVuaIUBOac5Mq/nYZFLYBvRZuqujcSFCZDrGe6F80Vgl +FkVkZooPacylpMwBZofLJNbYDWG7jPnzg5QHwgF/rh6vXQxB3bq52MqLTbqeWHK1H9FHL BqdIisMB255tGZOYipgP/iQjsGOip+UqdOqhh5c+u9rccm2R3xGzEbHotOitFofx0bjbAO H0TqXLZ21Q217h4SlfB0T6nM1q0I5fiQt5PuZ7gE6S0rShHPcw6fbe1XROjbNsQn0eeGap OeECIpB++0Azskh/a0p+EfCQzHGD69CmQlWTxeQUJsyGVZJry/I6Qx5bnr6/DQ== 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 4Vyc4P6jxqzXQH; Mon, 10 Jun 2024 16:01:41 +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 45AG1fa5001344; Mon, 10 Jun 2024 16:01:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45AG1fQw001341; Mon, 10 Jun 2024 16:01:41 GMT (envelope-from git) Date: Mon, 10 Jun 2024 16:01:41 GMT Message-Id: <202406101601.45AG1fQw001341@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 9747d11d9164 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 9747d11d91642cb9b81602d88e8aebeb388543c7 Auto-Submitted: auto-generated The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=9747d11d91642cb9b81602d88e8aebeb388543c7 commit 9747d11d91642cb9b81602d88e8aebeb388543c7 Author: Alan Somers AuthorDate: 2024-06-05 20:16:25 +0000 Commit: Alan Somers CommitDate: 2024-06-10 16:01:25 +0000 Add some ATF tests for ctladm So far only "ctladm port -c" and "ctladm port -r" are covered. MFC after: 2 weeks Sponsored by: Axcient Reviewed by: mav Pull Request: https://github.com/freebsd/freebsd-src/pull/1279 --- etc/mtree/BSD.tests.dist | 2 + usr.sbin/ctladm/Makefile | 3 + usr.sbin/ctladm/tests/Makefile | 10 +++ usr.sbin/ctladm/tests/port.sh | 155 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 170 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 3f447f9ec25e..86db4304b932 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -90,6 +90,8 @@ .. .. usr.sbin + ctladm + .. dtrace common aggs diff --git a/usr.sbin/ctladm/Makefile b/usr.sbin/ctladm/Makefile index 5e0df8065cce..b563891672be 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..b2cdea6f1de2 --- /dev/null +++ b/usr.sbin/ctladm/tests/port.sh @@ -0,0 +1,155 @@ +# 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 +}