• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python2
2import argparse
3import sys
4
5def main():
6  desc = 'Crash simulator script, useful for testing the bisection tool.\
7          bisection-tool.py --cmd "./pydir/bisection-test.py -c 2x3" \
8          --end 1000 --timeout 60'
9  argparser = argparse.ArgumentParser(description=desc)
10  argparser.add_argument('--include', '-i', default=[], dest='include',
11    action='append',
12    help='Include list, single values or ranges')
13  argparser.add_argument('--exclude', '-e', default=[], dest='exclude',
14    action='append',
15    help='Exclude list, single values or ranges')
16  argparser.add_argument('--crash', '-c', default=[], dest='crash',
17    action='append',
18    help='Crash list, single values or x-separated combinations like 2x4')
19
20  args = argparser.parse_args()
21
22  included = {-1}
23  for string in args.include:
24    include_range = string.split(':')
25    if len(include_range) == 1:
26      included.add(int(include_range[0]))
27    else:
28      for num in range(int(include_range[0]), int(include_range[1])):
29        included.add(num)
30
31  for string in args.exclude:
32    exclude_range = string.split(':')
33    if len(exclude_range) == 1:
34      try:
35        included.remove(int(exclude_range[0]))
36      except KeyError:
37        pass # Exclude works without a matching include
38    else:
39      for num in range(int(exclude_range[0]), int(exclude_range[1])):
40        included.remove(num)
41
42  for string in args.crash:
43    crash_combination = string.split('x')
44    fail = True
45    for crash in crash_combination:
46      if not int(crash) in included:
47        fail = False
48    if fail:
49      print 'Fail'
50      exit(1)
51  print 'Success'
52  exit(0)
53
54if __name__ == '__main__':
55  main()
56