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