summaryrefslogtreecommitdiffstats
path: root/src/test/test-tpm2.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
commitb750101eb236130cf056c675997decbac904cc49 (patch)
treea5df1a06754bdd014cb975c051c83b01c9a97532 /src/test/test-tpm2.c
parentInitial commit. (diff)
downloadsystemd-b750101eb236130cf056c675997decbac904cc49.tar.xz
systemd-b750101eb236130cf056c675997decbac904cc49.zip
Adding upstream version 252.22.upstream/252.22
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-tpm2.c')
-rw-r--r--src/test/test-tpm2.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/test-tpm2.c b/src/test/test-tpm2.c
new file mode 100644
index 0000000..c5f3d41
--- /dev/null
+++ b/src/test/test-tpm2.c
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "tpm2-util.h"
+#include "tests.h"
+
+static void test_tpm2_parse_pcrs_one(const char *s, uint32_t mask, int ret) {
+ uint32_t m;
+
+ assert_se(tpm2_parse_pcrs(s, &m) == ret);
+
+ if (ret >= 0)
+ assert_se(m == mask);
+}
+
+TEST(tpm2_parse_pcrs) {
+ test_tpm2_parse_pcrs_one("", 0, 0);
+ test_tpm2_parse_pcrs_one("0", 1, 0);
+ test_tpm2_parse_pcrs_one("1", 2, 0);
+ test_tpm2_parse_pcrs_one("0,1", 3, 0);
+ test_tpm2_parse_pcrs_one("0+1", 3, 0);
+ test_tpm2_parse_pcrs_one("0-1", 0, -EINVAL);
+ test_tpm2_parse_pcrs_one("0,1,2", 7, 0);
+ test_tpm2_parse_pcrs_one("0+1+2", 7, 0);
+ test_tpm2_parse_pcrs_one("0+1,2", 7, 0);
+ test_tpm2_parse_pcrs_one("0,1+2", 7, 0);
+ test_tpm2_parse_pcrs_one("0,2", 5, 0);
+ test_tpm2_parse_pcrs_one("0+2", 5, 0);
+ test_tpm2_parse_pcrs_one("foo", 0, -EINVAL);
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);