fixture.py (14141:b3ceff47211a) | fixture.py (14142:e732d3191b7c) |
---|---|
1# Copyright (c) 2019 ARM Limited 2# All rights reserved 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 23 unchanged lines hidden (view full) --- 32# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38# 39# Authors: Sean Wilson | 1# Copyright (c) 2019 ARM Limited 2# All rights reserved 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 23 unchanged lines hidden (view full) --- 32# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38# 39# Authors: Sean Wilson |
40# Nikos Nikoleris |
|
40 41import os 42import tempfile 43import shutil 44import threading | 41 42import os 43import tempfile 44import shutil 45import threading |
46import urllib 47import urllib2 |
|
45 46from testlib.fixture import Fixture 47from testlib.config import config, constants 48from testlib.helper import log_call, cacheresult, joinpath, absdirpath 49import testlib.log as log 50 51 52class VariableFixture(Fixture): --- 181 unchanged lines hidden (view full) --- 234 def setup(self, testitem): 235 # Check if the program exists if it does then only compile if 236 # recompile was given. 237 if self.recompile: 238 super(MakeTarget, self).setup() 239 elif not os.path.exists(self.path): 240 super(MakeTarget, self).setup() 241 | 48 49from testlib.fixture import Fixture 50from testlib.config import config, constants 51from testlib.helper import log_call, cacheresult, joinpath, absdirpath 52import testlib.log as log 53 54 55class VariableFixture(Fixture): --- 181 unchanged lines hidden (view full) --- 237 def setup(self, testitem): 238 # Check if the program exists if it does then only compile if 239 # recompile was given. 240 if self.recompile: 241 super(MakeTarget, self).setup() 242 elif not os.path.exists(self.path): 243 super(MakeTarget, self).setup() 244 |
242class DownloadedProgram(Fixture): | 245class DownloadedProgram(UniqueFixture): |
243 """ Like TestProgram, but checks the version in the gem5 binary repository 244 and downloads an updated version if it is needed. 245 """ | 246 """ Like TestProgram, but checks the version in the gem5 binary repository 247 and downloads an updated version if it is needed. 248 """ |
246 urlbase = "http://gem5.org/dist/current/" | |
247 | 249 |
248 def __init__(self, path, program, **kwargs): | 250 def __new__(cls, url, path, filename): 251 target = joinpath(path, filename) 252 return super(DownloadedProgram, cls).__new__(cls, target) 253 254 def _init(self, url, path, filename, **kwargs): |
249 """ | 255 """ |
256 url: string 257 The url of the archive |
|
250 path: string | 258 path: string |
251 The path to the directory containing the binary relative to 252 $GEM5_BASE/tests 253 program: string 254 The name of the binary file | 259 The absolute path of the directory containing the archive 260 filename: string 261 The name of the archive |
255 """ | 262 """ |
256 super(DownloadedProgram, self).__init__("download-" + program, 257 build_once=True, **kwargs) | |
258 | 263 |
259 self.program_dir = path 260 relative_path = joinpath(self.program_dir, program) 261 self.url = self.urlbase + relative_path 262 self.path = os.path.realpath( 263 joinpath(absdirpath(__file__), '../', relative_path) 264 ) | 264 self.url = url 265 self.path = path 266 self.filename = joinpath(path, filename) 267 self.name = "Downloaded:" + self.filename |
265 266 def _download(self): | 268 269 def _download(self): |
267 import urllib | |
268 import errno 269 log.test_log.debug("Downloading " + self.url + " to " + self.path) | 270 import errno 271 log.test_log.debug("Downloading " + self.url + " to " + self.path) |
270 if not os.path.exists(self.program_dir): | 272 if not os.path.exists(self.path): |
271 try: | 273 try: |
272 os.makedirs(self.program_dir) | 274 os.makedirs(self.path) |
273 except OSError as e: 274 if e.errno != errno.EEXIST: 275 raise | 275 except OSError as e: 276 if e.errno != errno.EEXIST: 277 raise |
276 urllib.urlretrieve(self.url, self.path) | 278 urllib.urlretrieve(self.url, self.filename) |
277 278 def _getremotetime(self): | 279 280 def _getremotetime(self): |
279 import urllib2, datetime, time | 281 import datetime, time |
280 import _strptime # Needed for python threading bug 281 282 u = urllib2.urlopen(self.url) 283 return time.mktime(datetime.datetime.strptime( \ 284 u.info().getheaders("Last-Modified")[0], 285 "%a, %d %b %Y %X GMT").timetuple()) 286 | 282 import _strptime # Needed for python threading bug 283 284 u = urllib2.urlopen(self.url) 285 return time.mktime(datetime.datetime.strptime( \ 286 u.info().getheaders("Last-Modified")[0], 287 "%a, %d %b %Y %X GMT").timetuple()) 288 |
287 def setup(self, testitem): 288 import urllib2 | 289 def _setup(self, testitem): |
289 # Check to see if there is a file downloaded | 290 # Check to see if there is a file downloaded |
290 if not os.path.exists(self.path): | 291 if not os.path.exists(self.filename): |
291 self._download() 292 else: 293 try: 294 t = self._getremotetime() 295 except urllib2.URLError: 296 # Problem checking the server, use the old files. | 292 self._download() 293 else: 294 try: 295 t = self._getremotetime() 296 except urllib2.URLError: 297 # Problem checking the server, use the old files. |
297 log.debug("Could not contact server. Binaries may be old.") | 298 log.test_log.debug("Could not contact server. Binaries may be old.") |
298 return 299 # If the server version is more recent, download it | 299 return 300 # If the server version is more recent, download it |
300 if t > os.path.getmtime(self.path): | 301 if t > os.path.getmtime(self.filename): |
301 self._download() | 302 self._download() |
303 304class DownloadedArchive(DownloadedProgram): 305 """ Like TestProgram, but checks the version in the gem5 binary repository 306 and downloads an updated version if it is needed. 307 """ 308 309 def _extract(self): 310 import tarfile 311 with tarfile.open(self.filename) as tf: 312 tf.extractall(self.path) 313 314 def _setup(self, testitem): 315 # Check to see if there is a file downloaded 316 if not os.path.exists(self.filename): 317 self._download() 318 self._extract() 319 else: 320 try: 321 t = self._getremotetime() 322 except urllib2.URLError: 323 # Problem checking the server, use the old files. 324 log.test_log.debug("Could not contact server. Binaries may be old.") 325 return 326 # If the server version is more recent, download it 327 if t > os.path.getmtime(self.filename): 328 self._download() 329 self._extract() |
|