403 lines
No EOL
14 KiB
C++
403 lines
No EOL
14 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include "tests/common/gtestRepeatHelper.h"
|
|
#include "tests/common/gtestFilter.h"
|
|
#include <gmock/gmock.h>
|
|
#if defined(US_TARGET_XONE)
|
|
#include <codecvt>
|
|
#elif defined(US_TARGET_PS4) || defined(US_TARGET_KILI)
|
|
#include <np.h>
|
|
#include <system_param.h>
|
|
#include <system_service.h>
|
|
#endif
|
|
|
|
//#defined PRINT_XUNIT_REPORT
|
|
|
|
US_TEST_NS_BEGIN;
|
|
|
|
struct GTestRepeatHelper_BF
|
|
{
|
|
#if defined(US_TARGET_XONE)
|
|
static bool usingExpectedConsoleAccount(Platform::String^ userId, Platform::String^ consoleId)
|
|
{
|
|
// devkits for dev
|
|
Platform::String^ XONE_CONSOLE_ID_LEIA = L"rNAYcm5g8xMve9LKIJl8GsskjPYfhMaNuTFkPtk3mY0=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_LEIA = L"2814641296545037";
|
|
|
|
Platform::String^ XONE_CONSOLE_ID_YODA = L"BYU+RypKSPXHf/KzeTEEhAHGih2D3qFej/O6IPyY2Ic=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_YODA = L"2814672985008037";
|
|
|
|
Platform::String^ XONE_CONSOLE_ID_OBIWAN = L"Q/Hh8Cad/VbeicPwHWL8IXkP96uFlwa5qJxLvK50FYw=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_OBIWAN = L"2814641911453133";
|
|
|
|
Platform::String^ XONE_CONSOLE_ID_CRA_83 = L"t6BROhvORS/3qgiQHVuD/7XmKCSdeV0gYJQ8IMmiqPg=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_CRA_83 = L"2814622264276993";
|
|
|
|
// devkits for buildfarm
|
|
Platform::String^ XONE_CONSOLE_ID_BA100 = L"KP52m2G2Oh/CmOrWhLzTEyMr9vLKE5FpZx6ljmuHi40=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_BA100 = L"2814638047582693";
|
|
|
|
Platform::String^ XONE_CONSOLE_ID_AG882 = L"zOOznieiG7CTTW9de7oQHtA7dWIVrYdPdjPvwwnIdcQ=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_AG882 = L"2814676350599535";
|
|
|
|
Platform::String^ XONE_CONSOLE_ID_BF364 = L"E3PKCA+NChGc05av26m72ug983+tt8shJT2xMKhKuaM=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_BF364 = L"2814680648308705";
|
|
|
|
Platform::String^ XONE_CONSOLE_ID_BA988 = L"Pp8fdxtJ5V3LT8tV36XCiQmsKse3DLE+wIyBKnxM4Tw=";
|
|
Platform::String^ XONE_DEFAULT_USER_ID_BA988 = L"2814614862382981";
|
|
|
|
if (userId->IsEmpty() || consoleId->IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_LEIA && consoleId == XONE_CONSOLE_ID_LEIA)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_YODA && consoleId == XONE_CONSOLE_ID_YODA)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_OBIWAN && consoleId == XONE_CONSOLE_ID_OBIWAN)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_CRA_83 && consoleId == XONE_CONSOLE_ID_CRA_83)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_BA100 && consoleId == XONE_CONSOLE_ID_BA100)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_AG882 && consoleId == XONE_CONSOLE_ID_AG882)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_BF364 && consoleId == XONE_CONSOLE_ID_BF364)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == XONE_DEFAULT_USER_ID_BA988 && consoleId == XONE_CONSOLE_ID_BA988)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
#elif defined(US_TARGET_PS4)
|
|
static bool usingExpectedConsoleAccount(const std::string userId, const std::string consoleTitleId)
|
|
{
|
|
const char* PS4_CONSOLE_ID_197 = "PS4-479";
|
|
const char* PS4_DEFAULT_USER_ID_197 = "ussdk_ps_4_01";
|
|
const char* PS4_CONSOLE_ID_207 = "PS4-390";
|
|
const char* PS4_DEFAULT_USER_ID_207 = "ussdk_ps_4_04";
|
|
const char* PS4_NEW_USER_ID_207 = "ussdk_ps_4_12";
|
|
const char* PS4_CONSOLE_ID_97 = "PS4-268";
|
|
const char* PS4_DEFAULT_USER_ID_97 = "ussdk_ps_4_05";
|
|
const char* PS4_CONSOLE_ID_232 = "PS4-467";
|
|
const char* PS4_DEFAULT_USER_ID_232 = "ussdk_ps_4_06";
|
|
const char* PS4_CONSOLE_ID_120 = "PS4-750";
|
|
const char* PS4_DEFAULT_USER_ID_120 = "ussdk_ps_4_02";
|
|
const char* PS4_CONSOLE_ID_126 = "PS4-309";
|
|
const char* PS4_DEFAULT_USER_ID_126 = "ussdk_ps_4_03";
|
|
const char* PS4_CONSOLE_ID_CRA_126 = "Cra-cons-030";
|
|
const char* PS4_DEFAULT_USER_ID_CRA_126 = "ussdk_ps_4_18";
|
|
|
|
if (userId.empty() || consoleTitleId.empty())
|
|
{
|
|
return false;
|
|
}
|
|
else if (userId == PS4_DEFAULT_USER_ID_232 && consoleTitleId == PS4_CONSOLE_ID_232)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == PS4_DEFAULT_USER_ID_197 && consoleTitleId == PS4_CONSOLE_ID_197)
|
|
{
|
|
return true;
|
|
}
|
|
else if ((userId == PS4_DEFAULT_USER_ID_207 || userId == PS4_NEW_USER_ID_207) && consoleTitleId == PS4_CONSOLE_ID_207)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == PS4_DEFAULT_USER_ID_97 && consoleTitleId == PS4_CONSOLE_ID_97)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == PS4_DEFAULT_USER_ID_120 && consoleTitleId == PS4_CONSOLE_ID_120)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == PS4_DEFAULT_USER_ID_126 && consoleTitleId == PS4_CONSOLE_ID_126)
|
|
{
|
|
return true;
|
|
}
|
|
else if (userId == PS4_DEFAULT_USER_ID_CRA_126 && consoleTitleId == PS4_CONSOLE_ID_CRA_126)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
#elif defined(US_TARGET_KILI)
|
|
static bool usingExpectedConsoleAccount(const std::string userId, const std::string consoleTitleId)
|
|
{
|
|
return true;
|
|
}
|
|
#endif
|
|
};
|
|
|
|
GTestRepeatHelper::GTestRepeatHelper(US_NS::uint32 iteration)
|
|
: m_currentlyFailed(false)
|
|
, m_currrentTest()
|
|
, m_countIteration(iteration)
|
|
, m_currentIteration(1)
|
|
, m_tests()
|
|
, m_failCount()
|
|
, m_usingExpectedConsoleAccount(false)
|
|
{
|
|
}
|
|
|
|
US_NS::uint32 GTestRepeatHelper::run(US_NS::int32 argc, US_NS::tchar** argv)
|
|
{
|
|
using namespace US_NS;
|
|
|
|
::testing::InitGoogleMock(reinterpret_cast<int*>(&argc), argv);
|
|
|
|
::testing::UnitTest::GetInstance()->listeners().Append(this);
|
|
|
|
PRINT_LINE("***** GTEST CUSTOM REPEAT HELPER (%u MAX ITERATIONS) *****\n", m_countIteration);
|
|
|
|
uint32 result = 0;
|
|
|
|
while (m_currentIteration <= m_countIteration)
|
|
{
|
|
if (m_tests.size() > 0)
|
|
{
|
|
GTestFilter::setGTestFilter(m_tests);
|
|
m_tests.clear();
|
|
}
|
|
else if(m_currentIteration != 2)
|
|
{
|
|
US_NS::GTestFilter::setGTestFilter();
|
|
}
|
|
else
|
|
{
|
|
break; //No error found after first iteration. Nothing to retry.
|
|
}
|
|
|
|
#if defined(PRINT_XUNIT_REPORT)
|
|
::testing::GTEST_FLAG(output) = "xml:ubiservices_xunit_result.xml";
|
|
#endif
|
|
|
|
result = RUN_ALL_TESTS();
|
|
|
|
#if defined(PRINT_XUNIT_REPORT)
|
|
//Only output first iteration.
|
|
::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
|
|
listeners.Release(listeners.default_xml_generator());
|
|
#endif
|
|
|
|
m_currentIteration++;
|
|
}
|
|
|
|
if (m_failCount.size() > 0)
|
|
{
|
|
if (!m_usingExpectedConsoleAccount)
|
|
{
|
|
PRINT_LINE("WARNING: EXPECTED CONSOLE ACCOUNT NOT USED TO RUN THE TESTS");
|
|
}
|
|
|
|
PRINT_LINE("************** US_ERROR_REPORT_BEGIN **************\n");
|
|
|
|
for (std::map<std::string, uint32>::const_iterator it = m_failCount.begin(); it != m_failCount.end(); ++it)
|
|
{
|
|
std::stringstream sstream;
|
|
sstream << it->first;
|
|
sstream << " Failed Count : ";
|
|
sstream << it->second << std::endl;
|
|
PRINT_LINE(sstream.str().c_str());
|
|
}
|
|
|
|
PRINT_LINE("************** US_ERROR_REPORT_END **************\n");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void GTestRepeatHelper::OnTestProgramStart(const ::testing::UnitTest& unit_test)
|
|
{
|
|
using namespace US_NS;
|
|
|
|
#if defined(US_TARGET_XONE)
|
|
std::ostringstream stringStream;
|
|
|
|
Windows::Xbox::System::User^ user = Windows::Xbox::System::User::Users->GetAt(0);
|
|
|
|
Platform::String^ userId = user->XboxUserId;
|
|
Platform::String^ consoleId = Windows::Xbox::System::Console::ApplicationSpecificDeviceId;
|
|
|
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> codecvt;
|
|
stringStream << "Console User Id: " << codecvt.to_bytes(userId->Data());
|
|
PRINT_LINE(stringStream.str().c_str());
|
|
|
|
stringStream.str(std::string());
|
|
stringStream.clear();
|
|
|
|
stringStream << "Console Title Specific Id: " << codecvt.to_bytes(consoleId->Data());
|
|
PRINT_LINE(stringStream.str().c_str());
|
|
|
|
m_usingExpectedConsoleAccount = GTestRepeatHelper_BF::usingExpectedConsoleAccount(userId, consoleId);
|
|
|
|
#elif defined(US_TARGET_PS4)
|
|
SceUserServiceInitializeParams params = { SCE_KERNEL_PRIO_FIFO_LOWEST };
|
|
const int32 resultInitialize = sceUserServiceInitialize(¶ms);
|
|
if (resultInitialize != SCE_OK && resultInitialize != SCE_USER_SERVICE_ERROR_ALREADY_INITIALIZED)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
SceUserServiceUserId userId = SCE_USER_SERVICE_USER_ID_INVALID;
|
|
const int returnInitialUser = sceUserServiceGetInitialUser(&userId);
|
|
if (returnInitialUser != SCE_OK)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
SceNpId npId;
|
|
const int resultUserId = sceNpGetNpId(userId, &npId);
|
|
if (resultUserId != SCE_OK)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
const char* uplayName = npId.handle.data;
|
|
std::ostringstream stringStream;
|
|
stringStream << "PS4 Username: " << uplayName;
|
|
PRINT_LINE(stringStream.str().c_str());
|
|
|
|
stringStream.str(std::string());
|
|
stringStream.clear();
|
|
|
|
char consoleIdBuff[SCE_SYSTEM_SERVICE_MAX_SYSTEM_NAME_LENGTH];
|
|
const int32_t returnConsoleId = sceSystemServiceParamGetString(SCE_SYSTEM_SERVICE_PARAM_ID_SYSTEM_NAME, consoleIdBuff,
|
|
SCE_SYSTEM_SERVICE_MAX_SYSTEM_NAME_LENGTH);
|
|
if (returnConsoleId != SCE_OK)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
stringStream << "PS4 System Name: " << consoleIdBuff;
|
|
PRINT_LINE(stringStream.str().c_str());
|
|
|
|
m_usingExpectedConsoleAccount = GTestRepeatHelper_BF::usingExpectedConsoleAccount(uplayName, consoleIdBuff);
|
|
|
|
#elif defined(US_TARGET_KILI)
|
|
SceUserServiceInitializeParams params = { SCE_KERNEL_PRIO_FIFO_LOWEST };
|
|
const int32 resultInitialize = sceUserServiceInitialize(¶ms);
|
|
if (resultInitialize != SCE_OK && resultInitialize != SCE_USER_SERVICE_ERROR_ALREADY_INITIALIZED)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
SceUserServiceUserId userId = SCE_USER_SERVICE_USER_ID_INVALID;
|
|
const int returnInitialUser = sceUserServiceGetInitialUser(&userId);
|
|
if (returnInitialUser != SCE_OK)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
/* SceNpId npId;
|
|
const int resultUserId = sceNpGetNpId(userId, &npId);
|
|
if (resultUserId != SCE_OK)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
const char* uplayName = npId.handle.data;*/
|
|
const char* uplayName = "";
|
|
std::ostringstream stringStream;
|
|
stringStream << "KILI Username: " << uplayName;
|
|
PRINT_LINE(stringStream.str().c_str());
|
|
|
|
stringStream.str(std::string());
|
|
stringStream.clear();
|
|
|
|
char consoleIdBuff[SCE_SYSTEM_SERVICE_MAX_SYSTEM_NAME_LENGTH];
|
|
const int32_t returnConsoleId = sceSystemServiceParamGetString(SCE_SYSTEM_SERVICE_PARAM_ID_SYSTEM_NAME, consoleIdBuff,
|
|
SCE_SYSTEM_SERVICE_MAX_SYSTEM_NAME_LENGTH);
|
|
if (returnConsoleId != SCE_OK)
|
|
{
|
|
m_usingExpectedConsoleAccount = false;
|
|
return;
|
|
}
|
|
|
|
stringStream << "KILI System Name: " << consoleIdBuff;
|
|
PRINT_LINE(stringStream.str().c_str());
|
|
|
|
m_usingExpectedConsoleAccount = GTestRepeatHelper_BF::usingExpectedConsoleAccount(uplayName, consoleIdBuff);
|
|
#else
|
|
m_usingExpectedConsoleAccount = true;
|
|
#endif
|
|
US_UNUSED(unit_test);
|
|
}
|
|
|
|
void GTestRepeatHelper::OnTestStart(const ::testing::TestInfo& test_info)
|
|
{
|
|
const ::std::string testName = test_info.name();
|
|
|
|
if(testName.substr(0, 7) == "MANUAL_" || testName.substr(0, 7) == "HELPER_")
|
|
{
|
|
PRINT_LINE("*************************************************************************\n");
|
|
PRINT_LINE("***WARNING, THIS TEST SHOULD ONLY BE RUN MANUALLY AND NOT BE SUBMITTED***\n");
|
|
PRINT_LINE("*************************************************************************\n");
|
|
PRINT_LINE("[ US_TEST_ERROR_FAILED ]\n"); // This strip triggers a failure on Anthill.
|
|
}
|
|
|
|
m_currrentTest = test_info.test_case_name();
|
|
m_currrentTest += ".";
|
|
m_currrentTest += test_info.name();
|
|
}
|
|
|
|
void GTestRepeatHelper::OnTestPartResult(const ::testing::TestPartResult& test_part_result)
|
|
{
|
|
if (test_part_result.failed() && m_tests.find(m_currrentTest) == m_tests.end())
|
|
{
|
|
m_tests.insert(m_currrentTest);
|
|
|
|
if (m_failCount.find(m_currrentTest) == m_failCount.end())
|
|
{
|
|
m_failCount[m_currrentTest] = 1;
|
|
}
|
|
else
|
|
{
|
|
m_failCount[m_currrentTest]++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void GTestRepeatHelper::OnTestEnd(const ::testing::TestInfo& test_info)
|
|
{
|
|
const ::std::string testName = test_info.name();
|
|
|
|
if (m_tests.find(m_currrentTest) != m_tests.end())
|
|
{
|
|
if (m_currentIteration < m_countIteration && testName.substr(0, 6) != "LOCAL_") // Local tests should NOT be flaky
|
|
{
|
|
PRINT_LINE("[ US_TEST_ERROR_WILL_RETRY ]\n");
|
|
}
|
|
else
|
|
{
|
|
PRINT_LINE("[ US_TEST_ERROR_FAILED ]\n"); // This strip triggers a failure on anthill.
|
|
}
|
|
}
|
|
}
|
|
|
|
US_TEST_NS_END; |