aboutsummaryrefslogtreecommitdiff
path: root/tests
AgeCommit message (Collapse)AuthorFilesLines
2015-05-25tests: convert `echo -n` to `printf`Mike Frysinger1-10/+10
The -n option is not standard in POSIX, so convert to printf which should work the same in every shell. Signed-off-by: Mike Frysinger <vapier@chromium.org>
2015-04-30Fix crash with poorly defined #size-cellsJack Miller2-0/+14
If you have a parent block with #size-cells improperly set to 0, and then subsequently try to include a regs property in the child, dtc will crash with SIGFPE while validating it. This patch fixes that crash, instead printing the same invalid length warning that was causing it. Test included. Signed-off-by: Jack Miller <jack@codezen.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-04-07Add testcases for fdt_path_offset_namelen()David Gibson1-0/+31
This extends the path_offset testcase to exercise the fdt_path_offset_namelen() function. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-04-07Extend path_offset testcase for handling of duplicated separatorsDavid Gibson1-0/+10
Paths with multiple '/' characters in a row (e.g. //somenode//somsubnode), or trailing '/' characters (e.g. '/somenode/somesubnode/') should be handled by fdt_path_offset(), and treated as equivalent to /somenode/somesubnode. Our current path_offset testcase doesn't check for these cases, so extend it so it does. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-04-07Use a helper function to clean up path_offset testcaseDavid Gibson1-35/+20
This introduces a check_path_offset() helper function into the path_offset testcase to simplify it. This will also make extending the test case with tests for path_offset_namelen() and some edge cases easier. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-02-23dtc: parser: Add label while overriding nodesNikhil Devshatwar2-0/+57
This patch changes the dtc grammar to allow following syntax i2cexp: &i2c2 { ... }; Current device tree compiler allows to define multiple labels when defining the device node the first time. Typically device nodes are defined in DTSI files. Now these nodes can be overwritten for updating some of the properties. Typically, device nodes are overridden in DTS files. When working with adapter boards, most of the time adapter board can fit to multiple base boards. But depending on which base board it is connected to, the devices on the adapter board would be children of different devices. e.g. On dra7-evm.dts, i2c2 is exported for expansion connector whereas on dra72-evm.dts, i2c5 is exported for expansion connector. This causes a problem when writing a generic device tree file for the adapter board. Because, you cannot know whether all the devices on adapter board are present on i2c or i2c5. The problem can be solved by adding a common label (e.g. i2cexp) in both of the DTS files when overriding the device nodes for i2c2 or i2c5. This way, generic adapter board file would override the i2cexp. And depending on which base board you use the adapter board, all the devices are automatically added for correct device nodes. Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2015-01-27fdtput: add delete node and property functionWang Long1-0/+22
add the delete node and property function for fdtput. usage: 1) delete nodes fdtput -r <options> <dt file> [<node>...] 2) delete properties fdtput -d <options> <dt file> <node> [<property>...] Signed-off-by: Wang Long <long.wanglong@huawei.com>
2014-08-08Properly handle embedded nul delimited string listsJack Miller3-0/+10
For example: reserved-names="res1\0res2\0res3"; Where \0 is an actual embedded NUL in the source instead of a string escape. To achieve this, use the len given by the lexer instead of strlen. Without this patch dtc will mangle the output and possibly hang on realloc.
2014-06-18Fix an off-by-2 error in the source output codeDavid Gibson2-0/+18
This has been there for ages, but the assertion makes no sense in the context of the test immediately preceding it. This caused an abort() when in -I dts -O dts mode with the right sort of internal labels in a string property value. Add a testcase for this and another candidate edge case (though this one we already get right). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-06-18Add a basic test for fdtdumpSimon Glass4-1/+98
We can test fdtdump by comparing its output with the source file that was compiled by dtc. Add a simple test that should at least catch regressions in basic functionality. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-05-12libfdt: Add helpers to read #address-cells and #size-cellsDavid Gibson5-0/+84
This patch makes a small start on libfdt functions which actually help to parse the contents of device trees, rather than purely manipulating the tree's structure. We add simple helpers to read and sanity check the #address-cells and #size-cells values for a given node. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-05-09Fix bug with references to root nodeDavid Gibson6-0/+44
At present, the lexer token for references to a path doesn't permit a reference to the root node &{/}. Fixing the lexer exposes another bug handling this case. This patch fixes both bugs and adds testcases. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2014-03-03Remove duplicate assignmentHeinrich Schuchardt1-1/+0
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2013-12-31Fix valgrind errors in sw_tree1David Gibson2-5/+26
The sw_tree1 testcase has accumulated some valgrind errors, at least in the "realloc" mode. * It had both a realloc_fdt() and explicit xmalloc() for the initial allocation which was redundant and caused errors. * It doesn't make sense to call fdt_resize() until after we've created the initial stub tree * Alignment gaps inserted into the tree contain uninitialized data, which trips an error when we write it out. We could zero the buffer, but that would make it easier to miss real bugs, so we add suppressions for the valgrind warnings instead. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-12-30Add option to run_tests.sh to stop immediately on a failing testDavid Gibson1-1/+8
This is a debugging convenience option, which makes it much easier to find the failing tests and fix them one by one. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-10-26libfdt: Add function to resize the buffer for a sequential write treeDavid Gibson2-8/+81
At present, when using sequential write mode, there's no straightforward means of resizing the buffer the fdt is being built into. This patch adds an fdt_resize() function for this purpose. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-09-20Ensure all tests have matching reg and unit addressStephen Warren19-1/+120
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. Adjust all the dtc test-cases to conform to this rule. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-06-03dtc: ensure #line directives don't consume data from the next lineStephen Warren1-0/+10
Previously, the #line parsing regex ended with ({WS}+[0-9]+)?. The {WS} could match line-break characters. If the #line directive did not contain the optional flags field at the end, this could cause any integer data on the next line to be consumed as part of the #line directive parsing. This could cause syntax errors (i.e. #line parsing consuming the leading 0 from a hex literal 0x1234, leaving x1234 to be parsed as cell data, which is a syntax error), or invalid compilation results (i.e. simply consuming literal 1234 as part of the #line processing, thus removing it from the cell data). Fix this by replacing {WS} with [ \t] so that it can't match line-breaks. Convert all instances of {WS}, even though the other instances should be irrelevant for any well-formed #line directive. This is done for consistency and ultimate safety. Reported-by: Ian Campbell <Ian.Campbell@citrix.com> Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29Add missing test binary to .gitignoreDavid Gibson1-0/+1
The subnode_iterate test binary was missing from .gitignore, this fixes it. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29fdtput: expand fdt if value does not fitSrinivas Kandagatla1-0/+6
If you try to insert a new node or extend a property with large value, using fdtput you will notice that it always fails. example: fdtput -v -p -ts ./tst.dtb "/node-1" "property-1" "value-1 Error at 'node-1': FDT_ERR_NOSPACE or fdtput -v -c ./tst.dtb "/node-1" Error at 'node-1': FDT_ERR_NOSPACE or fdtput -v -ts ./tst.dtb "/node" "property" "very big value" Decoding value: string: 'very big value' Value size 15 Error at 'property': FDT_ERR_NOSPACE All these error are returned from libfdt, as the size of the fdt passed has no space to accomdate these new properties. This patch adds realloc functions in fdtput to allocate new space in fdt when it detects a shortage in space for new value or node. With this patch, fdtput can insert a new node or property or extend a property with new value greater than original size. Also it packs the final blob to clean up any extra padding. Without this patch fdtput tool complains with FDT_ERR_NOSPACE when we try to add a node/property or extend the value of a property. Testcases for the new behaviour added by David Gibson. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29Remove some tests for misfeaturesDavid Gibson1-4/+0
There are a couple of fdtput related tests which are rather pointless - they explicitly test for the presence of an undesirable limitation in fdtput, which will cause test failures when we fix it. This patch removes the tests. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-05-29Use shorten_echo for wrap_testsDavid Gibson1-1/+1
We have certain tests which generate extremely long command lines, which are shortened in the testsuite output with the 'shorten_echo' function. Currently that is used in run_fdtput_test and run_wrap_test, this patch uses it for run_wrap_test as well, allowing more general tests with long command lines. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2013-04-28libfdt: Add fdt_next_subnode() to permit easy subnode iterationSimon Glass4-1/+143
Iterating through subnodes with libfdt is a little painful to write as we need something like this: for (depth = 0, count = 0, offset = fdt_next_node(fdt, parent_offset, &depth); (offset >= 0) && (depth > 0); offset = fdt_next_node(fdt, offset, &depth)) { if (depth == 1) { /* code body */ } } Using fdt_next_subnode() we can instead write this, which is shorter and easier to get right: for (offset = fdt_first_subnode(fdt, parent_offset); offset >= 0; offset = fdt_next_subnode(fdt, offset)) { /* code body */ } Also, it doesn't require two levels of indentation for the loop body. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-04-22Revert "utilfdt_read: pass back up the length of data read"Jon Loeliger1-1/+1
This reverts commit cc2c178727cdeca4eb9756637c2e09e50e0856e7. It was the wrong version of the patch.
2013-04-21utilfdt_read: pass back up the length of data readMike Frysinger1-1/+1
For a follow up commit, we want to be able to scan the buffer that was returned to us. In order to do that safely, we need to know how big the buffer actually is, so pass that back if requested. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2013-01-27Adjust util_is_printable_string() comment and fix testSimon Glass1-1/+2
This commit which changed the behaviour of this function broke one of the tests. Also the comment should be updated to reflect its new behaviour. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-01-06fdtget-runtest.sh: use printf instead of /bin/echo -eStephen Warren1-1/+1
Not all /bin/echo implementations support the -e option. Instead, use printf, which appears to be more widely available than /bin/echo -e. See commit eaec1db "fdtget-runtest.sh: Fix failures when /bin/sh isn't bash" for history. I have tested this on Ubuntu 10.04 with /bin/sh pointing to both dash and bash. Reported-by: Mike Frysinger <vapier@gentoo.org> # and implemented-by Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2013-01-06dtc/tests: don't include fdt.h prior to libfdt.hKim Phillips53-54/+0
tests will need fdt type definitions provided in a subsequent patch to libfdt_env.h. Since libfdt.h includes libfdt_env.h in the right order anyway, just remove the fdt.h include. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-10-08dtc: fix for_each_*() to skip first object if deletedStephen Warren3-0/+49
The previous definition of for_each_*() would always include the very first object within the list, irrespective of whether it was marked deleted, since the deleted flag was not checked on the first object, but only on any "next" object. Fix for_each_*() to check the deleted flag in the loop body every iteration to correct this. Incidentally, this change is why commit 45013d8 dtc: "Add ability to delete nodes and properties" only caused two "make checkm" failures; only two tests actually use multiple labels on the same property or node. With this current change applied, but commit 317a5d9 "dtc: zero out new label objects" reverted, "make checkm" fails 29 times; i.e. for every test that uses any labels at all. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-09-28dtc: cpp co-existence: add support for #line directivesStephen Warren2-0/+13
Line control directives of the following formats are supported: #line LINE "FILE" # LINE "FILE" [FLAGS] This allows dtc to consume the output of pre-processors, and to provide error messages that refer to the original filename, including taking into account any #include directives that the pre-processor may have performed. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-09-28dtc: cpp co-existence: allow names starting with # to be escapedStephen Warren5-1/+54
The device tree language as currently defined conflicts with the C pre- processor in one aspect - when a property or node name begins with a # character, a pre-processor would attempt to interpret it as a directive, fail, and most likely error out. This change allows a property/node name to be prefixed with \. This prevents a pre-processor from seeing # as the first non-whitespace character on the line, and hence prevents the conflict. \ was previously an illegal character in property/node names, so this change is backwards compatible. The \ is stripped from the name during parsing by dtc. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-09-06dtc: Add ability to delete nodes and propertiesStephen Warren4-36/+109
dtc currently allows the contents of properties to be changed, and the contents of nodes to be added to. There are situations where removing properties or nodes may be useful. This change implements the following syntax to do that: / { /delete-property/ propname; /delete-node/ nodename; }; or: /delete-node/ &noderef; Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-12fdtput: Add -p option to create subnodes along entire pathSimon Glass1-0/+13
This option mimics mkdir's -p option. It automatically creates nodes as needed along the path provided. If the node already exists, no error is given. Signed-off-by: Simon Glass <sjg@chromium.org>
2012-07-12fdtput: Add -c option to create nodesSimon Glass1-0/+13
This option allows the creation of new nodes in a dtb file. The syntax is: fdtput -c <dtb_file> <node_path> The node_path contains the path of the node to be created. All path components up to the final one must exist already. The final one must not exist already. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-08Allow toggling of semantic checksDavid Gibson3-2/+60
This patch adds -W and -E options to dtc which allow toggling on and off of the various built in semantic checks on the tree. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-07-08Add test for re-defining an identical labelStephen Warren2-0/+17
When merging one device tree over the top of a previous tree, it is possible to define a duplicate label that has the same name and points to the same property or node. This is currently allowed by the duplicate label checking code. However, alternative duplicate label checking algorithms might not allow this. Add an explicit test to ensure this capability is maintained. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-06-27Fix compilation warning/error in setprop_inplace.cStephen Warren1-4/+5
When compiling the current code-base with gcc 4.6.1, the following warning is raised, which is interpreted as an error: cc1: warnings being treated as errors tests/setprop_inplace.c: In function ‘main’: tests/setprop_inplace.c:62: error: format ‘%016llx’ expects type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’ tests/setprop_inplace.c:68: error: format ‘%016llx’ expects type ‘long long unsigned int’, but argument 2 has type ‘uint64_t’ Use printf format specifiers from <inttypes.h> to solve this. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-06-03libfdt: Add helper function to create a trivial, empty treeDavid Gibson1-11/+1
The libfdt read/write functions are now usable enough that it's become a moderately common pattern to use them to build and manipulate a device tree from scratch. For example, we do so ourself in our rw_tree1 testcase, and qemu is starting to use this model when building device trees for some targets such as e500. However, the read/write functions require some sort of valid tree to begin with, so this necessitates either having a trivial canned dtb to begin with or, more commonly, creating an empty tree using the serial-write functions first. This patch adds a helper function which uses the serial-write functions to create a trivial, empty but complete and valid tree in a supplied buffer, ready for manipulation with the read/write functions. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-06-03libfdt: Add helpers for 64-bit integer propertiesDavid Gibson16-2/+59
In device trees in the world, properties consisting of a single 64-bit integer are not as common as those consisting of a single 32-bit, cell sized integer, but they're common enough that they're worth including convenience functions for. This patch adds helper wrappers of fdt_setprop_inplace(), fdt_setprop() and fdt_appendprop() for handling 64-bit integer quantities in properties. For better consistency with the names of these new *_u64() functions we also add *_u32() functions as alternative names for the existing *_cell() functions handling 32-bit integers. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-06-03Remove test_tree1_dts0 testcasesDavid Gibson2-41/+0
The testcases based on test_tree1_dts0.dts were added purely to test dtc's backwards compatibility handling of the old dts-v0 format. Since that support has been removed, the dts has been updated to use the current dts-v1 syntax, which makes the testcases pass, but be completely useless. This patch removes the now obsolete testcases. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-04-19Add integer expressions files to .gitignoreSimon Glass1-1/+2
Several files were added, and should be in .gitignore. The *.test.dts pattern should catch future source files which are generated by tests. It also subsumes the old *.dtb.test.dts pattern. Signed-off-by: Simon Glass <sjg@chromium.org>
2012-04-19dtc: Adjust .gitignore to be in alphabetical orderSimon Glass1-2/+2
This is the intent, so correct it. Signed-off-by: Simon Glass <sjg@chromium.org>
2012-04-09dtc: Basic integer expressionsStephen Warren3-1/+124
Written by David Gibson <david@gibson.dropbear.id.au>. Additions by me: * Ported to ToT dtc. * Renamed cell to integer throughout. * Implemented value range checks. * Allow U/L/UL/LL/ULL suffix on literals. * Enabled the commented test. Signed-off-by: Stephen Warren <swarren@wwwdotorg.org>
2012-03-31fdtget-runtest.sh: Fix failures when /bin/sh isn't bashStephen Warren1-1/+1
On Ubuntu, /bin/sh is dash (at least by default), and dash's echo doesn't accept the -e option. This means that fdtget-runtest.sh's EXPECT file will contain "-e foo" rather than just "foo", which causes a test failure. To work around this, run /bin/echo instead of (builtin) echo, which has more chance of supporting the -e option. Another possible fix is to change all the #! lines to /bin/bash rather than /bin/sh, and change run_tests.sh to invoke sub-scripts using $SHELL instead of just "sh". However, that would require bash specifically, which may not be desirable. Signed-off-by: Stephen Warren <swarren@wwwdotorg.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-03-18dtc: Add -i option to support search pathsSimon Glass9-0/+47
It is often inconvenient to place device tree files in the same directory as their includes, or to specify the full path to include files. An example of this is in U-Boot where we have a .dtsi file for each SOC type, and this is included by the board .dts file. We need to either use a mechanism like: /include/ ARCH_CPU_DTS with sed or cpp to perform the replacement with the correct path, or we must specify the full path in the file: /include/ "../../arch/arm/dts/tegra20.dtsi" The first option is not desirable since it requires anyone compiling the file to first pre-process it. The second is not desirable since it introduces a path which is project-specific into a file which is supposed to be a hardware description. For example Linux and U-Boot are unlikely to put these include files in the same place. It is much more convenient to specify the search patch on the command line as is done with C pre-processors, for example. Introduce a -i option to add to the list of search paths used to find source and include files. We cannot use -I as it is already in use. Other suggestions welcome. Signed-off-by: Simon Glass <sjg@chromium.org>
2012-03-07fdtget: Add -d to provide a default valueSimon Glass1-0/+6
Sometimes the requested node or property is not present in the device tree. This option provides a way of reporting a default value in this case, rather than halting with an error. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-03-07fdtget: Fix multiple arg bug and add test for itSimon Glass2-1/+4
There is a rather unfortunate bug in fdtget in that if multiple argument sets are provided, it just repeats displaying the first set ones for each set. Fix this bug and add a test for it. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: David Gibson <david@gibson.dropbear.id.au>
2012-02-03Generate test data for fdtput more sensiblyDavid Gibson2-26/+41
Currently run_tests.sh generates several files of text test data. The procedure it uses for this is somewhat torturous and has several problems: * Since the test data is derived from a dts file, a cursory glance at the test output suggests something is wrong with the processing of that dts. This is misleading since in fact it's just being used as an arbirary string. * Since the base input has linefeeds removed, the head and sort commands used later have no effect. * Although an attempt is made to get rid of characters which the shell will mangle, it's not thorough enough. Specifically it leaves in \ which means that some string escapes found in the input data can get expanded somewhere along the line in some shells. This patch, therefore, replaces this generation of test data with a pre-canned "Lorem ipsum" of approximately 2k. On my system, where /bin/sh is dash, this fixes a test failure due to the aforementioned string escapes being evaluated on one but not the other of the two comparison paths (I haven't tracked down exactly where the expansion is happening). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-02-03Don't use diff to check fdt{get,put} resultsDavid Gibson2-12/+14
Currently the fdt{get,put}-runtest.sh scripts invoke diff to check if fdt{get,put} did the right thing. This isn't great though: it's not obvious from the diff output which is the expected and which is the actual result; diff's line by line behaviour is useless here, since all the results are a single line and finally, when there is a difference it always prints information even when the tests are supposed to be running in quiet mode. This patch uses cmp instead, and explicitly prints the expected results, when running in verbose mode (the invocation of fdtget itself will have already displayed the actual results in this mode. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2012-02-03Clean up invocation of fdt{get,put} testsDavid Gibson4-86/+104
This patch cleans up how the fdtget and fdtput tests are invoked. Specifically we no longer hide the full command lines with a wrapper function - this makes it possible to distinguish fdtget from similar fdtput tests and makes it easier to work out how to manually invoke an individual failing test. In addition, we remove the testing for errors from the fdt{get,put}-runtest.sh script, instead using an internal wrapper analagous to run_wrap_test which can test for any program invocation that's expected to return an error. For a couple of the fdtput tests this would result in printing out ludicrously large command lines. Therefore we introduce a new mechanism to cut those down to something reasonable. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>