1 /* $NetBSD: setprop.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 fdt_setprop() 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 21 #define SPACE 65536 22 #define NEW_STRING "here is quite a long test string, blah blah blah" 23 24 int main(int argc, char *argv[]) 25 { 26 void *fdt; 27 void *buf; 28 const uint32_t *intp; 29 const char *strp; 30 int err; 31 32 test_init(argc, argv); 33 fdt = load_blob_arg(argc, argv); 34 35 buf = xmalloc(SPACE); 36 37 err = fdt_open_into(fdt, buf, SPACE); 38 if (err) 39 FAIL("fdt_open_into(): %s", fdt_strerror(err)); 40 41 fdt = buf; 42 43 intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); 44 45 verbose_printf("Old int value was 0x%08x\n", *intp); 46 err = fdt_setprop_string(fdt, 0, "prop-int", NEW_STRING); 47 if (err) 48 FAIL("Failed to set \"prop-int\" to \"%s\": %s", 49 NEW_STRING, fdt_strerror(err)); 50 51 strp = check_getprop_string(fdt, 0, "prop-int", NEW_STRING); 52 verbose_printf("New value is \"%s\"\n", strp); 53 54 strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, 55 TEST_STRING_1); 56 57 verbose_printf("Old string value was \"%s\"\n", strp); 58 err = fdt_setprop_empty(fdt, 0, "prop-str"); 59 if (err) 60 FAIL("Failed to empty \"prop-str\": %s", 61 fdt_strerror(err)); 62 63 check_getprop(fdt, 0, "prop-str", 0, NULL); 64 65 err = fdt_setprop_u32(fdt, 0, "prop-u32", TEST_VALUE_2); 66 if (err) 67 FAIL("Failed to set \"prop-u32\" to 0x%08x: %s", 68 TEST_VALUE_2, fdt_strerror(err)); 69 check_getprop_cell(fdt, 0, "prop-u32", TEST_VALUE_2); 70 71 err = fdt_setprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2); 72 if (err) 73 FAIL("Failed to set \"prop-cell\" to 0x%08x: %s", 74 TEST_VALUE_2, fdt_strerror(err)); 75 check_getprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2); 76 77 err = fdt_setprop_u64(fdt, 0, "prop-u64", TEST_VALUE64_1); 78 if (err) 79 FAIL("Failed to set \"prop-u64\" to 0x%016llx: %s", 80 TEST_VALUE64_1, fdt_strerror(err)); 81 check_getprop_64(fdt, 0, "prop-u64", TEST_VALUE64_1); 82 83 PASS(); 84 } 85