# Matches the references to the udevice_id list
re_of_match = re.compile(
- r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
+ r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)([^,]*),')
re_phase = re.compile('^\s*DM_PHASE\((.*)\).*$')
re_hdr = re.compile('^\s*DM_HEADER\((.*)\).*$')
driver.uclass_id = m_id.group(1)
elif m_of_match:
compat = m_of_match.group(2)
+ suffix = m_of_match.group(3)
+ if suffix and suffix != ')':
+ self._warnings[driver.name].add(
+ "%s: Warning: unexpected suffix '%s' on .of_match line for compat '%s'" %
+ (fname, suffix, compat))
elif m_phase:
driver.phase = m_phase.group(1)
elif m_hdr:
def show_warnings(self):
"""Show any warnings that have been collected"""
used_drivers = [drv.name for drv in self._drivers.values() if drv.used]
- missing = self._missing_drivers
+ missing = self._missing_drivers.copy()
for name in sorted(self._warnings.keys()):
if name in missing or name in used_drivers:
warns = sorted(list(self._warnings[name]))
- # For now there is only ever one warning
print('%s: %s' % (name, warns[0]))
indent = ' ' * len(name)
+ for warn in warns[1:]:
+ print('%-s: %s' % (indent, warn))
if name in missing:
missing.remove(name)
print()
OUR_PATH = os.path.dirname(os.path.realpath(__file__))
+EXPECT_WARN = {'rockchip_rk3288_grf':
+ {'WARNING: the driver rockchip_rk3288_grf was not found in the driver list'}}
+
class FakeNode:
"""Fake Node object for testing"""
def __init__(self):
'nvidia,tegra20-i2c-dvc': 'TYPE_DVC'}, drv.compat)
self.assertEqual('i2c_bus', drv.priv)
self.assertEqual(1, len(scan._drivers))
+ self.assertEqual({}, scan._warnings)
def test_normalized_name(self):
"""Test operation of get_normalized_compat_name()"""
self.assertEqual(1, len(scan._missing_drivers))
self.assertEqual({'rockchip_rk3288_grf'}, scan._missing_drivers)
self.assertEqual('', stdout.getvalue().strip())
+ self.assertEqual(EXPECT_WARN, scan._warnings)
i2c = 'I2C_UCLASS'
compat = {'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF',
self.assertEqual('', stdout.getvalue().strip())
self.assertEqual('rockchip_rk3288_grf', name)
self.assertEqual([], aliases)
+ self.assertEqual(EXPECT_WARN, scan._warnings)
prop.value = 'rockchip,rk3288-srf'
with test_util.capture_sys_output() as (stdout, _):
self.assertEqual('', stdout.getvalue().strip())
self.assertEqual('rockchip_rk3288_grf', name)
self.assertEqual(['rockchip_rk3288_srf'], aliases)
+ self.assertEqual(EXPECT_WARN, scan._warnings)
def test_scan_errors(self):
"""Test detection of scanning errors"""
self.assertEqual(3, seq)
self.assertEqual({'mypath': 3}, uc.alias_path_to_num)
self.assertEqual({2: node, 3: node}, uc.alias_num_to_node)
+
+ def test_scan_warnings(self):
+ """Test detection of scanning warnings"""
+ buff = '''
+static const struct udevice_id tegra_i2c_ids[] = {
+ { .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
+ { }
+};
+
+U_BOOT_DRIVER(i2c_tegra) = {
+ .name = "i2c_tegra",
+ .id = UCLASS_I2C,
+ .of_match = tegra_i2c_ids + 1,
+};
+'''
+ # The '+ 1' above should generate a warning
+
+ prop = FakeProp()
+ prop.name = 'compatible'
+ prop.value = 'rockchip,rk3288-grf'
+ node = FakeNode()
+ node.props = {'compatible': prop}
+
+ # get_normalized_compat_name() uses this to check for root node
+ node.parent = FakeNode()
+
+ scan = src_scan.Scanner(None, None)
+ scan._parse_driver('file.c', buff)
+ self.assertEqual(
+ {'i2c_tegra':
+ {"file.c: Warning: unexpected suffix ' + 1' on .of_match line for compat 'tegra_i2c_ids'"}},
+ scan._warnings)
+
+ tprop = FakeProp()
+ tprop.name = 'compatible'
+ tprop.value = 'nvidia,tegra114-i2c'
+ tnode = FakeNode()
+ tnode.props = {'compatible': tprop}
+
+ # get_normalized_compat_name() uses this to check for root node
+ tnode.parent = FakeNode()
+
+ with test_util.capture_sys_output() as (stdout, _):
+ scan.get_normalized_compat_name(node)
+ scan.get_normalized_compat_name(tnode)
+ self.assertEqual('', stdout.getvalue().strip())
+
+ self.assertEqual(2, len(scan._missing_drivers))
+ self.assertEqual({'rockchip_rk3288_grf', 'nvidia_tegra114_i2c'},
+ scan._missing_drivers)
+ with test_util.capture_sys_output() as (stdout, _):
+ scan.show_warnings()
+ self.assertIn('rockchip_rk3288_grf', stdout.getvalue())
+
+ # This should show just the rockchip warning, since the tegra driver
+ # is not in self._missing_drivers
+ scan._missing_drivers.remove('nvidia_tegra114_i2c')
+ with test_util.capture_sys_output() as (stdout, _):
+ scan.show_warnings()
+ self.assertIn('rockchip_rk3288_grf', stdout.getvalue())
+ self.assertNotIn('tegra_i2c_ids', stdout.getvalue())
+
+ # Do a similar thing with used drivers. By marking the tegra driver as
+ # used, the warning related to that driver will be shown
+ drv = scan._drivers['i2c_tegra']
+ drv.used = True
+ with test_util.capture_sys_output() as (stdout, _):
+ scan.show_warnings()
+ self.assertIn('rockchip_rk3288_grf', stdout.getvalue())
+ self.assertIn('tegra_i2c_ids', stdout.getvalue())
+
+ # Add a warning to make sure multiple warnings are shown
+ scan._warnings['i2c_tegra'].update(
+ scan._warnings['nvidia_tegra114_i2c'])
+ del scan._warnings['nvidia_tegra114_i2c']
+ with test_util.capture_sys_output() as (stdout, _):
+ scan.show_warnings()
+ self.assertEqual('''i2c_tegra: WARNING: the driver nvidia_tegra114_i2c was not found in the driver list
+ : file.c: Warning: unexpected suffix ' + 1' on .of_match line for compat 'tegra_i2c_ids'
+
+rockchip_rk3288_grf: WARNING: the driver rockchip_rk3288_grf was not found in the driver list
+
+''',
+ stdout.getvalue())
+ self.assertIn('tegra_i2c_ids', stdout.getvalue())