From b750101eb236130cf056c675997decbac904cc49 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:35:18 +0200 Subject: Adding upstream version 252.22. Signed-off-by: Daniel Baumann --- src/test/test-tpm2.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/test-tpm2.c (limited to 'src/test/test-tpm2.c') 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); -- cgit v1.2.3