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