blob: 290c8768fa4ccc7ca6e9bcba50cba8df32b10c08 [file] [log] [blame]
Heinrich Schuchardtf8537802020-08-23 10:53:50 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test device path functions
4 *
5 * Copyright (c) 2020 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 */
7
Heinrich Schuchardtf8537802020-08-23 10:53:50 +02008#include <efi_loader.h>
9#include <test/lib.h>
10#include <test/test.h>
11#include <test/ut.h>
12
13static int lib_test_efi_dp_check_length(struct unit_test_state *uts)
14{
15 /* end of device path */
16 u8 d1[] __aligned(2) = {
17 0x7f, 0xff, 0x04, 0x00 };
18 /* device path node with length less then 4 */
19 u8 d2[] __aligned(2) = {
20 0x01, 0x02, 0x02, 0x00, 0x04, 0x00, 0x7f, 0xff, 0x04, 0x00 };
21 /* well formed device path */
22 u8 d3[] __aligned(2) = {
23 0x03, 0x02, 0x08, 0x00, 0x01, 0x00, 0x01, 0x00,
24 0x7f, 0xff, 0x04, 0x00 };
25
26 struct efi_device_path *p1 = (struct efi_device_path *)d1;
27 struct efi_device_path *p2 = (struct efi_device_path *)d2;
28 struct efi_device_path *p3 = (struct efi_device_path *)d3;
29
30 ut_asserteq((ssize_t)-EINVAL, efi_dp_check_length(p1, SIZE_MAX));
31 ut_asserteq((ssize_t)sizeof(d1), efi_dp_check_length(p1, sizeof(d1)));
32 ut_asserteq((ssize_t)sizeof(d1),
33 efi_dp_check_length(p1, sizeof(d1) + 4));
34 ut_asserteq((ssize_t)-1, efi_dp_check_length(p1, sizeof(d1) - 1));
35
36 ut_asserteq((ssize_t)-1, efi_dp_check_length(p2, sizeof(d2)));
37
38 ut_asserteq((ssize_t)-1, efi_dp_check_length(p3, sizeof(d3) - 1));
39 ut_asserteq((ssize_t)sizeof(d3), efi_dp_check_length(p3, sizeof(d3)));
40 ut_asserteq((ssize_t)sizeof(d3), efi_dp_check_length(p3, SSIZE_MAX));
41 ut_asserteq((ssize_t)-EINVAL,
42 efi_dp_check_length(p3, (size_t)SSIZE_MAX + 1));
43 ut_asserteq((ssize_t)sizeof(d3),
44 efi_dp_check_length(p3, sizeof(d3) + 4));
45
46 return 0;
47}
48
49LIB_TEST(lib_test_efi_dp_check_length, 0);