aboutsummaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
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>
2018-06-07libfdt: Add fdt_header_size()David Gibson1-6/+2
We have a couple of places within libfdt and its tests where we need to find the size of the header, based on the version. Add a helper function for it. 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>
2018-06-07Consolidate utilfdt_read_len() variantsDavid Gibson1-1/+1
There are no less than _four_ variants on utilfdt_read() which is a bit excessive. The _len() variants are particularly pointless, since we can achieve the same thing with very little extra verbosity by using the usual convention of ignoring return parameters if they're NULL. So, get rid of them (we keep the shorter names without _len, but add now-optional len parameters). 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>
2018-06-07libfdt: Safer access to memory reservationsDavid Gibson6-1/+87
fdt_num_mem_rsv() and fdt_get_mem_rsv() currently don't sanity check their parameters, or the memory reserve section offset in the header. That means that on a corrupted blob they could access outside of the range of memory that they should. This improves their safety checking, meaning they shouldn't access outside the blob's bounds, even if its contents are badly corrupted. 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-07libfdt: Safer access to strings sectionDavid Gibson7-4/+117
fdt_string() is used to retrieve strings from a DT blob's strings section. It's rarely used directly, but is widely used internally. However, it doesn't do any bounds checking, which means in the case of a corrupted blob it could access bad memory, which libfdt is supposed to avoid. This write a safe alternative to fdt_string, fdt_get_string(). It checks both that the given offset is within the string section and that the string it points to is properly \0 terminated within the section. It also returns the string's length as a convenience (since it needs to determine to do the checks anyway). fdt_string() is rewritten in terms of fdt_get_string() for compatibility. Most of the diff here is actually testing infrastructure. 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-07libfdt: Make fdt_check_header() more thoroughDavid Gibson4-1/+132
Currently fdt_check_header() performs only some rudimentary checks, which is not really what the name suggests. This strengthens fdt_check_header() to check as much about the blob as is possible from the header alone: as well as checking the magic number and version, it checks that the total size is sane, and that all the sub-blocks within the blob lie within the total size. * This broadens the meaning of FDT_ERR_TRUNCATED to cover all sorts of improperly terminated blocks as well as just a structure block without FDT_END. * This makes fdt_check_header() only succeed on "complete" blobs, not in-progress sequential write blobs. The only reason this didn't fail before was that this function used to be called by many RO functions which are supposed to also work on incomplete SW blobs. 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-07libfdt: Improve sequential write state checkingDavid Gibson4-1/+143
When creating a tree with the sequential write functions, certain things have to be done in a certain order. You must create the memory reserve map and only then can you create the actual tree structure. The -FDT_ERR_BADSTATE return code is for if you try to do things out of order. However, we weren't checking that very thoroughly, so it was possible to generate a corrupted blob if, for example, you started calling fdt_begin_node() etc. before calling fdt_finish_reservemap(). This makes the state checking more thorough disallow that. 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-04Make Property a subclass of bytearraySimon Glass1-1/+1
It is annoying to have to add .value when we want the value of a Property. Make Property a subclass of bytearray so that it can be used directly when the value is required. Fix the Property class comment while we are here. Suggested-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-06-04pylibfdt: Add a method to access the device tree directlySimon Glass1-2/+3
When calling libfdt functions which are not supported by the Fdt class it is necessary to get direct access to the device tree data. At present this requries using the internal _fdt member. Add a new method to provide public access to this, without allowing the data to be changed. Note that a bytearray type is returned rather than str, since the swig types are set up for bytearray to map correctly to const void *. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-05-04tests: Add a test case for the omit-if-no-ref keywordMaxime Ripard2-0/+33
The newly introduced /omit-if-no-ref/ needs a few test cases, make sure to test them. Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-03-09tests: Update valgrind suppressions for sw_tree1David Gibson1-1/+1
This test builds a tree in a previously uninitialized buffer, then writes the whole buffer out to a file to be used by other tests. Because part of the buffer may be uninitialized this causes a valgrind error. Pre-initializing the buffer would remove the error, however it would make valgrind not notice any accesses to the uninitialized portion *before* the write out, and those would be genuine errors. So, instead we use a valgrind suppressions file - however it has a couple of problems. First it unnecessarily lists the same call path twice. Second, the call path is only right for some C library versions. Change the second copy to cover possible path that occurs with a different glibc version. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-03-09tests: Remove valgrind error from tests/get_pathDavid Gibson1-1/+2
In the case where fdt_get_path() returns an error, a debug print will attempt to display a poisoned buffer, running over the end and accessing uninitialized memory. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-03-07checks: add graph binding checksRob Herring2-0/+27
Add checks for DT graph bindings. These checks check node names, unit-addresses and link connections on ports, port, and endpoint nodes. The graph nodes are matched by finding nodes named 'endpoint' or with a 'remote-endpoint' property. We can't match on 'ports' or 'port' nodes because those names are used for non-graph nodes. While the graph nodes aren't really buses, using the bus pointer to tag matched nodes is convenient. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-03-07checks: add a check for duplicate unit-addresses of child nodesRob Herring2-0/+15
Child nodes with the same unit-address (and different node names) are either an error or just bad DT design. Typical errors are the unit-address is just wrong (i.e. doesn't match reg value) or multiple children using the same overlapping area. Overlapping regions are considered an error in new bindings, but do exist in some existing trees. This check should flag most but not all of those errors. Finding all cases would require doing address translations and creating a full map of address spaces. Mixing more than one address/number space at a level is bad design. It only works if both spaces can use the same #address-cells and #size-cells sizes. It also complicates parsing have a mixture of types of child nodes. The best practice in this case is adding child container nodes for each address/number space or using additional address bits/cells to encode different address spaces. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-03-06Correct overlay syntactic sugar for generating target-path fragmentsDavid Gibson2-0/+60
We've recently added "syntactic sugar" support to generate runtime dtb overlays using similar syntax to the compile time overlays we've had for a while. This worked with the &label { ... } syntax, adjusting an existing labelled node, but would fail with the &{/path} { ... } syntax attempting to adjust an existing node referenced by its path. The previous code would always try to use the "target" property in the output overlay, which needs to be fixed up, and __fixups__ can only encode symbols, not paths, so the result could never work properly. This adds support for the &{/path} syntax for overlays, translating it into the "target-path" encoding in the output. It also changes existing behaviour a little because we now unconditionally one fragment for each overlay section in the source. Previously we would only create a fragment if we couldn't locally resolve the node referenced. We need this for path references, because the path is supposed to be referencing something in the (not yet known) base tree, rather than the overlay tree we are working with now. In particular one useful case for path based overlays is using &{/} - but the constructed overlay tree will always have a root node, meaning that without the change that would attempt to resolve the fragment locally, which is not what we want. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-03-06Improve tests for dtc overlay generationDavid Gibson4-81/+146
So far, the tests for generating runtime overlays with dtc weren't checking the syntactic sugar. This adds such a test. Furthermore the existing tests were only minimally testing dtc's output for the overlay. This adds a test comparing the dtc output with the more or less manually constructed overlays we already have for testing libfdt's overlay application code. This does require some minor changes to that manually constructed overlay which don't change the sematics but re-order / rename things to match the way dtc does it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-01-04Makefile.tests: Add LIBDL make(1) variable for portability sakekevans@FreeBSD.org1-1/+4
Some platforms (many, if not all, of the *BSD projects) do not provide a libdl, and instead provide the same functionality in libc. Instead of forcing these platforms to patch out the link against libdl, add a LIBDL make(1) variable to allow the -ldl argument to be excluded easily via make(1) arguments. Signed-off-by: Kyle Evans <kevans@FreeBSD.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-01-04Attempt to auto-detect stat(1) being used if not given proper invocationkevans@FreeBSD.org1-1/+8
GNU stat(1) uses '-c "%s"' as the proper invocation to print filesize of the file in question, while BSD stat(1) uses '-f "%Uz"'. Do some trivial autodetection to check if we're using GNU stat(1) and assume we're using BSD stat(1) if we don't detect otherwise. This should allow the test suite to run properly out-of-the-box on *BSDs and MacOS in addition to the current Linux support. Signed-off-by: Kyle Evans <kevans@FreeBSD.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2018-01-03tests: Improve compatibility with other platformskevans@FreeBSD.org1-4/+9
stat -c %s's equivalent on FreeBSD is stat -f %Uz; these differ enough, allow STATSZ in the environment to specify local replacement for a stat that outputs size in bytes of an argument. Signed-off-by: Kyle Evans <kevans@FreeBSD.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-15checks: add chosen node checksRob Herring2-0/+13
Add some checks for /chosen node. These check that chosen is located at the root level and that bootargs and stdout-path properties are strings. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13checks: add string list check for *-names propertiesRob Herring2-1/+2
Add a string list check for common properties ending in "-names" such as reg-names or interrupt-names. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13checks: add string list checkRob Herring2-1/+6
Add a check for string list properties with compatible being the first check. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-12-13checks: add a string check for 'label' propertyRob Herring2-1/+2
Add a string property check for 'label' property. 'label' is a human readable string typically used to identify connectors or ports on devices. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-11-11tests: Add some basic tests for the pci_bridge checksDavid Gibson4-0/+61
This adds some simple tests for the checks of correctly formatted PCI bridge nodes. Doesn't test all that much, but it's a start. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-30tests: Check non-matching cases for fdt_node_check_compatible()David Gibson1-0/+19
The current tests for fdt_node_check_compatible() test that it returns true on several matching cases, but don't test that it actually returns false on some non-matching cases, which isn't great coverage. Add some basic tests to address that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-26Remove leading underscores from identifiersDavid Gibson5-15/+13
In a number of places, dtc and associated tools and test code use leading _ characters on identifiers to flag them as "internal", an idiom taken from the Linux kernel. This is a bad idea in a userspace program, because identifiers with a leading _ are reserved for the C library / system. In some cases, the extra _ served no real purpose, so simply drop it. In others move to the end of the identifier, which is a convention we're free to use for our own purposes. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-26Fix some errors in commentsDavid Gibson1-4/+5
A comment in tests/stringlist.c refers to fdt_get_string(), which is not a function that exists. From the content, it's supposed to be referring to fdt_getprop_string(). A comment in libfdt.h has an extraneous space in a function name. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-26tests: Correct warning in sw_tree1.cDavid Gibson1-0/+2
At least some clang versions (correctly) warn that 'size' is used unititialized, if sw_tree1 is invoked with argc > 2. This corrects the warning. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-10-06tests: Avoid 64-bit arithmetic in assemblerDavid Gibson2-25/+28
For testing we (ab)use the assembler to build us a sample dtb, independent of the other tools (dtc and libfdt) that we're trying to test. In a few places this uses 64-bit arithmetic to decompose 64-bit constants into the individual bytes in the blob. Unfortunately, it seems that some builds of GNU as don't support >32 bit arithmetic, though it's not entirely clear to me which do and which don't (Fedora i386 does support 64-bit, Debian arm32 doesn't). Anyway, to be safe, this avoids 64-bit arithmetic in assembler at the cost of some extra awkwardness because we have to define the values in 32-bit halves. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>