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:
Bobby R. Bruce
2023-01-19 14:30:19 +00:00
committed by Zhantong Qiu
parent 4ee724e054
commit a9b69ee055
4 changed files with 76 additions and 87 deletions

View File

@@ -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:

View File

@@ -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"
}
]
}

View 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"
}
}
]
}