2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "controller.h"
|
|
|
|
#include <functional>
|
|
|
|
#include <chrono>
|
|
|
|
#include "BaseTest.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#define TEST_TIME_OUT 50
|
|
|
|
#define CREATE_TIME_OUT 25
|
|
|
|
#define LOG_INDENTATION " "
|
|
|
|
#define LOG_TAG "[TestController]"
|
|
|
|
|
|
|
|
static void initCrashCatch();
|
|
|
|
static void disableCrashCatch();
|
|
|
|
|
|
|
|
class RootTests : public TestList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RootTests()
|
|
|
|
{
|
2022-11-01 19:50:43 +08:00
|
|
|
#if __has_include("EffekseerForCocos2d-x.h")
|
|
|
|
addTest("Effekseer", []() { return new EffekseerTests(); });
|
|
|
|
#endif
|
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
// addTest("Node: Scene3D", [](){return new Scene3DTests(); });
|
2023-07-09 20:10:50 +08:00
|
|
|
#if defined(AX_PLATFORM_PC) || (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID)
|
2022-02-25 19:03:09 +08:00
|
|
|
addTest("ImGui", []() { return new ImGuiTests(); });
|
2020-09-08 13:38:16 +08:00
|
|
|
#endif
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Texture2D", []() { return new Texture2DTests(); });
|
|
|
|
addTest("ActionManager", []() { return new ActionManagerTests(); });
|
|
|
|
addTest("Actions - Basic", []() { return new ActionsTests(); });
|
|
|
|
addTest("Actions - Ease", []() { return new ActionsEaseTests(); });
|
|
|
|
addTest("Actions - Progress", []() { return new ActionsProgressTests(); });
|
2021-12-08 00:11:53 +08:00
|
|
|
addTest("Audio - NewAudioEngine", []() { return new AudioEngineTests(); });
|
2021-04-22 22:01:47 +08:00
|
|
|
|
2021-12-08 00:11:53 +08:00
|
|
|
addTest("Box2D - Basic", []() { return new Box2DTests(); });
|
2023-03-14 12:08:31 +08:00
|
|
|
#if defined(AX_PLATFORM_PC)
|
2021-12-08 00:11:53 +08:00
|
|
|
addTest("Box2D - TestBed", []() { return new Box2DTestBedTests(); });
|
2021-07-06 21:02:47 +08:00
|
|
|
#endif
|
2021-04-22 22:01:47 +08:00
|
|
|
addTest("Chipmunk2D - Basic", []() { return new ChipmunkTests(); });
|
2022-07-16 10:43:05 +08:00
|
|
|
#if defined(AX_PLATFORM_PC)
|
2021-06-16 19:34:09 +08:00
|
|
|
addTest("Chipmunk2D - TestBed", []() { return new ChipmunkTestBedTests(); });
|
2021-06-17 14:22:52 +08:00
|
|
|
#endif
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Bugs", []() { return new BugsTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Click and Move", []() { return new ClickAndMoveTest(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Configuration", []() { return new ConfigurationTests(); });
|
|
|
|
addTest("Console", []() { return new ConsoleTests(); });
|
|
|
|
addTest("Curl", []() { return new CurlTests(); });
|
|
|
|
addTest("Current Language", []() { return new CurrentLanguageTests(); });
|
2021-07-04 16:40:34 +08:00
|
|
|
addTest("Network Test", []() { return new NetworkTests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("EventDispatcher", []() { return new EventDispatcherTests(); });
|
|
|
|
addTest("Effects - Advanced", []() { return new EffectAdvanceTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Effects - Basic", []() { return new EffectTests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Extensions", []() { return new ExtensionsTests(); });
|
|
|
|
addTest("FileUtils", []() { return new FileUtilsTests(); });
|
|
|
|
addTest("Fonts", []() { return new FontTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Interval", []() { return new IntervalTests(); });
|
2022-07-16 10:43:05 +08:00
|
|
|
#if (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID)
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("JNIHelper", []() { return new JNITests(); });
|
|
|
|
#endif
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Material System", []() { return new MaterialSystemTest(); });
|
|
|
|
addTest("Navigation Mesh", []() { return new NavMeshTests(); });
|
|
|
|
addTest("Node: BillBoard Test", []() { return new BillBoardTests(); });
|
|
|
|
addTest("Node: Camera3D Test", []() { return new Camera3DTests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Node: Clipping", []() { return new ClippingNodeTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Node: Draw", []() { return new DrawPrimitivesTests(); });
|
|
|
|
addTest("Node: Label - New API", []() { return new NewLabelTests(); });
|
|
|
|
addTest("Node: Layer", []() { return new LayerTests(); });
|
|
|
|
addTest("Node: Light", []() { return new LightTests(); });
|
|
|
|
addTest("Node: Menu", []() { return new MenuTests(); });
|
|
|
|
addTest("Node: MotionStreak", []() { return new MotionStreakTests(); });
|
|
|
|
addTest("Node: Node", []() { return new CocosNodeTests(); });
|
|
|
|
addTest("Node: Parallax", []() { return new ParallaxTests(); });
|
|
|
|
addTest("Node: Particles", []() { return new ParticleTests(); });
|
|
|
|
addTest("Node: Particle3D (PU)", []() { return new Particle3DTests(); });
|
2022-07-16 10:43:05 +08:00
|
|
|
#if AX_USE_PHYSICS
|
2021-04-22 22:01:47 +08:00
|
|
|
addTest("Node: Physics", []() { return new PhysicsTests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
#endif
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Node: Physics3D", []() { return new Physics3DTests(); });
|
|
|
|
addTest("Node: RenderTexture", []() { return new RenderTextureTests(); });
|
|
|
|
addTest("Node: Scene", []() { return new SceneTests(); });
|
|
|
|
addTest("Node: Spine", []() { return new SpineTests(); });
|
|
|
|
addTest("Node: Sprite", []() { return new SpriteTests(); });
|
2022-07-05 14:48:46 +08:00
|
|
|
addTest("Node: MeshRenderer", []() { return new MeshRendererTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Node: SpritePolygon", []() { return new SpritePolygonTest(); });
|
|
|
|
addTest("Node: Terrain", []() { return new TerrainTests(); });
|
|
|
|
addTest("Node: FastTileMap", []() { return new FastTileMapTests(); });
|
|
|
|
addTest("Node: Text Input", []() { return new TextInputTests(); });
|
|
|
|
addTest("Node: UI", []() { return new UITests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Mouse", []() { return new MouseTests(); });
|
|
|
|
addTest("MultiTouch", []() { return new MultiTouchTests(); });
|
|
|
|
addTest("Renderer", []() { return new NewRendererTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("ReleasePool", []() { return new ReleasePoolTests(); });
|
|
|
|
addTest("Rotate World", []() { return new RotateWorldTests(); });
|
|
|
|
addTest("Scheduler", []() { return new SchedulerTests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Shader - Basic", []() { return new ShaderTests(); });
|
|
|
|
addTest("Shader - Sprite", []() { return new Shader2Tests(); });
|
|
|
|
addTest("TextureCache", []() { return new TextureCacheTests(); });
|
|
|
|
addTest("TexturePacker Encryption", []() { return new TextureAtlasEncryptionTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Touches", []() { return new TouchesTests(); });
|
|
|
|
addTest("Transitions", []() { return new TransitionsTests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Unit Test", []() { return new UnitTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Unzip Test", []() { return new ZipTests(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("URL Open Test", []() { return new OpenURLTests(); });
|
|
|
|
addTest("UserDefault", []() { return new UserDefaultTests(); });
|
2022-07-16 10:43:05 +08:00
|
|
|
#if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS || AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID)
|
2019-11-23 20:27:39 +08:00
|
|
|
addTest("Vibrate", []() { return new VibrateTests(); });
|
|
|
|
#endif
|
|
|
|
addTest("Zwoptex", []() { return new ZwoptexTests(); });
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("SpriteFrameCache", []() { return new SpriteFrameCacheTests(); }); // TODO
|
2022-07-16 10:43:05 +08:00
|
|
|
#if (AX_TARGET_PLATFORM == AX_PLATFORM_MAC || AX_TARGET_PLATFORM == AX_PLATFORM_WIN32 || \
|
|
|
|
AX_TARGET_PLATFORM == AX_PLATFORM_LINUX)
|
2021-12-31 12:12:40 +08:00
|
|
|
addTest("Window Test", []() { return new WindowTests(); }); // TODO wrong effect
|
2019-11-23 20:27:39 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
TestController::TestController() : _stopAutoTest(true), _isRunInBackground(false), _testSuite(nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
_rootTestList = new RootTests;
|
2019-11-23 20:27:39 +08:00
|
|
|
_rootTestList->runThisTest();
|
|
|
|
_director = Director::getInstance();
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
_touchListener = EventListenerTouchOneByOne::create();
|
2022-07-16 10:43:05 +08:00
|
|
|
_touchListener->onTouchBegan = AX_CALLBACK_2(TestController::blockTouchBegan, this);
|
2019-11-23 20:27:39 +08:00
|
|
|
_touchListener->setSwallowTouches(true);
|
|
|
|
|
|
|
|
_director->getEventDispatcher()->addEventListenerWithFixedPriority(_touchListener, -200);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestController::~TestController()
|
|
|
|
{
|
|
|
|
_director->getEventDispatcher()->removeEventListener(_touchListener);
|
|
|
|
|
|
|
|
_rootTestList->release();
|
|
|
|
_rootTestList = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::startAutoTest()
|
|
|
|
{
|
|
|
|
if (!_autoTestThread.joinable())
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
_stopAutoTest = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
_logIndentation = "";
|
|
|
|
_autoTestThread = std::thread(&TestController::traverseThreadFunc, this);
|
|
|
|
_autoTestThread.detach();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::stopAutoTest()
|
|
|
|
{
|
|
|
|
_stopAutoTest = true;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
|
|
|
if (_autoTestThread.joinable())
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
_sleepCondition.notify_all();
|
|
|
|
_autoTestThread.join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::traverseThreadFunc()
|
|
|
|
{
|
|
|
|
std::mutex sleepMutex;
|
2021-12-31 12:12:40 +08:00
|
|
|
auto lock = std::unique_lock<std::mutex>(sleepMutex);
|
2019-11-23 20:27:39 +08:00
|
|
|
_sleepUniqueLock = &lock;
|
|
|
|
traverseTestList(_rootTestList);
|
|
|
|
_sleepUniqueLock = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2021-12-31 12:12:40 +08:00
|
|
|
int testIndex = 0;
|
2023-07-09 20:10:50 +08:00
|
|
|
for (auto&& callback : testList->_testCallbacks)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
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())
|
|
|
|
{
|
2023-05-27 23:21:25 +08:00
|
|
|
scheduler->runOnAxmolThread([&]() { test->runThisTest(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
traverseTestList((TestList*)test);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
traverseTestSuite((TestSuite*)test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (testList == _rootTestList)
|
|
|
|
{
|
|
|
|
_stopAutoTest = true;
|
2023-07-09 20:10:50 +08:00
|
|
|
if (std::getenv("AXMOL_START_AUTOTEST"))
|
2023-08-31 19:55:52 +08:00
|
|
|
utils::killCurrentProcess();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!_stopAutoTest)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
// Backs up one level and release TestList object.
|
2023-05-27 23:21:25 +08:00
|
|
|
scheduler->runOnAxmolThread([&]() { testList->_parentTest->runThisTest(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
|
|
|
|
testList->release();
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::traverseTestSuite(TestSuite* testSuite)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
auto scheduler = _director->getScheduler();
|
|
|
|
int testIndex = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
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;
|
2023-07-09 20:10:50 +08:00
|
|
|
for (auto&& callback : testSuite->_testCallbacks)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
auto testName = testSuite->_childTestNames[testIndex++];
|
2021-12-31 12:12:40 +08:00
|
|
|
|
|
|
|
Scene* testScene = nullptr;
|
|
|
|
TestCase* testCase = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
TransitionScene* transitionScene = nullptr;
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
while (_isRunInBackground)
|
|
|
|
{
|
|
|
|
logEx("_director is paused");
|
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(500));
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
// Run test case in the cocos[GL] thread.
|
2023-05-27 23:21:25 +08:00
|
|
|
scheduler->runOnAxmolThread([&, logIndentation, testName]() {
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
return;
|
2019-11-23 20:27:39 +08:00
|
|
|
logEx("%s%sRun test:%s.", LOG_TAG, logIndentation.c_str(), testName.c_str());
|
|
|
|
|
|
|
|
auto scene = callback();
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
return;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (scene)
|
|
|
|
{
|
|
|
|
transitionScene = dynamic_cast<TransitionScene*>(scene);
|
|
|
|
if (transitionScene)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
testCase = (TestCase*)transitionScene->getInScene();
|
2019-11-23 20:27:39 +08:00
|
|
|
testCaseDuration = transitionScene->getDuration() + 0.5f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
testCase = (TestCase*)scene;
|
2019-11-23 20:27:39 +08:00
|
|
|
testCaseDuration = testCase->getDuration();
|
|
|
|
}
|
|
|
|
testSuite->_currTestIndex++;
|
|
|
|
testCase->setTestSuite(testSuite);
|
|
|
|
testCase->setTestCaseName(testName);
|
|
|
|
_director->replaceScene(scene);
|
|
|
|
|
|
|
|
testScene = scene;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
// Wait for the test case be created.
|
2019-11-23 20:27:39 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
if (_stopAutoTest)
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
// Wait for test completed.
|
2019-11-23 20:27:39 +08:00
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(int(1000 * testCaseDuration)));
|
|
|
|
|
|
|
|
if (transitionScene == nullptr)
|
|
|
|
{
|
|
|
|
waitTime = 0.0f;
|
|
|
|
while (!_stopAutoTest && testCase->getRunTime() < testCaseDuration)
|
|
|
|
{
|
|
|
|
_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)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
// Check the result of test.
|
2019-11-23 20:27:39 +08:00
|
|
|
checkTest(testCase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_stopAutoTest)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
// Backs up one level and release TestSuite object.
|
2019-11-23 20:27:39 +08:00
|
|
|
auto parentTest = testSuite->_parentTest;
|
2023-05-27 23:21:25 +08:00
|
|
|
scheduler->runOnAxmolThread([&]() { parentTest->runThisTest(); });
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
_sleepCondition.wait_for(*_sleepUniqueLock, std::chrono::milliseconds(1000));
|
|
|
|
testSuite->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
_logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
|
|
|
|
_logIndentation.erase(_logIndentation.rfind(LOG_INDENTATION));
|
|
|
|
}
|
|
|
|
|
|
|
|
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::onEnterBackground()
|
|
|
|
{
|
|
|
|
_isRunInBackground = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::onEnterForeground()
|
|
|
|
{
|
|
|
|
_isRunInBackground = false;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void TestController::logEx(const char* format, ...)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
char buff[1024];
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
vsnprintf(buff, 1020, format, args);
|
|
|
|
strcat(buff, "\n");
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID
|
2022-10-01 16:24:52 +08:00
|
|
|
__android_log_print(ANDROID_LOG_DEBUG, "axmol debug info", "%s", buff);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
#elif AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
|
2021-12-31 12:12:40 +08:00
|
|
|
WCHAR wszBuf[1024] = {0};
|
2019-11-23 20:27:39 +08:00
|
|
|
MultiByteToWideChar(CP_UTF8, 0, buff, -1, wszBuf, sizeof(wszBuf));
|
|
|
|
OutputDebugStringW(wszBuf);
|
|
|
|
|
|
|
|
#else
|
|
|
|
// Linux, Mac, iOS, etc
|
|
|
|
fprintf(stdout, "%s", buff);
|
|
|
|
fflush(stdout);
|
|
|
|
#endif
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static TestController* s_testController = nullptr;
|
|
|
|
|
|
|
|
TestController* TestController::getInstance()
|
|
|
|
{
|
|
|
|
if (s_testController == nullptr)
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
s_testController = new TestController;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
initCrashCatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
return s_testController;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestController::destroyInstance()
|
|
|
|
{
|
|
|
|
if (s_testController)
|
|
|
|
{
|
|
|
|
s_testController->stopAutoTest();
|
|
|
|
delete s_testController;
|
|
|
|
s_testController = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
disableCrashCatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestController::blockTouchBegan(Touch* touch, Event* event)
|
|
|
|
{
|
|
|
|
return !_stopAutoTest;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
2022-07-16 10:43:05 +08:00
|
|
|
#if AX_TARGET_PLATFORM == AX_PLATFORM_WIN32
|
2021-12-31 12:12:40 +08:00
|
|
|
# include <windows.h>
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-09-02 19:21:28 +08:00
|
|
|
static long __stdcall windowExceptionFilter(_EXCEPTION_POINTERS* excp)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (s_testController)
|
|
|
|
{
|
|
|
|
s_testController->handleCrash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initCrashCatch()
|
|
|
|
{
|
|
|
|
SetUnhandledExceptionFilter(windowExceptionFilter);
|
|
|
|
}
|
|
|
|
static void disableCrashCatch()
|
|
|
|
{
|
|
|
|
SetUnhandledExceptionFilter(UnhandledExceptionFilter);
|
|
|
|
}
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
#elif AX_TARGET_PLATFORM == AX_PLATFORM_MAC || AX_TARGET_PLATFORM == AX_PLATFORM_IOS || \
|
|
|
|
AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
# if AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID
|
2019-11-23 20:27:39 +08:00
|
|
|
static int s_fatal_signals[] = {
|
2021-12-31 12:12:40 +08:00
|
|
|
SIGILL, SIGABRT, SIGBUS, SIGFPE, SIGSEGV, SIGSTKFLT, SIGPIPE,
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
2021-12-31 12:12:40 +08:00
|
|
|
# else
|
2019-11-23 20:27:39 +08:00
|
|
|
static int s_fatal_signals[] = {
|
2021-12-31 12:12:40 +08:00
|
|
|
SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP, SIGTERM, SIGKILL,
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
2021-12-31 12:12:40 +08:00
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
static void signalHandler(int sig)
|
|
|
|
{
|
|
|
|
if (s_testController)
|
|
|
|
{
|
|
|
|
s_testController->handleCrash();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initCrashCatch()
|
|
|
|
{
|
2023-07-09 20:10:50 +08:00
|
|
|
for (auto&& sig : s_fatal_signals)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
signal(sig, signalHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disableCrashCatch()
|
|
|
|
{
|
2023-07-09 20:10:50 +08:00
|
|
|
for (auto&& sig : s_fatal_signals)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
signal(sig, SIG_DFL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
static void initCrashCatch() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
static void disableCrashCatch() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif
|