Browse Source

tests: add test cases for label-relative path references

Newly added &{label/path} feature doesn't yet have any tests. Add some.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
main
Ahmad Fatoum 4 years ago committed by David Gibson
parent
commit
26c54f840d
  1. 1
      tests/.gitignore
  2. 2
      tests/Makefile.tests
  3. 8
      tests/path-references.c
  4. 9
      tests/path-references.dts
  5. 51
      tests/relref_merge.c
  6. 40
      tests/relref_merge.dts
  7. 3
      tests/run_tests.sh

1
tests/.gitignore vendored

@ -54,6 +54,7 @@ tmp.* @@ -54,6 +54,7 @@ tmp.*
/property_iterate
/propname_escapes
/references
/relref_merge
/root_node
/rw_tree1
/rw_oom

2
tests/Makefile.tests

@ -18,7 +18,7 @@ LIB_TESTS_L = get_mem_rsv \ @@ -18,7 +18,7 @@ LIB_TESTS_L = get_mem_rsv \
open_pack rw_tree1 rw_oom set_name setprop del_property del_node \
appendprop1 appendprop2 propname_escapes \
string_escapes references path-references phandle_format \
boot-cpuid incbin \
boot-cpuid incbin relref_merge \
extra-terminating-null \
dtbs_equal_ordered \
dtb_reverse dtbs_equal_unordered \

8
tests/path-references.c

@ -53,7 +53,7 @@ int main(int argc, char *argv[]) @@ -53,7 +53,7 @@ int main(int argc, char *argv[])
void *fdt;
const char *p;
int len, multilen;
int n1, n2, n3, n4;
int n1, n2, n3, n4, n5;

test_init(argc, argv);
fdt = load_blob_arg(argc, argv);
@ -89,6 +89,12 @@ int main(int argc, char *argv[]) @@ -89,6 +89,12 @@ int main(int argc, char *argv[])
check_ref(fdt, n3, "/foobar/baz");
check_ref(fdt, n4, "/foo/baz");

n5 = fdt_path_offset(fdt, "/bar/baz");
if (n5 < 0)
FAIL("fdt_path_offset(/bar/baz): %s", fdt_strerror(n5));

check_ref(fdt, n5, "/bar/baz");

check_rref(fdt);

PASS();

9
tests/path-references.dts

@ -25,4 +25,13 @@ @@ -25,4 +25,13 @@
lref = &n3;
};
};
n5: bar {
baz {
};
};
};

n6: &{n5/baz} {
ref = &{n6/};
lref = &{n5/baz};
};

51
tests/relref_merge.c

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libfdt - Flat Device Tree manipulation
* Testcase for label relative child references in dtc
* Copyright (C) 2006 David Gibson, IBM Corporation.
* Copyright (C) 2020 Ahmad Fatoum, Pengutronix.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>

#include <libfdt.h>

#include "tests.h"
#include "testdata.h"

static void check_exist(void *fdt, const char *path)
{
int sn = fdt_path_offset(fdt, path);
if (sn < 0)
FAIL("%s expected but not found: %s", path, fdt_strerror(sn));
}

static void check_doesnt_exist(void *fdt, const char *path)
{
int sn = fdt_path_offset(fdt, path);
if (sn >= 0)
FAIL("%s found but not expected %d", path, sn);
}

int main(int argc, char *argv[])
{
void *fdt;

test_init(argc, argv);
fdt = load_blob_arg(argc, argv);

check_exist(fdt, "/node/subnode1");
check_exist(fdt, "/node/keep-me");
check_doesnt_exist(fdt, "/node/remove-me");

check_doesnt_exist(fdt, "/node2");
check_doesnt_exist(fdt, "/node/subnode3");

check_exist(fdt, "/node/subnode4");

check_exist(fdt, "/node/subnode1/add-me");

PASS();
}

40
tests/relref_merge.dts

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
/dts-v1/;

/ {
node_label: node {
keep-me {};
remove-me {};

subnode1 {
property-inline1;
property-inline2;
property-inline3;
};

subnode2 {
property-inline1;
};

subnode3 {
property-inline1;
};
};

node2_label: node2 {
property-inline1;
};
};
/omit-if-no-ref/ &{node_label/subnode1};
/omit-if-no-ref/ &node2_label;
/delete-node/ &{node_label/subnode3};

&{node_label/} {
/delete-node/ remove-me;

subnode4 { };
};

label: &{node_label/subnode1} {
selfref = &{node_label/subnode1};
add-me { };
};

3
tests/run_tests.sh

@ -669,6 +669,9 @@ dtc_tests () { @@ -669,6 +669,9 @@ dtc_tests () {
tree1_tests dtc_tree1_merge_path.test.dtb test_tree1.dtb
run_wrap_error_test $DTC -I dts -O dtb -o /dev/null "$SRCDIR/test_label_ref.dts"

run_dtc_test -I dts -O dtb -o dtc_relref_merge.test.dtb "$SRCDIR/relref_merge.dts"
run_test relref_merge dtc_relref_merge.test.dtb

# Check prop/node delete functionality
run_dtc_test -I dts -O dtb -o dtc_tree1_delete.test.dtb "$SRCDIR/test_tree1_delete.dts"
tree1_tests dtc_tree1_delete.test.dtb

Loading…
Cancel
Save