1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for properties with more than one terminating null
5 * Copyright (C) 2009 David Gibson, IBM Corporation.
6 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdint.h>
11
12 #include <libfdt.h>
13
14 #include "tests.h"
15 #include "testdata.h"
16
check_extranull(void * fdt,const char * prop,const char * str,int numnulls)17 static void check_extranull(void *fdt, const char *prop, const char *str, int numnulls)
18 {
19 int len = strlen(str);
20 char checkbuf[len+numnulls];
21
22 memset(checkbuf, 0, sizeof(checkbuf));
23 memcpy(checkbuf, TEST_STRING_1, len);
24
25 check_getprop(fdt, 0, prop, len+numnulls, checkbuf);
26 }
27
main(int argc,char * argv[])28 int main(int argc, char *argv[])
29 {
30 void *fdt;
31
32 test_init(argc, argv);
33
34 fdt = load_blob_arg(argc, argv);
35
36 check_extranull(fdt, "extranull0", TEST_STRING_1, 1);
37 check_extranull(fdt, "extranull1,1", TEST_STRING_1, 2);
38 check_extranull(fdt, "extranull1,2", TEST_STRING_1, 2);
39 check_extranull(fdt, "extranull2,1", TEST_STRING_1, 3);
40 check_extranull(fdt, "extranull2,2", TEST_STRING_1, 3);
41 check_extranull(fdt, "extranull2,3", TEST_STRING_1, 3);
42 check_extranull(fdt, "extranull2,4", TEST_STRING_1, 3);
43
44 PASS();
45 }
46