1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// SPDX-License-Identifier: GPL-2.0+
/*
* efi_selftest_memory
*
* Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
*
* This unit test checks the following boottime services:
* CopyMem, SetMem, CalculateCrc32
*
* The memory type used for the device tree is checked.
*/
#include <efi_selftest.h>
static struct efi_boot_services *boottime;
/**
* setup() - setup unit test
*
* @handle: handle of the loaded image
* @systable: system table
* Return: EFI_ST_SUCCESS for success
*/
static int setup(const efi_handle_t handle,
const struct efi_system_table *systable)
{
boottime = systable->boottime;
return EFI_ST_SUCCESS;
}
/*
* execute() - execute unit test
*
* Return: EFI_ST_SUCCESS for success
*/
static int execute(void)
{
u8 c1[] = "abcdefghijklmnop";
u8 c2[] = "abcdefghijklmnop";
u32 crc32;
efi_status_t ret;
ret = boottime->calculate_crc32(c1, 16, &crc32);
if (ret != EFI_SUCCESS) {
efi_st_error("CalculateCrc32 failed\n");
return EFI_ST_FAILURE;
}
if (crc32 != 0x943ac093) {
efi_st_error("CalculateCrc32 returned wrong value\n");
return EFI_ST_FAILURE;
}
boottime->copy_mem(&c1[5], &c1[3], 8);
if (memcmp(c1, "abcdedefghijknop", 16)) {
efi_st_error("CopyMem forward copy failed: %s\n", c1);
return EFI_ST_FAILURE;
}
boottime->copy_mem(&c2[3], &c2[5], 8);
if (memcmp(c2, "abcfghijklmlmnop", 16)) {
efi_st_error("CopyMem backward copy failed: %s\n", c2);
return EFI_ST_FAILURE;
}
boottime->set_mem(&c1[3], 8, 'x');
if (memcmp(c1, "abcxxxxxxxxjknop", 16)) {
efi_st_error("SetMem failed: %s\n", c1);
return EFI_ST_FAILURE;
}
return EFI_ST_SUCCESS;
}
EFI_UNIT_TEST(mem) = {
.name = "mem",
.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
.setup = setup,
.execute = execute,
};
|