Zhantong Qiu has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/67337?usp=email )

 (

2 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
 )Change subject: stdlib: Add null/None versioning in resources.json
......................................................................

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...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Jason Lowe-Power <power...@gmail.com>
---
M src/python/gem5/resources/downloader.py
M tests/pyunit/stdlib/resources/pyunit_workload_checks.py
A tests/pyunit/stdlib/resources/refs/workload-checks-custom-workload.json
A tests/pyunit/stdlib/resources/refs/workload-checks.json
4 files changed, 97 insertions(+), 87 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/python/gem5/resources/downloader.py b/src/python/gem5/resources/downloader.py
index 0b67ecd..4a2ed5d 100644
--- a/src/python/gem5/resources/downloader.py
+++ b/src/python/gem5/resources/downloader.py
@@ -154,8 +154,13 @@

     # 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]
diff --git a/tests/pyunit/stdlib/resources/pyunit_workload_checks.py b/tests/pyunit/stdlib/resources/pyunit_workload_checks.py
index fab0bbf..2bc31f5 100644
--- a/tests/pyunit/stdlib/resources/pyunit_workload_checks.py
+++ b/tests/pyunit/stdlib/resources/pyunit_workload_checks.py
@@ -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 @@
     DiskImageResource,
     obtain_resource,
 )
-from gem5.resources.downloader import _resources_json_version_required

 from typing import Dict

@@ -46,33 +44,12 @@

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

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

     @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:
diff --git a/tests/pyunit/stdlib/resources/refs/workload-checks-custom-workload.json b/tests/pyunit/stdlib/resources/refs/workload-checks-custom-workload.json
new file mode 100644
index 0000000..a9dd2aa
--- /dev/null
+++ b/tests/pyunit/stdlib/resources/refs/workload-checks-custom-workload.json
@@ -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"
+        }
+    ]
+}
diff --git a/tests/pyunit/stdlib/resources/refs/workload-checks.json b/tests/pyunit/stdlib/resources/refs/workload-checks.json
new file mode 100644
index 0000000..4f7e76b
--- /dev/null
+++ b/tests/pyunit/stdlib/resources/refs/workload-checks.json
@@ -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"
+            }
+        }
+    ]
+}

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/67337?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I9d8ae18cb3e61d58bc822bad30853fa3442cb33f
Gerrit-Change-Number: 67337
Gerrit-PatchSet: 14
Gerrit-Owner: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: Zhantong Qiu <zt...@ucdavis.edu>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to