summaryrefslogtreecommitdiffstats
path: root/test/parser/parser-test.h
Commit message (Collapse)AuthorAgeFilesLines
* Change parser interface to allow statAlan Dunn2016-03-151-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the GRUB2 parser incorrectly reports "[ -f <path> ]" as false if the size of the file is above 1 MB. This patch changes the parser interface to allow stating files (with parser_stat_file). Then in the implementation of "[ -f <path> ]", we can use parser_stat_file instead of parser_request_file which has the size limitation. I eliminate parser_check_dir in lieu of this new interface, which has the side effect of making "[ -d <path> ]" work (the error code for stat was not checked correctly before). I add a basic test for the test file operations -f, -s, and -d (to show that my changes to test file operations do not break them) and minorly modify the test framework to ensure it has enough fidelity to cause the expected results. Unfortunately the test wouldn't have caught the issue with -d, since the test framework stubs out the parser interface itself. Nor can the test framework catch the initial problem with -f because the imposed limit is (transitively) in function parser_request_file. Note that -f and -d follow symlinks despite the fact that GRUB does not (see http://lists.gnu.org/archive/html/grub-devel/2016-02/msg00142.html discussing GRUB's behavior). This is not a change to Petitboot's behavior though. Tested: The test test-grub2-test-file-ops passes. I booted Petitboot against a GRUB snippet: status=success if [ ! -f /large_file -a $status = success ] then status=fail_large_file fi if [ ! -d /a_directory -a $status = success ] then status=fail_dir fi menuentry $status { linux /vmlinux } (after making /large_file a file of size > 1 MiB and /a_directory a directory) and the menuentry had title "success", as desired. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover/pxe: Format IPAPPEND mac addresses correctlySamuel Mendoza-Jonas2014-12-031-0/+1
| | | | | | | | | | | | | | | | | | | | | The SYSAPPEND/IPAPPEND option 2 in PXE configs requires the MAC address of the booting interface to be appended to the boot options. Previously we formatted this as "BOOTIF=01:02:03:04:05:06", but syslinux/pxelinux implementation use this format: "BOOTIF=01-01-02-03-04-05-06", where the leading '01' represents the hardware type. The relevant part of the pxelinux doc is at: http://www.syslinux.org/wiki/index.php/SYSLINUX#SYSAPPEND_bitmask Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* pb-config: Move config storage modules to "platform" modules in discover codeJeremy Kerr2014-01-301-1/+0
| | | | | | | | | | | | | | | | | | There's no need to include the config storage code in lib/ as only the discover server should be using it. This change moves the config-storage code to discover/, with the platform-specific parts moved to a 'struct platform'. Each platform has a probe function, which is called during init. The first probe function to return a platform is used. At present we only have the one platform, but it's now non-intrusive to add others. We keep an array of platform pointers in a separate ("platforms") section, to allow the test module to drop-in its own test "platform". Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add support for checking directories in parser APIJeremy Kerr2014-01-301-0/+2
| | | | | | | | | | | | | This change adds a function to the parser API: int parser_check_dir(struct discover_context *ctx, struct discover_device *dev, const char *dirname) - which allows parsers to check for the presence of a directory (path of 'dirname') on the device ('dev'). We use this in the GRUB2 parser to implement the `test -d` check. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Check for full URLs in parser testsJeremy Kerr2014-01-171-3/+9
| | | | | | | | | | | | At present, we only match the 'file' portion of a URL in the parser tests, so we "serve" a file if just the filename (but not the scheme, hostname or path) matches the file we set with test_read_conf_embedded. This change introduces test_read_conf_embedded_url, which we can use to specify a full URL. In this case, the fake parser_request_file matches the entire URL before returning the file data. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/device-handler: Ensure we free unresolved boot options on removeJeremy Kerr2013-12-021-0/+1
| | | | | | | | | | When we remove a device, some options may still be unresolved, and so won't be deallocated through freeing the device. This chagne explicitly removes & frees any currently-unresolved options for this device. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Update test cases as per new parser requesting conf filesNeelesh Gupta2013-11-061-11/+10
| | | | | | | | | | Update the parser test code/cases as per new prototyping of parse() function which doesn't require buf and len to be passed from the caller, instead reading the configuration data either embedded or from file to a parser's known conffile. Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add check_file_contentsJeremy Kerr2013-10-041-2/+13
| | | | | | | We want to test grub2's save_env command, which requires a new function to check the contents of a file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add parser_request_fileJeremy Kerr2013-10-011-0/+7
| | | | | | Add a function to allow parsers to access files on a local device. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Remove unnecessary event passingJeremy Kerr2013-09-191-1/+2
| | | | | | | | | | | | | | | Currently, we pass "events" between the udev, user-event and device-handler layers. These events all get sent through device_handler_event, then de-multiplexed to an appropriate handler, depending on their source. Instead, just export relevant device_handler functions, and have the (old) event sources call these functions directly. This also means we can include a lot more of the device hander code in the parser tests. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/yaboot: implement default optionsJeremy Kerr2013-08-071-0/+8
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add check_resolved_url_resourceJeremy Kerr2013-07-231-0/+8
| | | | | | Add a check for external URL resources. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add test_set_conf_source()Jeremy Kerr2013-07-041-0/+1
| | | | | | | For non-local parsers (ie, PXE), we need to have the conf_url set. This change adds a function to provide the originating URL. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add check_not_present_resourceGeoff Levand2013-05-181-0/+8
| | | | | | | | | | | Add a new routine check_not_present_resource() to check that a resource is not present. This is typically used to check that an initrd entry has not been found. Also add any needed checks for no initrd to the existing tests. Signed-off-by: Geoff Levand <geoff@infradead.org>
* test/parser: Add test device hotplug functionsJeremy Kerr2013-05-161-0/+2
| | | | | | | | Add a function, test_hotplug_device(), to simulate the addition of devices during tests. This should make it possible to observe boot options' resources changing from unresolved state to resolved. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add resource check helpersJeremy Kerr2013-05-161-0/+19
| | | | | | | Add check_resolved_local_resource and check_unresolved_resource to check the resources returned from parsers. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add check_name helperJeremy Kerr2013-05-161-0/+8
| | | | | | Simple function to check a boot_option's name. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add check_args helperJeremy Kerr2013-05-161-0/+7
| | | | | | Add a small helper to check boot option arguments. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add check_boot_option_count helper & get_boot_optionJeremy Kerr2013-05-161-0/+19
| | | | | | | Add a helper function to check the expected boot option counts, and print the boot option details if the check fails. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Allow raw config data in test .c filesJeremy Kerr2013-05-161-0/+6
| | | | | | | | Add a little post-processing script (extract-config.awk) to allow us to put the config data directly into the test .c files, without having to quote the C string. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Allow tests to provide pre-loaded config dataJeremy Kerr2013-05-161-0/+5
| | | | | | | Some tests may want to use an existing buffer as config data, so add test_read_config_data() to allow this. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test: Replace parser tests with empty frameworkJeremy Kerr2013-05-161-0/+29
This change is a major rework of the parser tests. Currently, the parser tests just run the parsers on each subdir of data/, but we don't actually check the results. Rather than just running parsers and expecting a certain fixed output, the new tests are arbitraty (short!) C programs. This allows us to set up the device configuration / discover context etc in whatever manner necessary, and check that the boot options that the parsers emit are correct. This change removes all of the old tests, and adds a new "null" test. Actual tests will be added in subsequent changes. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
OpenPOWER on IntegriCloud