summaryrefslogtreecommitdiff
path: root/tools/dtoc/test_dtoc.py
diff options
context:
space:
mode:
authorWalter Lozano <walter.lozano@collabora.com>2020-07-28 19:06:23 -0300
committerSimon Glass <sjg@chromium.org>2020-07-28 19:30:39 -0600
commit6c74d1b83224a5be8ce73a13ed9b4cc8f8d6723a (patch)
tree7ab93a81213db0506ac52a562bd05dece4519a20 /tools/dtoc/test_dtoc.py
parent3b191c56c841596771b4120f09fb556adf958b5c (diff)
dtoc: add coverage test for unicode error
Add an additional test to dtoc in order improve the coverage, specifically to take into account the case of unicode error when scanning drivers. Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
Diffstat (limited to 'tools/dtoc/test_dtoc.py')
-rwxr-xr-xtools/dtoc/test_dtoc.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 08b02d4843..a351bd7728 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -13,6 +13,7 @@ import collections
import os
import struct
import sys
+import tempfile
import unittest
from dtoc import dtb_platdata
@@ -863,3 +864,28 @@ U_BOOT_DEVICE(spl_test2) = {
self.run_test(['invalid-cmd'], dtb_file, output)
self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
str(e.exception))
+
+ def testScanDrivers(self):
+ """Test running dtoc with additional drivers to scan"""
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ output = tools.GetOutputFilename('output')
+ with test_util.capture_sys_output() as (stdout, stderr):
+ dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
+ [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
+
+ def testUnicodeError(self):
+ """Test running dtoc with an invalid unicode file
+
+ To be able to perform this test without adding a weird text file which
+ would produce issues when using checkpatch.pl or patman, generate the
+ file at runtime and then process it.
+ """
+ dtb_file = get_dtb_file('dtoc_test_simple.dts')
+ output = tools.GetOutputFilename('output')
+ driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
+ with open(driver_fn, 'wb+') as df:
+ df.write(b'\x81')
+
+ with test_util.capture_sys_output() as (stdout, stderr):
+ dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
+ [driver_fn])