string BEXMLTextReader::raw_xml() { xmlBufferPtr node_content = xmlBufferCreate(); xmlOutputBufferPtr node = (xmlOutputBufferPtr) xmlMalloc ( sizeof(xmlOutputBuffer) ); memset ( node, 0, (size_t) sizeof(xmlOutputBuffer) ); node->buffer = node_content; xmlNodeDumpOutput ( node, xml_document, xmlTextReaderCurrentNode ( reader ), 0, true, "UTF-8" ); const xmlChar * xml_data = xmlBufferContent ( (xmlBufferPtr)node_content ); size_t xml_length = xmlBufferLength ( node_content ); string xml_result ( (char *)xml_data, xml_length ); xmlFree ( (xmlChar *)xml_data ); return xml_result; } // raw_xml
void symex_parseoptionst::report_properties( const path_searcht::property_mapt &property_map) { for(path_searcht::property_mapt::const_iterator it=property_map.begin(); it!=property_map.end(); it++) { if(get_ui()==ui_message_handlert::XML_UI) { xmlt xml_result("result"); xml_result.set_attribute("claim", id2string(it->first)); std::string status_string; switch(it->second.status) { case path_searcht::PASS: status_string="OK"; break; case path_searcht::FAIL: status_string="FAILURE"; break; case path_searcht::NOT_REACHED: status_string="OK"; break; } xml_result.set_attribute("status", status_string); std::cout << xml_result << "\n"; } else { status() << "[" << it->first << "] " << it->second.description << ": "; switch(it->second.status) { case path_searcht::PASS: status() << "OK"; break; case path_searcht::FAIL: status() << "FAILED"; break; case path_searcht::NOT_REACHED: status() << "OK"; break; } status() << eom; } if(cmdline.isset("show-trace") && it->second.status==path_searcht::FAIL) show_counterexample(it->second.error_trace); } if(!cmdline.isset("property")) { status() << eom; unsigned failed=0; for(path_searcht::property_mapt::const_iterator it=property_map.begin(); it!=property_map.end(); it++) if(it->second.status==path_searcht::FAIL) failed++; status() << "** " << failed << " of " << property_map.size() << " failed" << eom; } }
int freesasa_write_xml(FILE *output, freesasa_node *root, int options) { freesasa_node *child = NULL; xmlDocPtr doc = NULL; xmlNodePtr xml_root = NULL, xml_result_node = NULL; xmlNsPtr ns = NULL; xmlBufferPtr buf = NULL; xmlTextWriterPtr writer = NULL; int ret = FREESASA_FAIL; assert(freesasa_node_type(root) == FREESASA_NODE_ROOT); doc = xmlNewDoc(BAD_CAST "1.0"); if (doc == NULL) { fail_msg(""); goto cleanup; } xml_root = xmlNewNode(NULL, BAD_CAST "results"); if (xml_root == NULL) { fail_msg(""); goto cleanup; } ns = xmlNewNs(xml_root, BAD_CAST FREESASA_XMLNS, NULL); if (ns == NULL) { fail_msg(""); xmlFreeNode(xml_root); goto cleanup; } xmlDocSetRootElement(doc, xml_root); /* global attributes */ if (xmlNewProp(xml_root, BAD_CAST "source", BAD_CAST freesasa_string) == NULL) { fail_msg(""); goto cleanup; } if (xmlNewProp(xml_root, BAD_CAST "lengthUnit", BAD_CAST "Ångström") == NULL) { fail_msg(""); goto cleanup; } child = freesasa_node_children(root); while (child) { xml_result_node = xml_result(child, options); if (xml_result_node == NULL) { fail_msg(""); goto cleanup; } if (xmlAddChild(xml_root, xml_result_node) == NULL) { fail_msg(""); xmlFreeNode(xml_result_node); goto cleanup; } child = freesasa_node_next(child); } buf = xmlBufferCreate(); if (buf == NULL) { fail_msg(""); goto cleanup; } writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { xmlBufferFree(buf); fail_msg(""); goto cleanup; } if (xmlTextWriterStartDocument(writer, XML_DEFAULT_VERSION, xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF8), NULL) == -1) { fail_msg(""); goto cleanup; } if (xmlTextWriterFlush(writer) == -1) { fail_msg(""); goto cleanup; } if (xmlNodeDump(buf, doc, xml_root, 0, 1) == 0) { fail_msg(""); goto cleanup; } if (xmlTextWriterEndDocument(writer) == -1) { fail_msg(""); goto cleanup; } fprintf(output, "%s", (const char*) buf->content); fflush(output); if (ferror(output)) { fail_msg(strerror(errno)); goto cleanup; } ret = FREESASA_SUCCESS; cleanup: xmlFreeDoc(doc); xmlFreeTextWriter(writer); return ret; }
void symex_parse_optionst::report_cover( const path_searcht::property_mapt &property_map) { // report unsigned goals_covered=0; for(const auto &prop_pair : property_map) if(prop_pair.second.is_failure()) goals_covered++; switch(get_ui()) { case ui_message_handlert::uit::PLAIN: { status() << "\n** coverage results:" << eom; for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; status() << "[" << prop_pair.first << "]"; if(property.source_location.is_not_nil()) status() << ' ' << property.source_location; if(!property.description.empty()) status() << ' ' << property.description; status() << ": " << (property.is_failure()?"SATISFIED":"FAILED") << eom; } status() << '\n'; break; } case ui_message_handlert::uit::XML_UI: { for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; xmlt xml_result("result"); xml_result.set_attribute("goal", id2string(prop_pair.first)); xml_result.set_attribute( "description", id2string(property.description)); xml_result.set_attribute( "status", property.is_failure()?"SATISFIED":"FAILED"); if(property.source_location.is_not_nil()) xml_result.new_element()=xml(property.source_location); if(property.is_failure()) { const namespacet ns(goto_model.symbol_table); if(cmdline.isset("trace")) { convert(ns, property.error_trace, xml_result.new_element()); } else { xmlt &xml_test=xml_result.new_element("test"); for(const auto &step : property.error_trace.steps) { if(step.is_input()) { xmlt &xml_input=xml_test.new_element("input"); xml_input.set_attribute("id", id2string(step.io_id)); if(step.io_args.size()==1) xml_input.new_element("value")= xml(step.io_args.front(), ns); } } } } std::cout << xml_result << "\n"; } break; } case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["results"].make_array(); for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; json_objectt &result=result_array.push_back().make_object(); result["status"]= json_stringt(property.is_failure()?"satisfied":"failed"); result["goal"]=json_stringt(id2string(prop_pair.first)); result["description"]=json_stringt(id2string(property.description)); if(property.source_location.is_not_nil()) result["sourceLocation"]=json(property.source_location); if(property.is_failure()) { const namespacet ns(goto_model.symbol_table); if(cmdline.isset("trace")) { jsont &json_trace=result["trace"]; convert(ns, property.error_trace, json_trace); } else { json_arrayt &json_test=result["test"].make_array(); for(const auto &step : property.error_trace.steps) { if(step.is_input()) { json_objectt json_input; json_input["id"]=json_stringt(id2string(step.io_id)); if(step.io_args.size()==1) json_input["value"]=json(step.io_args.front(), ns); json_test.push_back(json_input); } } } } } json_result["totalGoals"]= json_numbert(std::to_string(property_map.size())); json_result["goalsCovered"]=json_numbert(std::to_string(goals_covered)); std::cout << ",\n" << json_result; break; } } status() << "** " << goals_covered << " of " << property_map.size() << " covered (" << std::fixed << std::setw(1) << std::setprecision(1) << (property_map.empty()? 100.0:100.0*goals_covered/property_map.size()) << "%)" << eom; if(get_ui()==ui_message_handlert::uit::PLAIN) { std::set<std::string> tests; for(const auto &prop_pair : property_map) if(prop_pair.second.is_failure()) tests.insert(get_test(prop_pair.second.error_trace)); std::cout << "Test suite:" << '\n'; for(const auto &t : tests) std::cout << t << '\n'; } }
void bmc_all_propertiest::report(const cover_goalst &cover_goals) { switch(bmc.ui) { case ui_message_handlert::uit::PLAIN: { status() << "\n** Results:" << eom; for(const auto &goal_pair : goal_map) status() << "[" << goal_pair.first << "] " << goal_pair.second.description << ": " << goal_pair.second.status_string() << eom; if(bmc.options.get_bool_option("trace")) { for(const auto &g : goal_map) if(g.second.status==goalt::statust::FAILURE) { std::cout << "\n" << "Trace for " << g.first << ":" << "\n"; show_goto_trace(std::cout, bmc.ns, g.second.goto_trace); } } status() << "\n** " << cover_goals.number_covered() << " of " << cover_goals.size() << " failed (" << cover_goals.iterations() << " iteration" << (cover_goals.iterations()==1?"":"s") << ")" << eom; } break; case ui_message_handlert::uit::XML_UI: { for(const auto &g : goal_map) { xmlt xml_result("result"); xml_result.set_attribute("property", id2string(g.first)); xml_result.set_attribute("status", g.second.status_string()); if(g.second.status==goalt::statust::FAILURE) convert(bmc.ns, g.second.goto_trace, xml_result.new_element()); std::cout << xml_result << "\n"; } break; } case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["result"].make_array(); for(const auto &g : goal_map) { json_objectt &result=result_array.push_back().make_object(); result["property"]=json_stringt(id2string(g.first)); result["description"]=json_stringt(id2string(g.second.description)); result["status"]=json_stringt(g.second.status_string()); if(g.second.status==goalt::statust::FAILURE) { jsont &json_trace=result["trace"]; convert(bmc.ns, g.second.goto_trace, json_trace); } } std::cout << ",\n" << json_result; } break; } }