From 511fd0b2bb60e640895e7c51f71db29ddeb42aa4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:05 -0700 Subject: binman: Add better Makefile debugging There is a debugging option in the Makefile to allow people to figure out which u-boot.dtsi files are used in the build. But is it not easy to use since it only shows files it finds, not those it is looking for. Update it and update the mention of it to the docs. Signed-off-by: Simon Glass --- tools/binman/README | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/binman/README b/tools/binman/README index cb47e73599..63f9722642 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -446,7 +446,8 @@ If you are having trouble figuring out what is going on, you can uncomment the 'warning' line in scripts/Makefile.lib to see what it has found: # Uncomment for debugging - # $(warning binman_dtsi_options: $(binman_dtsi_options)) + # This shows all the files that were considered and the one that we chose. + # u_boot_dtsi_options_debug = $(u_boot_dtsi_options_raw) Code coverage -- cgit From 9c0a8b1f44a18343acb48a7b6cf6ec724a7fac93 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:06 -0700 Subject: binman: Add docs explaining how to enable binman for a board The process is not obvious. Add a little section to explain how to move a board to use binman. Signed-off-by: Simon Glass --- tools/binman/README | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tools') diff --git a/tools/binman/README b/tools/binman/README index 63f9722642..4ef76c8f08 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -206,6 +206,27 @@ for its instructions in the 'binman' node. Binman has a few other options which you can see by running 'binman -h'. +Enabling binman for a board +--------------------------- + +At present binman is invoked from a rule in the main Makefile. Typically you +will have a rule like: + +ifneq ($(CONFIG_ARCH_),) +u-boot-.bin: checkbinman FORCE + $(call if_changed,binman) +endif + +This assumes that u-boot-.bin is a target, and is the final file +that you need to produce. You can make it a target by adding it to ALL-y +either in the main Makefile or in a config.mk file in your arch subdirectory. + +Once binman is executed it will pick up its instructions from a device-tree +file, typically -u-boot.dtsi, where is your CONFIG_SYS_SOC value. +You can use other, more specific CONFIG options - see 'Automatic .dtsi +inclusion' below. + + Image description format ------------------------ -- cgit From 00ebd1f74d94a0fa50545d59a4e61b3a28c82b07 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:07 -0700 Subject: binman: Add a Makefile for test-program compilation These test programs are includedd as binary files in U-Boot to avoid having to build them (and associated toolchain differences). Instructions on building are in the files themselves, but it seems better to provide a Makefile which can be manually run when desired. Add a Makefile, separate from the normal build system, to handle this. Signed-off-by: Simon Glass --- tools/binman/test/Makefile | 36 +++++++++++++++++++++++++++++++++ tools/binman/test/u_boot_no_ucode_ptr.c | 4 ---- tools/binman/test/u_boot_ucode_ptr.c | 4 ---- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 tools/binman/test/Makefile (limited to 'tools') diff --git a/tools/binman/test/Makefile b/tools/binman/test/Makefile new file mode 100644 index 0000000000..786d1b0577 --- /dev/null +++ b/tools/binman/test/Makefile @@ -0,0 +1,36 @@ +# +# Builds test programs +# +# Copyright (C) 2017 Google, Inc +# Written by Simon Glass +# +# SPDX-License-Identifier: GPL-2.0+ +# + +CFLAGS := -march=i386 -m32 -nostdlib -I ../../../include + +LDS_UCODE := -T u_boot_ucode_ptr.lds + +TARGETS = u_boot_ucode_ptr u_boot_no_ucode_ptr + +all: $(TARGETS) + +u_boot_no_ucode_ptr: CFLAGS += $(LDS_UCODE) +u_boot_no_ucode_ptr: u_boot_no_ucode_ptr.c + +u_boot_ucode_ptr: CFLAGS += $(LDS_UCODE) +u_boot_ucode_ptr: u_boot_ucode_ptr.c + +clean: + rm -f $(TARGETS) + +help: + @echo "Makefile for binman test programs" + @echo + @echo "Intended for use on x86 hosts" + @echo + @echo "Targets:" + @echo + @echo -e "\thelp - Print help (this is it!)" + @echo -e "\tall - Builds test programs (default targget)" + @echo -e "\tclean - Delete output files" diff --git a/tools/binman/test/u_boot_no_ucode_ptr.c b/tools/binman/test/u_boot_no_ucode_ptr.c index a17bb4c6c2..c4a2b85fc9 100644 --- a/tools/binman/test/u_boot_no_ucode_ptr.c +++ b/tools/binman/test/u_boot_no_ucode_ptr.c @@ -5,10 +5,6 @@ * * Simple program to create a bad _dt_ucode_base_size symbol to create an * error when it is used. This is used by binman tests. - * - * Build with: - * cc -march=i386 -m32 -o u_boot_no_ucode_ptr -T u_boot_ucode_ptr.lds \ - -nostdlib u_boot_no_ucode_ptr.c */ static unsigned long not__dt_ucode_base_size[2] diff --git a/tools/binman/test/u_boot_ucode_ptr.c b/tools/binman/test/u_boot_ucode_ptr.c index 434c9f4400..24f349fb9e 100644 --- a/tools/binman/test/u_boot_ucode_ptr.c +++ b/tools/binman/test/u_boot_ucode_ptr.c @@ -5,10 +5,6 @@ * * Simple program to create a _dt_ucode_base_size symbol which can be read * by 'nm'. This is used by binman tests. - * - * Build with: - * cc -march=i386 -m32 -o u_boot_ucode_ptr -T u_boot_ucode_ptr.lds -nostdlib \ - u_boot_ucode_ptr.c */ static unsigned long _dt_ucode_base_size[2] -- cgit From 680e3312c23b72142a767c91eb1d74d36e1094fe Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:08 -0700 Subject: binman: Rename tests to ftest At present these tests use the same filename as patman. This adds confusion when running all tests, since error messages look very similar. In fact binman tries to run the wrong tests at present. Rename the tests. Signed-off-by: Simon Glass --- tools/binman/binman.py | 4 +- tools/binman/ftest.py | 813 ++++++++++++++++++++++++++++++++++++++++++++++ tools/binman/func_test.py | 813 ---------------------------------------------- 3 files changed, 815 insertions(+), 815 deletions(-) create mode 100644 tools/binman/ftest.py delete mode 100644 tools/binman/func_test.py (limited to 'tools') diff --git a/tools/binman/binman.py b/tools/binman/binman.py index e75a59d951..d264bcdfa8 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -34,7 +34,7 @@ def RunTests(): """Run the functional tests and any embedded doctests""" import entry_test import fdt_test - import func_test + import ftest import test import doctest @@ -44,7 +44,7 @@ def RunTests(): suite.run(result) sys.argv = [sys.argv[0]] - for module in (func_test.TestFunctional, fdt_test.TestFdt, + for module in (ftest.TestFunctional, fdt_test.TestFdt, entry_test.TestEntry): suite = unittest.TestLoader().loadTestsFromTestCase(module) suite.run(result) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py new file mode 100644 index 0000000000..c4207ce5d2 --- /dev/null +++ b/tools/binman/ftest.py @@ -0,0 +1,813 @@ +# +# Copyright (c) 2016 Google, Inc +# Written by Simon Glass +# +# SPDX-License-Identifier: GPL-2.0+ +# +# To run a single test, change to this directory, and: +# +# python -m unittest func_test.TestFunctional.testHelp + +from optparse import OptionParser +import os +import shutil +import struct +import sys +import tempfile +import unittest + +import binman +import cmdline +import command +import control +import entry +import fdt +import fdt_util +import tools +import tout + +# Contents of test files, corresponding to different entry types +U_BOOT_DATA = '1234' +U_BOOT_IMG_DATA = 'img' +U_BOOT_SPL_DATA = '567' +BLOB_DATA = '89' +ME_DATA = '0abcd' +VGA_DATA = 'vga' +U_BOOT_DTB_DATA = 'udtb' +X86_START16_DATA = 'start16' +U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here' +FSP_DATA = 'fsp' +CMC_DATA = 'cmc' +VBT_DATA = 'vbt' + +class TestFunctional(unittest.TestCase): + """Functional tests for binman + + Most of these use a sample .dts file to build an image and then check + that it looks correct. The sample files are in the test/ subdirectory + and are numbered. + + For each entry type a very small test file is created using fixed + string contents. This makes it easy to test that things look right, and + debug problems. + + In some cases a 'real' file must be used - these are also supplied in + the test/ diurectory. + """ + @classmethod + def setUpClass(self): + # Handle the case where argv[0] is 'python' + self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) + self._binman_pathname = os.path.join(self._binman_dir, 'binman') + + # Create a temporary directory for input files + self._indir = tempfile.mkdtemp(prefix='binmant.') + + # Create some test files + TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA) + TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA) + TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA) + TestFunctional._MakeInputFile('blobfile', BLOB_DATA) + TestFunctional._MakeInputFile('me.bin', ME_DATA) + TestFunctional._MakeInputFile('vga.bin', VGA_DATA) + TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) + TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA) + TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA) + TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) + TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) + TestFunctional._MakeInputFile('vbt.bin', VBT_DATA) + self._output_setup = False + + # ELF file with a '_dt_ucode_base_size' symbol + with open(self.TestFile('u_boot_ucode_ptr')) as fd: + TestFunctional._MakeInputFile('u-boot', fd.read()) + + # Intel flash descriptor file + with open(self.TestFile('descriptor.bin')) as fd: + TestFunctional._MakeInputFile('descriptor.bin', fd.read()) + + @classmethod + def tearDownClass(self): + """Remove the temporary input directory and its contents""" + if self._indir: + shutil.rmtree(self._indir) + self._indir = None + + def setUp(self): + # Enable this to turn on debugging output + # tout.Init(tout.DEBUG) + command.test_result = None + + def tearDown(self): + """Remove the temporary output directory""" + tools._FinaliseForTest() + + def _RunBinman(self, *args, **kwargs): + """Run binman using the command line + + Args: + Arguments to pass, as a list of strings + kwargs: Arguments to pass to Command.RunPipe() + """ + result = command.RunPipe([[self._binman_pathname] + list(args)], + capture=True, capture_stderr=True, raise_on_error=False) + if result.return_code and kwargs.get('raise_on_error', True): + raise Exception("Error running '%s': %s" % (' '.join(args), + result.stdout + result.stderr)) + return result + + def _DoBinman(self, *args): + """Run binman using directly (in the same process) + + Args: + Arguments to pass, as a list of strings + Returns: + Return value (0 for success) + """ + (options, args) = cmdline.ParseArgs(list(args)) + options.pager = 'binman-invalid-pager' + options.build_dir = self._indir + + # For testing, you can force an increase in verbosity here + # options.verbosity = tout.DEBUG + return control.Binman(options, args) + + def _DoTestFile(self, fname): + """Run binman with a given test file + + Args: + fname: Device tree source filename to use (e.g. 05_simple.dts) + """ + return self._DoBinman('-p', '-I', self._indir, + '-d', self.TestFile(fname)) + + def _SetupDtb(self, fname, outfile='u-boot.dtb'): + """Set up a new test device-tree file + + The given file is compiled and set up as the device tree to be used + for ths test. + + Args: + fname: Filename of .dts file to read + outfile: Output filename for compiled device tree binary + + Returns: + Contents of device tree binary + """ + if not self._output_setup: + tools.PrepareOutputDir(self._indir, True) + self._output_setup = True + dtb = fdt_util.EnsureCompiled(self.TestFile(fname)) + with open(dtb) as fd: + data = fd.read() + TestFunctional._MakeInputFile(outfile, data) + return data + + def _DoReadFileDtb(self, fname, use_real_dtb=False): + """Run binman and return the resulting image + + This runs binman with a given test file and then reads the resulting + output file. It is a shortcut function since most tests need to do + these steps. + + Raises an assertion failure if binman returns a non-zero exit code. + + Args: + fname: Device tree source filename to use (e.g. 05_simple.dts) + use_real_dtb: True to use the test file as the contents of + the u-boot-dtb entry. Normally this is not needed and the + test contents (the U_BOOT_DTB_DATA string) can be used. + But in some test we need the real contents. + + Returns: + Tuple: + Resulting image contents + Device tree contents + """ + dtb_data = None + # Use the compiled test file as the u-boot-dtb input + if use_real_dtb: + dtb_data = self._SetupDtb(fname) + + try: + retcode = self._DoTestFile(fname) + self.assertEqual(0, retcode) + + # Find the (only) image, read it and return its contents + image = control.images['image'] + fname = tools.GetOutputFilename('image.bin') + self.assertTrue(os.path.exists(fname)) + with open(fname) as fd: + return fd.read(), dtb_data + finally: + # Put the test file back + if use_real_dtb: + TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) + + def _DoReadFile(self, fname, use_real_dtb=False): + """Helper function which discards the device-tree binary""" + return self._DoReadFileDtb(fname, use_real_dtb)[0] + + @classmethod + def _MakeInputFile(self, fname, contents): + """Create a new test input file, creating directories as needed + + Args: + fname: Filenaem to create + contents: File contents to write in to the file + Returns: + Full pathname of file created + """ + pathname = os.path.join(self._indir, fname) + dirname = os.path.dirname(pathname) + if dirname and not os.path.exists(dirname): + os.makedirs(dirname) + with open(pathname, 'wb') as fd: + fd.write(contents) + return pathname + + @classmethod + def TestFile(self, fname): + return os.path.join(self._binman_dir, 'test', fname) + + def AssertInList(self, grep_list, target): + """Assert that at least one of a list of things is in a target + + Args: + grep_list: List of strings to check + target: Target string + """ + for grep in grep_list: + if grep in target: + return + self.fail("Error: '%' not found in '%s'" % (grep_list, target)) + + def CheckNoGaps(self, entries): + """Check that all entries fit together without gaps + + Args: + entries: List of entries to check + """ + pos = 0 + for entry in entries.values(): + self.assertEqual(pos, entry.pos) + pos += entry.size + + def GetFdtLen(self, dtb): + """Get the totalsize field from a device tree binary + + Args: + dtb: Device tree binary contents + + Returns: + Total size of device tree binary, from the header + """ + return struct.unpack('>L', dtb[4:8])[0] + + def testRun(self): + """Test a basic run with valid args""" + result = self._RunBinman('-h') + + def testFullHelp(self): + """Test that the full help is displayed with -H""" + result = self._RunBinman('-H') + help_file = os.path.join(self._binman_dir, 'README') + self.assertEqual(len(result.stdout), os.path.getsize(help_file)) + self.assertEqual(0, len(result.stderr)) + self.assertEqual(0, result.return_code) + + def testFullHelpInternal(self): + """Test that the full help is displayed with -H""" + try: + command.test_result = command.CommandResult() + result = self._DoBinman('-H') + help_file = os.path.join(self._binman_dir, 'README') + finally: + command.test_result = None + + def testHelp(self): + """Test that the basic help is displayed with -h""" + result = self._RunBinman('-h') + self.assertTrue(len(result.stdout) > 200) + self.assertEqual(0, len(result.stderr)) + self.assertEqual(0, result.return_code) + + # Not yet available. + def testBoard(self): + """Test that we can run it with a specific board""" + self._SetupDtb('05_simple.dts', 'sandbox/u-boot.dtb') + TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA) + result = self._DoBinman('-b', 'sandbox') + self.assertEqual(0, result) + + def testNeedBoard(self): + """Test that we get an error when no board ius supplied""" + with self.assertRaises(ValueError) as e: + result = self._DoBinman() + self.assertIn("Must provide a board to process (use -b )", + str(e.exception)) + + def testMissingDt(self): + """Test that an invalid device tree file generates an error""" + with self.assertRaises(Exception) as e: + self._RunBinman('-d', 'missing_file') + # We get one error from libfdt, and a different one from fdtget. + self.AssertInList(["Couldn't open blob from 'missing_file'", + 'No such file or directory'], str(e.exception)) + + def testBrokenDt(self): + """Test that an invalid device tree source file generates an error + + Since this is a source file it should be compiled and the error + will come from the device-tree compiler (dtc). + """ + with self.assertRaises(Exception) as e: + self._RunBinman('-d', self.TestFile('01_invalid.dts')) + self.assertIn("FATAL ERROR: Unable to parse input tree", + str(e.exception)) + + def testMissingNode(self): + """Test that a device tree without a 'binman' node generates an error""" + with self.assertRaises(Exception) as e: + self._DoBinman('-d', self.TestFile('02_missing_node.dts')) + self.assertIn("does not have a 'binman' node", str(e.exception)) + + def testEmpty(self): + """Test that an empty binman node works OK (i.e. does nothing)""" + result = self._RunBinman('-d', self.TestFile('03_empty.dts')) + self.assertEqual(0, len(result.stderr)) + self.assertEqual(0, result.return_code) + + def testInvalidEntry(self): + """Test that an invalid entry is flagged""" + with self.assertRaises(Exception) as e: + result = self._RunBinman('-d', + self.TestFile('04_invalid_entry.dts')) + #print e.exception + self.assertIn("Unknown entry type 'not-a-valid-type' in node " + "'/binman/not-a-valid-type'", str(e.exception)) + + def testSimple(self): + """Test a simple binman with a single file""" + data = self._DoReadFile('05_simple.dts') + self.assertEqual(U_BOOT_DATA, data) + + def testDual(self): + """Test that we can handle creating two images + + This also tests image padding. + """ + retcode = self._DoTestFile('06_dual_image.dts') + self.assertEqual(0, retcode) + + image = control.images['image1'] + self.assertEqual(len(U_BOOT_DATA), image._size) + fname = tools.GetOutputFilename('image1.bin') + self.assertTrue(os.path.exists(fname)) + with open(fname) as fd: + data = fd.read() + self.assertEqual(U_BOOT_DATA, data) + + image = control.images['image2'] + self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size) + fname = tools.GetOutputFilename('image2.bin') + self.assertTrue(os.path.exists(fname)) + with open(fname) as fd: + data = fd.read() + self.assertEqual(U_BOOT_DATA, data[3:7]) + self.assertEqual(chr(0) * 3, data[:3]) + self.assertEqual(chr(0) * 5, data[7:]) + + def testBadAlign(self): + """Test that an invalid alignment value is detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('07_bad_align.dts') + self.assertIn("Node '/binman/u-boot': Alignment 23 must be a power " + "of two", str(e.exception)) + + def testPackSimple(self): + """Test that packing works as expected""" + retcode = self._DoTestFile('08_pack.dts') + self.assertEqual(0, retcode) + self.assertIn('image', control.images) + image = control.images['image'] + entries = image._entries + self.assertEqual(5, len(entries)) + + # First u-boot + self.assertIn('u-boot', entries) + entry = entries['u-boot'] + self.assertEqual(0, entry.pos) + self.assertEqual(len(U_BOOT_DATA), entry.size) + + # Second u-boot, aligned to 16-byte boundary + self.assertIn('u-boot-align', entries) + entry = entries['u-boot-align'] + self.assertEqual(16, entry.pos) + self.assertEqual(len(U_BOOT_DATA), entry.size) + + # Third u-boot, size 23 bytes + self.assertIn('u-boot-size', entries) + entry = entries['u-boot-size'] + self.assertEqual(20, entry.pos) + self.assertEqual(len(U_BOOT_DATA), entry.contents_size) + self.assertEqual(23, entry.size) + + # Fourth u-boot, placed immediate after the above + self.assertIn('u-boot-next', entries) + entry = entries['u-boot-next'] + self.assertEqual(43, entry.pos) + self.assertEqual(len(U_BOOT_DATA), entry.size) + + # Fifth u-boot, placed at a fixed position + self.assertIn('u-boot-fixed', entries) + entry = entries['u-boot-fixed'] + self.assertEqual(61, entry.pos) + self.assertEqual(len(U_BOOT_DATA), entry.size) + + self.assertEqual(65, image._size) + + def testPackExtra(self): + """Test that extra packing feature works as expected""" + retcode = self._DoTestFile('09_pack_extra.dts') + + self.assertEqual(0, retcode) + self.assertIn('image', control.images) + image = control.images['image'] + entries = image._entries + self.assertEqual(5, len(entries)) + + # First u-boot with padding before and after + self.assertIn('u-boot', entries) + entry = entries['u-boot'] + self.assertEqual(0, entry.pos) + self.assertEqual(3, entry.pad_before) + self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size) + + # Second u-boot has an aligned size, but it has no effect + self.assertIn('u-boot-align-size-nop', entries) + entry = entries['u-boot-align-size-nop'] + self.assertEqual(12, entry.pos) + self.assertEqual(4, entry.size) + + # Third u-boot has an aligned size too + self.assertIn('u-boot-align-size', entries) + entry = entries['u-boot-align-size'] + self.assertEqual(16, entry.pos) + self.assertEqual(32, entry.size) + + # Fourth u-boot has an aligned end + self.assertIn('u-boot-align-end', entries) + entry = entries['u-boot-align-end'] + self.assertEqual(48, entry.pos) + self.assertEqual(16, entry.size) + + # Fifth u-boot immediately afterwards + self.assertIn('u-boot-align-both', entries) + entry = entries['u-boot-align-both'] + self.assertEqual(64, entry.pos) + self.assertEqual(64, entry.size) + + self.CheckNoGaps(entries) + self.assertEqual(128, image._size) + + def testPackAlignPowerOf2(self): + """Test that invalid entry alignment is detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('10_pack_align_power2.dts') + self.assertIn("Node '/binman/u-boot': Alignment 5 must be a power " + "of two", str(e.exception)) + + def testPackAlignSizePowerOf2(self): + """Test that invalid entry size alignment is detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('11_pack_align_size_power2.dts') + self.assertIn("Node '/binman/u-boot': Alignment size 55 must be a " + "power of two", str(e.exception)) + + def testPackInvalidAlign(self): + """Test detection of an position that does not match its alignment""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('12_pack_inv_align.dts') + self.assertIn("Node '/binman/u-boot': Position 0x5 (5) does not match " + "align 0x4 (4)", str(e.exception)) + + def testPackInvalidSizeAlign(self): + """Test that invalid entry size alignment is detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('13_pack_inv_size_align.dts') + self.assertIn("Node '/binman/u-boot': Size 0x5 (5) does not match " + "align-size 0x4 (4)", str(e.exception)) + + def testPackOverlap(self): + """Test that overlapping regions are detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('14_pack_overlap.dts') + self.assertIn("Node '/binman/u-boot-align': Position 0x3 (3) overlaps " + "with previous entry '/binman/u-boot' ending at 0x4 (4)", + str(e.exception)) + + def testPackEntryOverflow(self): + """Test that entries that overflow their size are detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('15_pack_overflow.dts') + self.assertIn("Node '/binman/u-boot': Entry contents size is 0x4 (4) " + "but entry size is 0x3 (3)", str(e.exception)) + + def testPackImageOverflow(self): + """Test that entries which overflow the image size are detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('16_pack_image_overflow.dts') + self.assertIn("Image '/binman': contents size 0x4 (4) exceeds image " + "size 0x3 (3)", str(e.exception)) + + def testPackImageSize(self): + """Test that the image size can be set""" + retcode = self._DoTestFile('17_pack_image_size.dts') + self.assertEqual(0, retcode) + self.assertIn('image', control.images) + image = control.images['image'] + self.assertEqual(7, image._size) + + def testPackImageSizeAlign(self): + """Test that image size alignemnt works as expected""" + retcode = self._DoTestFile('18_pack_image_align.dts') + self.assertEqual(0, retcode) + self.assertIn('image', control.images) + image = control.images['image'] + self.assertEqual(16, image._size) + + def testPackInvalidImageAlign(self): + """Test that invalid image alignment is detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('19_pack_inv_image_align.dts') + self.assertIn("Image '/binman': Size 0x7 (7) does not match " + "align-size 0x8 (8)", str(e.exception)) + + def testPackAlignPowerOf2(self): + """Test that invalid image alignment is detected""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('20_pack_inv_image_align_power2.dts') + self.assertIn("Image '/binman': Alignment size 131 must be a power of " + "two", str(e.exception)) + + def testImagePadByte(self): + """Test that the image pad byte can be specified""" + data = self._DoReadFile('21_image_pad.dts') + self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 9) + U_BOOT_DATA, data) + + def testImageName(self): + """Test that image files can be named""" + retcode = self._DoTestFile('22_image_name.dts') + self.assertEqual(0, retcode) + image = control.images['image1'] + fname = tools.GetOutputFilename('test-name') + self.assertTrue(os.path.exists(fname)) + + image = control.images['image2'] + fname = tools.GetOutputFilename('test-name.xx') + self.assertTrue(os.path.exists(fname)) + + def testBlobFilename(self): + """Test that generic blobs can be provided by filename""" + data = self._DoReadFile('23_blob.dts') + self.assertEqual(BLOB_DATA, data) + + def testPackSorted(self): + """Test that entries can be sorted""" + data = self._DoReadFile('24_sorted.dts') + self.assertEqual(chr(0) * 5 + U_BOOT_SPL_DATA + chr(0) * 2 + + U_BOOT_DATA, data) + + def testPackZeroPosition(self): + """Test that an entry at position 0 is not given a new position""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('25_pack_zero_size.dts') + self.assertIn("Node '/binman/u-boot-spl': Position 0x0 (0) overlaps " + "with previous entry '/binman/u-boot' ending at 0x4 (4)", + str(e.exception)) + + def testPackUbootDtb(self): + """Test that a device tree can be added to U-Boot""" + data = self._DoReadFile('26_pack_u_boot_dtb.dts') + self.assertEqual(U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA, data) + + def testPackX86RomNoSize(self): + """Test that the end-at-4gb property requires a size property""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('27_pack_4gb_no_size.dts') + self.assertIn("Image '/binman': Image size must be provided when " + "using end-at-4gb", str(e.exception)) + + def testPackX86RomOutside(self): + """Test that the end-at-4gb property checks for position boundaries""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('28_pack_4gb_outside.dts') + self.assertIn("Node '/binman/u-boot': Position 0x0 (0) is outside " + "the image starting at 0xfffffff0 (4294967280)", + str(e.exception)) + + def testPackX86Rom(self): + """Test that a basic x86 ROM can be created""" + data = self._DoReadFile('29_x86-rom.dts') + self.assertEqual(U_BOOT_DATA + chr(0) * 3 + U_BOOT_SPL_DATA + + chr(0) * 6, data) + + def testPackX86RomMeNoDesc(self): + """Test that an invalid Intel descriptor entry is detected""" + TestFunctional._MakeInputFile('descriptor.bin', '') + with self.assertRaises(ValueError) as e: + self._DoTestFile('31_x86-rom-me.dts') + self.assertIn("Node '/binman/intel-descriptor': Cannot find FD " + "signature", str(e.exception)) + + def testPackX86RomBadDesc(self): + """Test that the Intel requires a descriptor entry""" + with self.assertRaises(ValueError) as e: + self._DoTestFile('30_x86-rom-me-no-desc.dts') + self.assertIn("Node '/binman/intel-me': No position set with " + "pos-unset: should another entry provide this correct " + "position?", str(e.exception)) + + def testPackX86RomMe(self): + """Test that an x86 ROM with an ME region can be created""" + data = self._DoReadFile('31_x86-rom-me.dts') + self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)]) + + def testPackVga(self): + """Test that an image with a VGA binary can be created""" + data = self._DoReadFile('32_intel-vga.dts') + self.assertEqual(VGA_DATA, data[:len(VGA_DATA)]) + + def testPackStart16(self): + """Test that an image with an x86 start16 region can be created""" + data = self._DoReadFile('33_x86-start16.dts') + self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)]) + + def testPackUbootMicrocode(self): + """Test that x86 microcode can be handled correctly + + We expect to see the following in the image, in order: + u-boot-nodtb.bin with a microcode pointer inserted at the correct + place + u-boot.dtb with the microcode removed + the microcode + """ + data = self._DoReadFile('34_x86_ucode.dts', True) + + # Now check the device tree has no microcode + second = data[len(U_BOOT_NODTB_DATA):] + fname = tools.GetOutputFilename('test.dtb') + with open(fname, 'wb') as fd: + fd.write(second) + dtb = fdt.FdtScan(fname) + ucode = dtb.GetNode('/microcode') + self.assertTrue(ucode) + for node in ucode.subnodes: + self.assertFalse(node.props.get('data')) + + fdt_len = self.GetFdtLen(second) + third = second[fdt_len:] + + # Check that the microcode appears immediately after the Fdt + # This matches the concatenation of the data properties in + # the /microcode/update@xxx nodes in x86_ucode.dts. + ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, + 0x78235609) + self.assertEqual(ucode_data, third[:len(ucode_data)]) + ucode_pos = len(U_BOOT_NODTB_DATA) + fdt_len + + # Check that the microcode pointer was inserted. It should match the + # expected position and size + pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, + len(ucode_data)) + first = data[:len(U_BOOT_NODTB_DATA)] + self.assertEqual('nodtb with microcode' + pos_and_size + + ' somewhere in here', first) + + def _RunPackUbootSingleMicrocode(self): + """Test that x86 microcode can be handled correctly + + We expect to see the following in the image, in order: + u-boot-nodtb.bin with a microcode pointer inserted at the correct + place + u-boot.dtb with the microcode + an empty microcode region + """ + # We need the libfdt library to run this test since only that allows + # finding the offset of a property. This is required by + # Entry_u_boot_dtb_with_ucode.ObtainContents(). + data = self._DoReadFile('35_x86_single_ucode.dts', True) + + second = data[len(U_BOOT_NODTB_DATA):] + + fdt_len = self.GetFdtLen(second) + third = second[fdt_len:] + second = second[:fdt_len] + + ucode_data = struct.pack('>2L', 0x12345678, 0x12345679) + self.assertIn(ucode_data, second) + ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA) + + # Check that the microcode pointer was inserted. It should match the + # expected position and size + pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, + len(ucode_data)) + first = data[:len(U_BOOT_NODTB_DATA)] + self.assertEqual('nodtb with microcode' + pos_and_size + + ' somewhere in here', first) + + def testPackUbootSingleMicrocode(self): + """Test that x86 microcode can be handled correctly with fdt_normal. + """ + self._RunPackUbootSingleMicrocode() + + def testUBootImg(self): + """Test that u-boot.img can be put in a file""" + data = self._DoReadFile('36_u_boot_img.dts') + self.assertEqual(U_BOOT_IMG_DATA, data) + + def testNoMicrocode(self): + """Test that a missing microcode region is detected""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('37_x86_no_ucode.dts', True) + self.assertIn("Node '/binman/u-boot-dtb-with-ucode': No /microcode " + "node found in ", str(e.exception)) + + def testMicrocodeWithoutNode(self): + """Test that a missing u-boot-dtb-with-ucode node is detected""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('38_x86_ucode_missing_node.dts', True) + self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " + "microcode region u-boot-dtb-with-ucode", str(e.exception)) + + def testMicrocodeWithoutNode2(self): + """Test that a missing u-boot-ucode node is detected""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('39_x86_ucode_missing_node2.dts', True) + self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " + "microcode region u-boot-ucode", str(e.exception)) + + def testMicrocodeWithoutPtrInElf(self): + """Test that a U-Boot binary without the microcode symbol is detected""" + # ELF file without a '_dt_ucode_base_size' symbol + try: + with open(self.TestFile('u_boot_no_ucode_ptr')) as fd: + TestFunctional._MakeInputFile('u-boot', fd.read()) + + with self.assertRaises(ValueError) as e: + self._RunPackUbootSingleMicrocode() + self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate " + "_dt_ucode_base_size symbol in u-boot", str(e.exception)) + + finally: + # Put the original file back + with open(self.TestFile('u_boot_ucode_ptr')) as fd: + TestFunctional._MakeInputFile('u-boot', fd.read()) + + def testMicrocodeNotInImage(self): + """Test that microcode must be placed within the image""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('40_x86_ucode_not_in_image.dts', True) + self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Microcode " + "pointer _dt_ucode_base_size at fffffe14 is outside the " + "image ranging from 00000000 to 0000002e", str(e.exception)) + + def testWithoutMicrocode(self): + """Test that we can cope with an image without microcode (e.g. qemu)""" + with open(self.TestFile('u_boot_no_ucode_ptr')) as fd: + TestFunctional._MakeInputFile('u-boot', fd.read()) + data, dtb = self._DoReadFileDtb('44_x86_optional_ucode.dts', True) + + # Now check the device tree has no microcode + self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)]) + second = data[len(U_BOOT_NODTB_DATA):] + + fdt_len = self.GetFdtLen(second) + self.assertEqual(dtb, second[:fdt_len]) + + used_len = len(U_BOOT_NODTB_DATA) + fdt_len + third = data[used_len:] + self.assertEqual(chr(0) * (0x200 - used_len), third) + + def testUnknownPosSize(self): + """Test that microcode must be placed within the image""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('41_unknown_pos_size.dts', True) + self.assertIn("Image '/binman': Unable to set pos/size for unknown " + "entry 'invalid-entry'", str(e.exception)) + + def testPackFsp(self): + """Test that an image with a FSP binary can be created""" + data = self._DoReadFile('42_intel-fsp.dts') + self.assertEqual(FSP_DATA, data[:len(FSP_DATA)]) + + def testPackCmc(self): + """Test that an image with a CMC binary can be created""" + data = self._DoReadFile('43_intel-cmc.dts') + self.assertEqual(CMC_DATA, data[:len(CMC_DATA)]) + + def testPackVbt(self): + """Test that an image with a VBT binary can be created""" + data = self._DoReadFile('46_intel-vbt.dts') + self.assertEqual(VBT_DATA, data[:len(VBT_DATA)]) diff --git a/tools/binman/func_test.py b/tools/binman/func_test.py deleted file mode 100644 index c4207ce5d2..0000000000 --- a/tools/binman/func_test.py +++ /dev/null @@ -1,813 +0,0 @@ -# -# Copyright (c) 2016 Google, Inc -# Written by Simon Glass -# -# SPDX-License-Identifier: GPL-2.0+ -# -# To run a single test, change to this directory, and: -# -# python -m unittest func_test.TestFunctional.testHelp - -from optparse import OptionParser -import os -import shutil -import struct -import sys -import tempfile -import unittest - -import binman -import cmdline -import command -import control -import entry -import fdt -import fdt_util -import tools -import tout - -# Contents of test files, corresponding to different entry types -U_BOOT_DATA = '1234' -U_BOOT_IMG_DATA = 'img' -U_BOOT_SPL_DATA = '567' -BLOB_DATA = '89' -ME_DATA = '0abcd' -VGA_DATA = 'vga' -U_BOOT_DTB_DATA = 'udtb' -X86_START16_DATA = 'start16' -U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here' -FSP_DATA = 'fsp' -CMC_DATA = 'cmc' -VBT_DATA = 'vbt' - -class TestFunctional(unittest.TestCase): - """Functional tests for binman - - Most of these use a sample .dts file to build an image and then check - that it looks correct. The sample files are in the test/ subdirectory - and are numbered. - - For each entry type a very small test file is created using fixed - string contents. This makes it easy to test that things look right, and - debug problems. - - In some cases a 'real' file must be used - these are also supplied in - the test/ diurectory. - """ - @classmethod - def setUpClass(self): - # Handle the case where argv[0] is 'python' - self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) - self._binman_pathname = os.path.join(self._binman_dir, 'binman') - - # Create a temporary directory for input files - self._indir = tempfile.mkdtemp(prefix='binmant.') - - # Create some test files - TestFunctional._MakeInputFile('u-boot.bin', U_BOOT_DATA) - TestFunctional._MakeInputFile('u-boot.img', U_BOOT_IMG_DATA) - TestFunctional._MakeInputFile('spl/u-boot-spl.bin', U_BOOT_SPL_DATA) - TestFunctional._MakeInputFile('blobfile', BLOB_DATA) - TestFunctional._MakeInputFile('me.bin', ME_DATA) - TestFunctional._MakeInputFile('vga.bin', VGA_DATA) - TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) - TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA) - TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA) - TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) - TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) - TestFunctional._MakeInputFile('vbt.bin', VBT_DATA) - self._output_setup = False - - # ELF file with a '_dt_ucode_base_size' symbol - with open(self.TestFile('u_boot_ucode_ptr')) as fd: - TestFunctional._MakeInputFile('u-boot', fd.read()) - - # Intel flash descriptor file - with open(self.TestFile('descriptor.bin')) as fd: - TestFunctional._MakeInputFile('descriptor.bin', fd.read()) - - @classmethod - def tearDownClass(self): - """Remove the temporary input directory and its contents""" - if self._indir: - shutil.rmtree(self._indir) - self._indir = None - - def setUp(self): - # Enable this to turn on debugging output - # tout.Init(tout.DEBUG) - command.test_result = None - - def tearDown(self): - """Remove the temporary output directory""" - tools._FinaliseForTest() - - def _RunBinman(self, *args, **kwargs): - """Run binman using the command line - - Args: - Arguments to pass, as a list of strings - kwargs: Arguments to pass to Command.RunPipe() - """ - result = command.RunPipe([[self._binman_pathname] + list(args)], - capture=True, capture_stderr=True, raise_on_error=False) - if result.return_code and kwargs.get('raise_on_error', True): - raise Exception("Error running '%s': %s" % (' '.join(args), - result.stdout + result.stderr)) - return result - - def _DoBinman(self, *args): - """Run binman using directly (in the same process) - - Args: - Arguments to pass, as a list of strings - Returns: - Return value (0 for success) - """ - (options, args) = cmdline.ParseArgs(list(args)) - options.pager = 'binman-invalid-pager' - options.build_dir = self._indir - - # For testing, you can force an increase in verbosity here - # options.verbosity = tout.DEBUG - return control.Binman(options, args) - - def _DoTestFile(self, fname): - """Run binman with a given test file - - Args: - fname: Device tree source filename to use (e.g. 05_simple.dts) - """ - return self._DoBinman('-p', '-I', self._indir, - '-d', self.TestFile(fname)) - - def _SetupDtb(self, fname, outfile='u-boot.dtb'): - """Set up a new test device-tree file - - The given file is compiled and set up as the device tree to be used - for ths test. - - Args: - fname: Filename of .dts file to read - outfile: Output filename for compiled device tree binary - - Returns: - Contents of device tree binary - """ - if not self._output_setup: - tools.PrepareOutputDir(self._indir, True) - self._output_setup = True - dtb = fdt_util.EnsureCompiled(self.TestFile(fname)) - with open(dtb) as fd: - data = fd.read() - TestFunctional._MakeInputFile(outfile, data) - return data - - def _DoReadFileDtb(self, fname, use_real_dtb=False): - """Run binman and return the resulting image - - This runs binman with a given test file and then reads the resulting - output file. It is a shortcut function since most tests need to do - these steps. - - Raises an assertion failure if binman returns a non-zero exit code. - - Args: - fname: Device tree source filename to use (e.g. 05_simple.dts) - use_real_dtb: True to use the test file as the contents of - the u-boot-dtb entry. Normally this is not needed and the - test contents (the U_BOOT_DTB_DATA string) can be used. - But in some test we need the real contents. - - Returns: - Tuple: - Resulting image contents - Device tree contents - """ - dtb_data = None - # Use the compiled test file as the u-boot-dtb input - if use_real_dtb: - dtb_data = self._SetupDtb(fname) - - try: - retcode = self._DoTestFile(fname) - self.assertEqual(0, retcode) - - # Find the (only) image, read it and return its contents - image = control.images['image'] - fname = tools.GetOutputFilename('image.bin') - self.assertTrue(os.path.exists(fname)) - with open(fname) as fd: - return fd.read(), dtb_data - finally: - # Put the test file back - if use_real_dtb: - TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) - - def _DoReadFile(self, fname, use_real_dtb=False): - """Helper function which discards the device-tree binary""" - return self._DoReadFileDtb(fname, use_real_dtb)[0] - - @classmethod - def _MakeInputFile(self, fname, contents): - """Create a new test input file, creating directories as needed - - Args: - fname: Filenaem to create - contents: File contents to write in to the file - Returns: - Full pathname of file created - """ - pathname = os.path.join(self._indir, fname) - dirname = os.path.dirname(pathname) - if dirname and not os.path.exists(dirname): - os.makedirs(dirname) - with open(pathname, 'wb') as fd: - fd.write(contents) - return pathname - - @classmethod - def TestFile(self, fname): - return os.path.join(self._binman_dir, 'test', fname) - - def AssertInList(self, grep_list, target): - """Assert that at least one of a list of things is in a target - - Args: - grep_list: List of strings to check - target: Target string - """ - for grep in grep_list: - if grep in target: - return - self.fail("Error: '%' not found in '%s'" % (grep_list, target)) - - def CheckNoGaps(self, entries): - """Check that all entries fit together without gaps - - Args: - entries: List of entries to check - """ - pos = 0 - for entry in entries.values(): - self.assertEqual(pos, entry.pos) - pos += entry.size - - def GetFdtLen(self, dtb): - """Get the totalsize field from a device tree binary - - Args: - dtb: Device tree binary contents - - Returns: - Total size of device tree binary, from the header - """ - return struct.unpack('>L', dtb[4:8])[0] - - def testRun(self): - """Test a basic run with valid args""" - result = self._RunBinman('-h') - - def testFullHelp(self): - """Test that the full help is displayed with -H""" - result = self._RunBinman('-H') - help_file = os.path.join(self._binman_dir, 'README') - self.assertEqual(len(result.stdout), os.path.getsize(help_file)) - self.assertEqual(0, len(result.stderr)) - self.assertEqual(0, result.return_code) - - def testFullHelpInternal(self): - """Test that the full help is displayed with -H""" - try: - command.test_result = command.CommandResult() - result = self._DoBinman('-H') - help_file = os.path.join(self._binman_dir, 'README') - finally: - command.test_result = None - - def testHelp(self): - """Test that the basic help is displayed with -h""" - result = self._RunBinman('-h') - self.assertTrue(len(result.stdout) > 200) - self.assertEqual(0, len(result.stderr)) - self.assertEqual(0, result.return_code) - - # Not yet available. - def testBoard(self): - """Test that we can run it with a specific board""" - self._SetupDtb('05_simple.dts', 'sandbox/u-boot.dtb') - TestFunctional._MakeInputFile('sandbox/u-boot.bin', U_BOOT_DATA) - result = self._DoBinman('-b', 'sandbox') - self.assertEqual(0, result) - - def testNeedBoard(self): - """Test that we get an error when no board ius supplied""" - with self.assertRaises(ValueError) as e: - result = self._DoBinman() - self.assertIn("Must provide a board to process (use -b )", - str(e.exception)) - - def testMissingDt(self): - """Test that an invalid device tree file generates an error""" - with self.assertRaises(Exception) as e: - self._RunBinman('-d', 'missing_file') - # We get one error from libfdt, and a different one from fdtget. - self.AssertInList(["Couldn't open blob from 'missing_file'", - 'No such file or directory'], str(e.exception)) - - def testBrokenDt(self): - """Test that an invalid device tree source file generates an error - - Since this is a source file it should be compiled and the error - will come from the device-tree compiler (dtc). - """ - with self.assertRaises(Exception) as e: - self._RunBinman('-d', self.TestFile('01_invalid.dts')) - self.assertIn("FATAL ERROR: Unable to parse input tree", - str(e.exception)) - - def testMissingNode(self): - """Test that a device tree without a 'binman' node generates an error""" - with self.assertRaises(Exception) as e: - self._DoBinman('-d', self.TestFile('02_missing_node.dts')) - self.assertIn("does not have a 'binman' node", str(e.exception)) - - def testEmpty(self): - """Test that an empty binman node works OK (i.e. does nothing)""" - result = self._RunBinman('-d', self.TestFile('03_empty.dts')) - self.assertEqual(0, len(result.stderr)) - self.assertEqual(0, result.return_code) - - def testInvalidEntry(self): - """Test that an invalid entry is flagged""" - with self.assertRaises(Exception) as e: - result = self._RunBinman('-d', - self.TestFile('04_invalid_entry.dts')) - #print e.exception - self.assertIn("Unknown entry type 'not-a-valid-type' in node " - "'/binman/not-a-valid-type'", str(e.exception)) - - def testSimple(self): - """Test a simple binman with a single file""" - data = self._DoReadFile('05_simple.dts') - self.assertEqual(U_BOOT_DATA, data) - - def testDual(self): - """Test that we can handle creating two images - - This also tests image padding. - """ - retcode = self._DoTestFile('06_dual_image.dts') - self.assertEqual(0, retcode) - - image = control.images['image1'] - self.assertEqual(len(U_BOOT_DATA), image._size) - fname = tools.GetOutputFilename('image1.bin') - self.assertTrue(os.path.exists(fname)) - with open(fname) as fd: - data = fd.read() - self.assertEqual(U_BOOT_DATA, data) - - image = control.images['image2'] - self.assertEqual(3 + len(U_BOOT_DATA) + 5, image._size) - fname = tools.GetOutputFilename('image2.bin') - self.assertTrue(os.path.exists(fname)) - with open(fname) as fd: - data = fd.read() - self.assertEqual(U_BOOT_DATA, data[3:7]) - self.assertEqual(chr(0) * 3, data[:3]) - self.assertEqual(chr(0) * 5, data[7:]) - - def testBadAlign(self): - """Test that an invalid alignment value is detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('07_bad_align.dts') - self.assertIn("Node '/binman/u-boot': Alignment 23 must be a power " - "of two", str(e.exception)) - - def testPackSimple(self): - """Test that packing works as expected""" - retcode = self._DoTestFile('08_pack.dts') - self.assertEqual(0, retcode) - self.assertIn('image', control.images) - image = control.images['image'] - entries = image._entries - self.assertEqual(5, len(entries)) - - # First u-boot - self.assertIn('u-boot', entries) - entry = entries['u-boot'] - self.assertEqual(0, entry.pos) - self.assertEqual(len(U_BOOT_DATA), entry.size) - - # Second u-boot, aligned to 16-byte boundary - self.assertIn('u-boot-align', entries) - entry = entries['u-boot-align'] - self.assertEqual(16, entry.pos) - self.assertEqual(len(U_BOOT_DATA), entry.size) - - # Third u-boot, size 23 bytes - self.assertIn('u-boot-size', entries) - entry = entries['u-boot-size'] - self.assertEqual(20, entry.pos) - self.assertEqual(len(U_BOOT_DATA), entry.contents_size) - self.assertEqual(23, entry.size) - - # Fourth u-boot, placed immediate after the above - self.assertIn('u-boot-next', entries) - entry = entries['u-boot-next'] - self.assertEqual(43, entry.pos) - self.assertEqual(len(U_BOOT_DATA), entry.size) - - # Fifth u-boot, placed at a fixed position - self.assertIn('u-boot-fixed', entries) - entry = entries['u-boot-fixed'] - self.assertEqual(61, entry.pos) - self.assertEqual(len(U_BOOT_DATA), entry.size) - - self.assertEqual(65, image._size) - - def testPackExtra(self): - """Test that extra packing feature works as expected""" - retcode = self._DoTestFile('09_pack_extra.dts') - - self.assertEqual(0, retcode) - self.assertIn('image', control.images) - image = control.images['image'] - entries = image._entries - self.assertEqual(5, len(entries)) - - # First u-boot with padding before and after - self.assertIn('u-boot', entries) - entry = entries['u-boot'] - self.assertEqual(0, entry.pos) - self.assertEqual(3, entry.pad_before) - self.assertEqual(3 + 5 + len(U_BOOT_DATA), entry.size) - - # Second u-boot has an aligned size, but it has no effect - self.assertIn('u-boot-align-size-nop', entries) - entry = entries['u-boot-align-size-nop'] - self.assertEqual(12, entry.pos) - self.assertEqual(4, entry.size) - - # Third u-boot has an aligned size too - self.assertIn('u-boot-align-size', entries) - entry = entries['u-boot-align-size'] - self.assertEqual(16, entry.pos) - self.assertEqual(32, entry.size) - - # Fourth u-boot has an aligned end - self.assertIn('u-boot-align-end', entries) - entry = entries['u-boot-align-end'] - self.assertEqual(48, entry.pos) - self.assertEqual(16, entry.size) - - # Fifth u-boot immediately afterwards - self.assertIn('u-boot-align-both', entries) - entry = entries['u-boot-align-both'] - self.assertEqual(64, entry.pos) - self.assertEqual(64, entry.size) - - self.CheckNoGaps(entries) - self.assertEqual(128, image._size) - - def testPackAlignPowerOf2(self): - """Test that invalid entry alignment is detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('10_pack_align_power2.dts') - self.assertIn("Node '/binman/u-boot': Alignment 5 must be a power " - "of two", str(e.exception)) - - def testPackAlignSizePowerOf2(self): - """Test that invalid entry size alignment is detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('11_pack_align_size_power2.dts') - self.assertIn("Node '/binman/u-boot': Alignment size 55 must be a " - "power of two", str(e.exception)) - - def testPackInvalidAlign(self): - """Test detection of an position that does not match its alignment""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('12_pack_inv_align.dts') - self.assertIn("Node '/binman/u-boot': Position 0x5 (5) does not match " - "align 0x4 (4)", str(e.exception)) - - def testPackInvalidSizeAlign(self): - """Test that invalid entry size alignment is detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('13_pack_inv_size_align.dts') - self.assertIn("Node '/binman/u-boot': Size 0x5 (5) does not match " - "align-size 0x4 (4)", str(e.exception)) - - def testPackOverlap(self): - """Test that overlapping regions are detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('14_pack_overlap.dts') - self.assertIn("Node '/binman/u-boot-align': Position 0x3 (3) overlaps " - "with previous entry '/binman/u-boot' ending at 0x4 (4)", - str(e.exception)) - - def testPackEntryOverflow(self): - """Test that entries that overflow their size are detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('15_pack_overflow.dts') - self.assertIn("Node '/binman/u-boot': Entry contents size is 0x4 (4) " - "but entry size is 0x3 (3)", str(e.exception)) - - def testPackImageOverflow(self): - """Test that entries which overflow the image size are detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('16_pack_image_overflow.dts') - self.assertIn("Image '/binman': contents size 0x4 (4) exceeds image " - "size 0x3 (3)", str(e.exception)) - - def testPackImageSize(self): - """Test that the image size can be set""" - retcode = self._DoTestFile('17_pack_image_size.dts') - self.assertEqual(0, retcode) - self.assertIn('image', control.images) - image = control.images['image'] - self.assertEqual(7, image._size) - - def testPackImageSizeAlign(self): - """Test that image size alignemnt works as expected""" - retcode = self._DoTestFile('18_pack_image_align.dts') - self.assertEqual(0, retcode) - self.assertIn('image', control.images) - image = control.images['image'] - self.assertEqual(16, image._size) - - def testPackInvalidImageAlign(self): - """Test that invalid image alignment is detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('19_pack_inv_image_align.dts') - self.assertIn("Image '/binman': Size 0x7 (7) does not match " - "align-size 0x8 (8)", str(e.exception)) - - def testPackAlignPowerOf2(self): - """Test that invalid image alignment is detected""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('20_pack_inv_image_align_power2.dts') - self.assertIn("Image '/binman': Alignment size 131 must be a power of " - "two", str(e.exception)) - - def testImagePadByte(self): - """Test that the image pad byte can be specified""" - data = self._DoReadFile('21_image_pad.dts') - self.assertEqual(U_BOOT_SPL_DATA + (chr(0xff) * 9) + U_BOOT_DATA, data) - - def testImageName(self): - """Test that image files can be named""" - retcode = self._DoTestFile('22_image_name.dts') - self.assertEqual(0, retcode) - image = control.images['image1'] - fname = tools.GetOutputFilename('test-name') - self.assertTrue(os.path.exists(fname)) - - image = control.images['image2'] - fname = tools.GetOutputFilename('test-name.xx') - self.assertTrue(os.path.exists(fname)) - - def testBlobFilename(self): - """Test that generic blobs can be provided by filename""" - data = self._DoReadFile('23_blob.dts') - self.assertEqual(BLOB_DATA, data) - - def testPackSorted(self): - """Test that entries can be sorted""" - data = self._DoReadFile('24_sorted.dts') - self.assertEqual(chr(0) * 5 + U_BOOT_SPL_DATA + chr(0) * 2 + - U_BOOT_DATA, data) - - def testPackZeroPosition(self): - """Test that an entry at position 0 is not given a new position""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('25_pack_zero_size.dts') - self.assertIn("Node '/binman/u-boot-spl': Position 0x0 (0) overlaps " - "with previous entry '/binman/u-boot' ending at 0x4 (4)", - str(e.exception)) - - def testPackUbootDtb(self): - """Test that a device tree can be added to U-Boot""" - data = self._DoReadFile('26_pack_u_boot_dtb.dts') - self.assertEqual(U_BOOT_NODTB_DATA + U_BOOT_DTB_DATA, data) - - def testPackX86RomNoSize(self): - """Test that the end-at-4gb property requires a size property""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('27_pack_4gb_no_size.dts') - self.assertIn("Image '/binman': Image size must be provided when " - "using end-at-4gb", str(e.exception)) - - def testPackX86RomOutside(self): - """Test that the end-at-4gb property checks for position boundaries""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('28_pack_4gb_outside.dts') - self.assertIn("Node '/binman/u-boot': Position 0x0 (0) is outside " - "the image starting at 0xfffffff0 (4294967280)", - str(e.exception)) - - def testPackX86Rom(self): - """Test that a basic x86 ROM can be created""" - data = self._DoReadFile('29_x86-rom.dts') - self.assertEqual(U_BOOT_DATA + chr(0) * 3 + U_BOOT_SPL_DATA + - chr(0) * 6, data) - - def testPackX86RomMeNoDesc(self): - """Test that an invalid Intel descriptor entry is detected""" - TestFunctional._MakeInputFile('descriptor.bin', '') - with self.assertRaises(ValueError) as e: - self._DoTestFile('31_x86-rom-me.dts') - self.assertIn("Node '/binman/intel-descriptor': Cannot find FD " - "signature", str(e.exception)) - - def testPackX86RomBadDesc(self): - """Test that the Intel requires a descriptor entry""" - with self.assertRaises(ValueError) as e: - self._DoTestFile('30_x86-rom-me-no-desc.dts') - self.assertIn("Node '/binman/intel-me': No position set with " - "pos-unset: should another entry provide this correct " - "position?", str(e.exception)) - - def testPackX86RomMe(self): - """Test that an x86 ROM with an ME region can be created""" - data = self._DoReadFile('31_x86-rom-me.dts') - self.assertEqual(ME_DATA, data[0x1000:0x1000 + len(ME_DATA)]) - - def testPackVga(self): - """Test that an image with a VGA binary can be created""" - data = self._DoReadFile('32_intel-vga.dts') - self.assertEqual(VGA_DATA, data[:len(VGA_DATA)]) - - def testPackStart16(self): - """Test that an image with an x86 start16 region can be created""" - data = self._DoReadFile('33_x86-start16.dts') - self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)]) - - def testPackUbootMicrocode(self): - """Test that x86 microcode can be handled correctly - - We expect to see the following in the image, in order: - u-boot-nodtb.bin with a microcode pointer inserted at the correct - place - u-boot.dtb with the microcode removed - the microcode - """ - data = self._DoReadFile('34_x86_ucode.dts', True) - - # Now check the device tree has no microcode - second = data[len(U_BOOT_NODTB_DATA):] - fname = tools.GetOutputFilename('test.dtb') - with open(fname, 'wb') as fd: - fd.write(second) - dtb = fdt.FdtScan(fname) - ucode = dtb.GetNode('/microcode') - self.assertTrue(ucode) - for node in ucode.subnodes: - self.assertFalse(node.props.get('data')) - - fdt_len = self.GetFdtLen(second) - third = second[fdt_len:] - - # Check that the microcode appears immediately after the Fdt - # This matches the concatenation of the data properties in - # the /microcode/update@xxx nodes in x86_ucode.dts. - ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, - 0x78235609) - self.assertEqual(ucode_data, third[:len(ucode_data)]) - ucode_pos = len(U_BOOT_NODTB_DATA) + fdt_len - - # Check that the microcode pointer was inserted. It should match the - # expected position and size - pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, - len(ucode_data)) - first = data[:len(U_BOOT_NODTB_DATA)] - self.assertEqual('nodtb with microcode' + pos_and_size + - ' somewhere in here', first) - - def _RunPackUbootSingleMicrocode(self): - """Test that x86 microcode can be handled correctly - - We expect to see the following in the image, in order: - u-boot-nodtb.bin with a microcode pointer inserted at the correct - place - u-boot.dtb with the microcode - an empty microcode region - """ - # We need the libfdt library to run this test since only that allows - # finding the offset of a property. This is required by - # Entry_u_boot_dtb_with_ucode.ObtainContents(). - data = self._DoReadFile('35_x86_single_ucode.dts', True) - - second = data[len(U_BOOT_NODTB_DATA):] - - fdt_len = self.GetFdtLen(second) - third = second[fdt_len:] - second = second[:fdt_len] - - ucode_data = struct.pack('>2L', 0x12345678, 0x12345679) - self.assertIn(ucode_data, second) - ucode_pos = second.find(ucode_data) + len(U_BOOT_NODTB_DATA) - - # Check that the microcode pointer was inserted. It should match the - # expected position and size - pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, - len(ucode_data)) - first = data[:len(U_BOOT_NODTB_DATA)] - self.assertEqual('nodtb with microcode' + pos_and_size + - ' somewhere in here', first) - - def testPackUbootSingleMicrocode(self): - """Test that x86 microcode can be handled correctly with fdt_normal. - """ - self._RunPackUbootSingleMicrocode() - - def testUBootImg(self): - """Test that u-boot.img can be put in a file""" - data = self._DoReadFile('36_u_boot_img.dts') - self.assertEqual(U_BOOT_IMG_DATA, data) - - def testNoMicrocode(self): - """Test that a missing microcode region is detected""" - with self.assertRaises(ValueError) as e: - self._DoReadFile('37_x86_no_ucode.dts', True) - self.assertIn("Node '/binman/u-boot-dtb-with-ucode': No /microcode " - "node found in ", str(e.exception)) - - def testMicrocodeWithoutNode(self): - """Test that a missing u-boot-dtb-with-ucode node is detected""" - with self.assertRaises(ValueError) as e: - self._DoReadFile('38_x86_ucode_missing_node.dts', True) - self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " - "microcode region u-boot-dtb-with-ucode", str(e.exception)) - - def testMicrocodeWithoutNode2(self): - """Test that a missing u-boot-ucode node is detected""" - with self.assertRaises(ValueError) as e: - self._DoReadFile('39_x86_ucode_missing_node2.dts', True) - self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot find " - "microcode region u-boot-ucode", str(e.exception)) - - def testMicrocodeWithoutPtrInElf(self): - """Test that a U-Boot binary without the microcode symbol is detected""" - # ELF file without a '_dt_ucode_base_size' symbol - try: - with open(self.TestFile('u_boot_no_ucode_ptr')) as fd: - TestFunctional._MakeInputFile('u-boot', fd.read()) - - with self.assertRaises(ValueError) as e: - self._RunPackUbootSingleMicrocode() - self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Cannot locate " - "_dt_ucode_base_size symbol in u-boot", str(e.exception)) - - finally: - # Put the original file back - with open(self.TestFile('u_boot_ucode_ptr')) as fd: - TestFunctional._MakeInputFile('u-boot', fd.read()) - - def testMicrocodeNotInImage(self): - """Test that microcode must be placed within the image""" - with self.assertRaises(ValueError) as e: - self._DoReadFile('40_x86_ucode_not_in_image.dts', True) - self.assertIn("Node '/binman/u-boot-with-ucode-ptr': Microcode " - "pointer _dt_ucode_base_size at fffffe14 is outside the " - "image ranging from 00000000 to 0000002e", str(e.exception)) - - def testWithoutMicrocode(self): - """Test that we can cope with an image without microcode (e.g. qemu)""" - with open(self.TestFile('u_boot_no_ucode_ptr')) as fd: - TestFunctional._MakeInputFile('u-boot', fd.read()) - data, dtb = self._DoReadFileDtb('44_x86_optional_ucode.dts', True) - - # Now check the device tree has no microcode - self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)]) - second = data[len(U_BOOT_NODTB_DATA):] - - fdt_len = self.GetFdtLen(second) - self.assertEqual(dtb, second[:fdt_len]) - - used_len = len(U_BOOT_NODTB_DATA) + fdt_len - third = data[used_len:] - self.assertEqual(chr(0) * (0x200 - used_len), third) - - def testUnknownPosSize(self): - """Test that microcode must be placed within the image""" - with self.assertRaises(ValueError) as e: - self._DoReadFile('41_unknown_pos_size.dts', True) - self.assertIn("Image '/binman': Unable to set pos/size for unknown " - "entry 'invalid-entry'", str(e.exception)) - - def testPackFsp(self): - """Test that an image with a FSP binary can be created""" - data = self._DoReadFile('42_intel-fsp.dts') - self.assertEqual(FSP_DATA, data[:len(FSP_DATA)]) - - def testPackCmc(self): - """Test that an image with a CMC binary can be created""" - data = self._DoReadFile('43_intel-cmc.dts') - self.assertEqual(CMC_DATA, data[:len(CMC_DATA)]) - - def testPackVbt(self): - """Test that an image with a VBT binary can be created""" - data = self._DoReadFile('46_intel-vbt.dts') - self.assertEqual(VBT_DATA, data[:len(VBT_DATA)]) -- cgit From d09682ef8cbbbf29a41f237298ee1e4dbd71e999 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:09 -0700 Subject: binman: Disable the no-unit_address_vs_reg warnings These warnings are not useful for binman tests. Disable them. Signed-off-by: Simon Glass --- tools/dtoc/fdt_util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py index 338d47a5e1..ba0b6cc381 100644 --- a/tools/dtoc/fdt_util.py +++ b/tools/dtoc/fdt_util.py @@ -75,7 +75,8 @@ def EnsureCompiled(fname): search_list = [] for path in search_paths: search_list.extend(['-i', path]) - args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb'] + args = ['-I', 'dts', '-o', dtb_output, '-O', 'dtb', + '-W', 'no-unit_address_vs_reg'] args.extend(search_list) args.append(dts_input) command.Run('dtc', *args) -- cgit From 6c328f29752224f15b7f098d8676f9eeed269a85 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:12 -0700 Subject: patman: Fix up tests to pass with newest checkpatch The checkpatch tool was updated but the patman tests were not. Fix this. Signed-off-by: Simon Glass --- tools/patman/test.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'tools') diff --git a/tools/patman/test.py b/tools/patman/test.py index 20dc9c1e0d..51145e8390 100644 --- a/tools/patman/test.py +++ b/tools/patman/test.py @@ -88,8 +88,7 @@ Signed-off-by: Simon Glass os.remove(expname) def GetData(self, data_type): - data=''' -From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001 + data='''From 4924887af52713cabea78420eff03badea8f0035 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 7 Apr 2011 10:14:41 -0700 Subject: [PATCH 1/4] Add microsecond boot time measurement @@ -101,6 +100,7 @@ an available microsecond counter. %s --- README | 11 ++++++++ + MAINTAINERS | 3 ++ common/bootstage.c | 50 ++++++++++++++++++++++++++++++++++++ include/bootstage.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/common.h | 8 ++++++ @@ -130,19 +130,31 @@ index 6f3748d..f9e4e65 100644 - Standalone program support: CONFIG_STANDALONE_LOAD_ADDR +diff --git a/MAINTAINERS b/MAINTAINERS +index b167b028ec..beb7dc634f 100644 +--- a/MAINTAINERS ++++ b/MAINTAINERS +@@ -474,3 +474,8 @@ S: Maintained + T: git git://git.denx.de/u-boot.git + F: * + F: */ ++ ++BOOTSTAGE ++M: Simon Glass ++L: u-boot@lists.denx.de ++F: common/bootstage.c diff --git a/common/bootstage.c b/common/bootstage.c new file mode 100644 index 0000000..2234c87 --- /dev/null +++ b/common/bootstage.c -@@ -0,0 +1,39 @@ +@@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011, Google Inc. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + -+ +/* + * This module records the progress of boot and arbitrary commands, and + * permits accurate timestamping of each. The records can optionally be @@ -151,26 +163,25 @@ index 0000000..2234c87 + +#include + -+ +struct bootstage_record { -+ uint32_t time_us; ++ u32 time_us; + const char *name; +}; + +static struct bootstage_record record[BOOTSTAGE_COUNT]; + -+uint32_t bootstage_mark(enum bootstage_id id, const char *name) ++u32 bootstage_mark(enum bootstage_id id, const char *name) +{ + struct bootstage_record *rec = &record[id]; + + /* Only record the first event for each */ +%sif (!rec->name) { -+ rec->time_us = (uint32_t)timer_get_us(); ++ rec->time_us = (u32)timer_get_us(); + rec->name = name; + } + if (!rec->name && + %ssomething_else) { -+ rec->time_us = (uint32_t)timer_get_us(); ++ rec->time_us = (u32)timer_get_us(); + rec->name = name; + } +%sreturn rec->time_us; @@ -210,7 +221,7 @@ index 0000000..2234c87 self.assertEqual(result.errors, 0) self.assertEqual(result.warnings, 0) self.assertEqual(result.checks, 0) - self.assertEqual(result.lines, 56) + self.assertEqual(result.lines, 62) os.remove(inf) def testNoSignoff(self): @@ -221,18 +232,18 @@ index 0000000..2234c87 self.assertEqual(result.errors, 1) self.assertEqual(result.warnings, 0) self.assertEqual(result.checks, 0) - self.assertEqual(result.lines, 56) + self.assertEqual(result.lines, 62) os.remove(inf) def testSpaces(self): inf = self.SetupData('spaces') result = checkpatch.CheckPatch(inf) self.assertEqual(result.ok, False) - self.assertEqual(len(result.problems), 2) + self.assertEqual(len(result.problems), 3) self.assertEqual(result.errors, 0) - self.assertEqual(result.warnings, 2) + self.assertEqual(result.warnings, 3) self.assertEqual(result.checks, 0) - self.assertEqual(result.lines, 56) + self.assertEqual(result.lines, 62) os.remove(inf) def testIndent(self): @@ -243,7 +254,7 @@ index 0000000..2234c87 self.assertEqual(result.errors, 0) self.assertEqual(result.warnings, 0) self.assertEqual(result.checks, 1) - self.assertEqual(result.lines, 56) + self.assertEqual(result.lines, 62) os.remove(inf) -- cgit From cb39a10979383921217e979b2aa0808babb877d3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:14 -0700 Subject: buildman: Allow skipping of tests which use the network Accessing the network slows down the test and limits the environment in which it can be run. Add an option to disable network tests. Signed-off-by: Simon Glass --- tools/buildman/buildman.py | 6 ++++-- tools/buildman/cmdline.py | 2 ++ tools/buildman/test.py | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/buildman/buildman.py b/tools/buildman/buildman.py index 607429df7b..11a4f162c5 100755 --- a/tools/buildman/buildman.py +++ b/tools/buildman/buildman.py @@ -30,7 +30,7 @@ import patchstream import terminal import toolchain -def RunTests(): +def RunTests(skip_net_tests): import func_test import test import doctest @@ -41,6 +41,8 @@ def RunTests(): suite.run(result) sys.argv = [sys.argv[0]] + if skip_net_tests: + test.use_network = False for module in (test.TestBuild, func_test.TestFunctional): suite = unittest.TestLoader().loadTestsFromTestCase(module) suite.run(result) @@ -56,7 +58,7 @@ options, args = cmdline.ParseArgs() # Run our meagre tests if options.test: - RunTests() + RunTests(options.skip_net_tests) # Build selected commits for selected boards else: diff --git a/tools/buildman/cmdline.py b/tools/buildman/cmdline.py index 0060e0317c..74247f0aff 100644 --- a/tools/buildman/cmdline.py +++ b/tools/buildman/cmdline.py @@ -82,6 +82,8 @@ def ParseArgs(): default=False, help='Show a build summary') parser.add_option('-S', '--show-sizes', action='store_true', default=False, help='Show image size variation in summary') + parser.add_option('--skip-net-tests', action='store_true', default=False, + help='Skip tests which need the network') parser.add_option('--step', type='int', default=1, help='Only build every n commits (0=just first and last)') parser.add_option('-t', '--test', action='store_true', dest='test', diff --git a/tools/buildman/test.py b/tools/buildman/test.py index 53ebc3756c..e81400f372 100644 --- a/tools/buildman/test.py +++ b/tools/buildman/test.py @@ -24,6 +24,8 @@ import commit import terminal import toolchain +use_network = True + settings_data = ''' # Buildman settings file @@ -410,8 +412,9 @@ class TestBuild(unittest.TestCase): def testToolchainDownload(self): """Test that we can download toolchains""" - self.assertEqual('https://www.kernel.org/pub/tools/crosstool/files/bin/x86_64/4.9.0/x86_64-gcc-4.9.0-nolibc_arm-unknown-linux-gnueabi.tar.xz', - self.toolchains.LocateArchUrl('arm')) + if use_network: + self.assertEqual('https://www.kernel.org/pub/tools/crosstool/files/bin/x86_64/4.9.0/x86_64-gcc-4.9.0-nolibc_arm-unknown-linux-gnueabi.tar.xz', + self.toolchains.LocateArchUrl('arm')) if __name__ == "__main__": -- cgit From 251f5867c96138fdc6987e5659d15726d1b0329f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:15 -0700 Subject: buildman: Fix up tests The tests were broken by two separate commits which adjusted the output when boards are listed. Fix this by adding back a PowerPC board and putting the name of each board in the test. Fixes: b9f7d881 (powerpc, 5xx: remove some "5xx" remains) Fixes: 8d7523c5 (buildman: Allow showing the list of boards with -n) Signed-off-by: Simon Glass --- tools/buildman/test.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/buildman/test.py b/tools/buildman/test.py index e81400f372..e564a8a142 100644 --- a/tools/buildman/test.py +++ b/tools/buildman/test.py @@ -91,6 +91,7 @@ boards = [ ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 1', 'board0', ''], ['Active', 'arm', 'armv7', '', 'Tester', 'ARM Board 2', 'board1', ''], ['Active', 'powerpc', 'powerpc', '', 'Tester', 'PowerPC board 1', 'board2', ''], + ['Active', 'powerpc', 'mpc83xx', '', 'Tester', 'PowerPC board 2', 'board3', ''], ['Active', 'sandbox', 'sandbox', '', 'Tester', 'Sandbox board', 'board4', ''], ] @@ -313,50 +314,60 @@ class TestBuild(unittest.TestCase): def testBoardSingle(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['sandbox']), - {'all': 1, 'sandbox': 1}) + {'all': ['board4'], 'sandbox': ['board4']}) def testBoardArch(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['arm']), - {'all': 2, 'arm': 2}) + {'all': ['board0', 'board1'], + 'arm': ['board0', 'board1']}) def testBoardArchSingle(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['arm sandbox']), - {'all': 3, 'arm': 2, 'sandbox' : 1}) + {'sandbox': ['board4'], + 'all': ['board0', 'board1', 'board4'], + 'arm': ['board0', 'board1']}) + def testBoardArchSingleMultiWord(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['arm', 'sandbox']), - {'all': 3, 'arm': 2, 'sandbox' : 1}) + {'sandbox': ['board4'], 'all': ['board0', 'board1', 'board4'], 'arm': ['board0', 'board1']}) def testBoardSingleAnd(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['Tester & arm']), - {'all': 2, 'Tester&arm': 2}) + {'Tester&arm': ['board0', 'board1'], 'all': ['board0', 'board1']}) def testBoardTwoAnd(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['Tester', '&', 'arm', 'Tester' '&', 'powerpc', 'sandbox']), - {'all': 5, 'Tester&powerpc': 2, 'Tester&arm': 2, - 'sandbox' : 1}) + {'sandbox': ['board4'], + 'all': ['board0', 'board1', 'board2', 'board3', + 'board4'], + 'Tester&powerpc': ['board2', 'board3'], + 'Tester&arm': ['board0', 'board1']}) def testBoardAll(self): """Test single board selection""" - self.assertEqual(self.boards.SelectBoards([]), {'all': 5}) + self.assertEqual(self.boards.SelectBoards([]), + {'all': ['board0', 'board1', 'board2', 'board3', + 'board4']}) def testBoardRegularExpression(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['T.*r&^Po']), - {'T.*r&^Po': 2, 'all': 2}) + {'all': ['board2', 'board3'], + 'T.*r&^Po': ['board2', 'board3']}) def testBoardDuplicate(self): """Test single board selection""" self.assertEqual(self.boards.SelectBoards(['sandbox sandbox', 'sandbox']), - {'all': 1, 'sandbox': 1}) + {'all': ['board4'], 'sandbox': ['board4']}) def CheckDirs(self, build, dirname): self.assertEqual('base%s' % dirname, build._GetOutputDir(1)) self.assertEqual('base%s/fred' % dirname, -- cgit From aab660fe18ac24ee859a203f517f939685af5e10 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:17 -0700 Subject: dtoc: Fix up tests The tool has changed slightly since it was originally written. Update the tests to suit. Signed-off-by: Simon Glass --- tools/dtoc/test_dtoc.py | 82 ++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) (limited to 'tools') diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index cc009b2a25..41ed80e6da 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -26,6 +26,27 @@ import tools our_path = os.path.dirname(os.path.realpath(__file__)) +HEADER = '''/* + * DO NOT MODIFY + * + * This file was generated by dtoc from a .dtb (device tree binary) file. + */ + +#include +#include ''' + +C_HEADER = '''/* + * DO NOT MODIFY + * + * This file was generated by dtoc from a .dtb (device tree binary) file. + */ + +#include +#include +#include +''' + + def get_dtb_file(dts_fname): """Compile a .dts file to a .dtb @@ -104,13 +125,12 @@ class TestDtoc(unittest.TestCase): dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: lines = infile.read().splitlines() - self.assertEqual(['#include ', '#include '], lines) + self.assertEqual(HEADER.splitlines(), lines) dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: lines = infile.read().splitlines() - self.assertEqual(['#include ', '#include ', - '#include ', ''], lines) + self.assertEqual(C_HEADER.splitlines() + [''], lines) def test_simple(self): """Test output from some simple nodes with various types of data""" @@ -119,8 +139,7 @@ class TestDtoc(unittest.TestCase): dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include + self.assertEqual(HEADER + ''' struct dtd_sandbox_i2c_test { }; struct dtd_sandbox_pmic_test { @@ -144,10 +163,7 @@ struct dtd_sandbox_spl_test_2 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include -#include - + self.assertEqual(C_HEADER + ''' static struct dtd_sandbox_spl_test dtv_spl_test = { \t.bytearray\t\t= {0x6, 0x0, 0x0}, \t.byteval\t\t= 0x5, @@ -225,8 +241,7 @@ U_BOOT_DEVICE(pmic_at_9) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include + self.assertEqual(HEADER + ''' struct dtd_source { \tstruct phandle_2_arg clocks[4]; }; @@ -238,10 +253,7 @@ struct dtd_target { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include -#include - + self.assertEqual(C_HEADER + ''' static struct dtd_target dtv_phandle_target = { \t.intval\t\t\t= 0x0, }; @@ -291,8 +303,7 @@ U_BOOT_DEVICE(phandle_source) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include + self.assertEqual(HEADER + ''' struct dtd_compat1 { \tfdt32_t\t\tintval; }; @@ -303,10 +314,7 @@ struct dtd_compat1 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include -#include - + self.assertEqual(C_HEADER + ''' static struct dtd_compat1 dtv_spl_test = { \t.intval\t\t\t= 0x1, }; @@ -325,8 +333,7 @@ U_BOOT_DEVICE(spl_test) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include + self.assertEqual(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -341,10 +348,7 @@ struct dtd_test3 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include -#include - + self.assertEqual(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; @@ -381,8 +385,7 @@ U_BOOT_DEVICE(test3) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include + self.assertEqual(HEADER + ''' struct dtd_test1 { \tfdt32_t\t\treg[2]; }; @@ -394,10 +397,7 @@ struct dtd_test2 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include -#include - + self.assertEqual(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; @@ -425,8 +425,7 @@ U_BOOT_DEVICE(test2) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include + self.assertEqual(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -441,10 +440,7 @@ struct dtd_test3 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include -#include - + self.assertEqual(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x123400000000, 0x5678}, }; @@ -481,8 +477,7 @@ U_BOOT_DEVICE(test3) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include + self.assertEqual(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -497,10 +492,7 @@ struct dtd_test3 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual('''#include -#include -#include - + self.assertEqual(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x567800000000}, }; -- cgit From 5a3f2226043cd46d446ab6eba39e47d131b47175 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:19 -0700 Subject: binman: Append to PYTHONPATH when running test coverage Rather that overwrite this, append to it, in case the caller has already set up the path correctly. Signed-off-by: Simon Glass --- tools/binman/binman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/binman/binman.py b/tools/binman/binman.py index d264bcdfa8..963d43a376 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -58,7 +58,7 @@ def RunTests(): def RunTestCoverage(): """Run the tests and check that we get 100% coverage""" # This uses the build output from sandbox_spl to get _libfdt.so - cmd = ('PYTHONPATH=%s/sandbox_spl/tools coverage run ' + cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools coverage run ' '--include "tools/binman/*.py" --omit "*test*,*binman.py" ' 'tools/binman/binman.py -t' % options.build_dir) os.system(cmd) -- cgit From 4d5994f91c5c781fb0c8b32b58abfc4d9d2ec878 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:20 -0700 Subject: binman: Set up 'entry' to permit full test coverage There is a little check at the top of entry.py which decides if importlib is available. At present this has no test coverage. To add this we will need to import the module twice, once with importlib and once without. In preparation for allowing a test to control the importing of this module, remove all global imports of the 'entry' module. Signed-off-by: Simon Glass --- tools/binman/entry_test.py | 4 ++-- tools/binman/ftest.py | 4 +++- tools/binman/image.py | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index 8a9ae017f0..85c4196892 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -9,16 +9,16 @@ import collections import unittest -import entry - class TestEntry(unittest.TestCase): def testEntryContents(self): """Test the Entry bass class""" + import entry base_entry = entry.Entry(None, None, None, read_node=False) self.assertEqual(True, base_entry.ObtainContents()) def testUnknownEntry(self): """Test that unknown entry types are detected""" + import entry Node = collections.namedtuple('Node', ['name', 'path']) node = Node('invalid-name', 'invalid-path') with self.assertRaises(ValueError) as e: diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index c4207ce5d2..eae1ab1c4b 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -20,7 +20,6 @@ import binman import cmdline import command import control -import entry import fdt import fdt_util import tools @@ -56,6 +55,9 @@ class TestFunctional(unittest.TestCase): """ @classmethod def setUpClass(self): + global entry + import entry + # Handle the case where argv[0] is 'python' self._binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) self._binman_pathname = os.path.join(self._binman_dir, 'binman') diff --git a/tools/binman/image.py b/tools/binman/image.py index 07fc930665..24c4f6f578 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -9,8 +9,6 @@ from collections import OrderedDict from operator import attrgetter -import entry -from entry import Entry import fdt_util import tools @@ -48,6 +46,11 @@ class Image: _entries: OrderedDict() of entries """ def __init__(self, name, node): + global entry + global Entry + import entry + from entry import Entry + self._node = node self._name = name self._size = None -- cgit From 934cdcfb1b1cac6a6c987f3f91e341c713770224 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:21 -0700 Subject: binman: Add tests for importlib availability Add a test that the 'entry' module works with or without importlib. The tests are numbered so that they are executed in the correct order. Signed-off-by: Simon Glass --- tools/binman/binman.py | 8 ++++++-- tools/binman/entry_test.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/binman/binman.py b/tools/binman/binman.py index 963d43a376..cf83edfd04 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -44,8 +44,12 @@ def RunTests(): suite.run(result) sys.argv = [sys.argv[0]] - for module in (ftest.TestFunctional, fdt_test.TestFdt, - entry_test.TestEntry): + + # Run the entry tests first ,since these need to be the first to import the + # 'entry' module. + suite = unittest.TestLoader().loadTestsFromTestCase(entry_test.TestEntry) + suite.run(result) + for module in (ftest.TestFunctional, fdt_test.TestFdt): suite = unittest.TestLoader().loadTestsFromTestCase(module) suite.run(result) diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index 85c4196892..789b26fd9f 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -7,9 +7,39 @@ # Test for the Entry class import collections +import os +import sys import unittest +import fdt +import fdt_util +import tools + class TestEntry(unittest.TestCase): + def GetNode(self): + binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) + tools.PrepareOutputDir(None) + fname = fdt_util.EnsureCompiled( + os.path.join(binman_dir,('test/05_simple.dts'))) + dtb = fdt.FdtScan(fname) + return dtb.GetNode('/binman/u-boot') + + def test1EntryNoImportLib(self): + """Test that we can import Entry subclassess successfully""" + + sys.modules['importlib'] = None + global entry + import entry + entry.Entry.Create(None, self.GetNode(), 'u-boot') + + def test2EntryImportLib(self): + del sys.modules['importlib'] + global entry + reload(entry) + entry.Entry.Create(None, self.GetNode(), 'u-boot-spl') + tools._RemoveOutputDir() + del entry + def testEntryContents(self): """Test the Entry bass class""" import entry -- cgit From 9fc60b4975b14da3693f3dd86378fb918ea13f41 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:22 -0700 Subject: binman: Add a main program to the tests Add a main program so that the tests can be executed directly, without going through the main binman program. Signed-off-by: Simon Glass --- tools/binman/entry_test.py | 4 ++++ tools/binman/ftest.py | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'tools') diff --git a/tools/binman/entry_test.py b/tools/binman/entry_test.py index 789b26fd9f..caa523ebf8 100644 --- a/tools/binman/entry_test.py +++ b/tools/binman/entry_test.py @@ -55,3 +55,7 @@ class TestEntry(unittest.TestCase): entry.Entry.Create(None, node, node.name) self.assertIn("Unknown entry type 'invalid-name' in node " "'invalid-path'", str(e.exception)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index eae1ab1c4b..539ebc57f5 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -813,3 +813,7 @@ class TestFunctional(unittest.TestCase): """Test that an image with a VBT binary can be created""" data = self._DoReadFile('46_intel-vbt.dts') self.assertEqual(VBT_DATA, data[:len(VBT_DATA)]) + + +if __name__ == "__main__": + unittest.main() -- cgit From a9871c6e7ea55e5b046b1491e96f85205b8a2178 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:23 -0700 Subject: binman: Increase test coverage back to 100% Make a minor tweak to fix test coverage. Signed-off-by: Simon Glass --- tools/binman/etype/u_boot_ucode.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'tools') diff --git a/tools/binman/etype/u_boot_ucode.py b/tools/binman/etype/u_boot_ucode.py index 8e51e99a11..f9f434d2cc 100644 --- a/tools/binman/etype/u_boot_ucode.py +++ b/tools/binman/etype/u_boot_ucode.py @@ -58,13 +58,10 @@ class Entry_u_boot_ucode(Entry_blob): def ObtainContents(self): # If the image does not need microcode, there is nothing to do ucode_dest_entry = self.image.FindEntryType('u-boot-with-ucode-ptr') - if ucode_dest_entry and not ucode_dest_entry.target_pos: - self.data = '' - return True - - # Handle microcode in SPL image as well - ucode_dest_entry = self.image.FindEntryType('u-boot-spl-with-ucode-ptr') - if ucode_dest_entry and not ucode_dest_entry.target_pos: + ucode_dest_entry_spl = self.image.FindEntryType( + 'u-boot-spl-with-ucode-ptr') + if ((not ucode_dest_entry or not ucode_dest_entry.target_pos) and + (not ucode_dest_entry_spl or not ucode_dest_entry_spl.target_pos)): self.data = '' return True -- cgit From a25ebed36fcf95d09629e8d2e95fdf4907798fb5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:24 -0700 Subject: binman: Check for files missing from test coverage Files that are never imported are not shown in the test-coverage report. Detect these and show an error. Signed-off-by: Simon Glass --- tools/binman/binman.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/binman/binman.py b/tools/binman/binman.py index cf83edfd04..7ad4d3030b 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -10,6 +10,7 @@ """See README for more information""" +import glob import os import sys import traceback @@ -67,12 +68,27 @@ def RunTestCoverage(): 'tools/binman/binman.py -t' % options.build_dir) os.system(cmd) stdout = command.Output('coverage', 'report') - coverage = stdout.splitlines()[-1].split(' ')[-1] + lines = stdout.splitlines() + + test_set= set([os.path.basename(line.split()[0]) + for line in lines if '/etype/' in line]) + glob_list = glob.glob(os.path.join(our_path, 'etype/*.py')) + all_set = set([os.path.basename(item) for item in glob_list]) + missing_list = all_set + missing_list.difference_update(test_set) + missing_list.remove('_testing.py') + coverage = lines[-1].split(' ')[-1] + ok = True + if missing_list: + print 'Missing tests for %s' % (', '.join(missing_list)) + ok = False if coverage != '100%': print stdout print "Type 'coverage html' to get a report in htmlcov/index.html" - raise ValueError('Coverage error: %s, but should be 100%%' % coverage) - + print 'Coverage error: %s, but should be 100%%' % coverage + ok = False + if not ok: + raise ValueError('Test coverage failure') def RunBinman(options, args): """Main entry point to binman once arguments are parsed -- cgit From 56509843003570f57f8600642258c77d525da0e5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:25 -0700 Subject: binman: Add test for u-boot-spl-bss-pad Add a test that we can pad the BSS with zero bytes. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 9 +++++++++ tools/binman/test/47_spl_bss_pad.dts | 17 +++++++++++++++++ tools/binman/test/Makefile | 5 ++++- tools/binman/test/bss_data | Bin 0 -> 5020 bytes tools/binman/test/bss_data.c | 18 ++++++++++++++++++ tools/binman/test/bss_data.lds | 16 ++++++++++++++++ 6 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/47_spl_bss_pad.dts create mode 100755 tools/binman/test/bss_data create mode 100644 tools/binman/test/bss_data.c create mode 100644 tools/binman/test/bss_data.lds (limited to 'tools') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 539ebc57f5..4e6aaad9d6 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -88,6 +88,10 @@ class TestFunctional(unittest.TestCase): with open(self.TestFile('descriptor.bin')) as fd: TestFunctional._MakeInputFile('descriptor.bin', fd.read()) + # ELF file with a '__bss_size' symbol + with open(self.TestFile('bss_data')) as fd: + TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + @classmethod def tearDownClass(self): """Remove the temporary input directory and its contents""" @@ -814,6 +818,11 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('46_intel-vbt.dts') self.assertEqual(VBT_DATA, data[:len(VBT_DATA)]) + def testSplBssPad(self): + """Test that we can pad SPL's BSS with zeros""" + data = self._DoReadFile('47_spl_bss_pad.dts') + self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/47_spl_bss_pad.dts b/tools/binman/test/47_spl_bss_pad.dts new file mode 100644 index 0000000000..6bd88b83f9 --- /dev/null +++ b/tools/binman/test/47_spl_bss_pad.dts @@ -0,0 +1,17 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot-spl { + }; + + u-boot-spl-bss-pad { + }; + + u-boot { + }; + }; +}; diff --git a/tools/binman/test/Makefile b/tools/binman/test/Makefile index 786d1b0577..217d13c666 100644 --- a/tools/binman/test/Makefile +++ b/tools/binman/test/Makefile @@ -11,7 +11,7 @@ CFLAGS := -march=i386 -m32 -nostdlib -I ../../../include LDS_UCODE := -T u_boot_ucode_ptr.lds -TARGETS = u_boot_ucode_ptr u_boot_no_ucode_ptr +TARGETS = u_boot_ucode_ptr u_boot_no_ucode_ptr bss_data all: $(TARGETS) @@ -21,6 +21,9 @@ u_boot_no_ucode_ptr: u_boot_no_ucode_ptr.c u_boot_ucode_ptr: CFLAGS += $(LDS_UCODE) u_boot_ucode_ptr: u_boot_ucode_ptr.c +bss_data: CFLAGS += bss_data.lds +bss_data: bss_data.c + clean: rm -f $(TARGETS) diff --git a/tools/binman/test/bss_data b/tools/binman/test/bss_data new file mode 100755 index 0000000000..afa28282aa Binary files /dev/null and b/tools/binman/test/bss_data differ diff --git a/tools/binman/test/bss_data.c b/tools/binman/test/bss_data.c new file mode 100644 index 0000000000..f865a9d9f6 --- /dev/null +++ b/tools/binman/test/bss_data.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2016 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + * + * Simple program to create a _dt_ucode_base_size symbol which can be read + * by 'nm'. This is used by binman tests. + */ + +int bss_data[10]; +int __bss_size = sizeof(bss_data); + +int main() +{ + bss_data[2] = 2; + + return 0; +} diff --git a/tools/binman/test/bss_data.lds b/tools/binman/test/bss_data.lds new file mode 100644 index 0000000000..6b2fe09d35 --- /dev/null +++ b/tools/binman/test/bss_data.lds @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2016 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) +ENTRY(_start) + +SECTIONS +{ + . = 0xfffffdf0; + _start = .; + __bss_size = 10; +} -- cgit From 8772213ea690e025248626096195fdebf402de02 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:26 -0700 Subject: binman: Add a test for x86-start16-spl This allows us to put the 16-bit x86 start-up code in SPL. Add a test for it. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 10 +++++++++- tools/binman/test/48_x86-start16-spl.dts | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tools/binman/test/48_x86-start16-spl.dts (limited to 'tools') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 4e6aaad9d6..c381a70031 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -34,6 +34,7 @@ ME_DATA = '0abcd' VGA_DATA = 'vga' U_BOOT_DTB_DATA = 'udtb' X86_START16_DATA = 'start16' +X86_START16_SPL_DATA = 'start16spl' U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here' FSP_DATA = 'fsp' CMC_DATA = 'cmc' @@ -74,6 +75,8 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile('vga.bin', VGA_DATA) TestFunctional._MakeInputFile('u-boot.dtb', U_BOOT_DTB_DATA) TestFunctional._MakeInputFile('u-boot-x86-16bit.bin', X86_START16_DATA) + TestFunctional._MakeInputFile('spl/u-boot-x86-16bit-spl.bin', + X86_START16_SPL_DATA) TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA) TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) @@ -677,7 +680,7 @@ class TestFunctional(unittest.TestCase): # Check that the microcode appears immediately after the Fdt # This matches the concatenation of the data properties in - # the /microcode/update@xxx nodes in x86_ucode.dts. + # the /microcode/update@xxx nodes in 34_x86_ucode.dts. ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, 0x78235609) self.assertEqual(ucode_data, third[:len(ucode_data)]) @@ -823,6 +826,11 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('47_spl_bss_pad.dts') self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data) + def testPackStart16Spl(self): + """Test that an image with an x86 start16 region can be created""" + data = self._DoReadFile('48_x86-start16-spl.dts') + self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)]) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/48_x86-start16-spl.dts b/tools/binman/test/48_x86-start16-spl.dts new file mode 100644 index 0000000000..e2009f15f0 --- /dev/null +++ b/tools/binman/test/48_x86-start16-spl.dts @@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <16>; + + x86-start16-spl { + }; + }; +}; -- cgit From 6b187df78754fc2064a73b94941bc2482a36e1a7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:27 -0700 Subject: binman: Add add test for SPL with a microcode pointer Add a test for this feature. It allows SPL to hold a pointer to the microcode block. This is used for 64-bit U-Boot on x86. Signed-off-by: Simon Glass --- tools/binman/etype/u_boot_spl_with_ucode_ptr.py | 2 +- tools/binman/ftest.py | 84 ++++++++++++++++--------- tools/binman/test/49_x86_ucode_spl.dts | 29 +++++++++ 3 files changed, 84 insertions(+), 31 deletions(-) create mode 100644 tools/binman/test/49_x86_ucode_spl.dts (limited to 'tools') diff --git a/tools/binman/etype/u_boot_spl_with_ucode_ptr.py b/tools/binman/etype/u_boot_spl_with_ucode_ptr.py index 1c6706df6d..7b25ccb048 100644 --- a/tools/binman/etype/u_boot_spl_with_ucode_ptr.py +++ b/tools/binman/etype/u_boot_spl_with_ucode_ptr.py @@ -25,4 +25,4 @@ class Entry_u_boot_spl_with_ucode_ptr(Entry_u_boot_with_ucode_ptr): self.elf_fname = 'spl/u-boot-spl' def GetDefaultFilename(self): - return 'spl/u-boot-spl.bin' + return 'spl/u-boot-spl-nodtb.bin' diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index c381a70031..dff7448f08 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -26,19 +26,20 @@ import tools import tout # Contents of test files, corresponding to different entry types -U_BOOT_DATA = '1234' -U_BOOT_IMG_DATA = 'img' -U_BOOT_SPL_DATA = '567' -BLOB_DATA = '89' -ME_DATA = '0abcd' -VGA_DATA = 'vga' -U_BOOT_DTB_DATA = 'udtb' -X86_START16_DATA = 'start16' -X86_START16_SPL_DATA = 'start16spl' -U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here' -FSP_DATA = 'fsp' -CMC_DATA = 'cmc' -VBT_DATA = 'vbt' +U_BOOT_DATA = '1234' +U_BOOT_IMG_DATA = 'img' +U_BOOT_SPL_DATA = '567' +BLOB_DATA = '89' +ME_DATA = '0abcd' +VGA_DATA = 'vga' +U_BOOT_DTB_DATA = 'udtb' +X86_START16_DATA = 'start16' +X86_START16_SPL_DATA = 'start16spl' +U_BOOT_NODTB_DATA = 'nodtb with microcode pointer somewhere in here' +U_BOOT_SPL_NODTB_DATA = 'splnodtb with microcode pointer somewhere in here' +FSP_DATA = 'fsp' +CMC_DATA = 'cmc' +VBT_DATA = 'vbt' class TestFunctional(unittest.TestCase): """Functional tests for binman @@ -78,6 +79,8 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile('spl/u-boot-x86-16bit-spl.bin', X86_START16_SPL_DATA) TestFunctional._MakeInputFile('u-boot-nodtb.bin', U_BOOT_NODTB_DATA) + TestFunctional._MakeInputFile('spl/u-boot-spl-nodtb.bin', + U_BOOT_SPL_NODTB_DATA) TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) TestFunctional._MakeInputFile('vbt.bin', VBT_DATA) @@ -91,10 +94,6 @@ class TestFunctional(unittest.TestCase): with open(self.TestFile('descriptor.bin')) as fd: TestFunctional._MakeInputFile('descriptor.bin', fd.read()) - # ELF file with a '__bss_size' symbol - with open(self.TestFile('bss_data')) as fd: - TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) - @classmethod def tearDownClass(self): """Remove the temporary input directory and its contents""" @@ -653,19 +652,11 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('33_x86-start16.dts') self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)]) - def testPackUbootMicrocode(self): - """Test that x86 microcode can be handled correctly - - We expect to see the following in the image, in order: - u-boot-nodtb.bin with a microcode pointer inserted at the correct - place - u-boot.dtb with the microcode removed - the microcode - """ - data = self._DoReadFile('34_x86_ucode.dts', True) + def _RunMicrocodeTest(self, dts_fname, nodtb_data): + data = self._DoReadFile(dts_fname, True) # Now check the device tree has no microcode - second = data[len(U_BOOT_NODTB_DATA):] + second = data[len(nodtb_data):] fname = tools.GetOutputFilename('test.dtb') with open(fname, 'wb') as fd: fd.write(second) @@ -684,13 +675,26 @@ class TestFunctional(unittest.TestCase): ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, 0x78235609) self.assertEqual(ucode_data, third[:len(ucode_data)]) - ucode_pos = len(U_BOOT_NODTB_DATA) + fdt_len + ucode_pos = len(nodtb_data) + fdt_len # Check that the microcode pointer was inserted. It should match the # expected position and size pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, len(ucode_data)) - first = data[:len(U_BOOT_NODTB_DATA)] + first = data[:len(nodtb_data)] + return first, pos_and_size + + def testPackUbootMicrocode(self): + """Test that x86 microcode can be handled correctly + + We expect to see the following in the image, in order: + u-boot-nodtb.bin with a microcode pointer inserted at the correct + place + u-boot.dtb with the microcode removed + the microcode + """ + first, pos_and_size = self._RunMicrocodeTest('34_x86_ucode.dts', + U_BOOT_NODTB_DATA) self.assertEqual('nodtb with microcode' + pos_and_size + ' somewhere in here', first) @@ -823,6 +827,9 @@ class TestFunctional(unittest.TestCase): def testSplBssPad(self): """Test that we can pad SPL's BSS with zeros""" + # ELF file with a '__bss_size' symbol + with open(self.TestFile('bss_data')) as fd: + TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) data = self._DoReadFile('47_spl_bss_pad.dts') self.assertEqual(U_BOOT_SPL_DATA + (chr(0) * 10) + U_BOOT_DATA, data) @@ -831,6 +838,23 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('48_x86-start16-spl.dts') self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)]) + def testPackUbootSplMicrocode(self): + """Test that x86 microcode can be handled correctly in SPL + + We expect to see the following in the image, in order: + u-boot-spl-nodtb.bin with a microcode pointer inserted at the + correct place + u-boot.dtb with the microcode removed + the microcode + """ + # ELF file with a '_dt_ucode_base_size' symbol + with open(self.TestFile('u_boot_ucode_ptr')) as fd: + TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) + first, pos_and_size = self._RunMicrocodeTest('49_x86_ucode_spl.dts', + U_BOOT_SPL_NODTB_DATA) + self.assertEqual('splnodtb with microc' + pos_and_size + + 'ter somewhere in here', first) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/49_x86_ucode_spl.dts b/tools/binman/test/49_x86_ucode_spl.dts new file mode 100644 index 0000000000..67db93ad50 --- /dev/null +++ b/tools/binman/test/49_x86_ucode_spl.dts @@ -0,0 +1,29 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <0x200>; + u-boot-spl-with-ucode-ptr { + }; + + u-boot-dtb-with-ucode { + }; + + u-boot-ucode { + }; + }; + + microcode { + update@0 { + data = <0x12345678 0x12345679>; + }; + update@1 { + data = <0xabcd0000 0x78235609>; + }; + }; +}; -- cgit From ca4f4ff7cf5acb230cf1948268b60efc5e54a977 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:28 -0700 Subject: binman: Add add test for using an Intel MRC binary MRC (Memory Reference Code) is a binary blob used to set up the SDRAM controller on some Intel boards. Add a test for this feature. With this test coverage on binman is back up to 100%. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 7 +++++++ tools/binman/test/50_intel_mrc.dts | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tools/binman/test/50_intel_mrc.dts (limited to 'tools') diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index dff7448f08..9083143894 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -40,6 +40,7 @@ U_BOOT_SPL_NODTB_DATA = 'splnodtb with microcode pointer somewhere in here' FSP_DATA = 'fsp' CMC_DATA = 'cmc' VBT_DATA = 'vbt' +MRC_DATA = 'mrc' class TestFunctional(unittest.TestCase): """Functional tests for binman @@ -84,6 +85,7 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile('fsp.bin', FSP_DATA) TestFunctional._MakeInputFile('cmc.bin', CMC_DATA) TestFunctional._MakeInputFile('vbt.bin', VBT_DATA) + TestFunctional._MakeInputFile('mrc.bin', MRC_DATA) self._output_setup = False # ELF file with a '_dt_ucode_base_size' symbol @@ -855,6 +857,11 @@ class TestFunctional(unittest.TestCase): self.assertEqual('splnodtb with microc' + pos_and_size + 'ter somewhere in here', first) + def testPackMrc(self): + """Test that an image with an MRC binary can be created""" + data = self._DoReadFile('50_intel_mrc.dts') + self.assertEqual(MRC_DATA, data[:len(MRC_DATA)]) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/50_intel_mrc.dts b/tools/binman/test/50_intel_mrc.dts new file mode 100644 index 0000000000..54cd52a2b7 --- /dev/null +++ b/tools/binman/test/50_intel_mrc.dts @@ -0,0 +1,13 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <16>; + + intel-mrc { + }; + }; +}; -- cgit From 9677faa34ee81c7abb4c08b0dc4ce4aace5473fc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2017 21:52:29 -0700 Subject: binman: Return non-zero exit code on test failure Return exit code 1 when test fail so that callers can detect this. Signed-off-by: Simon Glass --- tools/binman/binman.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/binman/binman.py b/tools/binman/binman.py index 7ad4d3030b..3ccf25f1f8 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -58,7 +58,11 @@ def RunTests(): for test, err in result.errors: print test.id(), err for test, err in result.failures: - print err + print err, result.failures + if result.errors or result.failures: + print 'binman tests FAILED' + return 1 + return 0 def RunTestCoverage(): """Run the tests and check that we get 100% coverage""" @@ -106,7 +110,7 @@ def RunBinman(options, args): sys.tracebacklimit = 0 if options.test: - RunTests() + ret_code = RunTests() elif options.test_coverage: RunTestCoverage() -- cgit