stdlib: Add null/None versioning in resources.json
This patch allows for the "version" field in the resources.json file to be `null` (translated to `None` in the Python JSON package) or not declared. In this case the resources.json file will be used regardless as to what version the gem5 binary is set. This is useful for testing purposes. Tests have been updated to utilize this where possible. Change-Id: I9d8ae18cb3e61d58bc822bad30853fa3442cb33f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67337 Maintainer: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
committed by
Zhantong Qiu
parent
4ee724e054
commit
a9b69ee055
@@ -154,8 +154,13 @@ def _get_resources_json() -> Dict:
|
||||
|
||||
# If the current version pulled is not correct, look up the
|
||||
# "previous-versions" field to find the correct one.
|
||||
# If the resource JSON file does not have a "version" field or it's
|
||||
# null/None, then we will use this resource JSON file (this is usefull for
|
||||
# testing purposes).
|
||||
version = _resources_json_version_required()
|
||||
if to_return["version"] != version:
|
||||
json_version = None if "version" not in to_return else to_return["version"]
|
||||
|
||||
if json_version and json_version != version:
|
||||
if version in to_return["previous-versions"].keys():
|
||||
to_return = _get_resources_json_at_path(
|
||||
path=to_return["previous-versions"][version]
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import unittest
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
from gem5.resources.workload import Workload, CustomWorkload
|
||||
@@ -34,7 +33,6 @@ from gem5.resources.resource import (
|
||||
DiskImageResource,
|
||||
obtain_resource,
|
||||
)
|
||||
from gem5.resources.downloader import _resources_json_version_required
|
||||
|
||||
from typing import Dict
|
||||
|
||||
@@ -46,33 +44,12 @@ class CustomWorkloadTestSuite(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls) -> None:
|
||||
file_contents = (
|
||||
"{"
|
||||
+ f'"version" : "{_resources_json_version_required()}",'
|
||||
+ """
|
||||
"url_base" : "http://dist.gem5.org/dist/v22-0",
|
||||
"previous-versions" : {},
|
||||
"resources": [
|
||||
{
|
||||
"type" : "binary",
|
||||
"name" : "x86-hello64-static",
|
||||
"documentation" : "A 'Hello World!' binary.",
|
||||
"architecture" : "X86",
|
||||
"is_zipped" : false,
|
||||
"md5sum" : "dbf120338b37153e3334603970cebd8c",
|
||||
"url" : "{url_base}/test-progs/hello/bin/x86/linux/hello64-static",
|
||||
"source" : "src/simple"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
)
|
||||
file = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
||||
file.write(file_contents)
|
||||
file.close()
|
||||
|
||||
cls.test_json = file.name
|
||||
os.environ["GEM5_RESOURCE_JSON"] = cls.test_json
|
||||
os.environ["GEM5_RESOURCE_JSON"] = os.path.join(
|
||||
os.path.realpath(os.path.dirname(__file__)),
|
||||
"refs",
|
||||
"workload-checks-custom-workload.json",
|
||||
)
|
||||
|
||||
cls.custom_workload = CustomWorkload(
|
||||
function="set_se_binary_workload",
|
||||
@@ -84,9 +61,8 @@ class CustomWorkloadTestSuite(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
# Remove the test json file and unset the environment variable so this
|
||||
# test does not interfere with others.
|
||||
os.remove(cls.test_json)
|
||||
# Unset the environment variable so this test does not interfere with
|
||||
# others.
|
||||
os.environ["GEM5_RESOURCE_JSON"]
|
||||
|
||||
def test_get_function_str(self) -> None:
|
||||
@@ -149,67 +125,18 @@ class WorkloadTestSuite(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# In this constructor we create a json file to load then create a test
|
||||
# workload.
|
||||
|
||||
file_contents = (
|
||||
"{"
|
||||
+ f'"version" : "{_resources_json_version_required()}",'
|
||||
+ """
|
||||
"url_base" : "http://dist.gem5.org/dist/v22-0",
|
||||
"previous-versions" : {},
|
||||
"resources": [
|
||||
{
|
||||
"type" : "kernel",
|
||||
"name" : "x86-linux-kernel-5.2.3",
|
||||
"documentation" : "The linux kernel (v5.2.3), compiled to X86.",
|
||||
"architecture" : "X86",
|
||||
"is_zipped" : false,
|
||||
"md5sum" : "4838c99b77d33c8307b939c16624e4ac",
|
||||
"url" : "{url_base}/kernels/x86/static/vmlinux-5.2.3",
|
||||
"source" : "src/linux-kernel"
|
||||
},
|
||||
{
|
||||
"type" : "disk-image",
|
||||
"name" : "x86-ubuntu-18.04-img",
|
||||
"documentation" : "A disk image containing Ubuntu 18.04 for x86..",
|
||||
"architecture" : "X86",
|
||||
"is_zipped" : true,
|
||||
"md5sum" : "90e363abf0ddf22eefa2c7c5c9391c49",
|
||||
"url" : "{url_base}/images/x86/ubuntu-18-04/x86-ubuntu.img.gz",
|
||||
"source" : "src/x86-ubuntu",
|
||||
"root_partition": "1"
|
||||
},
|
||||
{
|
||||
"type" : "workload",
|
||||
"name" : "simple-boot",
|
||||
"documentation" : "Description of workload here",
|
||||
"function" : "set_kernel_disk_workload",
|
||||
"resources" : {
|
||||
"kernel" : "x86-linux-kernel-5.2.3",
|
||||
"disk_image" : "x86-ubuntu-18.04-img"
|
||||
},
|
||||
"additional_params" : {
|
||||
"readfile_contents" : "echo 'Boot successful'; m5 exit"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
os.environ["GEM5_RESOURCE_JSON"] = os.path.join(
|
||||
os.path.realpath(os.path.dirname(__file__)),
|
||||
"refs",
|
||||
"workload-checks.json",
|
||||
)
|
||||
file = tempfile.NamedTemporaryFile(mode="w", delete=False)
|
||||
file.write(file_contents)
|
||||
file.close()
|
||||
|
||||
cls.test_json = file.name
|
||||
os.environ["GEM5_RESOURCE_JSON"] = cls.test_json
|
||||
cls.workload = Workload("simple-boot")
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
# Remove the test json file and unset the environment variable so this
|
||||
# test does not interfere with others.
|
||||
os.remove(cls.test_json)
|
||||
# Unset the environment variable so this test does not interfere with
|
||||
# others.
|
||||
os.environ["GEM5_RESOURCE_JSON"]
|
||||
|
||||
def test_get_function_str(self) -> None:
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"version" : null,
|
||||
"url_base" : "http://dist.gem5.org/dist/v22-0",
|
||||
"previous-versions" : {},
|
||||
"resources": [
|
||||
{
|
||||
"type" : "binary",
|
||||
"name" : "x86-hello64-static",
|
||||
"documentation" : "A 'Hello World!' binary.",
|
||||
"architecture" : "X86",
|
||||
"is_zipped" : false,
|
||||
"md5sum" : "dbf120338b37153e3334603970cebd8c",
|
||||
"url" : "{url_base}/test-progs/hello/bin/x86/linux/hello64-static",
|
||||
"source" : "src/simple"
|
||||
}
|
||||
]
|
||||
}
|
||||
40
tests/pyunit/stdlib/resources/refs/workload-checks.json
Normal file
40
tests/pyunit/stdlib/resources/refs/workload-checks.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"url_base" : "http://dist.gem5.org/dist/v22-0",
|
||||
"previous-versions" : {},
|
||||
"resources": [
|
||||
{
|
||||
"type" : "kernel",
|
||||
"name" : "x86-linux-kernel-5.2.3",
|
||||
"documentation" : "The linux kernel (v5.2.3), compiled to X86.",
|
||||
"architecture" : "X86",
|
||||
"is_zipped" : false,
|
||||
"md5sum" : "4838c99b77d33c8307b939c16624e4ac",
|
||||
"url" : "{url_base}/kernels/x86/static/vmlinux-5.2.3",
|
||||
"source" : "src/linux-kernel"
|
||||
},
|
||||
{
|
||||
"type" : "disk-image",
|
||||
"name" : "x86-ubuntu-18.04-img",
|
||||
"documentation" : "A disk image containing Ubuntu 18.04 for x86..",
|
||||
"architecture" : "X86",
|
||||
"is_zipped" : true,
|
||||
"md5sum" : "90e363abf0ddf22eefa2c7c5c9391c49",
|
||||
"url" : "{url_base}/images/x86/ubuntu-18-04/x86-ubuntu.img.gz",
|
||||
"source" : "src/x86-ubuntu",
|
||||
"root_partition": "1"
|
||||
},
|
||||
{
|
||||
"type" : "workload",
|
||||
"name" : "simple-boot",
|
||||
"documentation" : "Description of workload here",
|
||||
"function" : "set_kernel_disk_workload",
|
||||
"resources" : {
|
||||
"kernel" : "x86-linux-kernel-5.2.3",
|
||||
"disk_image" : "x86-ubuntu-18.04-img"
|
||||
},
|
||||
"additional_params" : {
|
||||
"readfile_contents" : "echo 'Boot successful'; m5 exit"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user