1 # Copyright (c) 2017 Mark D. Hill and David A. Wood
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met: redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer;
8 # redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Authors: Sean Wilson
33 from testlib
.test
import TestFunction
34 from testlib
.suite
import TestSuite
35 from testlib
.helper
import log_call
36 from testlib
.config
import constants
, config
37 from fixture
import TempdirFixture
, Gem5Fixture
, VariableFixture
40 def gem5_verify_config(name
,
46 valid_isas
=constants
.supported_isas
,
47 valid_variants
=constants
.supported_variants
,
48 length
=constants
.supported_lengths
[0]):
50 Helper class to generate common gem5 tests using verifiers.
52 The generated TestSuite will run gem5 with the provided config and
53 config_args. After that it will run any provided verifiers to verify
54 details about the gem5 run.
56 .. seealso:: For the verifiers see :mod:`testlib.gem5.verifier`
58 :param name: Name of the test.
59 :param config: The config to give gem5.
60 :param config_args: A list of arguments to pass to the given config.
62 :param verifiers: An iterable with Verifier instances which will be placed
63 into a suite that will be ran after a gem5 run.
65 :param gem5_args: An iterable with arguments to give to gem5. (Arguments
66 that would normally go before the config path.)
68 :param valid_isas: An iterable with the isas that this test can be ran
69 for. If None given, will run for all supported_isas.
71 :param valid_variants: An iterable with the variant levels that
72 this test can be ran for. (E.g. opt, debug)
74 fixtures
= list(fixtures
)
76 for opt
in valid_variants
:
77 for isa
in valid_isas
:
79 # Create a tempdir fixture to be shared throughout the test.
80 tempdir
= TempdirFixture()
81 gem5_returncode
= VariableFixture(
82 name
=constants
.gem5_returncode_fixture_name
)
84 # Common name of this generated testcase.
85 _name
= '{given_name}-{isa}-{opt}'.format(
90 # Create the running of gem5 subtest.
91 # NOTE: We specifically create this test before our verifiers so
92 # this is listed first.
94 gem5_execution
= TestFunction(
95 _create_test_run_gem5(config
, config_args
, gem5_args
),
97 tests
.append(gem5_execution
)
99 # Create copies of the verifier subtests for this isa and
101 for verifier
in verifiers
:
102 tests
.append(verifier
.instantiate_test(_name
))
104 # Add the isa and variant to tags list.
105 tags
= [isa
, opt
, length
]
107 # Create the gem5 target for the specific architecture and
109 _fixtures
= copy
.copy(fixtures
)
110 _fixtures
.append(Gem5Fixture(isa
, opt
))
111 _fixtures
.append(tempdir
)
112 _fixtures
.append(gem5_returncode
)
114 # Finally construct the self contained TestSuite out of our
116 testsuites
.append(TestSuite(
123 def _create_test_run_gem5(config
, config_args
, gem5_args
):
124 def test_run_gem5(params
):
126 Simple \'test\' which runs gem5 and saves the result into a tempdir.
128 NOTE: Requires fixtures: tempdir, gem5
130 fixtures
= params
.fixtures
132 if gem5_args
is None:
134 elif isinstance(gem5_args
, str):
135 # If just a single str, place it in an iterable
136 _gem5_args
= (gem5_args
,)
138 _gem5_args
= gem5_args
140 # FIXME/TODO: I don't like the idea of having to modify this test run
141 # or always collect results even if not using a verifier. There should
142 # be some configuration in here that only gathers certain results for
145 # I.E. Only the returncode verifier will use the gem5_returncode
146 # fixture, but we always require it even if that verifier isn't being
148 returncode
= fixtures
[constants
.gem5_returncode_fixture_name
]
149 tempdir
= fixtures
[constants
.tempdir_fixture_name
].path
150 gem5
= fixtures
[constants
.gem5_binary_fixture_name
].path
153 '-d', # Set redirect dir to tempdir.
155 '-re',# TODO: Change to const. Redirect stdout and stderr
157 command
.extend(_gem5_args
)
158 command
.append(config
)
159 # Config_args should set up the program args.
160 command
.extend(config_args
)
161 returncode
.value
= log_call(params
.log
, command
)