aboutsummaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
2017-08-09tests: Add stacked overlay tests on fdtoverlayPantelis Antoniou4-0/+47
Add a stacked overlay unit test, piggybacking on fdtoverlay. Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-07-13dtc: change default phandles to ePAPR style instead of bothRob Herring1-1/+1
Currently, both legacy (linux,phandle) and ePAPR (phandle) properties are inserted into dtbs by default. The newer ePAPR style has been supported in dtc and Linux kernel for 7 years. That should be a long enough transition period. We can save a little space by not putting both into the dtb. Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-06-15tests: fdtoverlay unit testPantelis Antoniou3-1/+67
Add an fdtoverlay unit test. Applies applies overlay(s) and then retrieves an inserted property to verify. Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-05-17Suppress expected error message in fdtdump testDavid Gibson1-1/+1
Since 548aea2 "fdtdump: Discourage use of fdtdump", fdtdump unconditionally prints a message discouraging its own use except for debugging purposes. This shows up messily in the "make check" output, so suppress it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-19Fix get_node_by_path string equality checkTim Montague2-1/+24
When determining if to recurse into a node, get_node_by_path does not check if the length of each node name is equal. If searching for /foo/baz, this can result in recursing into /foobar because strneq("foo", "foobar", 3) is true. This can result in a reference to /foo/baz to be incorrectly set to /foobar/baz. A test for this was added. Signed-off-by: Tim Montague <tmontague@ghs.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-08pylibfdt: Allow setup.py to operate stand-aloneSimon Glass1-3/+3
At present we require that setup.py is executed from the Makefile, which sets up various important things like the list of files to build and the version number. However many installation systems expect to be able to change to the directory containing setup.py and run it. This allows them to support (for example) building/installing for multiple Python versions, varying installation paths, particular C flags, etc. The problem in implementing this is that we don't want to duplicate the information in the Makefile. A common solution (so I am told) is to parse the Makefile to obtain the required information. Update the setup.py script to read a few Makefiles when it does not see the required information in its environment. This allows installation using: ./pylibfdt/setup.py install Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-04-02Add a libfdt function to write a property placeholderSimon Glass5-0/+10
The existing function to add a new property to a tree being built requires that the entire contents of the new property be passed in. For some applications it is more convenient to be able to add the property contents later, perhaps by reading from a file. This avoids double-buffering of the contents. Add a new function to support this and adjust the existing fdt_property() to use it. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21Build pylibfdt as part of the normal build processSimon Glass1-0/+28
If swig and the Python are available, build pylibfdt automatically. Adjust the tests to run Python tests too in this case. Signed-off-by: Simon Glass <sjg@chromium.org> [dwg: Make error message clearer that missing swig or python-dev isn't fatal to the whole build] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21Add tests for pylibfdtSimon Glass1-0/+288
Add a set of tests to cover the functionality in pylibfdt. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-21checks: Warn on node name unit-addresses with '0x' or leading 0sRob Herring3-0/+26
Node name unit-addresses should generally never begin with 0x or leading 0s. Add warnings to check for these cases, but only for nodes without a known bus type as there should be better bus specific checks of the unit address in those cases. Any unit addresses that don't follow the general rule will need to add a new bus type. There aren't any known ones ATM. Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06tests: Make realloc_fdt() really allocate *fdtNicolas Iooss1-2/+2
This bug has been found by using clang Static Analyzer: it reported that the value stored to fdt was never read. Signed-off-by: Nicolas Iooss <nicolas.iooss_linux@m4x.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-03-06Fix assorted sparse warningsDavid Gibson13-27/+27
This fixes a great many sparse warnings on the fdt and libfdt sources. These are mostly due to incorrect mixing of endian annotated and native integer types. This includes fixing a couple of quasi-bugs where we had endian conversions the wrong way around (this will have the right effect in practice, but is certainly conceptually incorrect). This doesn't make the whole tree sparse clean: there are many warnings in bison and lex generated code, and there are a handful of other remaining warnings that are (for now) more trouble than they're worth to fix (and are not genuine bugs). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-02-24libfdt: Add fdt_setprop_empty()David Gibson1-1/+1
Device trees can contain empty (zero length) properties, which are often used as boolean flags. These can already be created using fdt_setprop() passing a length of zero and a pointer which is ignored. It is safe to pass NULL, but that may not be obvious from the interface. To make it clearer, add an fdt_setprop_empty() helper macro. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2017-01-31dtc: Fix NULL pointer use in dtlabel + dtref caseStephen Boyd2-0/+10
If we have a construct like this: label: &handle { ... }; Running dtc on it will cause a segfault, because we use 'target' when it could be NULL. Move the add_label() call into the if statement to fix this potentially bad use of a NULL pointer. Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09dtc: Don't always generate __symbols__ for pluginsDavid Gibson1-8/+2
At the moment we generate a __symbols__ node if -@ is specified OR if the dts has the /plugin/ tag. That difference in behaviour from handling base trees is unnecessary and slightly confusing. It also means it's impossible to create a plugin without symbols. Since symbols in a plugin are only useful in the case of stacked plugins - and libfdt doesn't even support merging plugin symbols as part of overlay application yet - that's a thing that might be useful. So make __symbols__ generation depend only on -@. We also remove remove the testcases that checked explicitly for this not very useful behaviour. Instead we don't use -@ for our basic overlay testcase, and check that symbols are not generated. At some point in the future we should add support for symbol merging to libfdt and add testcases for stacked overlay application. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Don't use -@ on plugin de/recompile testsDavid Gibson1-2/+2
Using -@ again here obscures what's going on, because at the end we can't know which run actually generated the symbols node. We should just generate the symbols on the first run and leave it at that. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Remove "suppression of fixups" testsDavid Gibson2-28/+0
I think these were for an additional command line option which got dropped during development. At this point all they're testing is that fixups don't get generated for a non /plugin/ tree, which is already tested with one of the simpler cases previously. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Clarify dtc overlay testsDavid Gibson2-11/+14
This changes the names of the testfiles for a number of the testcases of the dtc overlay generation functionality to make them shorter and a bit cleaerer what's going on. In addition we move some of the check_path sanity checks closer to the dtc commands they verify. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: More thorough tests of libfdt overlay application without dtcDavid Gibson4-2/+161
At the moment we have some rudimentary tests of the fdt_overlay_apply() function which don't rely on overlay generation support in dtc. This is done by avoiding any external references in the sample overlay, in particularly using the 'target-path' syntax instead of 'target' to avoid needing external references in the fragment targets. Thus this test case doesn't exercise libfdt's processing of the __fixups__ node at all. We do test that somewhat in combination with dtc's overlay support. However, in the interests of being able to quickly determine which side a bug is on, it would be nice to exercise this without requiring the dtc support. This adds testcases to do so, by making some examples with manually constructed __symbols__ and __fixups__ nodes. In addition we rename some of the test data files and add some extra check_path tests to make it a bit clearer what's going on here. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Fix double expansion bugs in test codeDavid Gibson2-4/+6
Two test programs - check_path and overlay - define a CHECK() helper macro in such a way that in the case of an error it will re-execute the checked code fragment, instead of using the return value from the initial call. This can lead to misreporting errors, because the code may fail in a different way the second time around due to changes made during the first failing call. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Split overlay tests into those with do/don't exercise dtc plugin ↵David Gibson1-10/+16
generation The various tests for overlay/plugin support are currently lumped together in the overlay_tests shell function, which is executed by libfdt_tests. However, this includes both tests designed primarily to exercise libfdt's overlay application, and tests designed to exercise dtc's overlay generation. Split these up for improved clarity. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Test auto-alias generation on base tree, not overlayDavid Gibson1-5/+5
The current testcases for the -A "auto alias generation" option operate on a "plugin" tree. Although not technically wrong, this is an odd approach, since a plugin will almost certainly need the __symbols__ and/or __fixups__ syntax instead of aliases. On the other hand -A may be useful simply for generating aliases on a tree which is not using the overlay / plugin mechanism at all. Therefore change the tests to operate on a base tree example instead of a plugin. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Make overlay/plugin tests unconditionalDavid Gibson1-37/+34
When overlay apply supprt was added to libfdt the testcases included some which could only be executed with the (then) out of tree dtc with overlay output support. So, the test script automatically skipped those tests if it wasn't available. Now that the overlay support is merged into dtc mainline there's no reason to keep this logic. Instead run all the overlay tests unconditionally. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Add overlay testsPantelis Antoniou4-0/+64
Add a number of tests for dynamic objects/overlays. Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-12-09tests: Add check_path testPantelis Antoniou4-1/+88
Add a test that checks for existence or not of a node. It is useful for testing the various cases when generating symbols and fixups for dynamic device tree objects. Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-10-12tests: overlay: Rename the device tree blobs to be more explicitMaxime Ripard1-7/+7
Rename the blobs to have a more explicit output that will give us a clearer idea about whether a DT (and the test) has been compiled using a dtc with our without overlays support. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-10-11tests: overlay: Add test suffix to the compiled blobsMaxime Ripard1-8/+8
The compiled blobs in the overlay tests do not have the test suffix which is usually used to clean up and ignore the test artifacts. Let's add that suffix. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-10-07tests: overlay: Move back the bad fixup testsMaxime Ripard1-7/+7
The bad fixups tests were meant to be usable even for a non-overlay-enabled dtc. Move them out of that check. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-10-06libfdt: Don't use 'index' as a local variable nameDavid Gibson1-15/+15
Using 'index' as a local variable name shadows the standard library index() function. This causes warnings on at least some compiler versions. The recently added overlay code has a number of instances of this. This patch replaces 'index' with 'poffset', since 'index' is being used to mean "offset within a property value" in these cases. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-10-06tests: Add tests cases for the overlay codeMaxime Ripard17-1/+656
Add some test infrastructure to test that the overlay can be merged, but also that poorly formatted fixups would fail as expected. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> [dwg: Don't execute bad overlay tests without overlay aware dtc] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-09-22dtc: Fix assorted problems in the testcases for the -a optionDavid Gibson1-17/+14
We just added the -a option to allow padding of the output dtb's size to a specified alignment. Unfortunately the test cases for this had several bugs: * Didn't actually test anything since "alignbase" instead of $alignbase was passed to the checker function * Introduced an unnecessary run_local_test wrapper * Didn't provide very helpful output on failure * Only attempted to check one alignment value This patch fixes up these problems. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-09-22Implement the -a option to pad dtb alignedTim Wang1-0/+28
There is one condition that need cat the dtb files into one dtb.img which can support several boards use same SoC platform. And the original dtb file size is not aligned to any base. This may cause "Synchronous Abort" when load from a unligned address on some SoC machine, such as ARM. So this patch implement the -a <aligned number> option to pad zero at the end of dtb files and make the dtb size aligned to <aligned number>. Then, the aligned dtbs can cat together and load without "Synchronous Abort". Signed-off-by: Tim Wang <timwang@asrmicro.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-08-01libfdt: Add fdt_setprop_inplace_namelen_partialMaxime Ripard2-0/+13
Add a function to modify inplace only a portion of a property.. This is especially useful when the property is an array of values, and you want to update one of them without changing the DT size. Acked-by: Simon Glass <sjg@chromium.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> [dwg: Remove unnecessary unsigned qualifier, correct a comment] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-07-28libfdt: Add max phandle retrieval functionMaxime Ripard1-0/+6
Add a function to retrieve the highest phandle in a given device tree. Acked-by: Simon Glass <sjg@chromium.org> Reviewed-by: Stefan Agner <stefan@agner.ch> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-07-28libfdt: Add iterator over propertiesMaxime Ripard5-0/+125
Implement a macro based on fdt_first_property_offset and fdt_next_property_offset that provides a convenience to iterate over all the properties of a given node. Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Acked-by: Simon Glass <sjg@chromium.org> [dwg: Removed a stray trailing blank line] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-07-28libfdt: Add a subnodes iterator macroThierry Reding1-6/+2
The fdt_for_each_subnode() iterator macro provided by this patch can be used to iterate over a device tree node's subnodes. At each iteration a loop variable will be set to the next subnode. Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-05-27Alter grammar to allow multiple /dts-v1/ tagsDavid Gibson3-45/+44
This patch allows dtc to accept multiple /dts-v1/ tags (provided they're all at the beginning of the input), rather than giving a syntax error. This makes it more convenient to include one .dts file from another without having to be careful that the /dts-v1/ tag is in exactly one of them. We a couple of existing testcases to take advantage of this, which simplifies them slightly. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-02-19Warn on node name unit-address presence/absence mismatchStephen Warren3-0/+21
ePAPR 1.1 section 2.2.1.1 "Node Name Requirements" specifies that any node that has a reg property must include a unit address in its name with value matching the first entry in its reg property. Conversely, if a node does not have a reg property, the node name must not include a unit address. Also allow ranges property as it is deemed valid, but ePAPR is not clear about it. Implement a check for this. The code doesn't validate the format of the unit address; ePAPR implies this may vary from (containing bus) binding to binding, so doing so would be much more complex. Signed-off-by: Stephen Warren <swarren@nvidia.com> [robh: also allow non-empty ranges] Signed-off-by: Rob Herring <robh@kernel.org> [moved new test in check_table] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-02-19Catch unsigned 32bit overflow when parsing flattened device tree offsetsAnton Blanchard4-0/+35
We have a couple of checks of the form: if (offset+size > totalsize) die(); We need to check that offset+size doesn't overflow, otherwise the check will pass, and we may access past totalsize. Found with AFL. Signed-off-by: Anton Blanchard <anton@samba.org> [Added a testcase] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-01-12Prevent crash on modulo by zeroDavid Gibson1-1/+2
1937095 "Prevent crash on division by zero" fixed a crash when attempting a division by zero using the / operator in a dts. However, it missed the precisely equivalent crash with the % (modulus) operator. This patch fixes the oversight. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-01-04Fix some bugs in processing of line directivesDavid Gibson4-0/+8
In order to work with preprocessed dts files more easily, dts will parse line number information in the form emitted by cpp. Anton Blanchard (using a fuzzer) reported that including a line number directive with a nul character (a literal nul in the input file, not a \0 sequence) would cause dtc to SEGV. I spotted several more problems on examining the code: * It modified yytext in place which seems to work, but is ugly and I'm not sure if it's safe on all lex/flex versions * The regexp used in the lexer to recognize line number information accepts strings with escape characters, but it won't process these escapes. - GNU cpp at least, will generate \ escapes in line number information, at least with files containing " or \ in the name This patch reworks the handling of line number information to address these problems. \ escapes should now be handled directly. nuls in file names (either with a literal nul in the input file, or with a \0 escape sequence) are still not permitted, but will now result in a lexical error rather than a SEGV. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-01-03Fix crash on nul character in string escape sequenceDavid Gibson2-0/+1
If a dts file contains a string with \ followed by a nul byte - an actual nul in the input file, not the \\0 escape - then the assert() in get_escape_char() will trip, crashing dtc. As far as I can tell, there isn't any valid need for this assert(), so just remove it. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-01-03Gracefully handle bad octal literalsDavid Gibson2-0/+6
The code handling integer literals in dtc-lexer.l assumes that the flex regexp means that strtoull() can't fail to interpret the string as a valid integer (either decimal, octal, or hexadecimal). This is not true for octals. For example '09' is accepted as a literal by the regexp, strtoull() attempts to handle it as octal, but it has a bad digit. This changes the code to give a more useful error in this case. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2016-01-03Prevent crash on division by zeroDavid Gibson2-0/+7
Currently, attempting to divide by zero in an integer expression in a dts file will cause dtc to crash with a division by zero (SIGFPE). This patch corrects this to properly detect this case and raise an error. Reported-by: Anton Blanchard <anton@samba.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-30fdt: Add functions to retrieve stringsThierry Reding1-0/+32
Given a device tree node, a property name and an index, the new function fdt_stringlist_get() will return a pointer to the index'th string in the property's value and return its length (or an error code on failure) in an output argument. Signed-off-by: Thierry Reding <treding@nvidia.com> [Fix some -Wshadow warnings --dwg] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-30fdt: Add a function to get the index of a stringThierry Reding1-0/+40
The new fdt_stringlist_search() function will look up a given string in the list contained in the value of a named property of a given device tree node and return its index. Signed-off-by: Thierry Reding <treding@nvidia.com> [Fix some -Wshadow warnings --dwg] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-09-30fdt: Add a function to count stringsThierry Reding5-0/+99
Given a device tree node and a property name, the fdt_stringlist_count() function counts the number of strings found in the property value. This also adds a new error code, FDT_ERR_BADVALUE, that the function returns when it encounters a non-NUL-terminated string list. Signed-off-by: Thierry Reding <treding@nvidia.com> [Changed testcase name --dwg] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-07-09fdtdump: Fix bug printing bytestrings with negative valuesDavid Gibson1-0/+1
On systems where 'char' is signed, fdtdump will currently print the wrong thing on properties containing bytestring values with "negative" bytes (that is with values from 0x80..0xff). The fdtdump testcase is extended to cover this case too. This corrects the problem by forcing use of unsigned char - although this is perhaps another indication that fdtdump is a buggy hack and if you want to do real work you should use dtc -O dts. Reported-by: Igor Prusov <Igor.V.Prusov@mcst.ru> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-07-09Remove redundant fdtdump test codeDavid Gibson1-15/+0
The overall test runner script, for the fdtdump tests invokes the helper script fdtdump-runtest.sh. It then includes directly some code very similar to fdtdump-runtest.sh, which is never reached due to a "return". Remove the never-reached test code. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-07-09Move fdt_path_offset alias tests to right tests sectionDavid Gibson1-5/+5
The test script includes several specific tests for the handling of aliases in fdt_path_offset(). These are primarily tests of the fdt_path_offset() libfdt function itself, although dtc is used to generate a test file for convenience. Move these from the dtc tests section to the libfdt tests section accordingly. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>