bool TestController::checkTest(TestCase* testCase) { if (testCase) { switch (testCase->getTestType()) { case TestCase::Type::UNIT: { if (testCase && testCase->getExpectedOutput() != testCase->getActualOutput()) { logEx("%s %s test fail", LOG_TAG, testCase->getTestCaseName().c_str()); } else { logEx("%s %s test pass", LOG_TAG, testCase->getTestCaseName().c_str()); } break; } case TestCase::Type::ROBUSTNESS: { break; } case TestCase::Type::MANUAL: { break; } default: break; } } return true; }
void TestController::handleCrash() { disableCrashCatch(); logEx("%sCatch an crash event", LOG_TAG); if (!_stopAutoTest) { stopAutoTest(); } }
void TestController::handleCrash() { logEx("%sCatch an crash event", LOG_TAG); if (!_stopAutoTest) { stopAutoTest(); } #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX exit(1); #endif }
void Logger::log(const int priority, const char *text, const int len) { bool bNeedSync; char *caption; //printf("Log:%d, %s, %d", priority, text, len); switch(priority) { case LOG_DEBUG: bNeedSync = true; caption = "DEBUG"; break; case LOG_INFO: bNeedSync = true; caption = "INFO"; break; case LOG_NOTICE: bNeedSync = true; caption = "NOTICE"; break; case LOG_WARNING: bNeedSync = true; caption = "WARNING"; break; case LOG_ERR: bNeedSync = true; caption = "ERROR"; break; case LOG_CRIT: bNeedSync = true; caption = "CRIT"; break; case LOG_ALERT: bNeedSync = true; caption = "ALERT"; break; case LOG_EMERG: bNeedSync = true; caption = "EMERG"; break; default: bNeedSync = true; caption = "UNKOWN"; break; } logEx(caption, text, len, bNeedSync); }
void TestController::traverseTestList(TestList* testList) { if (testList == _rootTestList) { _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500)); } else { _logIndentation += LOG_INDENTATION; _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500)); } logEx("%s%sBegin traverse TestList:%s", LOG_TAG, _logIndentation.c_str(), testList->getTestName().c_str()); auto scheduler = _director->getScheduler(); int testIndex = 0; for (auto& callback : testList->_testCallbacks) { if (_stopAutoTest) break; while (_isRunInBackground) { logEx("_director is paused"); _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500)); } if (callback) { auto test = callback(); test->setTestParent(testList); test->setTestName(testList->_childTestNames[testIndex++]); if (test->isTestList()) { scheduler->performFunctionInCocosThread([&](){ test->runThisTest(); }); traverseTestList((TestList*)test); } else { traverseTestSuite((TestSuite*)test); } } } if (testList == _rootTestList) { _stopAutoTest = true; } else { if (!_stopAutoTest) { //Backs up one level and release TestList object. scheduler->performFunctionInCocosThread([&](){ testList->_parentTest->runThisTest(); }); _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500)); testList->release(); } _logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION)); } }
void TestController::traverseTestSuite(TestSuite* testSuite) { auto scheduler = _director->getScheduler(); int testIndex = 0; float testCaseDuration = 0.0f; _logIndentation += LOG_INDENTATION; logEx("%s%sBegin traverse TestSuite:%s", LOG_TAG, _logIndentation.c_str(), testSuite->getTestName().c_str()); _logIndentation += LOG_INDENTATION; testSuite->_currTestIndex = -1; auto logIndentation = _logIndentation; for (auto& callback : testSuite->_testCallbacks) { auto testName = testSuite->_childTestNames[testIndex++]; Scene* testScene = nullptr; TestCase* testCase = nullptr; TransitionScene* transitionScene = nullptr; if (_stopAutoTest) break; while (_isRunInBackground) { logEx("_director is paused"); _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500)); } //Run test case in the cocos[GL] thread. scheduler->performFunctionInCocosThread([&, logIndentation, testName](){ if (_stopAutoTest) return; logEx("%s%sRun test:%s.", LOG_TAG, logIndentation.c_str(), testName.c_str()); auto scene = callback(); if (_stopAutoTest) return; if (scene) { transitionScene = dynamic_cast<TransitionScene*>(scene); if (transitionScene) { testCase = (TestCase*)transitionScene->getInScene(); testCaseDuration = transitionScene->getDuration() + 0.5f; } else { testCase = (TestCase*)scene; testCaseDuration = testCase->getDuration(); } testSuite->_currTestIndex++; testCase->setTestSuite(testSuite); testCase->setTestCaseName(testName); testCase->setAutoTesting(true); _director->replaceScene(scene); testScene = scene; } }); if (_stopAutoTest) break; //Wait for the test case be created. float waitTime = 0.0f; while (!testScene && !_stopAutoTest) { _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(50)); if (!_isRunInBackground) { waitTime += 0.05f; } if (waitTime > CREATE_TIME_OUT) { logEx("%sCreate test %s time out", LOG_TAG, testName.c_str()); _stopAutoTest = true; break; } } if (_stopAutoTest) break; //Wait for test completed. _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(int(1000 * testCaseDuration))); if (transitionScene == nullptr) { waitTime = 0.0f; while (!_stopAutoTest && testCase->isAutoTesting()) { _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(50)); if (!_isRunInBackground) { waitTime += 0.05f; } if (waitTime > TEST_TIME_OUT) { logEx("%sRun test %s time out", LOG_TAG, testName.c_str()); _stopAutoTest = true; break; } } if (!_stopAutoTest) { //Check the result of test. checkTest(testCase); } } } if (!_stopAutoTest) { //Backs up one level and release TestSuite object. auto parentTest = testSuite->_parentTest; scheduler->performFunctionInCocosThread([parentTest](){ parentTest->runThisTest(); }); _sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(1000)); testSuite->release(); } _logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION)); _logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION)); }