summaryrefslogtreecommitdiffstats
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* discover: Pass UUID to discover_device_create()Samuel Mendoza-Jonas2016-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently discover_device_create() will search for existing discover devices by id to determine if a new device is required. However it is possible under some circumstances for distinct devices to have the same name. This is especially troublesome if the following network events are seen in network_handle_nlmsg(): - New interface, 'foo' with uuid x:x:x:x:x:x -> new discover device created with dev->device->id = 'foo' dev->uuid = x:x:x:x:x:x - New interface, 'foo' with uuid y:y:y:y:y:y -> existing device 'foo' found dev->uuid = y:y:y:y:y:y This can occur if an interface rename event arrives *after* an old name is reused, where temporarily Petitboot will see two distinct network interfaces with the same name. Now the two interfaces point to the same discover device, which can quickly result in a segfault if a 'remove' event occurs for one of the interfaces and the discover device is freed. To generally avoid this a 'uuid' parameter is added to discover_device_create(), which if present allows existing devices to be looked up by UUID rather than just their name. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* Update tests to support changes to pxe_parserSamuel Mendoza-Jonas2016-06-281-0/+57
| | | | | | | | | | | Substitute load_url_async() when running tests to support direct callers of load_url_async() who will expect to read a file in a callback. Stub out device_handler_discover_context_commit() since it will remove discover_options from the given discover_context, but the tests will check the discover_context to count boot_options. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* pb-discover: add dtb support for PXE configOliver O'Halloran2016-05-241-0/+3
| | | | | | | | | | | | | | Currently there is no way to manually specify a DTB file when with a PXE network boot configuration file. This makes it difficult when you need to work with or emulate a special snowflake machines with special snowflake hardware. Some ARM systems provide this feature with the "fdt" option so this patch adds support for using the ftd or dtb configuration options to the PXE config parser. Signed-off-by: Oliver O'Halloran <oohall@gmail.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* Allow evaluation of arbitrarily-positioned arguments in GRUB2 parserAlan Dunn2016-04-261-3/+3
| | | | | | | | | | | | | | | GRUB2 allows essentially arbitrary numbers of positional arguments, so ensure that they can be evaluated within scripts. GRUB2 also appears to support arbitrary numbers of leading 0's in positional parameters (i.e., $01 should evalute the same as $1), but this doesn't seem like a particularly important case to support. Tested: Modified test-grub2-pos-param to cover higher-numbered positional arguments. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* test/lib: Avoid array overflow of child_argv[]Anton Blanchard2016-03-231-1/+1
| | | | | | | We allocate 3 elements in child_argv, but write 4. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Fix handling of positional parametersAlan Dunn2016-03-152-0/+36
| | | | | | | | | | | | | | Positional parameters are set in the environment with '$' prepended to the name. This causes lookups to fail because parameter lookups don't include the '$'. TESTED: Added a test that covers positional parameters in GRUB2 parser. Build succeeds, tests pass. Bootstrapped-by: Nancy Yuen <yuenn@google.com> Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* Change parser interface to allow statAlan Dunn2016-03-154-6/+92
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* In GRUB2 parser save_env, treat unset variable value as emptyAlan Dunn2016-03-151-0/+6
| | | | | | | | | | | | | | It seems better to treat unset variable values as empty rather than crashing in save_env. While GRUB's behavior is actually to delete the variable from the environment block, it seems useful to at least not crash while later on someone can do further work to improve GRUB compatibility if desired. Tested: Modified test-grub2-save-env to cover this case. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Fix handling of empty stringsSam Mendoza-Jonas2016-02-091-1/+4
| | | | | | | | | | | If "" or '' are used in a statement to omit a word, we must still return a TOKEN_WORD for an empty string. In particular this fixes an issue where Petitboot would fail to parse the grub.cfg included in the Debian 8.2 install image, which includes a menuentry statement with an empty name. Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Fix behavior of save_env -fAlan Dunn2016-02-082-0/+38
| | | | | | | | | | | | | | | Currently, "save_env -f" in the GRUB2 parser only works with three arguments, which means only commands of the form "save_env -f <path>" that save *no* environment variables are allowed. Allow "save_env -f <path> [<var>]*", making "save_env -f" useful. Tested: Unit test test-grub2-save-env-dash-f tests this change, and the remaining unit tests still pass. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Allow unset and invalid defaultsJeremy Kerr2014-12-113-0/+53
| | | | | | | | | | | | | | If the default environment variable is unset or invalid (i.e., references a non-existent boot option), then GRUB2 will fallback to the first boot option present. This is preventing petitboot from autobooting where no default is explicitly set, or is stale. This change adds this fallback behaviour to petitboot. Because we don't know if the first option will be a default at parse time (as no other options matched the default env var), we need to keep options in a list, and register them with the discover server once the parse is complete. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/pxe: Format IPAPPEND mac addresses correctlySamuel Mendoza-Jonas2014-12-035-3/+63
| | | | | | | | | | | | | | | | | | | | | 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>
* test/parser: Add SLES btrfs snapshot stanzaJeremy Kerr2014-12-012-0/+28
| | | | | | | This has caused problems with the old delimiter code, add a test to ensure we don't regress. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: improve handling of word & delimiter tokensJeremy Kerr2014-12-014-0/+99
| | | | | | | | | | | | | | | | | | | | | | | Currently, the delimiter token handling is a little fragile: we try to ignore non-inter-word delimiters in the lexer with a selective set of regexes on the possible delimiter characters. This means we don't need to handle potential delimiters in every grammar rule, but there are other situations (not regex-able) where we may see delimters, and this will cause a parse error. Instead of relying on the regex behaviour, we have an 'inter_word' flag, which is set when we see the first word token, and cleared when we see an end-of-line token. We only emit TOKEN_DELIM when this flag is set. This means that we only get the delim tokens when they're required - when we're looking for word separators (becuase WORD DELIM WORD is distinct from WORD WORD - eg "linux /vmlinux" and "x$var"). We add a few new tests for the "menuentry" and "if" syntax, with different delimiter configurations. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add dependency on libpbcore.laJeremy Kerr2014-12-011-1/+1
| | | | | | | | | | | | | | Currently, build only a test object will fail: [jk@pablo obj]$ make ./test/parser/test-grub2-single CCLD test/parser/test-grub2-single libtool: link: cannot find the library `lib/libpbcore.la' or unhandled argument `lib/libpbcore.la' We're adding this to the link argument, but not as a dependency. This change adds the dependency. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* tests/lib/test-fold: Add mbs test with separatorsJeremy Kerr2014-09-231-1/+12
| | | | | | | Ensure we're doing the correct thing with mbs + separators in the fold code. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib/fold: Add support for multibyte stringsJeremy Kerr2014-09-231-4/+50
| | | | | | | | | | Currently, the fold_text function doesn't understand multibyte strings, so may break a line in the middle of a multibyte sequence. This change adds multibyte-awareness to the fold code, and uses proper width calculations for the contents of the folded string. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Implement PXE SYSAPPEND syntaxJeremy Kerr2014-08-252-0/+36
| | | | | | | This change implements SYSAPPEND/IPAPPEND 2, to add a BOOTIF argument to the kernel command line. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: distinguish parser.h from grub2/parser.hJeremy Kerr2014-08-051-0/+1
| | | | | | | | | | | | | 'make distcheck' will do a 'make all' srcdir == objdir, then later a 'make check' sith srcdir != objdir. Since gcc's cpp always assumes that a source file's directory is first in the include paths, we may see discover/parser.h included when we wanted the generated discover/grub2/parser.h. This change renames the grub2 lexer and parser files, to work-around this behaviour, and fix 'make distcheck'. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* automake: silence make outputJeremy Kerr2014-08-052-6/+5
| | | | | | | | | Currently, we get a lot of noise out of the build process; automake supports V={0,1}, which we can use to suppress the output a little. This needs a few cleanups for custom commands. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* autotools: Use non-recursive makeJeremy Kerr2014-08-014-160/+134
| | | | | | | | | | | | With the current testing infrastructure, we don't have a strictly hierarchical set of dependencies. This causes problems with a recursive make, and means we have to hack around some of the dependencies. This change generates a single, top-level makefile from all of the Makefile.am fragments. We still need the po/ directory as a separate SUBDIR, but all others can be converted to non-recursive. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add missing stubs for network_(un)register_interfaceJeremy Kerr2014-08-011-0/+16
| | | | | | | The device handler code needs these calls on interface add/remove, so we need to provide stubs for the test framework. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* autotools: Don't require custom automake optionsJeff Bailey2014-07-161-1/+1
| | | | | | | | | | | | | We need a couple of automake options to prevent errors when regenerating Makefile.ins during source preparation. Some makefiles assume GNU make, so add 'foreign' where necessary. Also, we are building objects in subdirectories, so we need 'subdir-objects'. Modified to suit recent petitboot by Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Jeff Bailey <jeffbailey@google.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* grub2: fix empty file handlingJeremy Kerr2014-06-052-0/+11
| | | | | | | | | | | Currently, we have a bug when parsing zero-length files: we subtract one from the length to exclude the trailing NUL (added by read_file), but a zero-length file will result in a length of -1. This change adds an explicit exit if we're attempting to parse an empty file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add pxe discovery testsJeremy Kerr2014-02-276-0/+204
| | | | | | Add tests to cover pxlinux-style configuration autodiscovery. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/pxe: pxe parser should only treat "::" paths as absoluteJeremy Kerr2014-02-277-4/+80
| | | | | | | | | | PXELinux treats all paths as relative, requiring a "::/path" syntax for truly absolute URLs. This change implements the same behaviour in petitboot, and updates the testcases to suit. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/pxe: Add pxelinux.cfg/ directory to autodiscovered pxe pathsJeremy Kerr2014-02-274-6/+10
| | | | | | | | | | The pxelinux project will perform autodiscovery by looking for files under the pxelinux.cfg/ prefix (in addition to any pxepathprefix from DHCP option 210) This change unifies petitboot's behaviour with pxelinux. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib/process: Don't abort stdout reads on EINTRJeremy Kerr2014-02-202-0/+58
| | | | | | | | | | | | | | | | | If our read() of the process stdout pipe fails with EINTR (eg, if we receive a SIGCHLD because the process exited), then process_read_stdout_once will return a non-zero exit code, and we'll abort any further stdout collection. Instead, we should check for EINTR, and allow the reads to continue. This change normalises the return value from process_read_stdout_once to return positive on success, negative on failure, and zero on competion. We use a positive return value for the non-error EINTR case. Also, add a pb_log if the read fails for non-EINTR reasons. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib/fold: Add text fold utilityJeremy Kerr2014-01-312-1/+159
| | | | | | | We want to fold help text into the ncurses UI, so add a little module to split text into lines. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* pb-config: Move config storage modules to "platform" modules in discover codeJeremy Kerr2014-01-303-3/+17
| | | | | | | | | | | | | | | | | | 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>
* test/parser: Add Fedora 20 ppc64 parser testcaseJeremy Kerr2014-01-303-0/+54
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add support for checking directories in parser APIJeremy Kerr2014-01-302-0/+40
| | | | | | | | | | | | | 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>
* discover: Use lowercase hex chars for MAC-address-based conf requestsJeremy Kerr2014-01-223-1/+41
| | | | | | | The de-facto PXELINUX standard specifies lowercase characters for the MAC addresses, so change our reuqests to suit. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Support DHCP "pathprefix" configuration optionJeremy Kerr2014-01-174-0/+117
| | | | | | | | | | | | | | | | | This change implements support for the DHCP "pathprefix" option. We use the following logic: - If pathprefix is present and a full URL, we base the config file location on pathprefix + conffile - If pathprefix is present but not a full URL, we use it as the path component of the URL, and pick up the host from other parameters in the DHCP response - If no pathprefix is present, we determine the configuration prefix from the DHCP bootfile parameter. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Check for full URLs in parser testsJeremy Kerr2014-01-178-12/+24
| | | | | | | | | | | | 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/grub: Use --id values for default option detectionBen Stoltz2014-01-172-0/+29
| | | | | | | | Fix Petitboot's grub.cfg parser to handle --id=label argument to menuentry, and use it (in preference to the option name) when looking for a default option. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib/process: Add add_stderr flag to process moduleJeremy Kerr2014-01-143-0/+113
| | | | | | | | | | | | For some process execution functions, we'd like to capture stderr as well as stdout. Currently, we unconditionally redirect subprocess stderr to the petitboot log file. This change adds an add_stderr flag to struct process, which indicates to the process library that we want stderr as well as stdout. If this is specified, the subprocess' stderr is captured to stdout_buf. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser: Add yaboot leftovers testJeremy Kerr2014-01-142-0/+36
| | | | | | | Add a test to ensure that boot option parameters don't leak into later options. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/yaboot: Clear globals_done when we see an image definitionJeremy Kerr2014-01-142-0/+31
| | | | | | | | | | Currently, we have a bug where a 'known_name' that appears before an image section will cause globals_done to be set, and we don't see any further global variables. This change sets globals_done only once we see an image section. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* configure: Use AC_GNU_SOURCEJeremy Kerr2013-12-181-2/+0
| | | | | | | Rather than #defining _GNU_SOURCE in our .c files, we can define this from config.h instead. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/lib: Add parent stdout testJeremy Kerr2013-12-182-0/+56
| | | | | | Looks like we missed adding a test source file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/yaboot: Fix assertion failure on empty yaboot filesJeremy Kerr2013-12-102-0/+13
| | | | | | | | | | yaboot configuration files with no option will cause an assertion failure (or segfault), as we unconditionally call yaboot_finish(). Check for the presence of an option in yaboot_finish() instead of asserting. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/device-handler: Ensure we free unresolved boot options on removeJeremy Kerr2013-12-024-1/+53
| | | | | | | | | | 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>
* discover/grub2: Populate $prefix from config file locationJeremy Kerr2013-11-272-0/+30
| | | | | | | Rather than always using the default prefix, we should determine it from the location of the grub2 config file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* test/parser/grub2: Fix inconsistent conf/env pathsJeremy Kerr2013-11-272-2/+2
| | | | | | | | In an upcoming change, we'll populate $prefix (which is used to locate the environment file) based on the location of the config file, so these paths will need to be consistent. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add support for -s and -f commandsJeremy Kerr2013-11-272-0/+48
| | | | | | | Implement -s and -f checks for grub, and test with the standard GRUB2 saved_default config. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: populate sysinfo with block devicesJeremy Kerr2013-11-221-0/+8
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Use pxeconffile for udhcpc option nameJeremy Kerr2013-11-224-4/+4
| | | | | | | | | | | | The patch that went upstream for udhcpc's option 209 handling uses the option name 'pxeconffile' rather than 'conffile', and it was added as a non-default option: http://git.busybox.net/busybox/commit/?id=d3092c99ae90f This change uses the new name, and explicilty requests this option. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* config: Implement config messagesJeremy Kerr2013-11-131-0/+7
| | | | | | On client connect, send a PB_PROTOCOL_ACTION_CONFIG message. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib: consolidate util macros in util/util.hJeremy Kerr2013-11-131-1/+1
| | | | | | | This change groups the offsetof, container_of and ARRAY_SIZE macros in a single header file util/util.h. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
OpenPOWER on IntegriCloud