From 24e3de124af4025d151a0b2775c6c3c04299de4b Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Thu, 28 Aug 2014 20:21:17 +0200 Subject: Create default timeouts for tests and adapt in test-w3c via DOM --- src/uscxml/Interpreter.cpp | 5 +- test/src/test-w3c.cpp | 201 +++++++++++++++++--------------------------- test/w3c/confEcma.xsl | 6 +- test/w3c/ecma/test175.scxml | 4 +- test/w3c/ecma/test185.scxml | 2 +- test/w3c/ecma/test186.scxml | 2 +- test/w3c/ecma/test187.scxml | 4 +- test/w3c/ecma/test207.scxml | 6 +- test/w3c/ecma/test208.scxml | 4 +- test/w3c/ecma/test210.scxml | 4 +- test/w3c/ecma/test236.scxml | 2 +- test/w3c/ecma/test237.scxml | 6 +- test/w3c/ecma/test252.scxml | 4 +- test/w3c/ecma/test409.scxml | 2 +- test/w3c/ecma/test422.scxml | 2 +- test/w3c/ecma/test423.scxml | 2 +- test/w3c/ecma/test553.scxml | 2 +- test/w3c/ecma/test554.scxml | 2 +- test/w3c/ecma/test579.scxml | 2 +- test/w3c/update-txml.sh | 7 +- 20 files changed, 112 insertions(+), 157 deletions(-) diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index e10a343..72bbfdb 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -1701,8 +1701,7 @@ void InterpreterImpl::send(const Arabica::DOM::Element& element) { if (iequals(delayAttr.unit, "ms")) { sendReq.delayMs = strTo(delayAttr.value); } else if (iequals(delayAttr.unit, "s")) { - sendReq.delayMs = strTo(delayAttr.value); - sendReq.delayMs *= 1000; + sendReq.delayMs = strTo(delayAttr.value) * 1000; } else { LOG(ERROR) << "Cannot make sense of delay value " << delay << ": does not end in 's' or 'ms'"; } @@ -1711,7 +1710,7 @@ void InterpreterImpl::send(const Arabica::DOM::Element& element) { LOG(ERROR) << "Syntax error in send element " << DOMUtils::xPathForNode(element) << " delayexpr:" << std::endl << e << std::endl; return; } - + try { // namelist if (HAS_ATTR(element, "namelist")) { diff --git a/test/src/test-w3c.cpp b/test/src/test-w3c.cpp index 0ff67df..a03eab7 100644 --- a/test/src/test-w3c.cpp +++ b/test/src/test-w3c.cpp @@ -13,88 +13,14 @@ #include #endif -#ifdef HAS_EXECINFO_H -#include -#endif - -#ifdef HAS_DLFCN_H -#include -#endif - #ifdef _WIN32 #include "XGetopt.h" #endif static bool withFlattening = false; +static double delayFactor = 1; static std::string documentURI; -#ifdef HAS_EXECINFO_H -void printBacktrace(void** array, int size) { - char** messages = backtrace_symbols(array, size); - for (int i = 0; i < size && messages != NULL; ++i) { - std::cerr << "\t" << messages[i] << std::endl; - } - std::cerr << std::endl; - free(messages); -} - -#ifdef HAS_DLFCN_H -#if 0 // deactivated as we use exceptions to signal errors now -// see https://gist.github.com/nkuln/2020860 -typedef void (*cxa_throw_type)(void *, void *, void (*) (void *)); -cxa_throw_type orig_cxa_throw = 0; - -void load_orig_throw_code() { - orig_cxa_throw = (cxa_throw_type) dlsym(RTLD_NEXT, "__cxa_throw"); -} - -extern "C" -void __cxa_throw (void *thrown_exception, void *pvtinfo, void (*dest)(void *)) { - std::cerr << __FUNCTION__ << " will throw exception from " << std::endl; - if (orig_cxa_throw == 0) - load_orig_throw_code(); - - void *array[50]; - size_t size = backtrace(array, 50); - printBacktrace(array, size); - orig_cxa_throw(thrown_exception, pvtinfo, dest); -} -#endif -#endif -#endif - - -// see http://stackoverflow.com/questions/2443135/how-do-i-find-where-an-exception-was-thrown-in-c -void customTerminate() { - static bool tried_throw = false; - try { - // try once to re-throw currently active exception - if (!tried_throw) { - throw; - tried_throw = true; - } else { - tried_throw = false; - }; - } catch (const std::exception &e) { - std::cerr << __FUNCTION__ << " caught unhandled exception. what(): " - << e.what() << std::endl; - } catch (const uscxml::Event &e) { - std::cerr << __FUNCTION__ << " caught unhandled exception. Event: " - << e << std::endl; - } catch (...) { - std::cerr << __FUNCTION__ << " caught unknown/unhandled exception." - << std::endl; - } - -#ifdef HAS_EXECINFO_H - void * array[50]; - int size = backtrace(array, 50); - - printBacktrace(array, size); -#endif - abort(); -} - int retCode = EXIT_FAILURE; class W3CStatusMonitor : public uscxml::InterpreterMonitor { @@ -170,62 +96,93 @@ class W3CStatusMonitor : public uscxml::InterpreterMonitor { int main(int argc, char** argv) { using namespace uscxml; - std::set_terminate(customTerminate); - -#if defined(HAS_SIGNAL_H) && !defined(WIN32) - signal(SIGPIPE, SIG_IGN); -#endif + try { + + #if defined(HAS_SIGNAL_H) && !defined(WIN32) + signal(SIGPIPE, SIG_IGN); + #endif - if (argc < 2) { - exit(EXIT_FAILURE); - } + if (argc < 2) { + exit(EXIT_FAILURE); + } - HTTPServer::getInstance(32954, 32955, NULL); // bind to some random tcp sockets for ioprocessor tests + HTTPServer::getInstance(32954, 32955, NULL); // bind to some random tcp sockets for ioprocessor tests - google::InitGoogleLogging(argv[0]); - google::LogToStderr(); + google::InitGoogleLogging(argv[0]); + google::LogToStderr(); + char* dfEnv = getenv("USCXML_DELAY_FACTOR"); + if (dfEnv) { + delayFactor = strTo(dfEnv); + } + + int option; + while ((option = getopt(argc, argv, "fd:")) != -1) { + switch(option) { + case 'f': + withFlattening = true; + break; + case 'd': + delayFactor = strTo(optarg); + break; + default: + break; + } + } - for (int i = 1; i < argc; i++) { - if (std::string(argv[i]) == "-f") { - withFlattening = true; + documentURI = argv[optind]; + + Interpreter interpreter; + LOG(INFO) << "Processing " << documentURI << (withFlattening ? " FSM converted" : "") << (delayFactor ? "" : " with delays *= " + toStr(delayFactor)); + if (withFlattening) { + Interpreter flatInterpreter = Interpreter::fromURI(documentURI); + interpreter = Interpreter::fromDOM(ChartToFSM::flatten(flatInterpreter).getDocument(), flatInterpreter.getNameSpaceInfo()); + interpreter.setSourceURI(flatInterpreter.getSourceURI()); } else { - documentURI = argv[i]; + interpreter = Interpreter::fromURI(documentURI); } - } - - Interpreter interpreter; - LOG(INFO) << "Processing " << documentURI << (withFlattening ? " FSM converted" : ""); - if (withFlattening) { - Interpreter flatInterpreter = Interpreter::fromURI(documentURI); - interpreter = Interpreter::fromDOM(ChartToFSM::flatten(flatInterpreter).getDocument(), flatInterpreter.getNameSpaceInfo()); - interpreter.setSourceURI(flatInterpreter.getSourceURI()); - } else { - interpreter = Interpreter::fromURI(documentURI); - } - if (interpreter) { -// std::list issues = interpreter.validate(); -// if (issues.size() > 0) { -// for (std::list::iterator issueIter = issues.begin(); issueIter != issues.end(); issueIter++) { -// std::cout << *issueIter << std::endl; -// } -// exit(EXIT_FAILURE); -// } - -// interpreter.setCmdLineOptions(argc, argv); -// interpreter->setCapabilities(Interpreter::CAN_NOTHING); -// interpreter->setCapabilities(Interpreter::CAN_BASIC_HTTP | Interpreter::CAN_GENERIC_HTTP); - - W3CStatusMonitor* vm = new W3CStatusMonitor(); - interpreter.addMonitor(vm); - -// if (interpreter.getDataModel().getNames().find("ecmascript") != interpreter.getDataModel().getNames().end()) { -// } + if (delayFactor != 1) { + Arabica::DOM::Document document = interpreter.getDocument(); + Arabica::DOM::Element root = document.getDocumentElement(); + Arabica::XPath::NodeSet sends = InterpreterImpl::filterChildElements(interpreter.getNameSpaceInfo().xmlNSPrefix + "send", root, true); + + for (int i = 0; i < sends.size(); i++) { + Arabica::DOM::Element send = Arabica::DOM::Element(sends[i]); + if (HAS_ATTR(send, "delay")) { + NumAttr delay(ATTR(send, "delay")); + int value = strTo(delay.value); + if (delay.unit == "s") + value *= 1000; + value *= delayFactor; + send.setAttribute("delay", toStr(value) + "ms"); + std::cout << ATTR(send, "delay") << std::endl; + } else if (HAS_ATTR(send, "delayexpr")) { + std::string delayExpr = ATTR(send, "delayexpr"); + send.setAttribute("delayexpr", + "(" + delayExpr + ".indexOf('ms', " + delayExpr + ".length - 2) !== -1 ? " + "(" + delayExpr + ".slice(0,-2) * " + toStr(delayFactor) + ") + \"ms\" : " + "(" + delayExpr + ".slice(0,-1) * 1000 * " + toStr(delayFactor) + ") + \"ms\")"); + std::cout << ATTR(send, "delayexpr") << std::endl; + } + } + std::list issues = interpreter.validate(); + for (std::list::iterator issueIter = issues.begin(); issueIter != issues.end(); issueIter++) { + std::cout << *issueIter << std::endl; + } + } + + if (interpreter) { + W3CStatusMonitor* vm = new W3CStatusMonitor(); + interpreter.addMonitor(vm); - interpreter.start(); - while(interpreter.runOnMainThread(25)); + interpreter.start(); + while(interpreter.runOnMainThread(25)); + } + } catch(Event e) { + std::cout << e << std::endl; + } catch(std::exception e) { + std::cout << e.what() << std::endl; } - return retCode; } \ No newline at end of file diff --git a/test/w3c/confEcma.xsl b/test/w3c/confEcma.xsl index 41a8129..705785d 100644 --- a/test/w3c/confEcma.xsl +++ b/test/w3c/confEcma.xsl @@ -244,13 +244,13 @@ - (Var.slice(0, - 1)) * 50 + 'ms' + Var - 'ms' + 's' @@ -745,4 +745,4 @@ it allows anything after the = --> _event.raw.match(/\n\naddress=(.*)$/) - + \ No newline at end of file diff --git a/test/w3c/ecma/test175.scxml b/test/w3c/ecma/test175.scxml index 1ec619f..6c69a25 100644 --- a/test/w3c/ecma/test175.scxml +++ b/test/w3c/ecma/test175.scxml @@ -9,8 +9,8 @@ event1 will be raised first. Succeed if event1 occurs before event2, otherwise - - + + diff --git a/test/w3c/ecma/test185.scxml b/test/w3c/ecma/test185.scxml index 7e4c408..46bb4eb 100644 --- a/test/w3c/ecma/test185.scxml +++ b/test/w3c/ecma/test185.scxml @@ -4,7 +4,7 @@ - + diff --git a/test/w3c/ecma/test186.scxml b/test/w3c/ecma/test186.scxml index ef42d18..74d7a1a 100644 --- a/test/w3c/ecma/test186.scxml +++ b/test/w3c/ecma/test186.scxml @@ -9,7 +9,7 @@ in the interval.) If var2 ends up == 1, we pass. Otherwise we fail --> - + diff --git a/test/w3c/ecma/test187.scxml b/test/w3c/ecma/test187.scxml index 06b08a2..59b16ba 100644 --- a/test/w3c/ecma/test187.scxml +++ b/test/w3c/ecma/test187.scxml @@ -6,7 +6,7 @@ parent session, should not receive childToParent. If it does, we fail. Otherwis - + @@ -14,7 +14,7 @@ parent session, should not receive childToParent. If it does, we fail. Otherwis - + diff --git a/test/w3c/ecma/test207.scxml b/test/w3c/ecma/test207.scxml index 5b89697..a482e58 100644 --- a/test/w3c/ecma/test207.scxml +++ b/test/w3c/ecma/test207.scxml @@ -6,7 +6,7 @@ raised in another session, but the spec doesn't define any way to refer to an ev - + @@ -16,8 +16,8 @@ raised in another session, but the spec doesn't define any way to refer to an ev - - + + diff --git a/test/w3c/ecma/test208.scxml b/test/w3c/ecma/test208.scxml index ed0de3e..5aba798 100644 --- a/test/w3c/ecma/test208.scxml +++ b/test/w3c/ecma/test208.scxml @@ -4,8 +4,8 @@ we get event1 or an error first, cancel didn't work and we fail. --> - - + + diff --git a/test/w3c/ecma/test210.scxml b/test/w3c/ecma/test210.scxml index 15d892d..146cbc8 100644 --- a/test/w3c/ecma/test210.scxml +++ b/test/w3c/ecma/test210.scxml @@ -7,8 +7,8 @@ delayed event1. Thus we get event2 first and pass. If we get event1 or an erro - - + + diff --git a/test/w3c/ecma/test236.scxml b/test/w3c/ecma/test236.scxml index 2907f36..7fb258b 100644 --- a/test/w3c/ecma/test236.scxml +++ b/test/w3c/ecma/test236.scxml @@ -5,7 +5,7 @@ events after the done.invoke. Hence timeout indicates success --> - + diff --git a/test/w3c/ecma/test237.scxml b/test/w3c/ecma/test237.scxml index 5453e33..cd54a86 100644 --- a/test/w3c/ecma/test237.scxml +++ b/test/w3c/ecma/test237.scxml @@ -6,7 +6,7 @@ the time timeout2 fires, success --> - + @@ -14,7 +14,7 @@ the time timeout2 fires, success --> - + @@ -26,7 +26,7 @@ the time timeout2 fires, success --> - + diff --git a/test/w3c/ecma/test252.scxml b/test/w3c/ecma/test252.scxml index 4bdf7e7..78c9315 100644 --- a/test/w3c/ecma/test252.scxml +++ b/test/w3c/ecma/test252.scxml @@ -5,7 +5,7 @@ timeout indicates success. --> - + @@ -19,7 +19,7 @@ timeout indicates success. --> - + diff --git a/test/w3c/ecma/test409.scxml b/test/w3c/ecma/test409.scxml index 5cb5865..325d01c 100644 --- a/test/w3c/ecma/test409.scxml +++ b/test/w3c/ecma/test409.scxml @@ -5,7 +5,7 @@ be raised. Therefore the timeout should fire to indicate success --> - + diff --git a/test/w3c/ecma/test422.scxml b/test/w3c/ecma/test422.scxml index 91ba18d..383dd1b 100644 --- a/test/w3c/ecma/test422.scxml +++ b/test/w3c/ecma/test422.scxml @@ -12,7 +12,7 @@ in s11. So we should receive invokeS1, invokeS12, but not invokeS12. Furthermor - + diff --git a/test/w3c/ecma/test423.scxml b/test/w3c/ecma/test423.scxml index 3fc15d3..9726441 100644 --- a/test/w3c/ecma/test423.scxml +++ b/test/w3c/ecma/test423.scxml @@ -4,7 +4,7 @@ - + diff --git a/test/w3c/ecma/test553.scxml b/test/w3c/ecma/test553.scxml index 8ccfd5a..302caca 100644 --- a/test/w3c/ecma/test553.scxml +++ b/test/w3c/ecma/test553.scxml @@ -5,7 +5,7 @@ of 's args causes an error.. --> - + diff --git a/test/w3c/ecma/test554.scxml b/test/w3c/ecma/test554.scxml index 7ef3597..e7dde01 100644 --- a/test/w3c/ecma/test554.scxml +++ b/test/w3c/ecma/test554.scxml @@ -5,7 +5,7 @@ before the timer goes off. --> - + diff --git a/test/w3c/ecma/test579.scxml b/test/w3c/ecma/test579.scxml index dbf7dc1..165b990 100644 --- a/test/w3c/ecma/test579.scxml +++ b/test/w3c/ecma/test579.scxml @@ -14,7 +14,7 @@ parent state has been visited and exited, the default history content must not b - + diff --git a/test/w3c/update-txml.sh b/test/w3c/update-txml.sh index 9fa2c99..4a6f7fd 100755 --- a/test/w3c/update-txml.sh +++ b/test/w3c/update-txml.sh @@ -11,7 +11,6 @@ find ./www.w3.org -name "*.txt" -exec cp {} ./txml \; find ./www.w3.org -name "*.xsl" -exec cp {} . \; rm -rf www.w3.org -sed -ie "s/Var<\/xsl:attribute>/(Var.slice(0, - 1)) * 50 + 'ms'<\/xsl:attribute>/" confEcma.xsl -sed -ie "s/'s'<\/xsl:attribute>/'ms'<\/xsl:attribute>/" confEcma.xsl - -rm confEcma.xsle +# sed -ie "s/Var<\/xsl:attribute>/(Var.slice(0, - 1)) * 50 + 'ms'<\/xsl:attribute>/" confEcma.xsl +# sed -ie "s/'s'<\/xsl:attribute>/'ms'<\/xsl:attribute>/" confEcma.xsl +#rm confEcma.xsle -- cgit v0.12