diff --git a/support/testing/tests/package/test_dtc.py b/support/testing/tests/package/test_dtc.py new file mode 100644 index 0000000000..47a1d75916 --- /dev/null +++ b/support/testing/tests/package/test_dtc.py @@ -0,0 +1,39 @@ +import os + +import infra.basetest + + +class TestDtc(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_PACKAGE_DTC=y + BR2_PACKAGE_DTC_PROGRAMS=y + BR2_ROOTFS_OVERLAY="{}" + # BR2_TARGET_ROOTFS_TAR is not set + BR2_TARGET_ROOTFS_CPIO=y + """.format( + # overlay to add a bats test suite + infra.filepath("tests/package/test_dtc/rootfs-overlay")) + + def test_run(self): + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") + self.emulator.boot(arch="armv7", + kernel="builtin", + options=["-initrd", cpio_file]) + + self.emulator.login() + + # Test 'dtc' + self.assertRunOk("dtc -I dts -O dtb -o /tmp/test_tree1.dtb /test_tree1.dts") + + # Test 'fdtdump' + self.assertRunOk("fdtdump /tmp/test_tree1.dtb") + + # Test 'fdtget' + out, exit_code = self.emulator.run("fdtget -t s /tmp/test_tree1.dtb / compatible") + self.assertEqual(out[0].strip(), "test_tree1") + + # Test 'fdtput' + self.assertRunOk("fdtput -t s /tmp/test_tree1.dtb / compatible 'test set compatible'") + out, exit_code = self.emulator.run("fdtget -t s /tmp/test_tree1.dtb / compatible") + self.assertEqual(out[0].strip(), "test set compatible") diff --git a/support/testing/tests/package/test_dtc/rootfs-overlay/test_tree1.dts b/support/testing/tests/package/test_dtc/rootfs-overlay/test_tree1.dts new file mode 100644 index 0000000000..6649e7cc0f --- /dev/null +++ b/support/testing/tests/package/test_dtc/rootfs-overlay/test_tree1.dts @@ -0,0 +1,48 @@ +/* From https://git.kernel.org/pub/scm/utils/dtc/dtc.git/tree/tests/test_tree1.dts?id=99031e3a4a6e479466ae795790b44727434ca27d */ + +/dts-v1/; + +/memreserve/ 0xdeadbeef00000000 0x100000; +/memreserve/ 123456789 010000; + +/ { + compatible = "test_tree1"; + prop-int = <0xdeadbeef>; + prop-int64 = /bits/ 64 <0xdeadbeef01abcdef>; + prop-str = "hello world"; + #address-cells = <1>; + #size-cells = <0>; + + subnode@1 { + compatible = "subnode1"; + reg = <1>; + prop-int = [deadbeef]; + + subsubnode { + compatible = "subsubnode1", "subsubnode"; + placeholder = "this is a placeholder string", "string2"; + prop-int = <0xdeadbeef>; + }; + + ss1 { + }; + }; + + subnode@2 { + reg = <2>; + linux,phandle = <0x2000>; + prop-int = <123456789>; + #address-cells = <1>; + #size-cells = <0>; + + ssn0: subsubnode@0 { + reg = <0>; + phandle = <0x2001>; + compatible = "subsubnode2", "subsubnode"; + prop-int = <0726746425>; + }; + + ss2 { + }; + }; +};