Re: [PATCH] dtoc: add coverage test for unicode error

2020-07-28 Thread Walter Lozano

Hi Simon,

On 27/7/20 20:35, Simon Glass wrote:

Hi Walter,

On Mon, 20 Jul 2020 at 12:29, Walter Lozano  wrote:

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 
---

  tools/dtoc/dtb_platdata.py | 14 +++---
  tools/dtoc/test_dtoc.py| 18 ++
  2 files changed, 29 insertions(+), 3 deletions(-)

This seems to be missing a .cxx file, so gives a build error.

Sorry for the error. I'm sending a new version with some additional 
improvements.


Regards,

Walter



Re: [PATCH] dtoc: add coverage test for unicode error

2020-07-27 Thread Simon Glass
Hi Walter,

On Mon, 20 Jul 2020 at 12:29, Walter Lozano  wrote:
>
> 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 
> ---
>
>  tools/dtoc/dtb_platdata.py | 14 +++---
>  tools/dtoc/test_dtoc.py| 18 ++
>  2 files changed, 29 insertions(+), 3 deletions(-)

This seems to be missing a .cxx file, so gives a build error.

Regards,
Simo


[PATCH] dtoc: add coverage test for unicode error

2020-07-20 Thread Walter Lozano
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 
---

 tools/dtoc/dtb_platdata.py | 14 +++---
 tools/dtoc/test_dtoc.py| 18 ++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index c28768f4a2..c37db5b86e 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -145,8 +145,10 @@ class DtbPlatdata(object):
 U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
 value: Driver name declared with U_BOOT_DRIVER(driver_name)
 _links: List of links to be included in dm_populate_phandle_data()
+_drivers_additional: List of additional drivers to use during scanning
 """
-def __init__(self, dtb_fname, include_disabled, warning_disabled):
+def __init__(self, dtb_fname, include_disabled, warning_disabled,
+ drivers_additional=[]):
 self._fdt = None
 self._dtb_fname = dtb_fname
 self._valid_nodes = None
@@ -157,6 +159,7 @@ class DtbPlatdata(object):
 self._drivers = []
 self._driver_aliases = {}
 self._links = []
+self._drivers_additional = drivers_additional
 
 def get_normalized_compat_name(self, node):
 """Get a node's normalized compat name
@@ -338,6 +341,10 @@ class DtbPlatdata(object):
 continue
 self.scan_driver(dirpath + '/' + fn)
 
+for fn in self._drivers_additional:
+print('Checking %s/%s' % (basedir, fn))
+self.scan_driver(basedir + '/' + fn)
+
 def scan_dtb(self):
 """Scan the device tree to obtain a tree of nodes and properties
 
@@ -654,7 +661,8 @@ class DtbPlatdata(object):
 
 self.out(''.join(self.get_buf()))
 
-def run_steps(args, dtb_file, include_disabled, output, 
warning_disabled=False):
+def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False,
+  drivers_additional=[]):
 """Run all the steps of the dtoc tool
 
 Args:
@@ -666,7 +674,7 @@ def run_steps(args, dtb_file, include_disabled, output, 
warning_disabled=False):
 if not args:
 raise ValueError('Please specify a command: struct, platdata')
 
-plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled)
+plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled, 
drivers_additional)
 plat.scan_drivers()
 plat.scan_dtb()
 plat.scan_tree()
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index 169ecd6e6e..d750e52a34 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
@@ -829,3 +830,20 @@ 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 testUnicodeError(self):
+"""Test running dtoc with an invalid unicode file
+
+To be able to perform this tests 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,
+   ['tools/dtoc/dtoc_test_unicode_error.cxx'])
-- 
2.20.1