summaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2016-06-13 08:52:55 (GMT)
committerStefan Radomski <github@mintwerk.de>2016-06-13 08:52:55 (GMT)
commit053e9bc973fbe88fc41a34064ffadc0deabac58d (patch)
tree6aeee286577159ffcb612d41972a9d18ab685c6d /test/src
parent6e13c7b6e0888323223afd5d2e36e86243df57af (diff)
downloaduscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.zip
uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.tar.gz
uscxml-053e9bc973fbe88fc41a34064ffadc0deabac58d.tar.bz2
Fixed dozens of memory leaks
Diffstat (limited to 'test/src')
-rw-r--r--test/src/test-lifecycle.cpp4
-rw-r--r--test/src/test-stress.cpp109
2 files changed, 111 insertions, 2 deletions
diff --git a/test/src/test-lifecycle.cpp b/test/src/test-lifecycle.cpp
index df77e96..14ebd94 100644
--- a/test/src/test-lifecycle.cpp
+++ b/test/src/test-lifecycle.cpp
@@ -342,8 +342,8 @@ int main(int argc, char** argv) {
assert(interpreter.step() == USCXML_INITIALIZED);
assert(interpreter.step() == USCXML_MICROSTEPPED);
assert(interpreter.step() == USCXML_MACROSTEPPED);
- assert(interpreter.step() == USCXML_IDLE);
- assert(interpreter.step(true) == USCXML_MICROSTEPPED);
+ assert(interpreter.step(0) == USCXML_IDLE);
+ assert(interpreter.step() == USCXML_MICROSTEPPED);
assert(interpreter.step() == USCXML_MICROSTEPPED);
assert(interpreter.step() == USCXML_FINISHED);
}
diff --git a/test/src/test-stress.cpp b/test/src/test-stress.cpp
new file mode 100644
index 0000000..588e0f7
--- /dev/null
+++ b/test/src/test-stress.cpp
@@ -0,0 +1,109 @@
+#include "uscxml/config.h"
+#include "uscxml/Interpreter.h"
+//#include "uscxml/Factory.h"
+#include "uscxml/server/HTTPServer.h"
+
+#include <easylogging++.h>
+
+#include "uscxml/plugins/invoker/dirmon/DirMonInvoker.h"
+#include <boost/algorithm/string.hpp>
+
+#ifdef _WIN32
+#include "XGetopt.h"
+#endif
+
+int startedAt;
+int lastTransitionAt;
+
+class StatusMonitor : public uscxml::InterpreterMonitor {
+ void beforeTakingTransition(const XERCESC_NS::DOMElement* transition) {
+ lastTransitionAt = time(NULL);
+ }
+
+};
+
+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);
+}
+
+int main(int argc, char** argv) {
+ using namespace uscxml;
+
+ if (argc < 2) {
+ printUsageAndExit();
+ }
+
+ HTTPServer::getInstance(8188, 8189);
+#ifndef _WIN32
+ opterr = 0;
+#endif
+ int option;
+ while ((option = getopt(argc, argv, "vl:p:")) != -1) {
+ switch(option) {
+ case 'p':
+ uscxml::Factory::setDefaultPluginPath(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);
+
+ Interpreter interpreter = Interpreter::fromURL(std::string(argv[optind]) + PATH_SEPERATOR + entryIter->first);
+// Interpreter interpreter = Interpreter::fromURL("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test422.scxml");
+ LOG(INFO) << "Processing " << interpreter.getImpl()->getBaseURL();
+ if (interpreter) {
+
+ interpreter.setMonitor(&vm);
+
+ InterpreterState state = InterpreterState::USCXML_UNDEF;
+ int now = time(NULL);
+
+ try {
+ while(state != USCXML_FINISHED && now - startedAt < 20 && now - lastTransitionAt < 2) {
+// while(state != USCXML_FINISHED) {
+ state = interpreter.step(200);
+ now = time(NULL);
+ }
+ } catch (...) {}
+ }
+ entryIter++;
+
+ // forever
+ if (entryIter == entries.end()) {
+ entryIter = entries.begin();
+ std::this_thread::sleep_for(std::chrono::seconds(10));
+ }
+ }
+
+ delete watcher;
+
+ return EXIT_SUCCESS;
+} \ No newline at end of file