mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
test: add simple test for PCR list parsing
This commit is contained in:
@@ -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
34
src/test/test-tpm2.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user