def find_races(self): input_vars = sorted(self.data['inputs'][0].copy()) vals = sorted( chain(*[ set(permutations(x)) for x in combinations_with_replacement([0, 1], len(input_vars)) ])) for testv in vals: test = {var: str(val) for var, val in zip(input_vars, testv)} print() print("TESTING %s" % format_test(test)) for test in self._prepare_test(test): self.test = test self.variables.update(test) self._run(output=True) self._analyze() self._cleanup() print() print("=========================================") print("Found issues:") tbl = PrettyTable(["Title", "Data"]) for pr in self.problems: tbl.add_row(pr) print(tbl)
def _run(self, output=True): try: self.start_model() except CycleFoundException as e: if output: print(self.table) msg = "Circuit is not stable", format_test(self.test) print(msg) if msg not in self.problems: self.problems.append(msg) else: if output: print(self.table)
def _analyze(self): signals = zip(*self.history) for i, var_h in enumerate(signals): v_str = ''.join(var_h) ones = len(re.findall('1+', v_str)) zeros = len(re.findall('0+', v_str)) var = self.columns[i] if ones + zeros > 2: msg = "Race condition", "{} [{}]".format(var, format_test(self.test)) if msg not in self.problems: self.problems.append(msg) print(msg) if self.result_func: locals = self.variables.copy() locals.update(self.actions) is_conform = eval(self.result_func, locals) if not is_conform: msg = "Circuit doesn't corresponds equation", format_test(self.test) if msg not in self.problems: self.problems.append(msg) print(msg)
def _analyze(self): signals = zip(*self.history) for i, var_h in enumerate(signals): v_str = ''.join(var_h) ones = len(re.findall('1+', v_str)) zeros = len(re.findall('0+', v_str)) var = self.columns[i] if ones + zeros > 2: msg = "Race condition", "{} [{}]".format( var, format_test(self.test)) if msg not in self.problems: self.problems.append(msg) print(msg) if self.result_func: locals = self.variables.copy() locals.update(self.actions) is_conform = eval(self.result_func, locals) if not is_conform: msg = "Circuit doesn't corresponds equation", format_test( self.test) if msg not in self.problems: self.problems.append(msg) print(msg)
def do_model(self): for test in self.data['inputs']: self.variables.update(self.data['inputs'][0]) print("TESTING %s" % format_test(test)) for test in self._prepare_test(test): self.test = test self.variables.update(test) self._run(output=True) self._analyze() self._cleanup() print() print("=========================================") print("Found issues:") tbl = PrettyTable(["Title", "Data"]) for pr in self.problems: tbl.add_row(pr) print(tbl)
def find_races(self): input_vars = sorted(self.data['inputs'][0].copy()) vals = sorted(chain(*[set(permutations(x)) for x in combinations_with_replacement([0, 1], len(input_vars))])) for testv in vals: test = {var: str(val) for var, val in zip(input_vars, testv)} print() print("TESTING %s" % format_test(test)) for test in self._prepare_test(test): self.test = test self.variables.update(test) self._run(output=True) self._analyze() self._cleanup() print() print("=========================================") print("Found issues:") tbl = PrettyTable(["Title", "Data"]) for pr in self.problems: tbl.add_row(pr) print(tbl)