Skip to content

Commit fb6b069

Browse files
committed
[test] Add device file consistency test
1 parent 6e0f3bd commit fb6b069

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ script:
2121
- (cd tools/generator; make generate-sam)
2222
- tools/device/scripts/stats --count
2323
- tools/device/scripts/stats --name >/dev/null
24-
- tools/device/scripts/stats --ram >/dev/null
2524
- python3 tools/sync_docs.py
2625
- git diff -- README.md
2726
- git status --porcelain

tools/device/setup.py

Whitespace-only changes.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
import unittest
3+
import glob
4+
import os
5+
6+
import modm_devices.parser
7+
8+
DEVICE_FILES = None
9+
10+
class DeviceFileTest(unittest.TestCase):
11+
12+
def setUp(self):
13+
global DEVICE_FILES
14+
if DEVICE_FILES is None:
15+
DEVICE_FILES = {}
16+
device_files = os.path.join(os.path.dirname(__file__), "../../../devices/**/*.xml")
17+
device_file_names = glob.glob(device_files)
18+
19+
# Parse the files and build the :target enumeration
20+
parser = modm_devices.parser.DeviceParser()
21+
for device_file_name in device_file_names:
22+
for device in parser.parse(device_file_name).get_devices():
23+
DEVICE_FILES[device.partname] = device
24+
self.devices = DEVICE_FILES
25+
26+
27+
def tearDown(self):
28+
self.devices = None
29+
30+
def get_drivers(self, device):
31+
drivers = []
32+
for d in device.properties["driver"]:
33+
if "instance" in d:
34+
drivers.extend( (d["name"], i) for i in d["instance"] )
35+
else:
36+
drivers.append( (d["name"],) )
37+
return drivers
38+
39+
def test_drivers(self):
40+
failures = 0
41+
for name, device in self.devices.items():
42+
def assertIn(key, obj):
43+
if key not in obj:
44+
print('{}: Missing "{}" key in "{}"!'.format(name, key, obj))
45+
nonlocal failures
46+
failures += 1
47+
return False
48+
return True
49+
drivers = self.get_drivers(device)
50+
gpios = device.get_driver("gpio")
51+
assertIn("gpio", gpios)
52+
for gpio in gpios.get("gpio", []):
53+
for signal in gpio.get("signal", []):
54+
assertIn("name", signal)
55+
if assertIn("driver", signal):
56+
if "instance" in signal:
57+
driver = (signal["driver"], signal["instance"])
58+
else:
59+
driver = (signal["driver"],)
60+
# assertIn(driver, drivers)
61+
62+
self.assertEqual(failures, 0, "Device file signals are missing 'driver' keys!")
63+
64+
65+
66+
67+
68+
69+
File renamed without changes.

0 commit comments

Comments
 (0)