-
Notifications
You must be signed in to change notification settings - Fork 378
/
go_find_some_bugs.py
118 lines (97 loc) · 3.22 KB
/
go_find_some_bugs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Copyright 2008-2015 Nokia Networks
# Copyright 2016- Robot Framework Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from math import ceil
import os
import time
import sys
import traceback
from rtest import simplifier
ROOT = os.path.dirname(__file__)
src = os.path.join(ROOT, '..', 'src')
sys.path.insert(0, src)
from .test_runner import Runner
def do_test(seed, path):
i = None
try:
ride_runner = init_ride_runner(seed, path)
for i in range(10000):
ride_runner.step()
return 'PASS', seed, i, path
except Exception:
print('-'*80)
traceback.print_exc()
print('i = ', i)
print('seed was', str(seed))
print('path was', path)
return 'FAIL', seed, i or 0, path
def init_ride_runner(seed, path):
return Runner(seed, path, ROOT).initialize()
def split(start, end):
return int(ceil(float(end - start) / 2)) + start
def skip_steps(runner, number_of_steps):
for i in range(number_of_steps):
runner.skip_step()
def debug(seed, path, last_index, trace, start, end):
print('*'*80)
if last_index == start:
return trace + [last_index]
if end <= start:
return debug(seed, path, last_index, trace + [end], end+1, last_index)
runner = init_ride_runner(seed, path)
if trace != []:
run_trace(runner, trace)
midpoint = split(start, end)
runner.skip_steps(midpoint)
try:
for j in range(midpoint, last_index):
runner.step()
return debug(seed, path, last_index, trace, start, midpoint-1)
except Exception as err:
if runner.count == last_index:
return debug(seed, path, last_index, trace, midpoint, end)
else:
print('New exception during debugging!')
return debug(seed, path, runner.count, trace, midpoint,
runner.count)
def run_trace(runner, trace):
i = 0
while i < trace[-1]:
if i in trace:
runner.step()
else:
runner.skip_step()
i += 1
def generate_seed():
seed = int(time.time() * 256)
if len(sys.argv) == 3:
seed = int(sys.argv[2])
return seed
def _debugging(seed, path, i):
print('='*80)
trace = debug(seed, path, i, [], 0, i)
print('#'*80)
print(trace)
print('%'*80)
print('seed = ', seed)
run_trace(init_ride_runner(seed, path), trace)
def main(path):
result, seed, i, path = do_test(generate_seed(), path)
# _debugging(seed, path, i)
# ???>>>!!! simplifier.simplify(range(i+1), init_ride_runner(seed, path))
return result != 'FAIL'
if __name__ == '__main__':
if not main(sys.argv[1]):
print('error occurred!')
sys.exit(1) #indicate failure