stdlib, resources, tests: Introduce Suite of Workloads
This patch introduces a new category called "suite". A suite is a collection of workloads. Each workload in a SuiteResource has a tag that can be narrowed down through the function with_input_group. Also, the set of input groups can be seen through list_input_groups. Added unit tests to test all functions of SuiteResource class. Change-Id: Iddda5c898b32b7cd874987dbe694ac09aa231f08 Co-authored-by: Kunal Pai <kunpai@ucdavis.edu>
This commit is contained in:
170
tests/pyunit/stdlib/resources/pyunit_suite_checks.py
Normal file
170
tests/pyunit/stdlib/resources/pyunit_suite_checks.py
Normal file
@@ -0,0 +1,170 @@
|
||||
# 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 contextlib
|
||||
import io
|
||||
import unittest
|
||||
import tempfile
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from gem5.resources.resource import (
|
||||
obtain_resource,
|
||||
SuiteResource,
|
||||
WorkloadResource,
|
||||
)
|
||||
from gem5.resources.client_api.client_wrapper import ClientWrapper
|
||||
from unittest.mock import patch
|
||||
|
||||
mock_config_json = {
|
||||
"sources": {
|
||||
"baba": {
|
||||
"url": Path(__file__).parent / "refs/suite-checks.json",
|
||||
"isMongo": False,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class CustomSuiteResourceTestSuite(unittest.TestCase):
|
||||
@classmethod
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def setUpClass(cls):
|
||||
cls.workload1 = obtain_resource("simple-workload-1")
|
||||
cls.workload2 = obtain_resource("simple-workload-2")
|
||||
cls.SuiteResource = SuiteResource(
|
||||
workload_obj_list={cls.workload1: set(), cls.workload2: set()}
|
||||
)
|
||||
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def test_with_input_group(self) -> None:
|
||||
"""
|
||||
Tests the `with_input_group` function.
|
||||
"""
|
||||
# test if an input group can return a single workload in a suite resource
|
||||
|
||||
with self.assertRaises(Exception) as context:
|
||||
filtered_suite = self.SuiteResource.with_input_group("testtag2")
|
||||
self.assertIsInstance(filtered_suite, SuiteResource)
|
||||
self.assertEqual(len(filtered_suite), 0)
|
||||
self.assertTrue(
|
||||
f"Input group invalid not found in Suite.\n"
|
||||
f"Available input groups are {filtered_suite.get_input_groups()}"
|
||||
in str(context.exception)
|
||||
)
|
||||
|
||||
def test_get_input_groups(self):
|
||||
"""
|
||||
Tests the `list_input_groups` function.
|
||||
"""
|
||||
self.assertEqual(self.SuiteResource.get_input_groups(), set())
|
||||
|
||||
|
||||
class SuiteResourceTestSuite(unittest.TestCase):
|
||||
@classmethod
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def setUpClass(cls):
|
||||
cls.suite = obtain_resource("suite-example", gem5_version="develop")
|
||||
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def test_with_input_group(self) -> None:
|
||||
"""
|
||||
Tests the `with_input_group` function.
|
||||
"""
|
||||
# test if an input group can return a single workload in a suite resource
|
||||
filtered_suite = self.suite.with_input_group("testtag2")
|
||||
self.assertIsInstance(filtered_suite, SuiteResource)
|
||||
self.assertEqual(len(filtered_suite), 1)
|
||||
for workload in filtered_suite:
|
||||
self.assertIsInstance(workload, WorkloadResource)
|
||||
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def test_with_input_group_multiple(self) -> None:
|
||||
# test if an input group can return multiple workloads in a suite resource
|
||||
filtered_suite = self.suite.with_input_group("testtag1")
|
||||
self.assertIsInstance(filtered_suite, SuiteResource)
|
||||
self.assertEqual(len(filtered_suite), 2)
|
||||
for workload in filtered_suite:
|
||||
self.assertIsInstance(workload, WorkloadResource)
|
||||
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def test_with_input_group_invalid(self) -> None:
|
||||
"""
|
||||
Tests the `with_input_group` function with an invalid input group.
|
||||
"""
|
||||
with self.assertRaises(Exception) as context:
|
||||
filtered_suite = self.suite.with_input_group("invalid")
|
||||
# check if exception is raised
|
||||
self.assertTrue(
|
||||
f"Input group invalid not found in Suite.\n"
|
||||
f"Available input groups are {filtered_suite.get_input_groups()}"
|
||||
in str(context.exception)
|
||||
)
|
||||
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def test_get_input_groups(self) -> None:
|
||||
"""
|
||||
Tests the `list_input_groups` function.
|
||||
"""
|
||||
expected_input_groups = set(["testtag1", "testtag2", "testtag3"])
|
||||
self.assertEqual(self.suite.get_input_groups(), expected_input_groups)
|
||||
|
||||
@patch(
|
||||
"gem5.resources.client.clientwrapper",
|
||||
new=ClientWrapper(mock_config_json),
|
||||
)
|
||||
def test_get_input_groups_not_found(self) -> None:
|
||||
"""
|
||||
Tests the `list_input_groups` function with an invalid input group.
|
||||
"""
|
||||
with self.assertRaises(Exception) as context:
|
||||
self.suite.get_input_groups("invalid")
|
||||
self.assertTrue(
|
||||
f"Input group invalid not found in Suite.\n"
|
||||
f"Available input groups are {self.suite.get_input_groups()}"
|
||||
in str(context.exception)
|
||||
)
|
||||
97
tests/pyunit/stdlib/resources/refs/suite-checks.json
Normal file
97
tests/pyunit/stdlib/resources/refs/suite-checks.json
Normal file
@@ -0,0 +1,97 @@
|
||||
[
|
||||
{
|
||||
"id": "suite-example",
|
||||
"category": "suite",
|
||||
"resource_version": "1.0.0",
|
||||
"gem5_versions": ["develop","23.1"],
|
||||
"workloads": [
|
||||
{
|
||||
"id": "simple-workload-1",
|
||||
"resource_version": "1.0.0",
|
||||
"input_group": ["testtag1", "testtag2"]
|
||||
},
|
||||
{
|
||||
"id": "simple-workload-2",
|
||||
"resource_version": "1.0.0",
|
||||
"input_group": ["testtag1", "testtag3"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "workload",
|
||||
"id": "simple-workload-1",
|
||||
"description": "Description of workload here",
|
||||
"function": "set_kernel_disk_workload",
|
||||
"resources": {
|
||||
"kernel": "x86-linux-kernel-5.2.3-example",
|
||||
"disk-image": "x86-ubuntu-18.04-img-example"
|
||||
},
|
||||
"additional_params": {
|
||||
"readfile_contents": "echo 'Boot successful'; m5 exit"
|
||||
},
|
||||
"resource_version": "1.0.0",
|
||||
"gem5_versions": [
|
||||
"develop"
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "workload",
|
||||
"id": "simple-workload-2",
|
||||
"description": "Description of workload here",
|
||||
"function": "set_kernel_disk_workload",
|
||||
"resources": {
|
||||
"kernel": "x86-linux-kernel-5.2.3-example",
|
||||
"disk-image": "x86-ubuntu-18.04-img-example"
|
||||
},
|
||||
"additional_params": {
|
||||
"readfile_contents": "echo 'Boot successful'; m5 exit"
|
||||
},
|
||||
"resource_version": "1.0.0",
|
||||
"gem5_versions": [
|
||||
"develop"
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "kernel",
|
||||
"id": "x86-linux-kernel-5.2.3-example",
|
||||
"description": "The linux kernel (v5.2.3), compiled to X86.",
|
||||
"architecture": "X86",
|
||||
"is_zipped": false,
|
||||
"md5sum": "4838c99b77d33c8307b939c16624e4ac",
|
||||
"url": "http://dist.gem5.org/dist/develop/kernels/x86/static/vmlinux-5.2.3",
|
||||
"source": "src/linux-kernel",
|
||||
"resource_version": "1.0.0",
|
||||
"gem5_versions": [
|
||||
"develop"
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "disk-image",
|
||||
"id": "x86-ubuntu-18.04-img-example",
|
||||
"description": "A disk image containing Ubuntu 18.04 for x86..",
|
||||
"architecture": "X86",
|
||||
"is_zipped": false,
|
||||
"md5sum": "dbf120338b37153e3334603970cebd8c",
|
||||
"url": "http://dist.gem5.org/dist/develop/test-progs/hello/bin/x86/linux/hello64-static",
|
||||
"source": "src/x86-ubuntu",
|
||||
"root_partition": "1",
|
||||
"resource_version": "1.0.0",
|
||||
"gem5_versions": [
|
||||
"develop"
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "binary",
|
||||
"id": "x86-hello64-static-example",
|
||||
"description": "A 'Hello World!' binary.",
|
||||
"architecture": "X86",
|
||||
"is_zipped": false,
|
||||
"md5sum": "dbf120338b37153e3334603970cebd8c",
|
||||
"url": "http://dist.gem5.org/dist/develop/test-progs/hello/bin/x86/linux/hello64-static",
|
||||
"source": "src/simple",
|
||||
"resource_version": "1.0.0",
|
||||
"gem5_versions": [
|
||||
"develop"
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user