#!/usr/bin/env python3 # Copyright (c) 2019 Nordic Semiconductor ASA # SPDX-License-Identifier: BSD-3-Clause import edtlib # Test suite for edtlib.py. Mostly uses string comparisons via the various # __repr__() methods. Can be run directly as an executable. # # This script expects to be run from the directory its in. This simplifies # things, as paths in the output can be assumed below. # # test.dts is the test file, and test-bindings/ has bindings. def run(): """ Runs all edtlib tests. Immediately exits with status 1 and a message on stderr on test suite failures. """ def fail(msg): raise Exception("test failed: " + msg) def verify_streq(actual, expected): actual = str(actual) if actual != expected: # Put values on separate lines to make it easy to spot differences fail("not equal (expected value last):\n'{}'\n'{}'" .format(actual, expected)) edt = edtlib.EDT("test.dts", "test-bindings") # # Test interrupts # verify_streq(edt.get_dev("/interrupt-parent-test/node").interrupts, "[, specifier: {'one': 1, 'two': 2, 'three': 3}>, , specifier: {'one': 4, 'two': 5, 'three': 6}>]") verify_streq(edt.get_dev("/interrupts-extended-test/node").interrupts, "[, specifier: {'one': 1}>, , specifier: {'one': 2, 'two': 3}>, , specifier: {'one': 4, 'two': 5, 'three': 6}>]") verify_streq(edt.get_dev("/interrupt-map-test/node@0").interrupts, "[, specifier: {'one': 0}>, , specifier: {'one': 0, 'two': 1}>, , specifier: {'one': 0, 'two': 0, 'three': 2}>]") verify_streq(edt.get_dev("/interrupt-map-test/node@1").interrupts, "[, specifier: {'one': 3}>, , specifier: {'one': 0, 'two': 4}>, , specifier: {'one': 0, 'two': 0, 'three': 5}>]") verify_streq(edt.get_dev("/interrupt-map-bitops-test/node@70000000E").interrupts, "[, specifier: {'one': 3, 'two': 2}>]") # # Test GPIOs # verify_streq(edt.get_dev("/gpio-test/node").gpios, "{'': [, specifier: {'one': 1}>, , specifier: {'one': 2, 'two': 3}>], 'foo': [, specifier: {'one': 4, 'two': 5}>], 'bar': [, specifier: {'one': 6, 'two': 7}>]}") # # Test clocks # verify_streq(edt.get_dev("/clock-test/node").clocks, "[, specifier: {}>, , specifier: {'one': 1}>, , specifier: {'one': 1, 'two': 2}>]") # # Test PWMs # verify_streq(edt.get_dev("/pwm-test/node").pwms, "[, specifier: {}>, , specifier: {'one': 1}>]") # # Test 'reg' # verify_streq(edt.get_dev("/reg-zero-address-cells/node").regs, "[, ]") verify_streq(edt.get_dev("/reg-zero-size-cells/node").regs, "[, ]") verify_streq(edt.get_dev("/reg-ranges/parent/node").regs, "[, , , , , ]") verify_streq(edt.get_dev("/reg-nested-ranges/grandparent/parent/node").regs, "[]") # # Test !include in bindings # verify_streq(edt.get_dev("/binding-include").description, "Parent binding") verify_streq(edt.get_dev("/binding-include").props, "{'compatible': , 'foo': , 'bar': , 'baz': }") # # Test 'sub-node:' in binding # verify_streq(edt.get_dev("/parent-with-sub-node/node").description, "Sub-node test") verify_streq(edt.get_dev("/parent-with-sub-node/node").props, "{'foo': , 'bar': }") # # Test Device.property (derived from DT and 'properties:' in the binding) # verify_streq(edt.get_dev("/props").props, r"{'compatible': , 'int': , 'array': , 'uint8-array': , 'string': , 'string-array': }") print("all tests passed") if __name__ == "__main__": run()