From 64a087e5e818b94ae1ccc18a31379a03ad0300fa Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Mon, 3 Oct 2022 12:41:25 -0700 Subject: [PATCH] tests: Add 'checkpoint-path' to checkpoint stdlib example The 'configs/example/gem5_library_example_tests/test_gem5_library_examples.py' example would dump the savepoint in the CWD. This is fine when running as an example, but we also run this script as a test. In this case the checkpoint litters the repository. To fix this, an optional 'checkpoint-path' argument is added to this example which specifies where the checkpoint is to be saved. In the tests, the checkpoint is saved to 'tests/gem5/resources'. This is our default location for resources needed/produced by tests and is ignored by git. Change-Id: Ib985433786c99c37794a1c67cc4337a5dfd0498d Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/64091 Reviewed-by: Jason Lowe-Power Tested-by: kokoro Maintainer: Jason Lowe-Power --- .../checkpoints/riscv-hello-save-checkpoint.py | 18 +++++++++++++++--- .../test_gem5_library_examples.py | 10 +++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/configs/example/gem5_library/checkpoints/riscv-hello-save-checkpoint.py b/configs/example/gem5_library/checkpoints/riscv-hello-save-checkpoint.py index c00b43d404..159c4b76e1 100644 --- a/configs/example/gem5_library/checkpoints/riscv-hello-save-checkpoint.py +++ b/configs/example/gem5_library/checkpoints/riscv-hello-save-checkpoint.py @@ -43,6 +43,7 @@ scons build/RISCV/gem5.opt ``` """ +import argparse from gem5.isas import ISA from gem5.utils.requires import requires from gem5.resources.resource import Resource @@ -53,6 +54,18 @@ from gem5.components.cachehierarchies.classic.no_cache import NoCache from gem5.components.processors.simple_processor import SimpleProcessor from gem5.simulate.simulator import Simulator +parser = argparse.ArgumentParser() + +parser.add_argument( + "--checkpoint-path", + type=str, + required=False, + default="riscv-hello-checkpoint/", + help="The directory to store the checkpoint.", +) + +args = parser.parse_args() + # This check ensures the gem5 binary is compiled to the RISCV ISA target. # If not, an exception will be thrown. requires(isa_required=ISA.RISCV) @@ -102,7 +115,6 @@ print( ) ) -checkpoint_path = "riscv-hello-checkpoint/" -print("Taking a checkpoint at", checkpoint_path) -simulator.save_checkpoint(checkpoint_path) +print("Taking a checkpoint at", args.checkpoint_path) +simulator.save_checkpoint(args.checkpoint_path) print("Done taking a checkpoint") diff --git a/tests/gem5/gem5_library_example_tests/test_gem5_library_examples.py b/tests/gem5/gem5_library_example_tests/test_gem5_library_examples.py index ee212ae455..d60fbb33a5 100644 --- a/tests/gem5/gem5_library_example_tests/test_gem5_library_examples.py +++ b/tests/gem5/gem5_library_example_tests/test_gem5_library_examples.py @@ -32,6 +32,11 @@ from testlib import * import re import os +if config.bin_path: + resource_path = config.bin_path +else: + resource_path = joinpath(absdirpath(__file__), "..", "resources") + hello_verifier = verifier.MatchRegex(re.compile(r"Hello world!")) save_checkpoint_verifier = verifier.MatchRegex( re.compile(r"Done taking a checkpoint") @@ -62,7 +67,10 @@ gem5_verify_config( "checkpoints", "riscv-hello-save-checkpoint.py", ), - config_args=[], + config_args=[ + "--checkpoint-path", + joinpath(resource_path, "riscv-hello-checkpoint-save"), + ], valid_isas=(constants.all_compiled_tag,), valid_hosts=constants.supported_hosts, length=constants.quick_tag,