stdlib: Improve PyStat support for SimObject Vectors

Change-Id: Iba0c93ffa5c4b18acf75af82965c63a8881df189
This commit is contained in:
Bobby R. Bruce
2024-05-02 04:55:58 -07:00
parent 178679cbfd
commit c0a1fa33fe
9 changed files with 292 additions and 57 deletions

View File

@@ -70,8 +70,9 @@ root = Root(full_system=False, system=stat_tester)
m5.instantiate()
m5.simulate()
simstats = get_simstat(root)
output = simstats.to_json()["system"]
simstats = get_simstat(stat_tester)
output = simstats.to_json()
value_dict = {}
for sample in args.samples:
@@ -90,7 +91,8 @@ for key in value_dict:
}
expected_output = {
"type": "Group",
"type": "SimObject",
"name": "system",
"time_conversion": None,
args.name: {
"value": scaler_dict,
@@ -99,6 +101,14 @@ expected_output = {
},
}
# Remove the time related fields from the outputs if they exist.
# `creation_time` is not deterministic, and `simulated_begin_time` and
# simulated_end_time are not under test here.
for field in ["creation_time", "simulated_begin_time", "simulated_end_time"]:
for map in [output, expected_output]:
if field in map:
del map[field]
if output != expected_output:
print("Output statistics do not match expected:", file=sys.stderr)
print("", file=sys.stderr)

View File

@@ -144,7 +144,8 @@ for x in range(args.num_vectors):
}
expected_output = {
"type": "Group",
"type": "SimObject",
"name": "system",
"time_conversion": None,
args.name: {
"type": "Vector2d",
@@ -159,7 +160,15 @@ m5.instantiate()
m5.simulate()
simstats = get_simstat(stat_tester)
output = simstats.to_json()["system"]
output = simstats.to_json()
# Remove the time related fields from the outputs if they exist.
# `creation_time` is not deterministic, and `simulated_begin_time` and
# simulated_end_time are not under test here.
for field in ["creation_time", "simulated_begin_time", "simulated_end_time"]:
for map in [output, expected_output]:
if field in map:
del map[field]
if output != expected_output:
print("Output statistics do not match expected:", file=sys.stderr)

View File

@@ -109,7 +109,8 @@ for i in range(len(args.value)):
}
expected_output = {
"type": "Group",
"type": "SimObject",
"name": "system",
"time_conversion": None,
args.name: {
"value": value_dict,
@@ -124,7 +125,15 @@ m5.instantiate()
m5.simulate()
simstats = get_simstat(stat_tester)
output = simstats.to_json()["system"]
output = simstats.to_json()
# Remove the time related fields from the outputs if they exist.
# `creation_time` is not deterministic, and `simulated_begin_time` and
# simulated_end_time are not under test here.
for field in ["creation_time", "simulated_begin_time", "simulated_end_time"]:
for map in [output, expected_output]:
if field in map:
del map[field]
if output != expected_output:
print("Output statistics do not match expected:", file=sys.stderr)

View File

@@ -0,0 +1,78 @@
# Copyright (c) 2024 The Regents of the University of California
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""This script is used for checking that SimObject Vectorsare
correctly parsed through to the gem5 PyStats."""
import m5
from m5.objects import (
Root,
ScalarStatTester,
VectorStatTester,
)
from m5.stats.gem5stats import get_simstat
root = Root(full_system=False)
root.stat_testers = [
ScalarStatTester(name="placeholder", value=11),
ScalarStatTester(
name="placeholder", value=22, description="Index 2 desc."
),
ScalarStatTester(name="placeholder", value=33),
VectorStatTester(
name="index_4",
values=[44, 55, 66],
description="A SimStat Vector within a SimObject Vector.",
),
]
m5.instantiate()
m5.simulate()
simstat = get_simstat(root)
# 'stat_testers' is a list of SimObjects
assert hasattr(simstat, "stat_testers"), "No stat_testers attribute found."
assert len(simstat.stat_testers) == 4, "stat_testers list is not of length 3."
# Accessable by index.
simobject = simstat.stat_testers[0]
# We can directly access the statistic we're interested in and its "str"
# representation should be the same as the value we set. In this case "11.0".
assert (
str(simobject.placeholder) == "11.0"
), "placeholder value is not 11.0 ()."
# They can also be accessed like so:
# "other_stat" is a SimObject with a single stat called "stat".
str(
simstat["stat_testers"][3]["index_4"][0]
) == "44.0", 'simstat[3]["index_4"][0] value is not 44.'
# We can also access other stats like type and description.
assert simstat.stat_testers[1].placeholder.description == "Index 2 desc."
assert simstat.stat_testers[1].placeholder.type == "Scalar"

View File

@@ -67,7 +67,8 @@ stat_tester.name = args.name
stat_tester.description = args.description
stat_tester.value = args.value
expected_output = {
"type": "Group",
"type": "SimObject",
"name": "system",
"time_conversion": None,
args.name: {
"value": args.value,
@@ -84,7 +85,15 @@ m5.instantiate()
m5.simulate()
simstats = get_simstat(stat_tester)
output = simstats.to_json()["system"]
output = simstats.to_json()
# Remove the time related fields from the outputs if they exist.
# `creation_time` is not deterministic, and `simulated_begin_time` and
# simulated_end_time are not under test here.
for field in ["creation_time", "simulated_begin_time", "simulated_end_time"]:
for map in [output, expected_output]:
if field in map:
del map[field]
if output != expected_output:
print("Output statistics do not match expected:", file=sys.stderr)

View File

@@ -235,3 +235,20 @@ gem5_verify_config(
valid_isas=(constants.all_compiled_tag,),
length=constants.quick_tag,
)
gem5_verify_config(
name="simstat-simobjectvector-test",
fixtures=(),
verifiers=[],
config=joinpath(
config.base_dir,
"tests",
"gem5",
"stats",
"configs",
"pystats_simobjectvector_check.py",
),
config_args=[],
valid_isas=(constants.all_compiled_tag,),
length=constants.quick_tag,
)