ct_common
1.0.1
Common library for combinatorial testing
|
00001 #include <iostream> 00002 #include <fstream> 00003 #include <map> 00004 00005 #include <ct_common/file_parse/ct_lexer.hpp> 00006 #include <ct_common/file_parse/ct_parser.tab.hpp> 00007 #include <ct_common/file_parse/assembler.h> 00008 #include <ct_common/file_parse/err_logger_cerr.h> 00009 #include <ct_common/common/sutmodel.h> 00010 #include <ct_common/common/tuplepool.h> 00011 00012 using namespace ct; 00013 using namespace ct::common; 00014 00015 int main(int argc, char* argv[]) { 00016 std::string file_name; 00017 if (argc < 2) { 00018 std::cerr << "please specify the file name" << std::endl; 00019 return 1; 00020 } 00021 file_name = argv[1]; 00022 std::ifstream infile; 00023 #ifdef _MSC_VER 00024 // handling file names with non-ascii characters 00025 wchar_t *wcstring = new wchar_t[file_name.size()+1]; 00026 setlocale(LC_ALL, ".OCP"); 00027 mbstowcs(wcstring, file_name.c_str(), file_name.size()+1); 00028 infile.open(wcstring); 00029 delete[] wcstring; 00030 setlocale(LC_ALL, ""); 00031 #else // _MSC_VER 00032 infile.open(file_name.c_str()); 00033 #endif // _MSC_VER 00034 if (!infile.is_open()) { 00035 std::cerr << "cannot open the input file" << std::endl; 00036 return 1; 00037 } 00038 SUTModel sut_model; 00039 Assembler assembler; 00040 try { 00041 ct::lexer lexer(&infile); 00042 assembler.setErrLogger(boost::shared_ptr<ErrLogger>(new ErrLogger_Cerr())); 00043 yy::ct_parser parser(lexer, 00044 sut_model.param_specs_, 00045 sut_model.strengths_, 00046 sut_model.seeds_, 00047 sut_model.constraints_, 00048 assembler); 00049 parser.parse(); 00050 } catch (std::runtime_error e) { 00051 std::cerr << e.what() << std::endl; 00052 } catch (...) { 00053 std::cerr << "unhandled exception when parsing input file" << std::endl; 00054 std::cerr << "exiting" << std::endl; 00055 return 1; 00056 } 00057 if (assembler.numErrs() > 0) { 00058 std::cerr << assembler.numErrs() << " errors in the input file, exiting" << std::endl; 00059 return 2; 00060 } 00061 std::cout << "successfully parsed the input file" << std::endl; 00062 std::cout << "# parameters: " << sut_model.param_specs_.size() << std::endl; 00063 std::cout << "# strengths: " << sut_model.strengths_.size() << std::endl; 00064 std::cout << "# seeds: " << sut_model.seeds_.size() << std::endl; 00065 std::cout << "# constraints: " << sut_model.constraints_.size() << std::endl; 00066 00067 std::vector<RawStrength> raw_strengths; 00068 TuplePool tuple_pool; 00069 for (std::size_t i = 0; i < sut_model.strengths_.size(); ++i) { 00070 attach_2_raw_strength(sut_model.strengths_[i], raw_strengths); 00071 } 00072 for (std::size_t i = 0; i < raw_strengths.size(); ++i) { 00073 Tuple tuple; 00074 for (std::size_t j = 0; j < raw_strengths[i].size(); ++j) { 00075 tuple.push_back(PVPair(raw_strengths[i][j], 0)); 00076 } 00077 if (tuple.size() <= 0) { 00078 continue; 00079 } 00080 do { 00081 tuple_pool.add(tuple); 00082 } while (tuple.to_the_next_tuple(sut_model.param_specs_)); 00083 } 00084 std::cout << "# target combinations: " << tuple_pool.size() << std::endl; 00085 00086 TuplePool forbidden_tuple_pool; 00087 for (std::size_t i = 0; i < sut_model.constraints_.size(); ++i) { 00088 std::set<std::size_t> rel_pids; 00089 sut_model.constraints_[i]->touch_pids(sut_model.param_specs_, rel_pids); 00090 Tuple tuple; 00091 for (std::set<std::size_t>::const_iterator iter = rel_pids.begin(); iter != rel_pids.end(); iter++) { 00092 tuple.push_back(PVPair(*iter, 0)); 00093 } 00094 do { 00095 EvalType_Bool result = sut_model.constraints_[i]->Evaluate(sut_model.param_specs_, tuple); 00096 if (!result.is_valid_ || !result.value_) { 00097 forbidden_tuple_pool.add(tuple); 00098 } 00099 } while (tuple.to_the_next_tuple_with_ivld(sut_model.param_specs_)); 00100 } 00101 std::cout << "# forbidden combinations: " << forbidden_tuple_pool.size() << std::endl; 00102 return 0; 00103 }