1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for misbehaviour on a truncated string
5 * Copyright (C) 2018 David Gibson, IBM Corporation.
6 */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdint.h>
12
13 #include <libfdt.h>
14
15 #include "tests.h"
16 #include "testdata.h"
17
main(int argc,char * argv[])18 int main(int argc, char *argv[])
19 {
20 void *fdt = &truncated_memrsv;
21 int err;
22 uint64_t addr, size;
23
24 test_init(argc, argv);
25
26 err = fdt_check_header(fdt);
27 if (err != 0)
28 FAIL("Bad header: %s", fdt_strerror(err));
29
30 err = fdt_num_mem_rsv(fdt);
31 if (err != -FDT_ERR_TRUNCATED)
32 FAIL("fdt_num_mem_rsv() returned %d instead of -FDT_ERR_TRUNCATED",
33 err);
34
35 err = fdt_get_mem_rsv(fdt, 0, &addr, &size);
36 if (err != 0)
37 FAIL("fdt_get_mem_rsv() failed on first entry: %s",
38 fdt_strerror(err));
39 if ((addr != TEST_ADDR_1) || (size != TEST_SIZE_1))
40 FAIL("Entry doesn't match: (0x%llx, 0x%llx) != (0x%llx, 0x%llx)",
41 (unsigned long long)addr, (unsigned long long)size,
42 TEST_ADDR_1, TEST_SIZE_1);
43
44 err = fdt_get_mem_rsv(fdt, 1, &addr, &size);
45 if (err != -FDT_ERR_BADOFFSET)
46 FAIL("fdt_get_mem_rsv(1) returned %d instead of -FDT_ERR_BADOFFSET",
47 err);
48
49 PASS();
50 }
51