stdlib: Add tests for PyStats's Vector and fix bugs
The big thing missing from the Vector stats was that each position in the vector could have it's own unique id (a str, float, or int) and each position in the vector can have its own description. Therefore, to add this the Vector is represented as a dictionary mapping the unique ID to a Pystat Scaler (whcih can have it's own unique description. Change-Id: I3a8634f43298f6491300cf5a4f9d25dee8101808
This commit is contained in:
137
tests/gem5/stats/configs/pystat_vector_check.py
Normal file
137
tests/gem5/stats/configs/pystat_vector_check.py
Normal file
@@ -0,0 +1,137 @@
|
||||
# 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.
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import m5
|
||||
from m5.objects import (
|
||||
Root,
|
||||
VectorStatTester,
|
||||
)
|
||||
from m5.stats.gem5stats import get_simstat
|
||||
|
||||
"""This script is used for checking that the Vector statistics set in "
|
||||
the simulation are correctly parsed through to the python Pystats.
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Tests the output of a Vector PyStat."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"value",
|
||||
help="Comma delimited list representing the vector.",
|
||||
type=lambda s: [float(item) for item in s.split(",")],
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--name",
|
||||
type=str,
|
||||
default="vector",
|
||||
required=False,
|
||||
help="Name of the vector statistic.",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--description",
|
||||
type=str,
|
||||
default="",
|
||||
required=False,
|
||||
help="Description of the vector statistic.",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--subnames",
|
||||
help="Comma delimited list representing the vector subnames.",
|
||||
type=str,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--subdescs",
|
||||
help="Comma delimited list representing the vector subdescs",
|
||||
type=str,
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
stat_tester = VectorStatTester()
|
||||
stat_tester.name = args.name
|
||||
stat_tester.description = args.description
|
||||
stat_tester.values = args.value
|
||||
|
||||
stat_tester.subnames = []
|
||||
if args.subnames:
|
||||
stat_tester.subnames = [str(item) for item in args.subnames.split(",")]
|
||||
|
||||
stat_tester.subdescs = []
|
||||
if args.subdescs:
|
||||
stat_tester.subdescs = [str(item) for item in args.subdescs.split(",")]
|
||||
|
||||
value_dict = {}
|
||||
for i in range(len(args.value)):
|
||||
i_name = i
|
||||
description = args.description
|
||||
if stat_tester.subnames and i < len(stat_tester.subnames):
|
||||
i_name = stat_tester.subnames[i]
|
||||
if stat_tester.subdescs and i < len(stat_tester.subdescs):
|
||||
description = stat_tester.subdescs[i]
|
||||
|
||||
value_dict[i_name] = {
|
||||
"value": args.value[i],
|
||||
"type": "Scalar",
|
||||
"unit": "Count",
|
||||
"description": description,
|
||||
"datatype": "f64",
|
||||
}
|
||||
|
||||
expected_output = {
|
||||
"type": "Group",
|
||||
"time_conversion": None,
|
||||
args.name: {
|
||||
"value": value_dict,
|
||||
"type": "Vector",
|
||||
"description": args.description,
|
||||
},
|
||||
}
|
||||
|
||||
root = Root(full_system=False, system=stat_tester)
|
||||
|
||||
m5.instantiate()
|
||||
m5.simulate()
|
||||
|
||||
simstats = get_simstat(stat_tester)
|
||||
output = simstats.to_json()["system"]
|
||||
|
||||
if output != expected_output:
|
||||
print("Output statistics do not match expected:", file=sys.stderr)
|
||||
print("", file=sys.stderr)
|
||||
print("Expected:", file=sys.stderr)
|
||||
print(expected_output, file=sys.stderr)
|
||||
print("", file=sys.stderr)
|
||||
print("Actual:", file=sys.stderr)
|
||||
print(output, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from typing import Union
|
||||
|
||||
import m5
|
||||
from m5.objects import (
|
||||
@@ -42,24 +41,18 @@ against the expected JSON output and that produced by the SimStats module.
|
||||
"""
|
||||
|
||||
parser = argparse.ArgumentParser(description="Tests the output of a SimStat.")
|
||||
subparsers = parser.add_subparsers(
|
||||
dest="statistic", help="SimStats statistic to test", required=True
|
||||
)
|
||||
|
||||
scalar_parser = subparsers.add_parser(
|
||||
"scalar", help="Test a scalar statistic."
|
||||
)
|
||||
scalar_parser.add_argument(
|
||||
parser.add_argument(
|
||||
"value", type=float, help="The value of the scalar statistic."
|
||||
)
|
||||
scalar_parser.add_argument(
|
||||
parser.add_argument(
|
||||
"--name",
|
||||
type=str,
|
||||
default="scalar",
|
||||
required=False,
|
||||
help="The name of the scalar statistic.",
|
||||
)
|
||||
scalar_parser.add_argument(
|
||||
parser.add_argument(
|
||||
"--description",
|
||||
type=str,
|
||||
default="",
|
||||
@@ -69,27 +62,21 @@ scalar_parser.add_argument(
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
expected_output = None
|
||||
stat_tester = None
|
||||
if args.statistic == "scalar":
|
||||
stat_tester = ScalarStatTester()
|
||||
stat_tester.name = args.name
|
||||
stat_tester.description = args.description
|
||||
stat_tester.value = args.value
|
||||
expected_output = {
|
||||
"type": "Group",
|
||||
"time_conversion": None,
|
||||
args.name: {
|
||||
"value": args.value,
|
||||
"type": "Scalar",
|
||||
"unit": "Count",
|
||||
"description": args.description,
|
||||
"datatype": "f64",
|
||||
},
|
||||
}
|
||||
|
||||
assert stat_tester is not None
|
||||
assert expected_output is not None
|
||||
stat_tester = ScalarStatTester()
|
||||
stat_tester.name = args.name
|
||||
stat_tester.description = args.description
|
||||
stat_tester.value = args.value
|
||||
expected_output = {
|
||||
"type": "Group",
|
||||
"time_conversion": None,
|
||||
args.name: {
|
||||
"value": args.value,
|
||||
"type": "Scalar",
|
||||
"unit": "Count",
|
||||
"description": args.description,
|
||||
"datatype": "f64",
|
||||
},
|
||||
}
|
||||
|
||||
root = Root(full_system=False, system=stat_tester)
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ gem5_verify_config(
|
||||
"simstat_output_check.py",
|
||||
),
|
||||
config_args=[
|
||||
"scalar",
|
||||
"42",
|
||||
"--name",
|
||||
"scalar_test",
|
||||
@@ -63,7 +62,6 @@ gem5_verify_config(
|
||||
"simstat_output_check.py",
|
||||
),
|
||||
config_args=[
|
||||
"scalar",
|
||||
"0",
|
||||
],
|
||||
valid_isas=(constants.all_compiled_tag,),
|
||||
@@ -83,7 +81,6 @@ gem5_verify_config(
|
||||
"simstat_output_check.py",
|
||||
),
|
||||
config_args=[
|
||||
"scalar",
|
||||
"-245",
|
||||
],
|
||||
valid_isas=(constants.all_compiled_tag,),
|
||||
@@ -103,7 +100,6 @@ gem5_verify_config(
|
||||
"simstat_output_check.py",
|
||||
),
|
||||
config_args=[
|
||||
"scalar",
|
||||
"42.869",
|
||||
"--name",
|
||||
"float_test",
|
||||
@@ -113,3 +109,76 @@ gem5_verify_config(
|
||||
valid_isas=(constants.all_compiled_tag,),
|
||||
length=constants.quick_tag,
|
||||
)
|
||||
|
||||
gem5_verify_config(
|
||||
name="pystat_vector_test",
|
||||
fixtures=(),
|
||||
verifiers=[],
|
||||
config=joinpath(
|
||||
config.base_dir,
|
||||
"tests",
|
||||
"gem5",
|
||||
"stats",
|
||||
"configs",
|
||||
"pystat_vector_check.py",
|
||||
),
|
||||
config_args=[
|
||||
"2.0,4,5.9,2.3,-8,0,0.0,-8.9",
|
||||
"--name",
|
||||
"vector_stat",
|
||||
"--description",
|
||||
"A vector statistic with a float value",
|
||||
],
|
||||
valid_isas=(constants.all_compiled_tag,),
|
||||
length=constants.quick_tag,
|
||||
)
|
||||
|
||||
gem5_verify_config(
|
||||
name="pystat_vector_with_subnames_test",
|
||||
fixtures=(),
|
||||
verifiers=[],
|
||||
config=joinpath(
|
||||
config.base_dir,
|
||||
"tests",
|
||||
"gem5",
|
||||
"stats",
|
||||
"configs",
|
||||
"pystat_vector_check.py",
|
||||
),
|
||||
config_args=[
|
||||
"2.0,4,3",
|
||||
"--name",
|
||||
"vector_stat",
|
||||
"--description",
|
||||
"A vector statistic with a float value",
|
||||
"--subnames",
|
||||
"first,second,third",
|
||||
],
|
||||
valid_isas=(constants.all_compiled_tag,),
|
||||
length=constants.quick_tag,
|
||||
)
|
||||
|
||||
gem5_verify_config(
|
||||
name="pystat_vector_with_subdescs_test",
|
||||
fixtures=(),
|
||||
verifiers=[],
|
||||
config=joinpath(
|
||||
config.base_dir,
|
||||
"tests",
|
||||
"gem5",
|
||||
"stats",
|
||||
"configs",
|
||||
"pystat_vector_check.py",
|
||||
),
|
||||
config_args=[
|
||||
"2.0,4,3",
|
||||
"--name",
|
||||
"vector_stat",
|
||||
"--description",
|
||||
"A vector statistic with a float value",
|
||||
"--subdescs",
|
||||
"first,second",
|
||||
],
|
||||
valid_isas=(constants.all_compiled_tag,),
|
||||
length=constants.quick_tag,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user