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