11cb0ef41Sopenharmony_ci#!/usr/bin/env python3 21cb0ef41Sopenharmony_ci# Copyright 2016 the V8 project authors. All rights reserved. 31cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 41cb0ef41Sopenharmony_ci# found in the LICENSE file. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciimport os 71cb0ef41Sopenharmony_ciimport sys 81cb0ef41Sopenharmony_ciimport unittest 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciTOOLS_PATH = os.path.dirname( 111cb0ef41Sopenharmony_ci os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 121cb0ef41Sopenharmony_cisys.path.append(TOOLS_PATH) 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cifrom testrunner.local import statusfile 151cb0ef41Sopenharmony_cifrom testrunner.local.utils import Freeze 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciTEST_VARIABLES = { 181cb0ef41Sopenharmony_ci 'system': 'linux', 191cb0ef41Sopenharmony_ci 'mode': 'release', 201cb0ef41Sopenharmony_ci} 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciTEST_STATUS_FILE = """ 231cb0ef41Sopenharmony_ci[ 241cb0ef41Sopenharmony_ci[ALWAYS, { 251cb0ef41Sopenharmony_ci 'foo/bar': [PASS, SKIP], 261cb0ef41Sopenharmony_ci 'baz/bar': [PASS, FAIL], 271cb0ef41Sopenharmony_ci 'foo/*': [PASS, SLOW], 281cb0ef41Sopenharmony_ci}], # ALWAYS 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci['%s', { 311cb0ef41Sopenharmony_ci 'baz/bar': [PASS, SLOW], 321cb0ef41Sopenharmony_ci 'foo/*': [FAIL], 331cb0ef41Sopenharmony_ci}], 341cb0ef41Sopenharmony_ci] 351cb0ef41Sopenharmony_ci""" 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_cidef make_variables(): 391cb0ef41Sopenharmony_ci variables = {} 401cb0ef41Sopenharmony_ci variables.update(TEST_VARIABLES) 411cb0ef41Sopenharmony_ci return variables 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ciclass UtilsTest(unittest.TestCase): 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci def test_freeze(self): 471cb0ef41Sopenharmony_ci self.assertEqual(2, Freeze({1: [2]})[1][0]) 481cb0ef41Sopenharmony_ci self.assertEqual(set([3]), Freeze({1: [2], 2: set([3])})[2]) 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci with self.assertRaises(Exception): 511cb0ef41Sopenharmony_ci Freeze({1: [], 2: set([3])})[2] = 4 521cb0ef41Sopenharmony_ci with self.assertRaises(Exception): 531cb0ef41Sopenharmony_ci Freeze({1: [], 2: set([3])}).update({3: 4}) 541cb0ef41Sopenharmony_ci with self.assertRaises(Exception): 551cb0ef41Sopenharmony_ci Freeze({1: [], 2: set([3])})[1].append(2) 561cb0ef41Sopenharmony_ci with self.assertRaises(Exception): 571cb0ef41Sopenharmony_ci Freeze({1: [], 2: set([3])})[2] |= set([3]) 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci # Sanity check that we can do the same calls on a non-frozen object. 601cb0ef41Sopenharmony_ci {1: [], 2: set([3])}[2] = 4 611cb0ef41Sopenharmony_ci {1: [], 2: set([3])}.update({3: 4}) 621cb0ef41Sopenharmony_ci {1: [], 2: set([3])}[1].append(2) 631cb0ef41Sopenharmony_ci {1: [], 2: set([3])}[2] |= set([3]) 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ciclass StatusFileTest(unittest.TestCase): 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci def test_eval_expression(self): 691cb0ef41Sopenharmony_ci variables = make_variables() 701cb0ef41Sopenharmony_ci variables.update(statusfile.VARIABLES) 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci self.assertTrue( 731cb0ef41Sopenharmony_ci statusfile._EvalExpression('system==linux and mode==release', 741cb0ef41Sopenharmony_ci variables)) 751cb0ef41Sopenharmony_ci self.assertTrue( 761cb0ef41Sopenharmony_ci statusfile._EvalExpression('system==linux or variant==default', 771cb0ef41Sopenharmony_ci variables)) 781cb0ef41Sopenharmony_ci self.assertFalse( 791cb0ef41Sopenharmony_ci statusfile._EvalExpression('system==linux and mode==debug', variables)) 801cb0ef41Sopenharmony_ci self.assertRaises( 811cb0ef41Sopenharmony_ci AssertionError, lambda: statusfile._EvalExpression( 821cb0ef41Sopenharmony_ci 'system==linux and mode==foo', variables)) 831cb0ef41Sopenharmony_ci self.assertRaises( 841cb0ef41Sopenharmony_ci SyntaxError, lambda: statusfile._EvalExpression( 851cb0ef41Sopenharmony_ci 'system==linux and mode=release', variables)) 861cb0ef41Sopenharmony_ci self.assertEquals( 871cb0ef41Sopenharmony_ci statusfile.VARIANT_EXPRESSION, 881cb0ef41Sopenharmony_ci statusfile._EvalExpression('system==linux and variant==default', 891cb0ef41Sopenharmony_ci variables)) 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci def test_read_statusfile_section_true(self): 921cb0ef41Sopenharmony_ci rules, prefix_rules = statusfile.ReadStatusFile( 931cb0ef41Sopenharmony_ci TEST_STATUS_FILE % 'system==linux', make_variables()) 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_ci self.assertEquals( 961cb0ef41Sopenharmony_ci { 971cb0ef41Sopenharmony_ci 'foo/bar': set(['PASS', 'SKIP']), 981cb0ef41Sopenharmony_ci 'baz/bar': set(['PASS', 'FAIL', 'SLOW']), 991cb0ef41Sopenharmony_ci }, 1001cb0ef41Sopenharmony_ci rules[''], 1011cb0ef41Sopenharmony_ci ) 1021cb0ef41Sopenharmony_ci self.assertEquals( 1031cb0ef41Sopenharmony_ci { 1041cb0ef41Sopenharmony_ci 'foo/': set(['SLOW', 'FAIL']), 1051cb0ef41Sopenharmony_ci }, 1061cb0ef41Sopenharmony_ci prefix_rules[''], 1071cb0ef41Sopenharmony_ci ) 1081cb0ef41Sopenharmony_ci self.assertEquals({}, rules['default']) 1091cb0ef41Sopenharmony_ci self.assertEquals({}, prefix_rules['default']) 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci def test_read_statusfile_section_false(self): 1121cb0ef41Sopenharmony_ci rules, prefix_rules = statusfile.ReadStatusFile( 1131cb0ef41Sopenharmony_ci TEST_STATUS_FILE % 'system==windows', make_variables()) 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci self.assertEquals( 1161cb0ef41Sopenharmony_ci { 1171cb0ef41Sopenharmony_ci 'foo/bar': set(['PASS', 'SKIP']), 1181cb0ef41Sopenharmony_ci 'baz/bar': set(['PASS', 'FAIL']), 1191cb0ef41Sopenharmony_ci }, 1201cb0ef41Sopenharmony_ci rules[''], 1211cb0ef41Sopenharmony_ci ) 1221cb0ef41Sopenharmony_ci self.assertEquals( 1231cb0ef41Sopenharmony_ci { 1241cb0ef41Sopenharmony_ci 'foo/': set(['PASS', 'SLOW']), 1251cb0ef41Sopenharmony_ci }, 1261cb0ef41Sopenharmony_ci prefix_rules[''], 1271cb0ef41Sopenharmony_ci ) 1281cb0ef41Sopenharmony_ci self.assertEquals({}, rules['default']) 1291cb0ef41Sopenharmony_ci self.assertEquals({}, prefix_rules['default']) 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ci def test_read_statusfile_section_variant(self): 1321cb0ef41Sopenharmony_ci rules, prefix_rules = statusfile.ReadStatusFile( 1331cb0ef41Sopenharmony_ci TEST_STATUS_FILE % 'system==linux and variant==default', 1341cb0ef41Sopenharmony_ci make_variables(), 1351cb0ef41Sopenharmony_ci ) 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_ci self.assertEquals( 1381cb0ef41Sopenharmony_ci { 1391cb0ef41Sopenharmony_ci 'foo/bar': set(['PASS', 'SKIP']), 1401cb0ef41Sopenharmony_ci 'baz/bar': set(['PASS', 'FAIL']), 1411cb0ef41Sopenharmony_ci }, 1421cb0ef41Sopenharmony_ci rules[''], 1431cb0ef41Sopenharmony_ci ) 1441cb0ef41Sopenharmony_ci self.assertEquals( 1451cb0ef41Sopenharmony_ci { 1461cb0ef41Sopenharmony_ci 'foo/': set(['PASS', 'SLOW']), 1471cb0ef41Sopenharmony_ci }, 1481cb0ef41Sopenharmony_ci prefix_rules[''], 1491cb0ef41Sopenharmony_ci ) 1501cb0ef41Sopenharmony_ci self.assertEquals( 1511cb0ef41Sopenharmony_ci { 1521cb0ef41Sopenharmony_ci 'baz/bar': set(['PASS', 'SLOW']), 1531cb0ef41Sopenharmony_ci }, 1541cb0ef41Sopenharmony_ci rules['default'], 1551cb0ef41Sopenharmony_ci ) 1561cb0ef41Sopenharmony_ci self.assertEquals( 1571cb0ef41Sopenharmony_ci { 1581cb0ef41Sopenharmony_ci 'foo/': set(['FAIL']), 1591cb0ef41Sopenharmony_ci }, 1601cb0ef41Sopenharmony_ci prefix_rules['default'], 1611cb0ef41Sopenharmony_ci ) 1621cb0ef41Sopenharmony_ci 1631cb0ef41Sopenharmony_ci 1641cb0ef41Sopenharmony_ciif __name__ == '__main__': 1651cb0ef41Sopenharmony_ci unittest.main() 166