lwip: undiif: Fix debug options to unique *_DEBUG macros

Don't reuse *_DEBUG macros intended for other source files.

Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
lwip: Allow LWIP_PLATFORM_* output to use dprintf

Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
lwip/undiif: split arphdr._hwlen_protolen

lwIP already split this in etharp.h

Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
core/lwip/undiif: dprint MAC/ARP/IP/ICMP/TCP/UDP headers; poll debug

Encapsulate in #ifdef; use snprintf and 1 dprintf-like statement.
Print debug message that polling has been forced

Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
Allow for UNDIIF_ID_DEBUG in 1 mk line

Add comments and 1 line to mk/devel.mk to debug headers of all
packets sent/recieved through undiif.c.

Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
derivative_info: be sure not to dereference pointers

All the BIOS get_derivative_info() implementations are incorrect. They
all dereference pointers to various deriviative-specific data objects
instead of using the address of the objects.

This broke chain loading on SYSLINUX because the ->partoffset field
contained the dereferenced value of 'Hidden' rather than the address.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: Regression testsuite

A number of Syslinux releases have contained regressions when compared
with previous versions. Now that the size of the derivative grid has
exploded (PXELINUX, SYSLINUX,.... bios, efi32, efi64) we need to have
some means of ensuring we don't introduce regressions so easily.

Start building a suite of regression tests. Regression tests should test
end-to-end functionality, e.g. loading a Linux kernel. If a test fails,
that failure represents a regression in some behaviour, e.g. Syslinux
behaves differently than it previously did.

The idea is that when bugs are reported in Syslinux, we can create new
tests that reproduce the buggy behaviour. Once a fix has been committed
the new test should pass. From that point forward, the test provides a
means of ensuring we never reintroduce that bug.

The collection of tests illustrates the agreed upon behaviour of
Syslinux.

To execute the regression testsuite type,

  make regression

Sample output might look like,

  Executing regression tests for SYSLINUX
      Running Linux kernel regression tests...
        [+] empty passed
        [+] kernelhello passed
      Running COM32 module regression tests...
        [+] chaindisk passed
  Executing regression tests for PXELINUX
      Running Linux kernel regression tests...
        [!] empty failed
        [+] kernelhello passed
        [+] pxetest passed

Qemu is used to execute the regression tests in a virtual environment.
Because it takes time to load Qemu, we can forgive the regression
testsuite for not executing instantaneously. However, developers should
keep in mind the idea of "failing fast" in their regression tests to
minimize execution time - that is, if a test is going to fail, make it
fail as quickly as possible to reduce the testrun time.

It's possible to have derivative-specific tests, where the test only
runs for a specific Syslinux boot loader. For an example see pxetest in
tests/linux/Makefile.

Currently the regression testsuite requires root privileges to execute
and makes several calls to sudo(8). In future it would be nice to get
rid of this requirement.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: Syslinux unit tests

Improve our faith in the validity of the Syslinux code by writing unit
tests where possible. These should be used in addition to the regression
tests - unit tests are a means of doing very fine-grained testing of
code, whereas the regression tests are end-to-end tests that exercise
abstract functionality.

Unit tests run on your development machine and above all else, their
execution time should be kept to a minimum to encourage repeated runs of
the unit testsuite.

The Syslinux header hierarchy has been reconstructed under
tests/unittest/include. This allows us to reuse header files where
appropriate by simply creating a file with the same name and including
the original, e.g.

tests/unittest/include/com32.h:

  #include <../../../com32/include/com32.h>

Places where we need to override definitions (so that the tests build in
a dev environment) obviously won't include the original header file, but
such scenarios should be kept to a minimum, since you're not really
testing any Syslinux code that way.

To execute the collection of unit tests type,

  make unittest

Sample output might look like,

  Executing unit tests
      Running library unit tests...
        [+] zonelist passed
        [+] movebits passed
        [+] memscan passed

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: delete tests before making release

Binary files exist in tests/ which can dramatically increase the size of
the release tarballs. Delete both regression and unit tests when
building any kind of a release.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
mem: fix regression in recent memscan changes

A thinko in commit a1331f8d ("memscan: pass enum syslinux_memmap_types
around") causes many machines not to boot because the expression
"!SMT_FREE" always evaluates to "false", regardless of the value of
'type', which means that mem_init() may use reserved memory regions for
general allocation.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
mem: explicitly include dprintf.h

It is good practice to explicitly include required header files as it
clearly highlights dependencies.

This practice also makes it easier to write unit tests since we
explicitly include dummy header files from unittest/include.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: make mmap_entry globally available to unit tests

There's a bunch of places that need to deal with mmap_entry entries when
doing tests, so make the structure readily available. Since we're going
to get a collection of header files that could be considered the
"unit test infrastructure" we might as well create a new directory for
them.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: unit tests for core/mem

We can exercise the memory subsystem through unit tests with a little
bit of coaxing. We need to create a number of fake data objects in order
to get it to build. This is less than ideal, but once we've got good
test coverage and confidence in our tests we can begin refactoring.

Had this unit test already been in place, commit 33c4ab1b ("mem: fix
regression in recent memscan changes") would have never been required
because buggy commit a1331f8d ("memscan: pass enum syslinux_memmap_types
around") would have broke the unit test. Ordinarily, this unit test
would have been part of the bugfix commit 33c4ab1b, but the bugfix needs
to be backported to 5.xx on its own.

test_mem_init_reserved() tests whether SMT_RESERVED regions are
incorrectly added to the memory subsystems's freelist.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: delete test executables after each run

The unit tests are designed to be small and should build very quickly,
so there should be no downside to rebuilding them for every run. The
upside is that we don't litter our build trees with target executables
and we don't need to explicitly list dependencies in Makefiles to ensure
our tests get rebuilt whenever a dependency changes.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
pxe: mark all PXE regions as SMT_TERMINAL

There are more than just the UNDI code and data regions. Mark all of the
regions as SMT_TERMINAL if the start address and size are non-zero.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
pxe: use bios_fbm() and real_base_mem to calculate free space

We don't need to individually add the PXE regions, we already have two
symbols that denote the memory region that will be freed when calling
unload_pxe().

This essentially reverts commit 03dda0f1 ("pxe: mark all PXE regions as
SMT_TERMINAL").

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
load_linux: extract the logic for cmdline_offset

There's bits of historical baggage surrounding these values. Pull the
calculation out into a separate function for clarity.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: verify kernel cmdline parameter

Add a new test that verifies the kernel cmdline arguments we setup in
our config file are passed to the kernel correctly.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
load_linux: dynamically calculate the cmdline region

Users are hitting issues where the offset calculated by,

    (0x9ff0 - cmdline_size) & ~15;

is not useable memory, e.g. it is SMT_RESERVED. Instead we should be
trying to find the highest lowmem address.

Cc: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
tests: syslinux_memmap_highest() unit tests

Exercise the new syslinux_memmap_highest() function.

Signed-off-by: Matt Fleming <matt.fleming@intel.com>