test: add simple test for PCR list parsing

This commit is contained in:
Lennart Poettering
2021-05-25 23:40:10 +02:00
parent d57f6340b6
commit a3f9cd27cd
2 changed files with 36 additions and 0 deletions

View 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']],

34
src/test/test-tpm2.c Normal file
View File

@@ -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;
}