X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Ftesting%2FTestManager.cpp;h=c8c65e3bf8f041db6aed7a7da5d1a017070d5d45;hb=080dc0740d8b02011dee032f5d44eeb5f2ffe23f;hp=20a29a2f5a2f4336b832124458247a73953def92;hpb=2e2f6d4e2ffe1c8b86c812807f0e501ab78f56f9;p=anna.git diff --git a/source/testing/TestManager.cpp b/source/testing/TestManager.cpp index 20a29a2..c8c65e3 100644 --- a/source/testing/TestManager.cpp +++ b/source/testing/TestManager.cpp @@ -194,7 +194,7 @@ throw() { bool TestManager::configureTTPS(int testTicksPerSecond) throw() { - if (testTicksPerSecond == 0) { + if (testTicksPerSecond == 0) { if (a_clock) { a_timeController->cancel(a_clock); LOGDEBUG(anna::Logger::debug("Testing timer clock stopped !", ANNA_FILE_LOCATION)); @@ -260,6 +260,23 @@ bool TestManager::gotoTestCase(unsigned int id) throw() { return false; } +bool TestManager::runTestCase(unsigned int id) throw() { + test_pool_it it = a_testPool.find(id); + if (it != a_testPool.end()) { + a_currentTestIt = it; + + // execTestCases will get the next one, we must return 1 position: + if (a_currentTestIt == a_testPool.begin()) + a_currentTestIt = a_testPool.end(); + else + a_currentTestIt--; + + return execTestCases(1); + } + + return false; +} + TestCase *TestManager::findTestCase(unsigned int id) const throw() { // id = -1 provides current test case triggered if (!tests()) return NULL; @@ -278,10 +295,38 @@ TestCase *TestManager::getTestCase(unsigned int id, const std::string &descripti return result; } -bool TestManager::clearPool() throw() { - if (!tests()) return false; - for (test_pool_it it = a_testPool.begin(); it != a_testPool.end(); it++) delete it->second; - // TODO: stop the possible command threads or there will be a core dump +bool TestManager::clearPool(std::string &result) throw() { + + result = ""; + + if (!tests()) { + result = "There are not programmed test cases to be removed"; + return false; + } + + int total = a_testPool.size(); + int unsafe = 0; + + test_pool_it it; + for (it = a_testPool.begin(); it != a_testPool.end(); it++) { + if (!it->second->safeToClear()) { // Check that non pending threads are running (command steps): + unsafe++; + } + } + + if (unsafe > 0) { + result = "Some test cases cannot be removed ("; + result += anna::functions::asString(unsafe); + result += "/"; + result += anna::functions::asString(total); + result += "), mainly those having running-thread steps. Check for stuck external procedures or try later."; + return false; + } + + // Here is safe to clear: + for (it = a_testPool.begin(); it != a_testPool.end(); it++) { + delete it->second; + } a_testPool.clear(); a_key1TestCaseMap.clear(); @@ -290,6 +335,8 @@ bool TestManager::clearPool() throw() { a_poolCycle = 1; configureTTPS(0); // stop a_statSummary.clear(); + + result = "all the programmed test cases have been dropped"; return true; } @@ -520,7 +567,7 @@ throw() { if (a_clock) { result->createAttribute("AsynchronousSendings", a_synchronousAmount); int ticksPerSecond = (a_synchronousAmount * 1000) / a_clock->getTimeout(); - result->createAttribute("TicksPerSecond", ticksPerSecond); + result->createAttribute("TicksPerSecond", a_clock->isActive() ? ticksPerSecond : 0); } if (a_currentTestIt != a_testPool.end()) { result->createAttribute("CurrentTestCaseId", (*a_currentTestIt).first);