blob: 29be495412d3b3e1d3f27c3da2f7ee5fa585571f [file] [log] [blame]
Eddie James1a55a7a2023-10-24 10:43:51 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for measured boot functions
4 *
5 * Copyright 2023 IBM Corp.
6 * Written by Eddie James <eajames@linux.ibm.com>
7 */
8
Eddie James1a55a7a2023-10-24 10:43:51 -05009#include <bootm.h>
10#include <malloc.h>
11#include <test/suites.h>
12#include <test/test.h>
13#include <test/ut.h>
14#include <asm/io.h>
15
16#define MEASUREMENT_TEST(_name, _flags) \
17 UNIT_TEST(_name, _flags, measurement_test)
18
19static int measure(struct unit_test_state *uts)
20{
21 struct bootm_headers images;
22 const size_t size = 1024;
23 u8 *kernel;
24 u8 *initrd;
25 size_t i;
26
27 kernel = malloc(size);
28 initrd = malloc(size);
29
30 images.os.image_start = map_to_sysmem(kernel);
31 images.os.image_len = size;
32
33 images.rd_start = map_to_sysmem(initrd);
34 images.rd_end = images.rd_start + size;
35
36 images.ft_addr = malloc(size);
37 images.ft_len = size;
38
39 env_set("bootargs", "measurement testing");
40
41 for (i = 0; i < size; ++i) {
42 kernel[i] = 0xf0 | (i & 0xf);
43 initrd[i] = (i & 0xf0) | 0xf;
44 images.ft_addr[i] = i & 0xff;
45 }
46
47 ut_assertok(bootm_measure(&images));
48
49 free(images.ft_addr);
50 free(initrd);
51 free(kernel);
52
53 return 0;
54}
55MEASUREMENT_TEST(measure, 0);
56
57int do_ut_measurement(struct cmd_tbl *cmdtp, int flag, int argc,
58 char *const argv[])
59{
60 struct unit_test *tests = UNIT_TEST_SUITE_START(measurement_test);
61 const int n_ents = UNIT_TEST_SUITE_COUNT(measurement_test);
62
63 return cmd_ut_category("measurement", "measurement_test_", tests,
64 n_ents, argc, argv);
65}