source: icGREP/icgrep-devel/QA/abc_testgen.py @ 5727

Last change on this file since 5727 was 4132, checked in by cameron, 5 years ago

Restructure - collapse cc_codegenobject into cc_compiler

File size: 2.7 KB
Line 
1#
2# abc_testgen.py
3#
4# Generate grep test cases for ab*c pattern to segment
5# handling support (long lines, b* crossing segment boundaries).
6#
7from random import randint
8import os
9import shutil
10#
11#
12output_home = 'abc'
13
14#
15# Generate a line that matches ab*c with a given offset from
16# the line beginning, a given length of the match and a given
17# total line length (including new line).
18#
19def generate_line_to_match(offset, match_length, line_length):
20  return "%sa%sc%s\n" % (('_' * offset), ("b" * (match_length - 2)), ('_' * (line_length - (offset + match_length) - 1)))
21
22#
23# Generate lines that do not match ab*c of total length lgth.
24#
25def generate_non_match_lines(lgth):
26  lgth_remain = lgth
27  linedata = ""
28  while lgth_remain > 0:
29    this_line_lgth = randint(1, lgth_remain)
30    if this_line_lgth == 1: linedata += "\n"
31    else: linedata += "a%s\n" % ("b" * (this_line_lgth - 2))
32    lgth_remain -= this_line_lgth
33  return linedata
34
35def generate_case(line_pos, match_pos, match_length, line_length, extra):
36  file_name = "ab{%i}c@%i.txt" % (match_length - 2, line_pos+match_pos)
37  line_to_match = generate_line_to_match(match_pos-line_pos, match_length, line_length)
38  f1 = file(output_home + "/ExpectedOutput/" + file_name, "w")
39  f1.write(line_to_match)
40  f1.close()
41  f2 = file(output_home + "/TestFiles/" + file_name, "w")
42  f2.write(generate_non_match_lines(line_pos))
43  f2.write(line_to_match)
44  f2.write(generate_non_match_lines(extra))
45  f2.close()
46
47def main():
48  if os.path.exists(output_home + ".bak" ):
49    shutil.rmtree(output_home + ".bak")
50  if os.path.exists( output_home ):
51    shutil.move(output_home, output_home + ".bak")
52  os.mkdir(output_home)
53  os.mkdir(output_home + "/TestFiles/")
54  os.mkdir(output_home + "/ExpectedOutput/")
55
56  for block_size in [64, 128, 1024]:
57     for segment_blocks in [2,3,5,11,15,19,25,30,31,32,43]:
58        segment_base = block_size * segment_blocks
59        for segments_in_match in range(4):
60          additional_blocks = randint(0, segment_blocks - 1)
61          match_blocks = segments_in_match * segment_blocks + additional_blocks
62          match_extra = randint(0, block_size - 1)
63          match_length = match_blocks * block_size + match_extra
64          min_segment_offset = segment_base - (additional_blocks * block_size + match_extra)   
65          max_segment_offset = segment_base - match_extra
66          match_abs_pos = randint(min_segment_offset, max_segment_offset) + randint(0, 10) * segment_base
67          line_abs_pos = match_abs_pos - randint(1, match_abs_pos)
68          line_length = (match_abs_pos - line_abs_pos) + match_length + randint(1, segment_base)
69          extra = randint(0, segment_base * 4)
70          generate_case(line_abs_pos, match_abs_pos, match_length, line_length, extra)
71
72if __name__ == "__main__":
73  main()
74
75
76 
Note: See TracBrowser for help on using the repository browser.