|
| 1 | +# Copyright 2008 the V8 project authors. All rights reserved. |
| 2 | +# Redistribution and use in source and binary forms, with or without |
| 3 | +# modification, are permitted provided that the following conditions are |
| 4 | +# met: |
| 5 | +# |
| 6 | +# * Redistributions of source code must retain the above copyright |
| 7 | +# notice, this list of conditions and the following disclaimer. |
| 8 | +# * Redistributions in binary form must reproduce the above |
| 9 | +# copyright notice, this list of conditions and the following |
| 10 | +# disclaimer in the documentation and/or other materials provided |
| 11 | +# with the distribution. |
| 12 | +# * Neither the name of Google Inc. nor the names of its |
| 13 | +# contributors may be used to endorse or promote products derived |
| 14 | +# from this software without specific prior written permission. |
| 15 | +# |
| 16 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | + |
| 28 | +import test |
| 29 | +import os |
| 30 | +import shutil |
| 31 | +from shutil import rmtree |
| 32 | +from os import mkdir |
| 33 | +from glob import glob |
| 34 | +from os.path import join, dirname, exists |
| 35 | +import re |
| 36 | +import shlex |
| 37 | + |
| 38 | +FAKETIME_FLAGS_PATTERN = re.compile(r"//\s+FaketimeFlags:(.*)") |
| 39 | +FAKETIME_BIN_PATH = os.path.join("tools", "faketime", "src", "faketime") |
| 40 | + |
| 41 | +class TimersTestCase(test.TestCase): |
| 42 | + |
| 43 | + def __init__(self, path, file, mode, context, config): |
| 44 | + super(TimersTestCase, self).__init__(context, path, mode) |
| 45 | + self.file = file |
| 46 | + self.config = config |
| 47 | + self.mode = mode |
| 48 | + |
| 49 | + def GetLabel(self): |
| 50 | + return "%s %s" % (self.mode, self.GetName()) |
| 51 | + |
| 52 | + def GetName(self): |
| 53 | + return self.path[-1] |
| 54 | + |
| 55 | + def GetCommand(self): |
| 56 | + result = [FAKETIME_BIN_PATH]; |
| 57 | + |
| 58 | + source = open(self.file).read() |
| 59 | + faketime_flags_match = FAKETIME_FLAGS_PATTERN.search(source) |
| 60 | + if faketime_flags_match: |
| 61 | + result += shlex.split(faketime_flags_match.group(1).strip()) |
| 62 | + |
| 63 | + result += [self.config.context.GetVm(self.mode)] |
| 64 | + result += [self.file] |
| 65 | + |
| 66 | + return result |
| 67 | + |
| 68 | + def GetSource(self): |
| 69 | + return open(self.file).read() |
| 70 | + |
| 71 | + |
| 72 | +class TimersTestConfiguration(test.TestConfiguration): |
| 73 | + |
| 74 | + def __init__(self, context, root): |
| 75 | + super(TimersTestConfiguration, self).__init__(context, root) |
| 76 | + |
| 77 | + def Ls(self, path): |
| 78 | + def SelectTest(name): |
| 79 | + return name.startswith('test-') and name.endswith('.js') |
| 80 | + return [f[:-3] for f in os.listdir(path) if SelectTest(f)] |
| 81 | + |
| 82 | + def ListTests(self, current_path, path, mode): |
| 83 | + all_tests = [current_path + [t] for t in self.Ls(join(self.root))] |
| 84 | + result = [] |
| 85 | + for test in all_tests: |
| 86 | + if self.Contains(path, test): |
| 87 | + file_path = join(self.root, reduce(join, test[1:], "") + ".js") |
| 88 | + result.append(TimersTestCase(test, file_path, mode, self.context, self)) |
| 89 | + return result |
| 90 | + |
| 91 | + def GetBuildRequirements(self): |
| 92 | + return ['sample', 'sample=shell'] |
| 93 | + |
| 94 | + def GetTestStatus(self, sections, defs): |
| 95 | + status_file = join(self.root, 'simple.status') |
| 96 | + if exists(status_file): |
| 97 | + test.ReadConfigurationInto(status_file, sections, defs) |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +def GetConfiguration(context, root): |
| 102 | + return TimersTestConfiguration(context, root) |
0 commit comments