Home | History | Annotate | Download | only in raw
      1 # Copyright (C) 2014 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 
     15 import sys
     16 import os
     17 
     18 if len(sys.argv) != 3:
     19   raise Exception("Usage: extract_webgl_tests.py <webgl_sdk_tests_path> <version>")
     20 
     21 top_list = sys.argv[1] + "/00_test_list.txt"
     22 version = sys.argv[2]
     23 tests = []
     24 lists = []
     25 lists.append(top_list)
     26 
     27 def filter_by_version(lines):
     28   version_lines = [ line for line in lines if "--min-version" in line ]
     29   version_lines.extend([ line for line in lines if "--max-version" in line ])
     30   lines = [ line for line in lines if not line in version_lines ]
     31   for line in version_lines:
     32     assert len(line.split()) == 3
     33     min_version = line.split()[1] if line.split()[0] == "--min-version" else "0.0.0"
     34     max_version = line.split()[1] if line.split()[0] == "--max-version" else "9.9.9"
     35     test = line.split()[2]
     36     if (version >= min_version and version <= max_version):
     37       lines.append(test)
     38   return lines
     39 
     40 while not len(lists) == 0:
     41   lists2 = lists
     42   lists = []
     43   for list in lists2:
     44     directory = os.path.dirname(os.path.realpath(list))
     45     with open(list) as file:
     46       # Filter out comments and --min-version
     47       lines = [ line.strip() for line in file.readlines()]
     48       lines = [ line for line in lines if not "//" in line ]
     49       lines = [ line for line in lines if not "#" in line ]
     50       lines = [ line.replace("--slow","") for line in lines ]
     51       lines = filter_by_version(lines)
     52       # Append lists and tests found in this list.
     53       lines = [ directory + "/" + line for line in lines ]
     54       lists.extend([ line for line in lines if "00_test_list.txt" in line ])
     55       tests.extend([ line for line in lines if ".html" in line ])
     56 
     57 # Directories for formating test-names/relative-paths.
     58 name_directory = os.path.dirname(os.path.realpath(top_list))
     59 path_directory = os.path.realpath(os.path.join(name_directory, os.pardir))
     60 
     61 tests = sorted(tests)
     62 for test in tests:
     63   test_path = test.replace(path_directory + "/", "")
     64   test_name = test.replace(name_directory + "/", "")
     65   test_name = test_name.replace("/","_")
     66   test_name = test_name.replace(".","_")
     67   test_name = test_name.replace("-","_")
     68   print "    public void test_" + test_name + "() throws Exception { doTest(\"" + test_path + "\"); }"
     69 
     70