mirror of https://github.com/axmolengine/axmol.git
Test automation support:Catch crash event on WIN32/MAC/IOS/ANDROID
This commit is contained in:
parent
eb928432ce
commit
6bcddbc779
|
@ -33,6 +33,7 @@
|
||||||
USING_NS_CC;
|
USING_NS_CC;
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
AppDelegate::AppDelegate()
|
||||||
|
: _testController(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,13 +180,21 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||||
void AppDelegate::applicationDidEnterBackground()
|
void AppDelegate::applicationDidEnterBackground()
|
||||||
{
|
{
|
||||||
_testController->onEnterBackground();
|
if (_testController)
|
||||||
|
{
|
||||||
|
_testController->onEnterBackground();
|
||||||
|
}
|
||||||
|
|
||||||
Director::getInstance()->stopAnimation();
|
Director::getInstance()->stopAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function will be called when the app is active again
|
// this function will be called when the app is active again
|
||||||
void AppDelegate::applicationWillEnterForeground()
|
void AppDelegate::applicationWillEnterForeground()
|
||||||
{
|
{
|
||||||
_testController->onEnterForeground();
|
if (_testController)
|
||||||
|
{
|
||||||
|
_testController->onEnterForeground();
|
||||||
|
}
|
||||||
|
|
||||||
Director::getInstance()->startAnimation();
|
Director::getInstance()->startAnimation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ void TestController::traverseTestList(TestList* testList)
|
||||||
if (testList == _rootTestList)
|
if (testList == _rootTestList)
|
||||||
{
|
{
|
||||||
_sleepUniqueLock = std::unique_lock<std::mutex>(_sleepMutex);
|
_sleepUniqueLock = std::unique_lock<std::mutex>(_sleepMutex);
|
||||||
_sleepCondition.wait_for(_sleepUniqueLock, std::chrono::milliseconds(2500));
|
_sleepCondition.wait_for(_sleepUniqueLock, std::chrono::milliseconds(500));
|
||||||
//disable touch
|
//disable touch
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -358,8 +358,16 @@ bool TestController::checkTest(TestCase* testCase)
|
||||||
|
|
||||||
void TestController::handleCrash()
|
void TestController::handleCrash()
|
||||||
{
|
{
|
||||||
logEx("TestController::handleCrash");
|
logEx("%sCatch an crash event", LOG_TAG);
|
||||||
stopAutoTest();
|
|
||||||
|
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 TestController::onEnterBackground()
|
void TestController::onEnterBackground()
|
||||||
|
@ -399,11 +407,15 @@ void TestController::logEx(const char * format, ...)
|
||||||
|
|
||||||
static TestController* s_testController = nullptr;
|
static TestController* s_testController = nullptr;
|
||||||
|
|
||||||
|
static void initCrashCatch();
|
||||||
|
|
||||||
TestController* TestController::getInstance()
|
TestController* TestController::getInstance()
|
||||||
{
|
{
|
||||||
if (s_testController == nullptr)
|
if (s_testController == nullptr)
|
||||||
{
|
{
|
||||||
s_testController = new (std::nothrow) TestController;
|
s_testController = new (std::nothrow) TestController;
|
||||||
|
|
||||||
|
initCrashCatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
return s_testController;
|
return s_testController;
|
||||||
|
@ -423,3 +435,71 @@ bool TestController::blockTouchBegan(Touch* touch, Event* event)
|
||||||
{
|
{
|
||||||
return !_stopAutoTest;
|
return !_stopAutoTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
static long __stdcall windowExceptionFilter(_EXCEPTION_POINTERS* excp)
|
||||||
|
{
|
||||||
|
if (s_testController)
|
||||||
|
{
|
||||||
|
s_testController->handleCrash();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXCEPTION_EXECUTE_HANDLER;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initCrashCatch()
|
||||||
|
{
|
||||||
|
SetUnhandledExceptionFilter(windowExceptionFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||||
|
|
||||||
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||||
|
static int s_fatal_signals[] = {
|
||||||
|
SIGILL,
|
||||||
|
SIGABRT,
|
||||||
|
SIGBUS,
|
||||||
|
SIGFPE,
|
||||||
|
SIGSEGV,
|
||||||
|
SIGSTKFLT,
|
||||||
|
SIGPIPE,
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
static int s_fatal_signals[] = {
|
||||||
|
SIGABRT,
|
||||||
|
SIGBUS,
|
||||||
|
SIGFPE,
|
||||||
|
SIGILL,
|
||||||
|
SIGSEGV,
|
||||||
|
SIGTRAP,
|
||||||
|
SIGTERM,
|
||||||
|
SIGKILL,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void signalHandler(int sig)
|
||||||
|
{
|
||||||
|
if (s_testController)
|
||||||
|
{
|
||||||
|
s_testController->handleCrash();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initCrashCatch()
|
||||||
|
{
|
||||||
|
for (auto sig : s_fatal_signals) {
|
||||||
|
signal(sig, signalHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static void initCrashCatch()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -47,7 +47,6 @@ public:
|
||||||
static TestController* getInstance();
|
static TestController* getInstance();
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
|
|
||||||
TestController();
|
|
||||||
~TestController();
|
~TestController();
|
||||||
|
|
||||||
void startAutoTest();
|
void startAutoTest();
|
||||||
|
@ -59,10 +58,18 @@ public:
|
||||||
void onEnterForeground();
|
void onEnterForeground();
|
||||||
|
|
||||||
bool blockTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
|
bool blockTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void logEx(const char * format, ...);
|
TestController();
|
||||||
|
|
||||||
|
void traverseTestList(TestList* testList);
|
||||||
|
void traverseTestSuite(TestSuite* testSuite);
|
||||||
|
bool checkTest(TestCase* testCase);
|
||||||
|
|
||||||
|
void logEx(const char * format, ...);
|
||||||
|
|
||||||
bool _stopAutoTest;
|
bool _stopAutoTest;
|
||||||
|
bool _isRunInBackground;
|
||||||
|
|
||||||
TestList* _rootTestList;
|
TestList* _rootTestList;
|
||||||
|
|
||||||
|
@ -76,13 +83,6 @@ private:
|
||||||
cocos2d::EventListenerTouchOneByOne* _touchListener;
|
cocos2d::EventListenerTouchOneByOne* _touchListener;
|
||||||
|
|
||||||
std::string _logIndentation;
|
std::string _logIndentation;
|
||||||
|
|
||||||
bool _isRunInBackground;
|
|
||||||
|
|
||||||
void traverseTestList(TestList* testList);
|
|
||||||
void traverseTestSuite(TestSuite* testSuite);
|
|
||||||
|
|
||||||
bool checkTest(TestCase* testCase);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue