1/*	$NetBSD: nop_property.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $	*/
2
3// SPDX-License-Identifier: LGPL-2.1-or-later
4/*
5 * libfdt - Flat Device Tree manipulation
6 *	Testcase for fdt_nop_property()
7 * Copyright (C) 2006 David Gibson, IBM Corporation.
8 */
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13#include <ctype.h>
14#include <stdint.h>
15
16#include <libfdt.h>
17
18#include "tests.h"
19#include "testdata.h"
20
21int main(int argc, char *argv[])
22{
23	void *fdt;
24	const uint32_t *intp;
25	const char *strp;
26	int err;
27	int lenerr;
28
29	test_init(argc, argv);
30	fdt = load_blob_arg(argc, argv);
31
32	intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
33	verbose_printf("int value was 0x%08x\n", *intp);
34
35	err = fdt_nop_property(fdt, 0, "prop-int");
36	if (err)
37		FAIL("Failed to nop \"prop-int\": %s", fdt_strerror(err));
38
39	intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
40	if (intp)
41		FAIL("prop-int still present after nopping");
42	if (lenerr != -FDT_ERR_NOTFOUND)
43		FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
44
45	strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
46			     TEST_STRING_1);
47	verbose_printf("string value was \"%s\"\n", strp);
48	err = fdt_nop_property(fdt, 0, "prop-str");
49	if (err)
50		FAIL("Failed to nop \"prop-str\": %s", fdt_strerror(err));
51
52	strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
53	if (strp)
54		FAIL("prop-str still present after nopping");
55	if (lenerr != -FDT_ERR_NOTFOUND)
56		FAIL("Unexpected error on second getprop: %s", fdt_strerror(err));
57
58	PASS();
59}
60