1e5c31af7Sopenharmony_ci#!/usr/bin/env python3
2e5c31af7Sopenharmony_ci
3e5c31af7Sopenharmony_ci# VK-GL-CTS log scrubber
4e5c31af7Sopenharmony_ci# ----------------------
5e5c31af7Sopenharmony_ci#
6e5c31af7Sopenharmony_ci# Copyright (c) 2019 The Khronos Group Inc.
7e5c31af7Sopenharmony_ci# Copyright (c) 2019 Google LLC
8e5c31af7Sopenharmony_ci#
9e5c31af7Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
10e5c31af7Sopenharmony_ci# you may not use this file except in compliance with the License.
11e5c31af7Sopenharmony_ci# You may obtain a copy of the License at
12e5c31af7Sopenharmony_ci#
13e5c31af7Sopenharmony_ci#      http://www.apache.org/licenses/LICENSE-2.0
14e5c31af7Sopenharmony_ci#
15e5c31af7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
16e5c31af7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
17e5c31af7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18e5c31af7Sopenharmony_ci# See the License for the specific language governing permissions and
19e5c31af7Sopenharmony_ci# limitations under the License.
20e5c31af7Sopenharmony_ci
21e5c31af7Sopenharmony_ci# This script attempts to find out which tests have changed since a
22e5c31af7Sopenharmony_ci# certain time, release or changelist. The commit messages are scrubbed
23e5c31af7Sopenharmony_ci# for dEQP test names, and these are merged to find a suitable set.
24e5c31af7Sopenharmony_ci#
25e5c31af7Sopenharmony_ci# The changelists that claim to change all tests are ignored.
26e5c31af7Sopenharmony_ci
27e5c31af7Sopenharmony_ciimport subprocess
28e5c31af7Sopenharmony_ciimport sys
29e5c31af7Sopenharmony_ciimport fnmatch
30e5c31af7Sopenharmony_ciimport re
31e5c31af7Sopenharmony_ci
32e5c31af7Sopenharmony_ciassert sys.version_info >= (3, 0)
33e5c31af7Sopenharmony_ci
34e5c31af7Sopenharmony_ciif len(sys.argv) == 1:
35e5c31af7Sopenharmony_ci	print("""
36e5c31af7Sopenharmony_ciVK-GL-CTS log scrubber
37e5c31af7Sopenharmony_ci----------------------
38e5c31af7Sopenharmony_ciThis script attempts to list changed tests since certain time or
39e5c31af7Sopenharmony_cigit revision. It does this by looking at git log.
40e5c31af7Sopenharmony_ci
41e5c31af7Sopenharmony_ciCaveat: git log messages are written by humans, so there may be
42e5c31af7Sopenharmony_cierrors. Overly broad changes are ignored (e.g, dEQP-VK.*).
43e5c31af7Sopenharmony_ci
44e5c31af7Sopenharmony_ciUsage: Give the git log parameters
45e5c31af7Sopenharmony_ci
46e5c31af7Sopenharmony_ciExamples:""")
47e5c31af7Sopenharmony_ci	print(sys.argv[0], '--since="two months ago"')
48e5c31af7Sopenharmony_ci	print(sys.argv[0], '--since="7.7.2019"')
49e5c31af7Sopenharmony_ci	print(sys.argv[0], 'vulkan-cts-1.1.3.1..HEAD')
50e5c31af7Sopenharmony_ci	quit()
51e5c31af7Sopenharmony_ci
52e5c31af7Sopenharmony_ciparams = ""
53e5c31af7Sopenharmony_cifirst = True
54e5c31af7Sopenharmony_cifor x in sys.argv[1:]:
55e5c31af7Sopenharmony_ci	if not first:
56e5c31af7Sopenharmony_ci		params = params + " "
57e5c31af7Sopenharmony_ci	params = params + x
58e5c31af7Sopenharmony_ci	first = False
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_cires = []
61e5c31af7Sopenharmony_ci
62e5c31af7Sopenharmony_cirawlogoutput = subprocess.check_output(['git', 'log', params, '--pretty=format:"%B"'])
63e5c31af7Sopenharmony_cilogoutput = rawlogoutput.decode().split()
64e5c31af7Sopenharmony_cifor x in logoutput:
65e5c31af7Sopenharmony_ci	xs = x.strip()
66e5c31af7Sopenharmony_ci	# regexp matches various over-large test masks like "dEQP-*", "dEQP-VK*", "dEQP-VK.*",
67e5c31af7Sopenharmony_ci	# but not "dEQP-VK.a" or "dEQP-VK.*a"
68e5c31af7Sopenharmony_ci	if xs.startswith('dEQP-') and not re.search('dEQP-\w*\**\.*\**$',xs):
69e5c31af7Sopenharmony_ci		found = False
70e5c31af7Sopenharmony_ci		killlist = []
71e5c31af7Sopenharmony_ci		for y in res:
72e5c31af7Sopenharmony_ci			if fnmatch.fnmatch(xs, y):
73e5c31af7Sopenharmony_ci				found = True
74e5c31af7Sopenharmony_ci			if fnmatch.fnmatch(y, xs):
75e5c31af7Sopenharmony_ci				killlist.append(y)
76e5c31af7Sopenharmony_ci		for y in killlist:
77e5c31af7Sopenharmony_ci			res.remove(y)
78e5c31af7Sopenharmony_ci		if not found:
79e5c31af7Sopenharmony_ci			res.append(xs)
80e5c31af7Sopenharmony_cifor x in sorted(res):
81e5c31af7Sopenharmony_ci	print(x)
82e5c31af7Sopenharmony_ciprint(len(res), 'total')
83