def test_check_gteq_no_gteq_defined(self): variables=[] variables.append(Variable('four', 'TestType', 13)) gteq = None checker = ComplianceChecker() with pytest.raises(ComplianceError): checker.check_gteq(gteq, variables)
def test_check_invariant_compliant_invariant(self): invariant = Function('inv', 2) invariant.parameters = [] invariant.parameters.append(Parameter('t1', 'int')) invariant.parameters.append(Parameter('t2', 'bool')) variables = [] variables.append(Variable('t1','int', 10)) variables.append(Variable('t2','bool', 11)) invariant.returndt = 'bool' checker = ComplianceChecker() assert checker.check_invariant(invariant, variables) == True
def test_check_merge_modifies_number_less(self): variables = [] variables.append(Variable('one', 'int', 4)) variables.append(Variable('two', 'bool', 4)) merge = Procedure('merge_proc', 10) merge.add_parameter(Parameter('one1', 'int')) merge.add_parameter(Parameter('two1', 'bool')) merge.add_modifies('two') checker = ComplianceChecker() with pytest.raises(ComplianceError): checker.check_merge(merge, variables)
def test_check_invariant_different_number_parameters(self): invariant = Function('inv', 2) invariant.parameters = [] invariant.parameters.append(Parameter('t1', 'int')) variables = [] variables.append(Variable('t1','int', 10)) variables.append(Variable('t2','bool', 11)) invariant.returndt = 'bool' checker = ComplianceChecker() with pytest.raises(ComplianceError): checker.check_invariant(invariant, variables)
def test_check_merge_compliant(self): variables = [] variables.append(Variable('one', 'int', 4)) variables.append(Variable('two', 'bool', 4)) merge = Procedure('merge_proc', 10) merge.add_parameter(Parameter('one1', 'int')) merge.add_parameter(Parameter('two1', 'bool')) merge.add_modifies('one') merge.add_modifies('two') checker = ComplianceChecker() assert checker.check_merge(merge, variables) == True
def test_check_gteq_diff_parameter_number_less(self): variables=[] variables.append(Variable('one', 'int', 10)) variables.append(Variable('two', 'TestType', 13)) gteq = Function('gteq', 2) gteq.parameters.append(Parameter('one1', 'int')) gteq.parameters.append(Parameter('one2', 'int')) gteq.returndt = 'bool' checker = ComplianceChecker() with pytest.raises(ComplianceError): checker.check_gteq(gteq, variables)
def test_check_gteq_compliant_gteq(self): variables=[] variables.append(Variable('one', 'int', 10)) variables.append(Variable('two', 'TestType', 13)) gteq = Function('gteq', 2) gteq.parameters.append(Parameter('one1', 'int')) gteq.parameters.append(Parameter('one2', 'int')) gteq.parameters.append(Parameter('two1', 'TestType')) gteq.parameters.append(Parameter('two2', 'TestType')) gteq.returndt = 'bool' checker = ComplianceChecker() assert checker.check_gteq(gteq, variables) == True
def analyze(self, specification_path): if not specification_path: logging.error('Please provide a specification file!') return False if specification_path[specification_path.rindex('.'):].strip().lower( ) != '.spec': logging.error('Specification file needs to have .spec extension.') return False try: spec_file = open(specification_path) spec_name = self.get_specification_name(specification_path) logging.info('************ ' + spec_name + ' ***************') logging.info('Checking the syntax') spec_content = spec_file.readlines() stx_chkr = SyntaxChecker() message = stx_chkr.check(spec_name, spec_content) logging.info('Parsing the specification') parser = Parser() specification = parser.parse(spec_name, spec_content) logging.info('Checking the well-formedness of the specification') compliance_checker = ComplianceChecker() compliance_checker.check(specification) logging.info('Checking convergence') convergence_checker = ConvergenceChecker() convergence_checker.check(specification) logging.info('Checking safety') safety_checker = SafetyChecker() safe, failed = safety_checker.check(specification) if safe: logging.info('The specification is safe!!!') else: #generate tokens here raise Exception # else: # logging.info('starting token generation') # for failure in failed: # #failure is a pair of procedure names which failed stability check # token_generator = TokenGenerator() # tokens = token_generator.generate_tokens(specification, failed) # logging.info('The tokens are as follows ::\n' + token_generator.convert_to_text(tokens)) # if tokens: # logging.info('The possible token(s) for ensuring stability of ' + failure[0].name + ' and ' +failure[1].name +' ::\n' + str(tokens)+ '\n') # else: # logging.info('Not able to determine a token for the stability of ' + failure[0].name + ' and ' +failure[1].name) except Exception as e: logging.error(str(e) + '\n') return False return True
def test_check_check_invariant_called(self, mock): checker = ComplianceChecker() spec = self.get_compliant_spec() checker.check(spec) assert mock.called == True
def test_check_invariant_invariant_not_defined(self): invariant = None variables = [] checker = ComplianceChecker() with pytest.raises(ComplianceError): checker.check_invariant(invariant, variables)
def test_check_merge_merge_not_defined(self): variables = [] merge = '' checker = ComplianceChecker() with pytest.raises(ComplianceError): checker.check_merge(merge, variables)