diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | test/samples/uscxml/test-communication.scxml | 8 | ||||
-rw-r--r-- | test/samples/uscxml/test-java-invoker.scxml | 9 | ||||
-rw-r--r-- | test/samples/uscxml/test-openal.scxml | 154 | ||||
-rw-r--r-- | test/samples/uscxml/test-simplest.scxml | 3 | ||||
-rw-r--r-- | test/src/test-stress.cpp | 183 | ||||
-rw-r--r-- | test/src/test-url.cpp | 19 |
7 files changed, 333 insertions, 48 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 983e179..a78c079 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,6 +33,11 @@ target_link_libraries(test-eventdelay uscxml) add_test(test-eventdelay ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-eventdelay) set_target_properties(test-eventdelay PROPERTIES FOLDER "Tests") +add_executable(test-stress src/test-stress.cpp) +target_link_libraries(test-stress uscxml) +add_test(test-stress ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-stress ${CMAKE_SOURCE_DIR}/test/samples/w3c) +set_target_properties(test-stress PROPERTIES FOLDER "Tests") + if (OFF) add_executable(test-dirmon src/test-dirmon.cpp) target_link_libraries(test-dirmon uscxml) diff --git a/test/samples/uscxml/test-communication.scxml b/test/samples/uscxml/test-communication.scxml index 4811a3f..2cba08e 100644 --- a/test/samples/uscxml/test-communication.scxml +++ b/test/samples/uscxml/test-communication.scxml @@ -1,6 +1,7 @@ <scxml datamodel="ecmascript" initial="start" binding="late" name="foo"> - <state id="start"> - + <script src="http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js" /> + + <state id="start"> <!-- Setup datamodel, print environment and send ourself an event to transition to next state --> <datamodel> @@ -24,6 +25,9 @@ This is some content you got there dude! </send> </onentry> <transition event="transitionToNext" target="step1" cond="_event.data.bar == 'this is the bar data'" /> + <transition event="*" target="final"> + <log label="FAIL!" expr="dump(_event)" /> + </transition> </state> <state id="step1"> <onentry> diff --git a/test/samples/uscxml/test-java-invoker.scxml b/test/samples/uscxml/test-java-invoker.scxml index 97d66c8..a226913 100644 --- a/test/samples/uscxml/test-java-invoker.scxml +++ b/test/samples/uscxml/test-java-invoker.scxml @@ -7,16 +7,17 @@ <script>dump(_event);</script> </finalize> <content> - <foo></foo> - </content> - + </content> </invoke> <transition event="*" target="invokeJSON" /> </state> <state id="invokeJSON"> <invoke type="java"> <content> - <foo></foo> + { + "foo": "bar", + "baz": 12 + } </content> <finalize> <script>dump(_event);</script> diff --git a/test/samples/uscxml/test-openal.scxml b/test/samples/uscxml/test-openal.scxml index 9a1dec0..b17e34b 100644 --- a/test/samples/uscxml/test-openal.scxml +++ b/test/samples/uscxml/test-openal.scxml @@ -1,55 +1,125 @@ <scxml datamodel="ecmascript" name="spatial.audio.test"> <script src="http://uscxml.tk.informatik.tu-darmstadt.de/scripts/dump.js" /> <script> - var bubblesDeg = 0; - var electricDeg = 90; + var audioPos = 0; + var audioURL = "http://uscxml.tk.informatik.tu-darmstadt.de/audio"; </script> - <state id="click.continuously"> - <invoke type="openal" id="audio.id1" /> + <state id="audiotests"> + <invoke type="openal" id="audio" /> <state id="ready"> <onentry> - <send event="spatial-audio.play" delay="1ms" /> + <send event="start" delay="10ms" /> <log expr="'Ready'" /> </onentry> - <transition target="play" event="spatial-audio.play" /> - </state> - <parallel id="play"> - <state id="bubbles"> - <onentry> - <send target="#_audio.id1" event="play" id="bubbles"> - <param name="src" expr="'http://www.talkingwav.com/various/applause.wav'" /> - </send> - </onentry> - </state> - <state id="electric"> - <onentry> - <send target="#_audio.id1" event="play" id="electric"> - <param name="src" expr="'http://www.talkingwav.com/various/aaaaagh.wav'" /> + <transition target="wav" event="spatial-audio.play" /> + <parallel id="start"> + <state id="move.audio"> + <send target="#_audio" event="move.source"> </send> - </onentry> - </state> - <state id="rotate"> - <state id="rotateinner"> - <onentry> - <send event="rotate" delay="1000ms" /> - <send target="#_audio.id1" event="move.source"> - <param name="source" expr="'bubbles'" /> - <param name="circle" expr="bubblesDeg + 'deg'" /> - </send> - <send target="#_audio.id1" event="move.source"> - <param name="source" expr="'electric'" /> - <param name="circle" expr="electricDeg + 'deg'" /> - </send> - <script> - bubblesDeg += 10; - electricDeg += 20; - </script> - </onentry> - <transition event="rotate" type="internal" target="rotateinner" /> </state> - </state> - </parallel> + <state id="play.audio"> + <state id="wav"> + <state id="11025-8bit-wav"> + <onentry> + <log expr="'11025-8bit-wav'" /> + <send target="#_audio" event="play" delay="10ms"><param name="src" expr="audioURL + '/wav/11025-8bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="22050-8bit-wav" /> + </state> + <state id="22050-8bit-wav"> + <onentry> + <log expr="'22050-8bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/22050-8bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="44100-8bit-wav" /> + </state> + <state id="44100-8bit-wav"> + <onentry> + <log expr="'44100-8bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/44100-8bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="11025-16bit-wav" /> + </state> + <state id="11025-16bit-wav"> + <onentry> + <log expr="'11025-16bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/11025-16bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="22050-16bit-wav" /> + </state> + <state id="22050-16bit-wav"> + <onentry> + <log expr="'22050-16bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/22050-16bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="44100-16bit-wav" /> + </state> + <state id="44100-16bit-wav"> + <onentry> + <log expr="'44100-16bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/44100-16bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="11025-24bit-wav" /> + </state> + <state id="11025-24bit-wav"> + <onentry> + <log expr="'11025-24bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/11025-24bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="22050-24bit-wav" /> + </state> + <state id="22050-24bit-wav"> + <onentry> + <log expr="'22050-24bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/22050-24bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="44100-24bit-wav" /> + </state> + <state id="44100-24bit-wav"> + <onentry> + <log expr="'44100-24bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/44100-24bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="11025-32bit-wav" /> + </state> + <state id="11025-32bit-wav"> + <onentry> + <log expr="'11025-32bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/11025-32bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="22050-32bit-wav" /> + </state> + <state id="22050-32bit-wav"> + <onentry> + <log expr="'22050-32bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/22050-32bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="44100-32bit-wav" /> + </state> + <state id="44100-32bit-wav"> + <onentry> + <log expr="'44100-32bit-wav'" /> + <send target="#_audio" event="play"><param name="src" expr="audioURL + '/wav/44100-32bit-mono.wav'" /></send> + </onentry> + <transition event="audio.end" target="final" /> + </state> + </state> + <state id="caf"> + </state> + <state id="flac"> + </state> + <state id="mp3"> + </state> + <state id="ogg"> + </state> + <state id="aiff"> + </state> + </state> + </parallel> + </state> + <transition event="error.*" target="final"> + <log expr="dump(_event);" /> + </transition> </state> - <final id="final" /> </scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/test-simplest.scxml b/test/samples/uscxml/test-simplest.scxml new file mode 100644 index 0000000..8e90e38 --- /dev/null +++ b/test/samples/uscxml/test-simplest.scxml @@ -0,0 +1,3 @@ +<scxml> + <final id="foo" /> +</scxml>
\ No newline at end of file diff --git a/test/src/test-stress.cpp b/test/src/test-stress.cpp new file mode 100644 index 0000000..50b5f34 --- /dev/null +++ b/test/src/test-stress.cpp @@ -0,0 +1,183 @@ +#include "uscxml/config.h" +#include "uscxml/Interpreter.h" +#include <glog/logging.h> + +#include "uscxml/plugins/invoker/filesystem/dirmon/DirMonInvoker.h" + +#ifdef HAS_SIGNAL_H +#include <signal.h> +#endif + +#ifdef HAS_EXECINFO_H +#include <execinfo.h> +#endif + +#ifdef HAS_DLFCN_H +#include <dlfcn.h> +#endif + +#ifdef _WIN32 +#include "XGetopt.h" +#endif + +#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); +} + +int startedAt; +int lastTransitionAt; + +#ifdef HAS_DLFCN_H +// 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 + + +// 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(); +} + +void printUsageAndExit() { + printf("test-stress version " USCXML_VERSION " (" CMAKE_BUILD_TYPE " build - " CMAKE_COMPILER_STRING ")\n"); + printf("Usage\n"); + printf("\ttest-stress"); +#ifdef BUILD_AS_PLUGINS + printf(" [-p pluginPath]"); +#endif + printf(" <PATH>\n"); + printf("\n"); + exit(1); +} + +class StatusMonitor : public uscxml::InterpreterMonitor { + void beforeTakingTransitions(uscxml::Interpreter interpreter, const Arabica::XPath::NodeSet<std::string>& transitions) { + lastTransitionAt = time(NULL); + } + +}; + +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 + + if (argc < 2) { + printUsageAndExit(); + } + + google::InitGoogleLogging(argv[0]); + google::LogToStderr(); + +#ifndef _WIN32 + opterr = 0; +#endif + int option; + while ((option = getopt(argc, argv, "vl:p:")) != -1) { + switch(option) { + case 'l': + google::InitGoogleLogging(optarg); + break; + case 'p': + uscxml::Factory::pluginPath = optarg; + break; + case '?': + break; + default: + printUsageAndExit(); + break; + } + } + + DirectoryWatch* watcher = new DirectoryWatch(argv[optind], true); + watcher->updateEntries(true); + std::map<std::string, struct stat> entries = watcher->getAllEntries(); + + StatusMonitor vm; + + std::map<std::string, struct stat>::iterator entryIter = entries.begin(); + while(entryIter != entries.end()) { + if (!boost::ends_with(entryIter->first, ".scxml")) { + entryIter++; + continue; + } + + startedAt = time(NULL); + lastTransitionAt = time(NULL); + + LOG(INFO) << "Processing " << entryIter->first; + Interpreter interpreter = Interpreter::fromURI(std::string(argv[optind]) + PATH_SEPERATOR + entryIter->first); + if (interpreter) { + interpreter.setCmdLineOptions(argc, argv); + + interpreter.addMonitor(&vm); + + interpreter.start(); + int now = time(NULL); + while(now - startedAt < 20 && now - lastTransitionAt < 2) { + // let the interpreter run for a bit + tthread::this_thread::sleep_for(tthread::chrono::seconds(1)); + now = time(NULL); + } + + } + entryIter++; + } + + delete watcher; + return EXIT_SUCCESS; +}
\ No newline at end of file diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 69f9014..e0f8343 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -51,6 +51,25 @@ int main(int argc, char** argv) { std::string exeName = argv[0];
exeName = exeName.substr(exeName.find_last_of("\\/") + 1);
+ {
+ try {
+ URL url("http://asdfasdfasdfasdf.wgferg");
+ url.download(true);
+ assert(false);
+ } catch (Event e) {
+ }
+ }
+
+ {
+ try {
+ URL url("http://uscxml.tk.informatik.tu-darmstadt.de/foobarfoo.html");
+ url.download(true);
+ assert(false);
+ } catch (Event e) {
+ std::cout << e << std::endl;
+ }
+ }
+
#if 0
{
Interpreter interpreter = Interpreter::fromURI("/Users/sradomski/Desktop/application_small.scxml");
|