]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add simple test for PCR list parsing 19727/head
authorLennart Poettering <lennart@poettering.net>
Tue, 25 May 2021 21:40:10 +0000 (23:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 May 2021 21:40:10 +0000 (23:40 +0200)
src/test/meson.build
src/test/test-tpm2.c [new file with mode: 0644]

index e02eaf78ff9e1e6e1644d9ab1673c4729d1139f6..c7b2bbfedc36cea550c6b2d025aa9362cc393c36 100644 (file)
@@ -422,6 +422,8 @@ tests += [
 
         [['src/test/test-sleep.c']],
 
+        [['src/test/test-tpm2.c']],
+
         [['src/test/test-replace-var.c']],
 
         [['src/test/test-calendarspec.c']],
diff --git a/src/test/test-tpm2.c b/src/test/test-tpm2.c
new file mode 100644 (file)
index 0000000..a1fd0aa
--- /dev/null
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "tpm2-util.h"
+#include "tests.h"
+
+static void test_tpm2_parse_pcrs(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);
+}
+
+int main(int argc, char *argv[]) {
+
+        test_setup_logging(LOG_DEBUG);
+
+        test_tpm2_parse_pcrs("", 0, 0);
+        test_tpm2_parse_pcrs("0", 1, 0);
+        test_tpm2_parse_pcrs("1", 2, 0);
+        test_tpm2_parse_pcrs("0,1", 3, 0);
+        test_tpm2_parse_pcrs("0+1", 3, 0);
+        test_tpm2_parse_pcrs("0-1", 0, -EINVAL);
+        test_tpm2_parse_pcrs("0,1,2", 7, 0);
+        test_tpm2_parse_pcrs("0+1+2", 7, 0);
+        test_tpm2_parse_pcrs("0+1,2", 7, 0);
+        test_tpm2_parse_pcrs("0,1+2", 7, 0);
+        test_tpm2_parse_pcrs("0,2", 5, 0);
+        test_tpm2_parse_pcrs("0+2", 5, 0);
+        test_tpm2_parse_pcrs("foo", 0, -EINVAL);
+
+        return 0;
+}