aboutsummaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
2019-03-29libfdt: Add phandle generation helperThierry Reding5-3/+61
The new fdt_generate_phandle() function can be used to generate a new, unused phandle given a specific device tree blob. The implementation is somewhat naive in that it simply walks the entire device tree to find the highest phandle value and then returns a phandle value one higher than that. A more clever implementation might try to find holes in the current set of phandle values and fill them. But this implementation is relatively simple and works reliably. Also add a test that validates that phandles generated by this new API are indeed unique. Signed-off-by: Thierry Reding <treding@nvidia.com> Message-Id: <20190326153302.17109-3-thierry.reding@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-03-29libfdt: Add new maximum phandle lookup functionThierry Reding1-0/+9
The fdt_get_max_phandle() function has some shortcomings. On one hand it returns just a uint32_t which means to check for the "negative" error code a caller has to explicitly check against the error code (uint32_t)-1. In addition, the -1 is the only error code that can be returned, so a caller cannot tell the difference between the various failures. Fix this by adding a new fdt_find_max_phandle() function that returns an error code on failure and 0 on success, just like other APIs, and stores the maximum phandle value in an output argument on success. This also refactors fdt_get_max_phandle() to use the new function. Add a note pointing out that the new fdt_find_max_phandle() function should be preferred over fdt_get_max_phandle(). Signed-off-by: Thierry Reding <treding@nvidia.com> Message-Id: <20190326153302.17109-1-thierry.reding@gmail.com> [dwg: Reword for some inaccuracies in the commit message] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-03-29libfdt: add fdt_append_addrrange()AKASHI Takahiro7-0/+182
This function will append an address range property using parent node's "#address-cells" and "#size-cells" properties. It will be used in implementing kdump with kexec_file_load system call at linux kernel for arm64 once it is merged into kernel tree. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Message-Id: <20190327061552.17170-2-takahiro.akashi@linaro.org> [dwg: Correct a SEGV error in the testcase] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-03-25Revert "libfdt: Add phandle generation helper"David Gibson5-62/+3
This reverts commit 54ea41c22415cb0e283d22faf71202051c89400c. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-03-21libfdt: Add phandle generation helperThierry Reding5-3/+62
The new fdt_generate_phandle() function can be used to generate a new, unused phandle given a specific device tree blob. The implementation is somewhat naive in that it simply walks the entire device tree to find the highest phandle value and then returns a phandle value one higher than that. A more clever implementation might try to find holes in the current set of phandle values and fill them. But this implementation is relatively simple and works reliably. Also add a test that validates that phandles generated by this new API are indeed unique. Signed-off-by: Thierry Reding <treding@nvidia.com> Message-Id: <20190320151003.28941-1-thierry.reding@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-02-19pylibfdt:tests: Extend the way how to find a Python moduleLumir Balhar1-1/+1
Python 3 C extensions have suffix containing platform, Python version and another details in the name so the condition has to be extended. Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Message-Id: <20190218164856.23861-5-frenzy@frenzy.cz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-02-19pylibfdt: Change how passing tests are recognizedLumir Balhar1-1/+1
When some warning appears in test result, "ok" is still at the end of the line but without three dots. Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Message-Id: <20190218164856.23861-4-frenzy@frenzy.cz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-02-19pylibfdt: Test fdt.setprop take bytes on Python 3, add error handlingPetr Viktorin1-5/+7
Signed-off-by: Petr Viktorin <pviktori@redhat.com> Message-Id: <20190218164856.23861-3-frenzy@frenzy.cz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2019-02-19pylibfdt: Proper handling of bytes/unicode strings and octal literalsLumir Balhar1-10/+10
Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Message-Id: <20190218164856.23861-1-frenzy@frenzy.cz> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-24libfdt: Add a test for fdt_getprop_by_offset()Simon Glass6-1/+94
This function does not have its own test at present. Add one. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23Refine make tests_clean targetDavid Gibson2-4/+4
Remove some redundancy, and also clean up *.test.dt.yaml files generated during the tests. Also add the latter to gitignore. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23tests: Use modern octal literals for PythonDavid Gibson1-2/+2
Python3 removes support for C-style octal literals, using 0oXXXX instead. Python2 also supports this form, so move to the new style. Reported-by: Lumir Balhar <lbalhar@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-23pylibfdt: Allow switch to Python 3 via environment variable PYTHONLumir Balhar2-4/+4
Python 2 is still the default but it can be changed by setting environment variable PYTHON before build/test. Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-14tests: Don't lose errors from make checkmDavid Gibson1-1/+1
For unclear reasons we had some code to copy a transcript of "make checkm" runs to a vglog.XXX file. It's not really clear why this was there, and it had the nasty side effect of discarding errors from run_tests.sh, meaning that an error on the valgrind run wouldn't show up clearly in Travis CI builds. Remove that logic so that we see errors more clearly. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-14tests: Property count valgrind errors in wrapped testsDavid Gibson1-0/+3
The logic in wrap_test() was effectively squashing valgrind errors into the "FAIL" bucket rather than their own bucket as intended. Correct it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-11-07libfdt: return correct value if #size-cells property is not presentJohn Clarke2-2/+2
According to the device tree specification, the default value for #size-cells is 1, but fdt_size_cells() was returning 2 if this property was not present. This patch also makes fdt_address_cells() and fdt_size_cells() conform to the behaviour documented in libfdt.h. The defaults are only returned if fdt_getprop() returns -FDT_ERR_NOTFOUND, otherwise the actual error is returned. Signed-off-by: John Clarke <johnc@kirriwa.net>
2018-10-04tests: Wrap check_align() calls with base_run_test()Lubomir Rintel1-2/+2
Otherwise the FAIL results won't be accounted for in the summary. Easily testable by artifically causing them to fail: - if [ $(($size % $align)) -eq 0 ] ;then + if [ $(($size % $align)) -eq 666 ] ;then Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-27Fix dts output with a REF_PATH markerRob Herring2-1/+7
Commit 8c59a97ce096 ("Fix missing labels when emitting dts format") fixed label output, but broke output when there is a REF_PATH marker. The problem is a REF_PATH marker causes a zero length string to be emitted. The write_propval_string() function requires a length of at least 1 (including the terminating '\0'), but that was not being checked. For the integer output, a length of 0 is valid as it is possible to have labels inside the starting '<': int-prop = < start: 0x1234>; REF_PHANDLE is another marker that we don't explicitly handle, but it doesn't cause a problem as it is fundamentally just an int. Fixes: 8c59a97ce096 ("Fix missing labels when emitting dts format") Reported-by: Kumar Gala <kumar.gala@linaro.org> Cc: Grant Likely <grant.likely@arm.com> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-26Added test cases for target referencesFredrik Markstrom2-0/+34
This commit adds test cases for commits "Correct overlay syntactic sugar for generating target-path fragments" and "Merge nodes with local target label references". It verifies that target path references are not resolved locally and that target label references that can be resolved locally are. Signed-off-by: Fredrik Markstrom <fredrik.markstrom@gmail.com> [dwg: Fixed some whitespace problems] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-21checks: fix simple-bus compatible matchingRob Herring3-0/+40
Since commit 7975f6422260 ("Fix widespread incorrect use of strneq(), replace with new strprefixeq()") simple-bus checks have been silently skipped. The problem was 'end - str' is one more than the string length and the strnlen in strprefixeq fails. This can't be fixed simply by subtracting one as it is possible to have multiple '\0' at the end of the property. Fix this by making the 'compatible' property string list check a dependency, and then we can assume the property is null terminated and we can just use streq() for comparisons. Add some tests so the problem doesn't happen again. Fixes: 7975f6422260 ("Fix widespread incorrect use of strneq(), replace with new strprefixeq()") Reported-by: Kumar Gala <kumar.gala@linaro.org> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-20Fix missing labels when emitting dts formatGrant Likely1-2/+2
When there is a label inside a sequence of ints at the end of a property, an assertion is hit because write_propval() expects all the labels to be at the very end of the property data. This is clearly wrong behaviour. To reproduce run: "dtc -O dts tests/label01.dts". dtc fails on property /randomnode/blob. Fix by reworking the write_propval() loop to remove the separate iterating over label markers. Instead handle the label markers as part of the main marker iteration loop. This guarantees that each label marker is handled at the right location, even if all the data markers have already been handled, and has the added advantage of making the code simpler. However, a side effect of this code is that a label at the very end of an int sequence will be emitted outside the sequence delimiters. For example: Input: intprop = < 1 2 L1: >, L2: < 3 4 L3: > L4:; Output: intprop = < 1 2 >, L1: L2: < 3 4 > L3: L4:; The two representations are equivalent in the data model, but the current test case was looking for the former, but needed to be modified to look for the later. The alternative would be to render labels before closing the sequence, but that makes less sense syntactically because labels between sequences are normally to point at the next one, not the former. For example: Input: intprop = < 1 2 L1: >, L2: < 3 4 L3: > L4:; Output: intprop = < 1 2 L1: L2: >, < 3 4 L3: L4: >; DTC doesn't current have the information to know if the label should be inside or outside the sequence, but in common usage, it is more likely that L1 & L2 refer to the second sequence, not the end of the first. Fixes: 32b9c6130762 ("Preserve datatype markers when emitting dts format") Reported-by: Ɓukasz Dobrowolski <lukasz.dobrowolski@nokia.com> Signed-off-by: Grant Likely <grant.likely@arm.com> Cc: David Gibson <david@gibson.dropbear.id.au> Cc: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-17Revert dts output formatting changes of spaces around bracketsRob Herring1-12/+12
Commit 32b9c6130762 ("Preserve datatype markers when emitting dts format") add spaces between <> and [] and the encapsulated numbers. Fix this to keep the prior formatting and not break some users needlessly. Fixes: 32b9c6130762 ("Preserve datatype markers when emitting dts format") Reported-by: Stewart Smith <stewart@linux.ibm.com> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-13Add support for YAML encoded outputGrant Likely2-0/+28
YAML encoded DT is useful for validation of DTs using binding schemas. The YAML encoding is an intermediate format used for validation and is therefore subject to change as needed. The YAML output is dependent on DTS input with type information preserved. Signed-off-by: Grant Likely <grant.likely@arm.com> [robh: make YAML support optional, build fixes, Travis CI test, preserve type information in paths and phandles] Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-13pylibfdt: Add a means to add and delete notesSimon Glass1-0/+31
These methods are needed to permit larger changes to the device tree blob. Add two new methods and an associate test. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-10Make valgrind optionalDavid Gibson2-0/+15
Some platforms don't have valgrind support, and sometimes you simply might not want to use valgrind. But at present, dtc, or more specifically its testsuite, won't compile without valgrind because we use the valgrind client interface in some places to improve our testing and suppress false positives. This adds some Makefile detection to correctly handle the case where valgrind is not available. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-10tests: Better testing of dtc -I fs modeDavid Gibson4-5/+182
Greg Kurz added a trivial test of the -I fs mode recently, which was previously basically untested. This is an oversight, since we recently had a bug which completely broke it. This replaces Greg's test with a more thorough test of -I fs mode. We use a test helper to create the familiar test_tree1 in "fs" form, then use dtc -I fs to process it, and check that the results match what they should. We only check the content in -I fs -O dtb mode, since that's simplest, but we do run -I fs -O dts mode as well to make sure it doesn't blow up (the aforementioned bug caused just such a blow up, specific to -O dts mode, for example). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-10tests: Allow dtbs_equal_unordered to ignore mem reservesDavid Gibson1-8/+28
For some upcoming tests we want to be able to test if two trees are equal, but we don't care about the memory reservation map. So, this adds an option to the dtbs_equal_unordered test helper which tells it to ignore the reserve map. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-09-10dtc: trivial '-I fs -O dts' testGreg Kurz1-0/+5
Some recent changes caused '-I fs -O dts' to crash instantly when emitting the first property holding actual data, ie, coming from a non-empty file. This got fixed already by another patch. This simply adds a test for the original problem. Signed-off-by: Greg Kurz <groug@kaod.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-23tests: Correction to vg_prepare_blob()David Gibson1-6/+8
vg_prepare_blob() assumes a valid return from fdt_num_mem_rsv() in order to make sensible initialization of the valgrind mem checker. Usually that's fine, but it breaks down on the (deliberately corrupted) truncated_memrsv testcase. That led to marking a negative-size (== enormously sized once cast to size_t) as defined with VALGRIND_MAKE_MEM_DEFINED, which casued valgrind to freeze up and consume ludicrous amounts of memory until OOMing. This correction makes us robust in that case. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-20tests: Don't call memcmp() with NULL argumentsDavid Gibson1-2/+2
You're not supposed to pass NULL to memcmp(), and some sanitizers complain about it, even when the length is zero. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-20libfdt: fdt_address_cells() and fdt_size_cells()Sebastian Huber6-0/+84
Add internal fdt_cells() to avoid copy and paste. Test error cases and default values. Fix typo in fdt_size_cells() documentation comment. Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-11pylibfdt: Support the sequential-write interfaceSimon Glass1-6/+115
It is useful to be able to create a device tree from scratch using software. This is supported in libfdt but not currently available in the Python bindings. Add a new FdtSw class to handle this, with various methods corresponding to the libfdt functions. When the tree is complete, calling AsFdt() will return the completed device-tree object. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-07-09tests: Improve fdt_resize() testsDavid Gibson2-4/+33
We primarily test fdt_resize() in the sw_tree1 testcase, but it has some deficiencies: - It didn't check for errors actually originating in fdt_resize(), just for errors before and after - It only tested cases where the resized buffer was at the same address as the original one, whereas fdt_resize() is also supposed to work if the new buffer is entirely separate, or partly overlapping Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-29Preserve datatype markers when emitting dts formatGrant Likely2-0/+35
If datatype markers are present in the property value, use them to output the data in the correct format instead of trying to guess the datatype. This also will preserve data grouping, such as in an interrupts list. This is a step forward for preserving and using datatype information when processing DTS/DTB files. Schema validation tools can use the datatype information to make sure a DT is correctly formed and intepreted. Signed-off-by: Grant Likely <grant.likely@arm.com> [robh: rework marker handling and fix label output] Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-17tests: Fix incorrect check name 'prop_name_chars'Rob Herring1-1/+1
'prop_name_chars' is not a valid check name, but the test was passing due to a bug in dtc-checkfails.sh. Fix it to be the correct name, 'property_name_chars'. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-17tests: fix grep for checks error messagesRob Herring1-2/+2
I noticed the error type passed in didn't matter for check tests to pass. There's a couple of problems with the grep regex. The error/warning messages begin with the output filename now, so "ERROR" or "Warning" is not at the beginning of the line. Secondly, the parentheses seem to be wrong. It's not clear to me what was intended. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-14pylibfdt: Support setting the name of a nodeSimon Glass1-0/+15
Add a method to call fdt_set_name(). Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-14pylibfdt: Add functions to set and get properties as stringsSimon Glass1-0/+25
It is common to want to set a property to a nul-terminated string in a device tree. Add python methods to handle this. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-13pylibfdt: Update the bytearray size with pack()Simon Glass1-0/+1
At present pack() calls fdt_pack() which may well reduce the size of the device-tree data. However this does not currently update the size of the bytearray to take account of any reduction. This means that there may be unused data at the end of the bytearray and any users of as_bytearray() will see this extra data. Fix this by resizing the bytearray after packing. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-13pylibfdt: Allow reading integer values from propertiesSimon Glass3-0/+24
Extend the Properties class with some functions to read a single integer property. Add a new getprop_obj() function to return a Property object instead of the raw data. This suggested approach can be extended to handle other types, as well as arrays. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-12pylibfdt: Avoid accessing the internal _fdt member in testsSimon Glass1-3/+2
We can use the accessor now, so do so. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-12pylibfdt: Add functions to update propertiesSimon Glass1-0/+48
Allow updating and creating properties, including special methods for integers. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-09pylibfdt: Support device-tree creation/expansionSimon Glass1-1/+17
Add support for fdt_open_into() and fdt_create_empty_tree() from the Python library. The former is named resize() since it better fits with what the Python binding actually does. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-09pylibfdt: Add support for reading the memory reserve mapSimon Glass1-0/+8
Add a way to access this information from Python. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-09pylibfdt: Add support for the rest of the header functionsSimon Glass1-0/+8
Export all of these through Python. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-08pylibfdt: Add support for fdt_next_node()Simon Glass1-0/+18
This function requires a bit of typemap effort to get the depth parameter to work correctly. Add support for it, along with a test. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-07libfdt: Add fdt_check_full() functionDavid Gibson5-1/+76
This new function implements a complete and thorough check of an fdt blob's structure. Given a buffer containing an fdt, it should return 0 only if the fdt within is structurally sound in all regards. It doesn't check anything about the blob's contents (i.e. the actual values of the nodes and properties), of course. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-06-07tests: Use valgrind client requests for better checkingDavid Gibson4-1/+59
libfdt is never supposed to access memory outside the the blob, or outside the sub-blocks within it, even if the blob is badly corrupted. We can leverage valgrind's client requests to do better testing of this. This adds a vg_prepare_blob() function which marks just the valid parts of an fdt blob as properly initialized, explicitly marking the rest as uninitialized. This means valgrind should catch any bad accesses. We add a call to vg_prepare_blob() to load_blob() so that lots of the existing testcases will benefit from the extra checking. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
2018-06-07tests: Better handling of valgrind errors saving blobsDavid Gibson4-34/+13
Currently we have 3 valgrind suppression files in the tests, all of which are to handle memcheck errors that originate from saving entire buffers containing blobs where the gaps between sub-blocks might not be initialized. We can more simply suppress those errors by having the save_blob() helper use valgrind's client interface to mark the data as initialized before we write it out. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-06-07tests: Remove unused #defineDavid Gibson1-2/+0
This was leftover from an earlier implementation of load_blob(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>