File: test-Fix-test-expectation-based-on-kernel-config.patch

package info (click to toggle)
keyutils 1.6.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,372 kB
  • sloc: sh: 5,429; ansic: 4,813; makefile: 278
file content (81 lines) | stat: -rw-r--r-- 2,657 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From: Pavel Reichl <preichl@redhat.com>
Date: Tue, 20 Dec 2022 14:13:29 +0100
Subject: test: Fix test expectation based on kernel config

Some test results are dependent on the kernel configuration option
CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE.

Check the kernel configuration file for its presence and expect appropriate
test results.

Function has_kernel_config is based on its xfstsests counterpart.

Signed-off-by: Pavel Reichl <preichl@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Origin: https://web.git.kernel.org/pub/scm/linux/kernel/git/dhowells/keyutils.git/commit/?id=c076dff259e99d84d3822b4d2ad7f3f66532f411
---
 tests/features/builtin_trusted/runtest.sh | 12 ++++++++++--
 tests/prepare.inc.sh                      | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/tests/features/builtin_trusted/runtest.sh b/tests/features/builtin_trusted/runtest.sh
index f7d20ca..164382d 100644
--- a/tests/features/builtin_trusted/runtest.sh
+++ b/tests/features/builtin_trusted/runtest.sh
@@ -38,7 +38,11 @@ expect_error EACCES
 create_key --fail user a a $stk
 expect_error EOPNOTSUPP
 create_key --fail user a a $blk
-expect_error EACCES
+if has_kernel_config "CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE"; then
+	expect_error EOPNOTSUPP
+else
+	expect_error EACCES
+fi
 
 # Try adding a key to the keyrings
 marker "TRY ADDING ASYMMETRIC KEYS"
@@ -94,7 +98,11 @@ expect_error EACCES
 create_key --fail -x asymmetric "" "$x509" $stk
 expect_error ENOKEY
 create_key --fail -x asymmetric "" "$x509" $blk
-expect_error EACCES
+if has_kernel_config "CONFIG_SYSTEM_BLACKLIST_AUTH_UPDATE"; then
+	expect_error EOPNOTSUPP
+else
+	expect_error EACCES
+fi
 
 echo "++++ FINISHED TEST: $result" >>$OUTPUTFILE
 
diff --git a/tests/prepare.inc.sh b/tests/prepare.inc.sh
index 52ec52c..fd44312 100644
--- a/tests/prepare.inc.sh
+++ b/tests/prepare.inc.sh
@@ -4,6 +4,26 @@
 includes=${BASH_SOURCE[0]}
 includes=${includes%/*}/
 
+# Check if currently running kernel has option set
+function has_kernel_config()
+{
+        local option=$1
+        local uname=$(uname -r)
+        local config_list="$KCONFIG_PATH
+                     /lib/modules/$uname/build/.config
+                     /boot/config-$uname
+                     /lib/kernel/config-$uname"
+
+        for config in $config_list; do
+                [ ! -f $config ] && continue
+                grep -qE "^${option}=[my]" $config
+                return
+        done
+
+        echo "Failed to find kernel configuration file"
+        return false
+}
+
 # --- need to run in own session keyring
 watch_fd=0
 if [ "$1" != "--inside-test-session" ]