Nikos Nikoleris has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/18988
Change subject: tests: Add support for downloaded archive fixtures
......................................................................
tests: Add support for downloaded archive fixtures
This changes add support for specifying fixtures that download
archives and uncompress them to the desired directory.
Change-Id: Ib3f6ee111b8d6130200507cbd170ecaf9fb39445
Signed-off-by: Nikos Nikoleris <nikos.nikole...@arm.com>
---
M tests/gem5/fixture.py
1 file changed, 74 insertions(+), 0 deletions(-)
diff --git a/tests/gem5/fixture.py b/tests/gem5/fixture.py
index 00f43ef..62ae335 100644
--- a/tests/gem5/fixture.py
+++ b/tests/gem5/fixture.py
@@ -1,3 +1,15 @@
+# Copyright (c) 2019 ARM Limited
+# All rights reserved
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
# Copyright (c) 2017 Mark D. Hill and David A. Wood
# All rights reserved.
#
@@ -293,3 +305,65 @@
# If the server version is more recent, download it
if t > os.path.getmtime(self.path):
self._download()
+
+class DownloadedArchive(Fixture):
+ """ Like TestProgram, but checks the version in the gem5 binary
repository
+ and downloads an updated version if it is needed.
+ """
+ def __init__(self, url, path, filename, **kwargs):
+ """
+ url: string
+ The url of the archive
+ path: string
+ The absolute path of the directory containing the archive
+ filename: string
+ The name of the archive
+ """
+ super(DownloadedArchive, self).__init__("download-" + filename,
+ build_once=True, **kwargs)
+
+ self.url = url
+ self.path = path
+ self.filename = joinpath(path, filename)
+
+ def _download(self):
+ import urllib
+ import errno
+ log.test_log.debug("Downloading " + self.url + " to " + self.path)
+ if not os.path.exists(self.path):
+ try:
+ os.makedirs(self.path)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+ urllib.urlretrieve(self.url, self.filename)
+
+ def _getremotetime(self):
+ import urllib2, datetime, time
+ import _strptime # Needed for python threading bug
+
+ u = urllib2.urlopen(self.url)
+ return time.mktime(datetime.datetime.strptime( \
+ u.info().getheaders("Last-Modified")[0],
+ "%a, %d %b %Y %X GMT").timetuple())
+
+ def _extract(self):
+ os.system('tar -xf %s -C %s' % (self.filename, self.path))
+
+ def setup(self, testitem):
+ import urllib2
+ # Check to see if there is a file downloaded
+ if not os.path.exists(self.filename):
+ self._download()
+ self._extract()
+ else:
+ try:
+ t = self._getremotetime()
+ except urllib2.URLError:
+ # Problem checking the server, use the old files.
+ log.debug("Could not contact server. Binaries may be old.")
+ return
+ # If the server version is more recent, download it
+ if t > os.path.getmtime(self.filename):
+ self._download()
+ self._extract()
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/18988
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ib3f6ee111b8d6130200507cbd170ecaf9fb39445
Gerrit-Change-Number: 18988
Gerrit-PatchSet: 1
Gerrit-Owner: Nikos Nikoleris <nikos.nikole...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev