summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-12-28 20:35:08 -0700
committerSimon Glass <sjg@chromium.org>2021-01-05 12:26:35 -0700
commit970349a96dac3ad46c33851b1a773bfe3f1d4b33 (patch)
treed16d27c3ccee0b99d2e02affc5fef11c2be74083 /tools
parent10ea9c0b059c37e6b2026fe1334d1d57c465984d (diff)
downloadu-boot-970349a96dac3ad46c33851b1a773bfe3f1d4b33.tar.gz
dtoc: Tidy up src_scan tests
Some of these tests don't actually check anything. Add a few more checks to complete the tests. Also add a simple scan test that does the basics. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/dtoc/test_src_scan.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py
index d25da5760a..7d686530d6 100644
--- a/tools/dtoc/test_src_scan.py
+++ b/tools/dtoc/test_src_scan.py
@@ -14,6 +14,7 @@ import unittest
from unittest import mock
from dtoc import src_scan
+from patman import test_util
from patman import tools
# This is a test so is allowed to access private things in the module it is
@@ -30,15 +31,26 @@ class TestSrcScan(unittest.TestCase):
def tearDownClass(cls):
tools.FinaliseOutputDir()
- @classmethod
- def test_scan_drivers(cls):
- """Test running dtoc with additional drivers to scan"""
+ def test_simple(self):
+ """Simple test of scanning drivers"""
+ scan = src_scan.Scanner(None, True, None)
+ scan.scan_drivers()
+ self.assertIn('sandbox_gpio', scan._drivers)
+ self.assertIn('sandbox_gpio_alias', scan._driver_aliases)
+ self.assertEqual('sandbox_gpio',
+ scan._driver_aliases['sandbox_gpio_alias'])
+ self.assertNotIn('sandbox_gpio_alias2', scan._driver_aliases)
+
+ def test_additional(self):
+ """Test with additional drivers to scan"""
scan = src_scan.Scanner(
None, True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
scan.scan_drivers()
+ self.assertIn('sandbox_gpio_alias2', scan._driver_aliases)
+ self.assertEqual('sandbox_gpio',
+ scan._driver_aliases['sandbox_gpio_alias2'])
- @classmethod
- def test_unicode_error(cls):
+ def test_unicode_error(self):
"""Test running dtoc with an invalid unicode file
To be able to perform this test without adding a weird text file which
@@ -49,7 +61,11 @@ class TestSrcScan(unittest.TestCase):
with open(driver_fn, 'wb+') as fout:
fout.write(b'\x81')
- src_scan.Scanner(None, True, [driver_fn])
+ scan = src_scan.Scanner(None, True, [driver_fn])
+ with test_util.capture_sys_output() as (stdout, _):
+ scan.scan_drivers()
+ self.assertRegex(stdout.getvalue(),
+ r"Skipping file '.*' due to unicode error\s*")
def test_driver(self):
"""Test the Driver class"""