This patch makes changes to the stdlib based on the gem5 Vision project. Firstly, a MongoDB database is supported. A JSON database's support is continued. The JSON can either be a local path or a raw GitHub link. The data for these databases is stored in src/python under "gem5-config.json". This will be used by default. However, the configuration can be overridden: - by providing a path using the GEM5_CONFIG env variable. - by placing a gem5-config.json file in the current working directory. An AbstractClient is an abstract class that implements searching and sorting relevant to the databases. Clients is an optional list that can be passed while defining any Resource class and obtain_resource. These databases can be defined in the config JSON. Resources now have versions. This allows for a single version, e.g., 'x86-ubuntu-boot', to have multiple versions. As such, the key of a resource is its ID and Version (e.g., 'x86-ubuntu-boot/v2.1.0'). Different versions of a resource might be compatible with different versions of gem5. By default, it picks the latest version compatible with the gem5 Version of the user. A gem5 resource schema now has additional fields. These are: - source_url: Stores URL of GitHub Source of the resource. - license: License information of the resource. - tags: Words to identify a resource better, like hello for hello-world - example_usage: How to use the resource in a simulation. - gem5_versions: List of gem5 versions that resource is compatible with. - resource_version: The version of the resource itself. - size: The download size of the resource, if it exists. - code_examples: List of objects. These objects contain the path to where a resource is used in gem5 example config scripts, and if the resource itself is used in tests or not. - category: Category of the resource, as defined by classes in src/python/gem5/resources/resource.py. Some fields have been renamed: - "name" is changed to "id" - "documentation" is changed to "description" Besides these, the schema also supports resource specialization. It adds fields relevant to a specific resource as specified in src/python/gem5/resources/resource.py These changes have been made to better present information on the new gem5 Resources website. But, they do not affect the way resources are used by a gem5 user. This patch is also backwards compatible. Existing code doesn't break with this new infrastructure. Also, refs in the tests have been changed to match this new schema. Tests have been changed to work with the two clients. Change-Id: Ia9bf47f7900763827fd5e873bcd663cc3ecdba40 Co-authored-by: Kunal Pai <kunpai@ucdavis.edu> Co-authored-by: Parth Shah <helloparthshah@gmail.com> Co-authored-by: Harshil Patel <harshilp2107@gmail.com> Co-authored-by: aarsli <arsli@ucdavis.edu> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/70858 Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Jason Lowe-Power <power.jg@gmail.com> Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
224 lines
7.6 KiB
Python
224 lines
7.6 KiB
Python
# Copyright (c) 2023 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 unittest
|
|
import os
|
|
|
|
from gem5.resources.workload import Workload, CustomWorkload
|
|
from gem5.resources.resource import (
|
|
BinaryResource,
|
|
DiskImageResource,
|
|
obtain_resource,
|
|
)
|
|
|
|
from typing import Dict
|
|
|
|
from gem5.resources.client_api.client_wrapper import ClientWrapper
|
|
from unittest.mock import patch
|
|
from pathlib import Path
|
|
|
|
mock_config_json1 = {
|
|
"sources": {
|
|
"baba": {
|
|
"url": Path(__file__).parent
|
|
/ "refs/workload-checks-custom-workload.json",
|
|
"isMongo": False,
|
|
}
|
|
},
|
|
}
|
|
|
|
mock_config_json2 = {
|
|
"sources": {
|
|
"baba": {
|
|
"url": Path(__file__).parent / "refs/workload-checks.json",
|
|
"isMongo": False,
|
|
}
|
|
},
|
|
}
|
|
|
|
|
|
class CustomWorkloadTestSuite(unittest.TestCase):
|
|
"""
|
|
Tests the `gem5.resources.workload.CustomWorkload` class.
|
|
"""
|
|
|
|
@classmethod
|
|
@patch(
|
|
"gem5.resources.client.clientwrapper",
|
|
new=ClientWrapper(mock_config_json1),
|
|
)
|
|
def setUpClass(cls) -> None:
|
|
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",
|
|
parameters={
|
|
"binary": obtain_resource("x86-hello64-static"),
|
|
"arguments": ["hello", 6],
|
|
},
|
|
)
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
# Unset the environment variable so this test does not interfere with
|
|
# others.
|
|
os.environ["GEM5_RESOURCE_JSON"]
|
|
|
|
def test_get_function_str(self) -> None:
|
|
# Tests `CustomResource.get_function_str`
|
|
|
|
self.assertEqual(
|
|
"set_se_binary_workload", self.custom_workload.get_function_str()
|
|
)
|
|
|
|
def test_get_parameters(self) -> None:
|
|
# Tests `CustomResource.get_parameter`
|
|
|
|
parameters = self.custom_workload.get_parameters()
|
|
self.assertTrue(isinstance(parameters, Dict))
|
|
self.assertEquals(2, len(parameters))
|
|
|
|
self.assertTrue("binary" in parameters)
|
|
self.assertTrue(isinstance(parameters["binary"], BinaryResource))
|
|
|
|
self.assertTrue("arguments" in parameters)
|
|
self.assertTrue(isinstance(parameters["arguments"], list))
|
|
self.assertEquals(2, len(parameters["arguments"]))
|
|
self.assertEquals("hello", parameters["arguments"][0])
|
|
self.assertEquals(6, parameters["arguments"][1])
|
|
|
|
def test_add_parameters(self) -> None:
|
|
# Tests `CustomResource.set_parameter` for the case where we add a new
|
|
# parameter value.
|
|
|
|
self.custom_workload.set_parameter("test_param", 10)
|
|
|
|
self.assertTrue("test_param" in self.custom_workload.get_parameters())
|
|
self.assertEquals(
|
|
10, self.custom_workload.get_parameters()["test_param"]
|
|
)
|
|
|
|
# Cleanup
|
|
del self.custom_workload.get_parameters()["test_param"]
|
|
|
|
def test_override_parameter(self) -> None:
|
|
# Tests `CustomResource.set_parameter` for the case where we override
|
|
# a parameter's value.
|
|
|
|
old_value = self.custom_workload.get_parameters()["binary"]
|
|
|
|
self.custom_workload.set_parameter("binary", "test")
|
|
self.assertTrue("binary" in self.custom_workload.get_parameters())
|
|
self.assertEquals(
|
|
"test", self.custom_workload.get_parameters()["binary"]
|
|
)
|
|
|
|
# We set the overridden parameter back to it's old valu self.custom_workload.set_parameter("binary", old_value)
|
|
|
|
|
|
class WorkloadTestSuite(unittest.TestCase):
|
|
"""
|
|
Tests the `gem5.resources.workload.Workload` class.
|
|
"""
|
|
|
|
@classmethod
|
|
@patch(
|
|
"gem5.resources.client.clientwrapper",
|
|
ClientWrapper(mock_config_json2),
|
|
)
|
|
def setUpClass(cls):
|
|
os.environ["GEM5_RESOURCE_JSON"] = os.path.join(
|
|
os.path.realpath(os.path.dirname(__file__)),
|
|
"refs",
|
|
"workload-checks.json",
|
|
)
|
|
cls.workload = Workload("simple-boot")
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
# Unset the environment variable so this test does not interfere with
|
|
# others.
|
|
os.environ["GEM5_RESOURCE_JSON"]
|
|
|
|
def test_get_function_str(self) -> None:
|
|
# Tests `Resource.get_function_str`
|
|
|
|
self.assertEquals(
|
|
"set_kernel_disk_workload", self.workload.get_function_str()
|
|
)
|
|
|
|
def test_get_parameters(self) -> None:
|
|
# Tests `Resource.get_parameters`
|
|
|
|
parameters = self.workload.get_parameters()
|
|
|
|
self.assertTrue(isinstance(parameters, Dict))
|
|
self.assertEqual(3, len(parameters))
|
|
|
|
self.assertTrue("kernel" in parameters)
|
|
self.assertTrue(isinstance(parameters["kernel"], BinaryResource))
|
|
|
|
self.assertTrue("disk-image" in parameters)
|
|
self.assertTrue(
|
|
isinstance(parameters["disk-image"], DiskImageResource)
|
|
)
|
|
|
|
self.assertTrue("readfile_contents" in parameters)
|
|
self.assertTrue(
|
|
"echo 'Boot successful'; m5 exit", parameters["readfile_contents"]
|
|
)
|
|
|
|
def test_add_parameters(self) -> None:
|
|
# Tests `Resource.set_parameter` for the case where we add a new
|
|
# parameter value.
|
|
|
|
self.workload.set_parameter("test_param", 10)
|
|
|
|
self.assertTrue("test_param" in self.workload.get_parameters())
|
|
self.assertEquals(10, self.workload.get_parameters()["test_param"])
|
|
|
|
# Cleanup
|
|
del self.workload.get_parameters()["test_param"]
|
|
|
|
def test_override_parameter(self) -> None:
|
|
# Tests `Resource.set_parameter` for the case where we override
|
|
# a parameter's value.
|
|
|
|
old_value = self.workload.get_parameters()["readfile_contents"]
|
|
|
|
self.workload.set_parameter("readfile_contents", "test")
|
|
self.assertTrue("readfile_contents" in self.workload.get_parameters())
|
|
self.assertEquals(
|
|
"test", self.workload.get_parameters()["readfile_contents"]
|
|
)
|
|
|
|
# We set the overridden parameter back to it's old value.
|
|
self.workload.set_parameter("readfile_contents", old_value)
|