diff options
author | Simon Glass <sjg@chromium.org> | 2020-12-28 20:35:03 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-01-05 12:26:35 -0700 |
commit | 1e0f3f46bd9afed12b331cbe945abd4046250ed5 (patch) | |
tree | 52b4a57072ec55552342b9ec01dd4d8fcd604a87 /tools/dtoc/test_dtoc.py | |
parent | a7d5f96ef1cf13b83a143d6977e2937bcc1b6c75 (diff) | |
download | u-boot-1e0f3f46bd9afed12b331cbe945abd4046250ed5.zip u-boot-1e0f3f46bd9afed12b331cbe945abd4046250ed5.tar.gz u-boot-1e0f3f46bd9afed12b331cbe945abd4046250ed5.tar.bz2 |
dtoc: Allow specifying the base directory for tests
The base directory of U-Boot, where the source is, it currently calculated
from the directory of the dtb_platdata.py script. If this is installed
elsewhere that will not work. Also it is inconvenient for tests.
Add a parameter to allow specifying this base directory.
To test this, pass a temporary directory with some files in it and check
that they are passed to scan_driver().
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/dtoc/test_dtoc.py')
-rwxr-xr-x | tools/dtoc/test_dtoc.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index d56cd31..c517fd5 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -12,9 +12,11 @@ tool. import collections import glob import os +import shutil import struct import tempfile import unittest +from unittest import mock from dtb_platdata import conv_name_to_c from dtb_platdata import get_compat_name @@ -981,3 +983,35 @@ U_BOOT_DRVINFO(spl_test2) = { self.assertEqual( {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'}, leafs) + + def test_scan_dirs(self): + """Test scanning of source directories""" + def add_file(fname): + pathname = os.path.join(indir, fname) + dirname = os.path.dirname(pathname) + os.makedirs(dirname, exist_ok=True) + tools.WriteFile(pathname, '', binary=False) + fname_list.append(pathname) + + try: + outdir = tools.GetOutputDir() + indir = tempfile.mkdtemp(prefix='dtoc.') + dtb_file = get_dtb_file('dtoc_test_simple.dts') + + fname_list = [] + add_file('fname.c') + add_file('dir/fname2.c') + + # Mock out scan_driver and check that it is called with the + # expected files + with mock.patch.object(dtb_platdata.DtbPlatdata, "scan_driver") \ + as mocked: + dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], + True, basedir=indir) + self.assertEqual(2, len(mocked.mock_calls)) + self.assertEqual(mock.call(fname_list[0]), + mocked.mock_calls[0]) + self.assertEqual(mock.call(fname_list[1]), + mocked.mock_calls[1]) + finally: + shutil.rmtree(indir) |