[llvm] [AMDGPU][test]added unique and sort options for update_mc_test_check script (PR #111769)
Ivan Kosarev via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 05:00:04 PDT 2024
================
@@ -298,23 +325,88 @@ def main():
else:
gen_prefix += getStdCheckLine(prefix, o, mc_mode)
- generated_prefixes.append(gen_prefix.rstrip("\n"))
+ generated_prefixes[input_line] = gen_prefix.rstrip("\n")
# write output
- prefix_id = 0
for input_info in ti.iterlines(output_lines):
input_line = input_info.line
- if isTestLine(input_line, mc_mode):
+ if input_line in testlines:
output_lines.append(input_line)
- output_lines.append(generated_prefixes[prefix_id])
- prefix_id += 1
+ output_lines.append(generated_prefixes[input_line])
elif should_add_line_to_output(input_line, prefix_set, mc_mode):
output_lines.append(input_line)
- elif input_line in ti.run_lines or input_line == "":
- output_lines.append(input_line)
+ if ti.args.unique or ti.args.sort:
+ # split with double newlines
+ test_units = "\n".join(output_lines).split("\n\n")
+
+ # select the key line for each test unit
+ test_dic = {}
+ for unit in test_units:
+ lines = unit.split("\n")
+ for l in lines:
+ # if contains multiple lines, use
+ # the first testline or runline as key
+ if isTestLine(l, mc_mode):
+ test_dic[unit] = l
+ break
+ elif isRunLine(l):
+ test_dic[unit] = l
+ break
+
+ # unique
+ if ti.args.unique:
+ new_test_units = []
+ written_lines = set()
+ for unit in test_units:
+ # if not testline/runline, we just add it
+ if unit not in test_dic:
+ new_test_units.append(unit)
+ else:
+ if test_dic[unit] in written_lines:
+ common.debug("Duplicated test skipped: ", unit)
+ continue
+ else:
+ written_lines.add(test_dic[unit])
+ new_test_units.append(unit)
+ test_units = new_test_units
+
+ # sort
+ if ti.args.sort:
+
+ def compare(l1, l2):
+ # get key string to be compared
+ if l1 in test_dic:
+ l1 = test_dic[l1]
+ else:
+ l1 = l1.split("\n")[0]
+ if l2 in test_dic:
+ l2 = test_dic[l2]
+ else:
+ l2 = l2.split("\n")[0]
+
+ isl1_runline = isRunLine(l1)
+ isl2_runline = isRunLine(l2)
+
+ if isl1_runline and not isl2_runline:
+ return -1
+ elif not isl1_runline and isl2_runline:
+ return 1
+ else:
+ if l1 < l2:
+ return -1
+ elif l1 > l2:
+ return 1
+ else:
+ return 0
+
+ test_units = sorted(test_units, key=functools.cmp_to_key(compare))
----------------
kosarev wrote:
Can this be simplified to something like:
```suggestion
def get_key(line):
# get key string to be compared
if line in test_dic:
line = test_dic[line]
else:
line = line.split("\n")[0]
return (not isRunLine(line), line)
test_units = sorted(test_units, key=get_key)
```
?
https://github.com/llvm/llvm-project/pull/111769
More information about the llvm-commits
mailing list