Esempio n. 1
0
void printAsserts(Analyzer& analyzer, SgProject* sageProject) {
  if(boolOptions["rers-binary"]) {
	for(int i=0;i<62;i++) {
	  cout << "assert: error_"<<i<<": ";
	  if(analyzer.binaryBindingAssert[i]) {
		cout << color("green")<<"YES (REACHABLE)"<<color("normal");
	  } else {
		cout << color("cyan")<<"NO (UNREACHABLE)"<<color("normal");
	  }
	  cout << endl;
	}
	return;
  }
  LabelSet lset=analyzer.getTransitionGraph()->labelSetOfIoOperations(InputOutput::FAILED_ASSERT);
  list<pair<SgLabelStatement*,SgNode*> > assertNodes=analyzer.listOfLabeledAssertNodes(sageProject);
  for(list<pair<SgLabelStatement*,SgNode*> >::iterator i=assertNodes.begin();i!=assertNodes.end();++i) {
	cout << "assert: "
		 << SgNodeHelper::getLabelName((*i).first)
	  //	 << SgNodeHelper::nodeToString((*i).second)<< " : "
	  ;
	cout << ": ";
	Label lab=analyzer.getLabeler()->getLabel((*i).second);
	if(lset.find(lab)!=lset.end()) {
	  cout << color("green")<<"YES (REACHABLE)"<<color("normal");
	}
	else {
	  cout << color("cyan")<<"NO (UNREACHABLE)"<<color("normal");
	}
	cout << endl;
  }
}
Esempio n. 2
0
void printAssertStatistics(Analyzer& analyzer, SgProject* sageProject) {
  LabelSet lset=analyzer.getTransitionGraph()->labelSetOfIoOperations(InputOutput::FAILED_ASSERT);
  list<pair<SgLabelStatement*,SgNode*> > assertNodes=analyzer.listOfLabeledAssertNodes(sageProject);
  int reachable=0;
  int unreachable=0;
  for(list<pair<SgLabelStatement*,SgNode*> >::iterator i=assertNodes.begin();i!=assertNodes.end();++i) {
	Label lab=analyzer.getLabeler()->getLabel((*i).second);
	if(lset.find(lab)!=lset.end())
	  reachable++;
	else
	  unreachable++;
  }
  int n=assertNodes.size();
  assert(reachable+unreachable == n);

  if(boolOptions["rers-binary"]) {
	reachable=0;
	unreachable=0;
	for(int i=0;i<62;i++) {
	  if(analyzer.binaryBindingAssert[i])
		reachable++;
	  else
		unreachable++;
	}
  }
  cout<<"Assert reachability statistics: "
	  <<color("normal")<<"YES: "<<color("green")<<reachable
	  <<color("normal")<<", NO: " <<color("cyan")<<unreachable
	  <<color("normal")<<", TOTAL: " <<n
	  <<endl
	;
}
Esempio n. 3
0
void generateAssertsCsvFile(Analyzer& analyzer, SgProject* sageProject, string filename) {
  ofstream* csv = NULL;
  csv = new ofstream();
  // use binary and \r\n tp enforce DOS line endings
  // http://tools.ietf.org/html/rfc4180
  csv->open(filename.c_str(), ios::trunc|ios::binary);
  //*csv << "Index;\"Assert Error Label\";ReachabilityResult;Confidence\r\n";
  
  LabelSet lset=analyzer.getTransitionGraph()->labelSetOfIoOperations(InputOutput::FAILED_ASSERT);
  list<pair<SgLabelStatement*,SgNode*> > assertNodes=analyzer.listOfLabeledAssertNodes(sageProject);
  if(boolOptions["rers-binary"]) {
	for(int i=0;i<62;i++) {
	  *csv << i<<",";
	  if(analyzer.binaryBindingAssert[i]) {
		*csv << "yes,9";
	  } else {
		*csv << "no,9";
	  }
	  *csv << "\n";
	}
  } else {
	for(list<pair<SgLabelStatement*,SgNode*> >::iterator i=assertNodes.begin();i!=assertNodes.end();++i) {
	  string name=SgNodeHelper::getLabelName((*i).first);
	  if(name=="globalError")
		name="error_60";
	  name=name.substr(6,name.size()-6);
	  *csv << name
		   <<","
		;
	  Label lab=analyzer.getLabeler()->getLabel((*i).second);
	  if(lset.find(lab)!=lset.end()) {
		*csv << "yes,9";
	  } else {
		*csv << "no,9";
	  }
	  *csv << "\n";
	}
  }
  if (csv) delete csv;
}
Esempio n. 4
0
void generateLTLOutput(Analyzer& analyzer, string ltl_file) {
  extern CodeThorn::LTL::Formula* ltl_val;
  //
  // Verification
  //
  int n = 0;
  int n_yes = 0;
  int n_no = 0;
  int n_undecided = 0;
  int n_failed = 0;

  assert(analyzer.getEStateSet());
  assert(analyzer.getTransitionGraph());
  if (ltl_file.size()) {
    CodeThorn::FixpointLTL::Checker* checker1 = 0; 
    CodeThorn::UnifiedLTL::UChecker* checker2 = 0; 
    switch(analyzer.getLTLVerifier()) {
    case 1: 
      checker1 = new CodeThorn::FixpointLTL::Checker(*analyzer.getEStateSet(), 
						     *analyzer.getTransitionGraph());
      break;
    case 2:
      checker2 = new CodeThorn::UnifiedLTL::UChecker(*analyzer.getEStateSet(),
						     *analyzer.getTransitionGraph());
      break;
    default: 
      cerr << "Error: unknown ltl-verifier specified with ltl-verifier option."<<endl;
      exit(1);
    }
    ltl_input = fopen(ltl_file.c_str(), "r");
    if (ltl_input == NULL)
      cerr<<"Error: could not open file "<<ltl_file.c_str()<<endl;
    assert(ltl_input);

    ofstream* csv = NULL;
    if (args.count("csv-ltl")) {
      csv = new ofstream();
      // use binary and \r\n tp enforce DOS line endings
      // http://tools.ietf.org/html/rfc4180
      csv->open(args["csv-ltl"].as<string>().c_str(), ios::trunc|ios::binary);
      //*csv << "Index,\"LTL formula\",Result,Confidence\r\n";
    }

    while ( !ltl_eof) {
      try { 
	ltl_label = 0;
        if (ltl_parse()) {
          cerr<<color("red")<< "Syntax error" <<color("normal")<<endl;
	  ++n;
	  ++n_failed;
	  continue;
        }
        if (ltl_val == NULL) {
	  // empty line
	  continue;
	}
      } catch(const char* s) {
        if (ltl_val) cout<<color("normal")<<string(*ltl_val)<<endl;
        cout<< s<<endl<<color("red")<< "Grammar Error" <<color("normal")<<endl;
	++n;
	++n_failed;
	continue;
      } catch(...) {
	cout<<color("red")<< "Parser exception" << endl;
	++n;
	++n_failed;
	continue;
      }  
	  
      ++n;
      string formula = *ltl_val;
      cout<<endl<<"Verifying formula "<<color("white")<<formula<<color("normal")<<"."<<endl;
      //if (csv) *csv << n <<";\"" <<formula<<"\";";
      if (csv) *csv << n+60 <<",";
      try {
	AType::BoolLattice result;
	if (checker1) result = checker1->verify(*ltl_val);
	if (checker2) result = checker2->verify(*ltl_val);

	if (result.isTrue()) {
	  ++n_yes;
	  cout<<color("green")<<"YES"<<color("normal")<<endl;
	  if (csv) *csv << "yes,9\r\n";
	} else if (result.isFalse()) {
	  ++n_no;
	  cout<<color("cyan")<<"NO"<<color("normal")<<endl;
	  if (csv) *csv << "no,9\r\n";
	} else {
	  ++n_undecided;
	  cout<<color("magenta")<<"UNKNOWN"<<color("normal")<<endl;
	  if (csv) *csv << "unknown,0\r\n";
	}
      } catch(const char* str) {
	++n_failed;
	cerr << "Exception raised: " << str << endl;
	cout<<color("red")<<"ERROR"<<color("normal")<<endl;
	if (csv) *csv << "error,0\r\n";
      } catch(string str) {
	++n_failed;
	cerr << "Exception raised: " << str << endl;
	cout<<color("red")<<"ERROR"<<color("normal")<<endl;
	if (csv) *csv << "error,0\r\n";
      } catch(...) {
	++n_failed;
	cout<<color("red")<<"ERROR"<<color("normal")<<endl;
	if (csv) *csv << "error,0\r\n";
      }  
    }
    fclose(ltl_input);
    if (csv) delete csv;
    if (checker1) delete checker1;
    if (checker2) delete checker2;
    assert(n_yes+n_no+n_undecided+n_failed == n);
    cout<<"\nStatistics "<<endl
        <<"========== "<<endl
	<<n_yes      <<"/"<<n<<color("green")  <<" YES, "       <<color("normal") 	
	<<n_no       <<"/"<<n<<color("cyan")   <<" NO, "        <<color("normal") 	
	<<n_undecided<<"/"<<n<<color("magenta")<<" UNKNOWN, "   <<color("normal") 	
	<<n_failed   <<"/"<<n<<color("red")    <<" ERROR"       <<color("normal") 	
	<<endl;

  } 
}