]> git.sur5r.net Git - u-boot/blobdiff - tools/dtoc/dtoc.py
Merge git://git.denx.de/u-boot-imx
[u-boot] / tools / dtoc / dtoc.py
index 1f17ea47e0214fcb84c2c9f91b1841d7bc6d5934..008c0f4d693397eb87393bdc56b6d3d7b678783b 100755 (executable)
@@ -1,10 +1,9 @@
-#!/usr/bin/python
+#!/usr/bin/env python2
+# SPDX-License-Identifier: GPL-2.0+
 #
 # Copyright (C) 2016 Google, Inc
 # Written by Simon Glass <sjg@chromium.org>
 #
-# SPDX-License-Identifier:     GPL-2.0+
-#
 
 """Device tree to C tool
 
@@ -29,6 +28,7 @@ see doc/driver-model/of-plat.txt
 from optparse import OptionParser
 import os
 import sys
+import unittest
 
 # Bring in the patman libraries
 our_path = os.path.dirname(os.path.realpath(__file__))
@@ -36,9 +36,24 @@ sys.path.append(os.path.join(our_path, '../patman'))
 
 import dtb_platdata
 
+def run_tests():
+    """Run all the test we have for dtoc"""
+    import test_dtoc
+
+    result = unittest.TestResult()
+    sys.argv = [sys.argv[0]]
+    for module in (test_dtoc.TestDtoc,):
+        suite = unittest.TestLoader().loadTestsFromTestCase(module)
+        suite.run(result)
 
-if __name__ != "__main__":
-    pass
+    print result
+    for _, err in result.errors:
+        print err
+    for _, err in result.failures:
+        print err
+
+if __name__ != '__main__':
+    sys.exit(1)
 
 parser = OptionParser()
 parser.add_option('-d', '--dtb-file', action='store',
@@ -47,22 +62,14 @@ parser.add_option('--include-disabled', action='store_true',
                   help='Include disabled nodes')
 parser.add_option('-o', '--output', action='store', default='-',
                   help='Select output filename')
+parser.add_option('-t', '--test', action='store_true', dest='test',
+                  default=False, help='run tests')
 (options, args) = parser.parse_args()
 
-if not args:
-    raise ValueError('Please specify a command: struct, platdata')
-
-plat = dtb_platdata.DtbPlatdata(options.dtb_file, options.include_disabled)
-plat.scan_dtb()
-plat.scan_tree()
-plat.setup_output(options.output)
-structs = plat.scan_structs()
-plat.scan_phandles()
+# Run our meagre tests
+if options.test:
+    run_tests()
 
-for cmd in args[0].split(','):
-    if cmd == 'struct':
-        plat.generate_structs(structs)
-    elif cmd == 'platdata':
-        plat.generate_tables()
-    else:
-        raise ValueError("Unknown command '%s': (use: struct, platdata)" % cmd)
+else:
+    dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
+                           options.output)