pdict = pargs.__dict__ # create a namedtuple object for fast attribute lookup key_list = pdict.keys() arg_list = [pdict[k] for k in key_list] Config = namedtuple('Config', key_list) nt_config = Config(*arg_list) return nt_config parsed_args, parser = parse_args() config = make_config(parsed_args, parser) print('Random testing using config={}'.format(config)) start = time.time() elapsed = time.time()-start t = SUT.t() ntests = 0 while (config.maxtests == -1) or (ntests < config.maxtests): ntests += 1 t.restart() test = [] for s in xrange(0,config.depth): a = random.choice(t.enabled()) test.append(a) try: a[2]() except:
for tran in t.enabled(): newtest = list(test) newtest.append(tran[0]) try: tran[2]() except: pass try: t.check() except: _, _, tb = sys.exc_info() traceback.print_tb(tb) tbInfo = traceback.extract_tb(tb) filename, line, func, text = tbInfo[-1] print "TEST:" for step in newtest: print step print "EXITING DUE TO FAILED TEST" sys.exit(1) if t.state() not in visited: dfs(newtest, visited) t.backtrack(old) start = time.time() t = SUT.t() t.restart() dfs([], [])
import sut import random import sys maxdepth = int(sys.argv[1]) t = sut.t() visited = [] def dfs(trail, depth): if depth >= maxdepth: return old = t.state() if old in visited: return visited.append(old) next = t.enabled() for a in next: newtrail = list(trail) newtrail.append(a) t.backtrack(old) a[2]() if (not t.check()): print "Property failed!" (_, _, tb) = t.failure() traceback.print_tb(tb) print "TEST:" for step in (newtrail): print step[0]
import sut import random t = sut.t() LEN = 2000 N = 1000 states = [] for n in xrange(0,N): t.restart() for s in xrange(0,LEN): action = random.choice(t.enabled()) action[2]() assert(t.check()) if t.state() not in states: print "NEW STATE!!!",t.state() states.append(t.state()) else: if (random.random() < 0.15): t.backtrack(random.choice(states)) assert(t.check())