• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2016 the V8 project authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import os
7import sys
8import unittest
9
10TOOLS_PATH = os.path.dirname(
11    os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12sys.path.append(TOOLS_PATH)
13
14from testrunner.local import statusfile
15from testrunner.local.utils import Freeze
16
17TEST_VARIABLES = {
18    'system': 'linux',
19    'mode': 'release',
20}
21
22TEST_STATUS_FILE = """
23[
24[ALWAYS, {
25  'foo/bar': [PASS, SKIP],
26  'baz/bar': [PASS, FAIL],
27  'foo/*': [PASS, SLOW],
28}],  # ALWAYS
29
30['%s', {
31  'baz/bar': [PASS, SLOW],
32  'foo/*': [FAIL],
33}],
34]
35"""
36
37
38def make_variables():
39  variables = {}
40  variables.update(TEST_VARIABLES)
41  return variables
42
43
44class UtilsTest(unittest.TestCase):
45
46  def test_freeze(self):
47    self.assertEqual(2, Freeze({1: [2]})[1][0])
48    self.assertEqual(set([3]), Freeze({1: [2], 2: set([3])})[2])
49
50    with self.assertRaises(Exception):
51      Freeze({1: [], 2: set([3])})[2] = 4
52    with self.assertRaises(Exception):
53      Freeze({1: [], 2: set([3])}).update({3: 4})
54    with self.assertRaises(Exception):
55      Freeze({1: [], 2: set([3])})[1].append(2)
56    with self.assertRaises(Exception):
57      Freeze({1: [], 2: set([3])})[2] |= set([3])
58
59    # Sanity check that we can do the same calls on a non-frozen object.
60    {1: [], 2: set([3])}[2] = 4
61    {1: [], 2: set([3])}.update({3: 4})
62    {1: [], 2: set([3])}[1].append(2)
63    {1: [], 2: set([3])}[2] |= set([3])
64
65
66class StatusFileTest(unittest.TestCase):
67
68  def test_eval_expression(self):
69    variables = make_variables()
70    variables.update(statusfile.VARIABLES)
71
72    self.assertTrue(
73        statusfile._EvalExpression('system==linux and mode==release',
74                                   variables))
75    self.assertTrue(
76        statusfile._EvalExpression('system==linux or variant==default',
77                                   variables))
78    self.assertFalse(
79        statusfile._EvalExpression('system==linux and mode==debug', variables))
80    self.assertRaises(
81        AssertionError, lambda: statusfile._EvalExpression(
82            'system==linux and mode==foo', variables))
83    self.assertRaises(
84        SyntaxError, lambda: statusfile._EvalExpression(
85            'system==linux and mode=release', variables))
86    self.assertEquals(
87        statusfile.VARIANT_EXPRESSION,
88        statusfile._EvalExpression('system==linux and variant==default',
89                                   variables))
90
91  def test_read_statusfile_section_true(self):
92    rules, prefix_rules = statusfile.ReadStatusFile(
93        TEST_STATUS_FILE % 'system==linux', make_variables())
94
95    self.assertEquals(
96        {
97            'foo/bar': set(['PASS', 'SKIP']),
98            'baz/bar': set(['PASS', 'FAIL', 'SLOW']),
99        },
100        rules[''],
101    )
102    self.assertEquals(
103        {
104            'foo/': set(['SLOW', 'FAIL']),
105        },
106        prefix_rules[''],
107    )
108    self.assertEquals({}, rules['default'])
109    self.assertEquals({}, prefix_rules['default'])
110
111  def test_read_statusfile_section_false(self):
112    rules, prefix_rules = statusfile.ReadStatusFile(
113        TEST_STATUS_FILE % 'system==windows', make_variables())
114
115    self.assertEquals(
116        {
117            'foo/bar': set(['PASS', 'SKIP']),
118            'baz/bar': set(['PASS', 'FAIL']),
119        },
120        rules[''],
121    )
122    self.assertEquals(
123        {
124            'foo/': set(['PASS', 'SLOW']),
125        },
126        prefix_rules[''],
127    )
128    self.assertEquals({}, rules['default'])
129    self.assertEquals({}, prefix_rules['default'])
130
131  def test_read_statusfile_section_variant(self):
132    rules, prefix_rules = statusfile.ReadStatusFile(
133        TEST_STATUS_FILE % 'system==linux and variant==default',
134        make_variables(),
135    )
136
137    self.assertEquals(
138        {
139            'foo/bar': set(['PASS', 'SKIP']),
140            'baz/bar': set(['PASS', 'FAIL']),
141        },
142        rules[''],
143    )
144    self.assertEquals(
145        {
146            'foo/': set(['PASS', 'SLOW']),
147        },
148        prefix_rules[''],
149    )
150    self.assertEquals(
151        {
152            'baz/bar': set(['PASS', 'SLOW']),
153        },
154        rules['default'],
155    )
156    self.assertEquals(
157        {
158            'foo/': set(['FAIL']),
159        },
160        prefix_rules['default'],
161    )
162
163
164if __name__ == '__main__':
165  unittest.main()
166