From: David Howells <dhowells@redhat.com>
To: Jarkko Sakkinen <jarkko@kernel.org>
Cc: dhowells@redhat.com, keyrings@vger.kernel.org
Subject: [PATCH keyutils] tests: Add skips for testing of unsupported features
Date: Thu, 24 Apr 2025 11:44:40 +0100 [thread overview]
Message-ID: <3089643.1745491480@warthog.procyon.org.uk> (raw)
Hi Jarkko,
Here's a patch I'm proposing to add to the keyutils testsuite so that I can
use it with some older OS versions.
David
---
tests: Add skips for testing of unsupported features
Add skips for features that are either unsupported by the kernel or by the
keyutils package.
Signed-off-by: David Howells <dhowells@redhat.com>
---
tests/features/limits/runtest.sh | 6 +++++
tests/hex2bin.pl | 21 +++++++++++++++++++
tests/keyctl/id/bad-args/runtest.sh | 6 +++++
tests/keyctl/id/noargs/runtest.sh | 6 +++++
tests/keyctl/id/valid/runtest.sh | 6 +++++
tests/keyctl/move/bad-args/runtest.sh | 6 +++++
tests/keyctl/move/noargs/runtest.sh | 6 +++++
tests/keyctl/move/recursion/runtest.sh | 6 +++++
tests/keyctl/move/valid/runtest.sh | 6 +++++
tests/keyctl/session/valid2/runtest.sh | 6 +++++
tests/keyctl/supports/bad-args/runtest.sh | 6 +++++
tests/keyctl/supports/valid/runtest.sh | 6 +++++
tests/prepare.inc.sh | 23 ++++++++++++++++++++
tests/toolbox.inc.sh | 33 ++++++++++++++++++++++++------
14 files changed, 136 insertions(+), 7 deletions(-)
diff --git a/tests/features/limits/runtest.sh b/tests/features/limits/runtest.sh
index 3af2f5a..7642071 100644
--- a/tests/features/limits/runtest.sh
+++ b/tests/features/limits/runtest.sh
@@ -9,6 +9,12 @@
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
+if ! keyutils_at_or_later_than 1.6.2
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl --test'"
+ exit 0
+fi
+
# This doesn't work on MIPS earler than 3.19 because of a kernel bug
kver=`uname -r`
kmch=`uname -m`
diff --git a/tests/hex2bin.pl b/tests/hex2bin.pl
new file mode 100644
index 0000000..4f0f27a
--- /dev/null
+++ b/tests/hex2bin.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+use strict;
+
+die "Format:\n\t$0 <hex> [<hex>]*\n\t$0 -\n" unless (@ARGV);
+
+my $str = "";
+
+if ($ARGV[0] eq "-") {
+ shift(@ARGV);
+ $str .= $_ while (<STDIN>);
+} else {
+ $str = join("", @ARGV);
+}
+
+$str =~ s/[ \t\n]//g;
+die "odd length string\n" if (length($str) & 1);
+
+for (; $str; $str = substr($str, 2)) {
+ my $pair = hex(substr($str, 0, 2));
+ print pack("C", $pair);
+}
diff --git a/tests/keyctl/id/bad-args/runtest.sh b/tests/keyctl/id/bad-args/runtest.sh
index 957d1a5..bba62c6 100644
--- a/tests/keyctl/id/bad-args/runtest.sh
+++ b/tests/keyctl/id/bad-args/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_id_command = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl id'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/id/noargs/runtest.sh b/tests/keyctl/id/noargs/runtest.sh
index aff9de6..b95c596 100644
--- a/tests/keyctl/id/noargs/runtest.sh
+++ b/tests/keyctl/id/noargs/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_id_command = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl id'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/id/valid/runtest.sh b/tests/keyctl/id/valid/runtest.sh
index ffed995..2c06b3d 100644
--- a/tests/keyctl/id/valid/runtest.sh
+++ b/tests/keyctl/id/valid/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_id_command = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl id'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/move/bad-args/runtest.sh b/tests/keyctl/move/bad-args/runtest.sh
index b1c7e66..9410941 100644
--- a/tests/keyctl/move/bad-args/runtest.sh
+++ b/tests/keyctl/move/bad-args/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_move_key = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl move'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/move/noargs/runtest.sh b/tests/keyctl/move/noargs/runtest.sh
index 29a91f1..8ad91e9 100644
--- a/tests/keyctl/move/noargs/runtest.sh
+++ b/tests/keyctl/move/noargs/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_move_key = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl move'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/move/recursion/runtest.sh b/tests/keyctl/move/recursion/runtest.sh
index 36cd5cb..8b90be8 100644
--- a/tests/keyctl/move/recursion/runtest.sh
+++ b/tests/keyctl/move/recursion/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_move_key = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl move'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/move/valid/runtest.sh b/tests/keyctl/move/valid/runtest.sh
index 31b51d7..20ccff2 100644
--- a/tests/keyctl/move/valid/runtest.sh
+++ b/tests/keyctl/move/valid/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_move_key = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl move'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/session/valid2/runtest.sh b/tests/keyctl/session/valid2/runtest.sh
index 12ad234..1642395 100644
--- a/tests/keyctl/session/valid2/runtest.sh
+++ b/tests/keyctl/session/valid2/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_id_command = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl id'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/supports/bad-args/runtest.sh b/tests/keyctl/supports/bad-args/runtest.sh
index 05581a4..f87f517 100644
--- a/tests/keyctl/supports/bad-args/runtest.sh
+++ b/tests/keyctl/supports/bad-args/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_capabilities = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl supports'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/keyctl/supports/valid/runtest.sh b/tests/keyctl/supports/valid/runtest.sh
index 2c62ef2..4e41200 100644
--- a/tests/keyctl/supports/valid/runtest.sh
+++ b/tests/keyctl/supports/valid/runtest.sh
@@ -6,6 +6,12 @@
# ---- do the actual testing ----
+if [ $have_capabilities = 0 ]
+then
+ toolbox_skip_test $TEST "SKIPPING DUE TO LACK OF 'keyctl supports'"
+ exit 0
+fi
+
result=PASS
echo "++++ BEGINNING TEST" >$OUTPUTFILE
diff --git a/tests/prepare.inc.sh b/tests/prepare.inc.sh
index 4033d69..be134da 100644
--- a/tests/prepare.inc.sh
+++ b/tests/prepare.inc.sh
@@ -112,11 +112,14 @@ then
esac
fi
+have_capabilities=0
have_key_invalidate=0
have_big_key_type=0
have_dh_compute=0
-have_restrict_keyring=0
+have_move_key=0
have_notify=0
+have_public_key=0
+have_restrict_keyring=0
if keyctl supports capabilities >&/dev/null
then
@@ -179,3 +182,21 @@ if [ "$SKIPINSTALLREQ" = "yes" ]
then
skip_install_required=1
fi
+
+#
+# Check if "keyctl id" is supported
+#
+have_id_command=0
+if keyutils_at_or_later_than 1.6.2
+then
+ have_id_command=1
+fi
+
+#
+# Check if "keyctl pkey_*" are supported
+#
+have_pkey_commands=0
+if keyutils_at_or_later_than 1.6
+then
+ have_pkey_commands=1
+fi
diff --git a/tests/toolbox.inc.sh b/tests/toolbox.inc.sh
index 6f4fb18..212b353 100644
--- a/tests/toolbox.inc.sh
+++ b/tests/toolbox.inc.sh
@@ -613,8 +613,15 @@ function create_key ()
my_keyring=$4
fi
- echo keyctl add "$@" >>$OUTPUTFILE
- keyctl add "$@" >>$OUTPUTFILE 2>&1
+ if [ "$1" = "-x" ] && version_less_than $OSRELEASE 9
+ then
+ shift
+ echo perl ../../../hex2bin.pl "$3" "|" keyctl padd "$1 $2 $4" >>$OUTPUTFILE
+ perl ../../../hex2bin.pl "$3" | keyctl padd "$1" "$2" "$4" >>$OUTPUTFILE
+ else
+ echo keyctl add "$@" >>$OUTPUTFILE
+ keyctl add "$@" >>$OUTPUTFILE 2>&1
+ fi
e=$?
if [ $e == $my_exitval ]
then
@@ -682,8 +689,15 @@ function pcreate_key ()
my_keyring=$3
fi
- echo echo -n $data \| keyctl padd "$@" >>$OUTPUTFILE
- echo -n $data | keyctl padd "$@" >>$OUTPUTFILE 2>&1
+ if [ "$1" = "-x" ] && version_less_than $OSRELEASE 9
+ then
+ shift
+ echo echo -n $data \| perl ../../../hex2bin.pl "|" keyctl padd "$@" >>$OUTPUTFILE
+ echo -n $data | perl ../../../hex2bin.pl - | keyctl padd "$@" >>$OUTPUTFILE
+ else
+ echo echo -n $data \| keyctl padd "$@" >>$OUTPUTFILE
+ echo -n $data | keyctl padd "$@" >>$OUTPUTFILE 2>&1
+ fi
e=$?
if [ $e == $my_exitval ]
then
@@ -1232,8 +1246,15 @@ function update_key ()
shift
fi
- echo keyctl update "$@" >>$OUTPUTFILE
- keyctl update "$@" >>$OUTPUTFILE 2>&1
+ if [ "x$1" = "x-x" ] && version_less_than $OSRELEASE 9
+ then
+ shift
+ echo perl ../../../hex2bin.pl "$2" "|" keyctl pupdate "$1" >>$OUTPUTFILE
+ perl ../../../hex2bin.pl "$2" | keyctl pupdate "$1" >>$OUTPUTFILE
+ else
+ echo keyctl update "$@" >>$OUTPUTFILE
+ keyctl update "$@" >>$OUTPUTFILE 2>&1
+ fi
e=$?
if [ $e == $my_exitval ]
then
next reply other threads:[~2025-04-24 10:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 10:44 David Howells [this message]
2025-04-30 16:05 ` [PATCH keyutils] tests: Add skips for testing of unsupported features Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3089643.1745491480@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=jarkko@kernel.org \
--cc=keyrings@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.