dtoc: Save scan information across test runs
At present most of the tests scan the U-Boot source tree as part of their run. This information does not change across tests, so we can save time by remembering it. Add a way to set up this information and use it for each test, taking a copy first, so as not to mess up the original. This reduces the run time from about 1.6 seconds to 1.5 seconds on my machine. For code coverage (which cannot run in parallel), it reduces from 33 seconds to 5. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -670,7 +670,8 @@ OUTPUT_FILES = {
|
|||||||
|
|
||||||
|
|
||||||
def run_steps(args, dtb_file, include_disabled, output, output_dirs,
|
def run_steps(args, dtb_file, include_disabled, output, output_dirs,
|
||||||
warning_disabled=False, drivers_additional=None, basedir=None):
|
warning_disabled=False, drivers_additional=None, basedir=None,
|
||||||
|
scan=None):
|
||||||
"""Run all the steps of the dtoc tool
|
"""Run all the steps of the dtoc tool
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -687,6 +688,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
|
|||||||
scanning
|
scanning
|
||||||
basedir (str): Base directory of U-Boot source code. Defaults to the
|
basedir (str): Base directory of U-Boot source code. Defaults to the
|
||||||
grandparent of this file's directory
|
grandparent of this file's directory
|
||||||
|
scan (src_src.Scanner): Scanner from a previous run. This can help speed
|
||||||
|
up tests. Use None for normal operation
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: if args has no command, or an unknown command
|
ValueError: if args has no command, or an unknown command
|
||||||
"""
|
"""
|
||||||
@@ -695,9 +699,10 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
|
|||||||
if output and output_dirs and any(output_dirs):
|
if output and output_dirs and any(output_dirs):
|
||||||
raise ValueError('Must specify either output or output_dirs, not both')
|
raise ValueError('Must specify either output or output_dirs, not both')
|
||||||
|
|
||||||
scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
|
if not scan:
|
||||||
|
scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
|
||||||
|
scan.scan_drivers()
|
||||||
plat = DtbPlatdata(scan, dtb_file, include_disabled)
|
plat = DtbPlatdata(scan, dtb_file, include_disabled)
|
||||||
scan.scan_drivers()
|
|
||||||
plat.scan_dtb()
|
plat.scan_dtb()
|
||||||
plat.scan_tree()
|
plat.scan_tree()
|
||||||
plat.scan_reg_sizes()
|
plat.scan_reg_sizes()
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ def run_tests(processes, args):
|
|||||||
sys.argv = [sys.argv[0]]
|
sys.argv = [sys.argv[0]]
|
||||||
test_name = args and args[0] or None
|
test_name = args and args[0] or None
|
||||||
|
|
||||||
|
test_dtoc.setup()
|
||||||
|
|
||||||
test_util.RunTestSuites(
|
test_util.RunTestSuites(
|
||||||
result, debug=True, verbosity=1, test_preserve_dirs=False,
|
result, debug=True, verbosity=1, test_preserve_dirs=False,
|
||||||
processes=processes, test_name=test_name, toolpath=[],
|
processes=processes, test_name=test_name, toolpath=[],
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ tool.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import copy
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
@@ -20,6 +21,7 @@ from dtb_platdata import tab_to
|
|||||||
from dtoc import dtb_platdata
|
from dtoc import dtb_platdata
|
||||||
from dtoc import fdt
|
from dtoc import fdt
|
||||||
from dtoc import fdt_util
|
from dtoc import fdt_util
|
||||||
|
from dtoc import src_scan
|
||||||
from dtoc.src_scan import conv_name_to_c
|
from dtoc.src_scan import conv_name_to_c
|
||||||
from dtoc.src_scan import get_compat_name
|
from dtoc.src_scan import get_compat_name
|
||||||
from patman import test_util
|
from patman import test_util
|
||||||
@@ -53,6 +55,9 @@ C_HEADER = '''/*
|
|||||||
#include <dt-structs.h>
|
#include <dt-structs.h>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
# Scanner saved from a previous run of the tests (to speed things up)
|
||||||
|
saved_scan = None
|
||||||
|
|
||||||
# This is a test so is allowed to access private things in the module it is
|
# This is a test so is allowed to access private things in the module it is
|
||||||
# testing
|
# testing
|
||||||
# pylint: disable=W0212
|
# pylint: disable=W0212
|
||||||
@@ -71,6 +76,19 @@ def get_dtb_file(dts_fname, capture_stderr=False):
|
|||||||
capture_stderr=capture_stderr)
|
capture_stderr=capture_stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
global saved_scan
|
||||||
|
|
||||||
|
# Disable warnings so that calls to get_normalized_compat_name() will not
|
||||||
|
# output things.
|
||||||
|
saved_scan = src_scan.Scanner(None, True, False)
|
||||||
|
saved_scan.scan_drivers()
|
||||||
|
|
||||||
|
def copy_scan():
|
||||||
|
"""Get a copy of saved_scan so that each test can start clean"""
|
||||||
|
return copy.deepcopy(saved_scan)
|
||||||
|
|
||||||
|
|
||||||
class TestDtoc(unittest.TestCase):
|
class TestDtoc(unittest.TestCase):
|
||||||
"""Tests for dtoc"""
|
"""Tests for dtoc"""
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -120,7 +138,8 @@ class TestDtoc(unittest.TestCase):
|
|||||||
dtb_file (str): Filename of .dtb file
|
dtb_file (str): Filename of .dtb file
|
||||||
output (str): Filename of output file
|
output (str): Filename of output file
|
||||||
"""
|
"""
|
||||||
dtb_platdata.run_steps(args, dtb_file, False, output, [], True)
|
dtb_platdata.run_steps(args, dtb_file, False, output, [], True,
|
||||||
|
None, None, scan=copy_scan())
|
||||||
|
|
||||||
def test_name(self):
|
def test_name(self):
|
||||||
"""Test conversion of device tree names to C identifiers"""
|
"""Test conversion of device tree names to C identifiers"""
|
||||||
@@ -175,7 +194,9 @@ class TestDtoc(unittest.TestCase):
|
|||||||
"""Test output from a device tree file with no nodes"""
|
"""Test output from a device tree file with no nodes"""
|
||||||
dtb_file = get_dtb_file('dtoc_test_empty.dts')
|
dtb_file = get_dtb_file('dtoc_test_empty.dts')
|
||||||
output = tools.GetOutputFilename('output')
|
output = tools.GetOutputFilename('output')
|
||||||
self.run_test(['struct'], dtb_file, output)
|
|
||||||
|
# Run this one without saved_scan to complete test coverage
|
||||||
|
dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], True)
|
||||||
with open(output) as infile:
|
with open(output) as infile:
|
||||||
lines = infile.read().splitlines()
|
lines = infile.read().splitlines()
|
||||||
self.assertEqual(HEADER.splitlines(), lines)
|
self.assertEqual(HEADER.splitlines(), lines)
|
||||||
@@ -343,7 +364,8 @@ U_BOOT_DRVINFO(gpios_at_0) = {
|
|||||||
dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
|
dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
|
||||||
output = tools.GetOutputFilename('output')
|
output = tools.GetOutputFilename('output')
|
||||||
with test_util.capture_sys_output() as _:
|
with test_util.capture_sys_output() as _:
|
||||||
dtb_platdata.run_steps(['struct'], dtb_file, False, output, [])
|
dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
|
||||||
|
scan=copy_scan())
|
||||||
with open(output) as infile:
|
with open(output) as infile:
|
||||||
data = infile.read()
|
data = infile.read()
|
||||||
self._check_strings(HEADER + '''
|
self._check_strings(HEADER + '''
|
||||||
@@ -352,7 +374,8 @@ struct dtd_invalid {
|
|||||||
''', data)
|
''', data)
|
||||||
|
|
||||||
with test_util.capture_sys_output() as _:
|
with test_util.capture_sys_output() as _:
|
||||||
dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [])
|
dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [],
|
||||||
|
scan=copy_scan())
|
||||||
with open(output) as infile:
|
with open(output) as infile:
|
||||||
data = infile.read()
|
data = infile.read()
|
||||||
self._check_strings(C_HEADER + '''
|
self._check_strings(C_HEADER + '''
|
||||||
@@ -502,7 +525,8 @@ U_BOOT_DRVINFO(phandle_target) = {
|
|||||||
"""Test that phandle targets are generated when unsing cd-gpios"""
|
"""Test that phandle targets are generated when unsing cd-gpios"""
|
||||||
dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
|
dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
|
||||||
output = tools.GetOutputFilename('output')
|
output = tools.GetOutputFilename('output')
|
||||||
dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True)
|
dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True,
|
||||||
|
scan=copy_scan())
|
||||||
with open(output) as infile:
|
with open(output) as infile:
|
||||||
data = infile.read()
|
data = infile.read()
|
||||||
self._check_strings(C_HEADER + '''
|
self._check_strings(C_HEADER + '''
|
||||||
@@ -903,7 +927,8 @@ U_BOOT_DRVINFO(spl_test2) = {
|
|||||||
def test_output_conflict(self):
|
def test_output_conflict(self):
|
||||||
"""Test a conflict between and output dirs and output file"""
|
"""Test a conflict between and output dirs and output file"""
|
||||||
with self.assertRaises(ValueError) as exc:
|
with self.assertRaises(ValueError) as exc:
|
||||||
dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True)
|
dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True,
|
||||||
|
scan=copy_scan())
|
||||||
self.assertIn("Must specify either output or output_dirs, not both",
|
self.assertIn("Must specify either output or output_dirs, not both",
|
||||||
str(exc.exception))
|
str(exc.exception))
|
||||||
|
|
||||||
@@ -919,7 +944,8 @@ U_BOOT_DRVINFO(spl_test2) = {
|
|||||||
fnames = glob.glob(outdir + '/*')
|
fnames = glob.glob(outdir + '/*')
|
||||||
self.assertEqual(2, len(fnames))
|
self.assertEqual(2, len(fnames))
|
||||||
|
|
||||||
dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True)
|
dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True,
|
||||||
|
scan=copy_scan())
|
||||||
fnames = glob.glob(outdir + '/*')
|
fnames = glob.glob(outdir + '/*')
|
||||||
self.assertEqual(4, len(fnames))
|
self.assertEqual(4, len(fnames))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user