Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,14 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzTest_Traits_Windows.h>
@@ -0,0 +1,20 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#define AZ_TRAIT_AZTEST_ATTACH_RESULT_LISTENER 0
// Unit Test traits ...
#define AZ_TRAIT_UNIT_TEST_ASSET_MANAGER_TEST_DEFAULT_TIMEOUT_SECS 5
#define AZ_TRAIT_UNIT_TEST_ENTITY_ID_GEN_TEST_COUNT 10000
#define AZ_TRAIT_UNIT_TEST_DILLER_TRIGGER_EVENT_COUNT 100000
#define AZ_TRAIT_UNIT_TEST_NAME_COUNT 1000
@@ -0,0 +1,167 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/PlatformIncl.h>
#include <string>
#include <iostream>
#include <AzTest/Platform.h>
//-------------------------------------------------------------------------------------------------
class ModuleHandle
: public AZ::Test::IModuleHandle
{
public:
explicit ModuleHandle(const std::string& lib)
: m_libHandle(NULL)
{
std::string libext = lib;
if (!AZ::Test::EndsWith(libext, ".dll"))
{
libext += ".dll";
}
m_libHandle = ::LoadLibraryA(libext.c_str()); // LoadLibrary conflicts with CryEngine code, so use LoadLibraryA
if (m_libHandle == NULL)
{
DWORD dw = ::GetLastError();
std::cerr << "FAILED to load library: " << libext << "; GetLastError() returned " << dw << std::endl;
}
}
ModuleHandle(const ModuleHandle&) = delete;
ModuleHandle& operator=(const ModuleHandle&) = delete;
~ModuleHandle() override
{
if (m_libHandle != NULL)
{
FreeLibrary(m_libHandle);
}
}
bool IsValid() override { return m_libHandle != NULL; }
std::shared_ptr<AZ::Test::IFunctionHandle> GetFunction(const std::string& name) override;
private:
friend class FunctionHandle;
HINSTANCE m_libHandle;
};
//-------------------------------------------------------------------------------------------------
class FunctionHandle
: public AZ::Test::IFunctionHandle
{
public:
explicit FunctionHandle(ModuleHandle& module, std::string symbol)
: m_proc(NULL)
{
m_proc = ::GetProcAddress(module.m_libHandle, symbol.c_str());
}
FunctionHandle(const FunctionHandle&) = delete;
FunctionHandle& operator=(const FunctionHandle&) = delete;
~FunctionHandle() override = default;
int operator()(int argc, char** argv) override
{
using Fn = int(int, char**);
Fn* fn = reinterpret_cast<Fn*>(m_proc);
return (*fn)(argc, argv);
}
int operator()() override
{
using Fn = int();
Fn* fn = reinterpret_cast<Fn*>(m_proc);
return (*fn)();
}
bool IsValid() override { return m_proc != NULL; }
private:
FARPROC m_proc;
};
//-------------------------------------------------------------------------------------------------
std::shared_ptr<AZ::Test::IFunctionHandle> ModuleHandle::GetFunction(const std::string& name)
{
return std::make_shared<FunctionHandle>(*this, name);
}
//-------------------------------------------------------------------------------------------------
namespace AZ
{
namespace Test
{
Platform& GetPlatform()
{
static Platform s_platform;
return s_platform;
}
bool Platform::SupportsWaitForDebugger()
{
return true;
}
std::shared_ptr<IModuleHandle> Platform::GetModule(const std::string& lib)
{
return std::make_shared<ModuleHandle>(lib);
}
void Platform::WaitForDebugger()
{
while (!::IsDebuggerPresent()) {}
}
void Platform::SuppressPopupWindows()
{
// use SetErrorMode to disable popup windows in case a required library cannot be found
DWORD errorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);
::SetErrorMode(errorMode | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
}
std::string Platform::GetModuleNameFromPath(const std::string& path)
{
size_t start = path.rfind('\\');
if (start == std::string::npos)
{
start = 0;
}
size_t end = path.rfind('.');
return path.substr(start, end);
}
void Platform::Printf(const char* format, ...)
{
char message[MAX_PRINT_MSG];
va_list mark;
va_start(mark, format);
azvsnprintf(message, MAX_PRINT_MSG, format, mark);
va_end(mark);
OutputDebugString(message);
}
AZ::EnvironmentInstance Platform::GetTestRunnerEnvironment()
{
// Not currently supported
return nullptr;
}
} // Test
} // AZ
@@ -0,0 +1,70 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <stdlib.h>
#include <windows.h>
#include <sysinfoapi.h>
#include <fileapi.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/std/functional.h>
#include <AzCore/IO/SystemFile.h>
#include <AzTest/Platform.h>
namespace AZ
{
namespace Test
{
ScopedAutoTempDirectory::ScopedAutoTempDirectory()
{
constexpr const DWORD bufferSize = static_cast<DWORD>(AZ::IO::MaxPathLength);
char tempDir[bufferSize] = {0};
GetTempPathA(bufferSize, tempDir);
char workingTempPathBuffer[bufferSize] = {'\0'};
int maxAttempts = 2000; // Prevent an infinite loop by setting an arbitrary maximum attempts at finding an available temp folder name
while (maxAttempts > 0)
{
// Use the system's tick count to base the folder name
DWORD currentTick = GetTickCount64();
azsnprintf(workingTempPathBuffer, bufferSize, "%sUnitTest-%X", tempDir, aznumeric_cast<unsigned int>(currentTick));
// Check if the requested directory name is available and re-generate if it already exists
bool exists = AZ::IO::SystemFile::Exists(workingTempPathBuffer);
if (exists)
{
Sleep(1);
maxAttempts--;
continue;
}
break;
}
AZ_Error("AzTest", maxAttempts > 0, "Unable to determine a temp directory");
if (maxAttempts > 0)
{
// Create the temp directory and track it for deletion
bool tempDirectoryCreated = AZ::IO::SystemFile::CreateDir(workingTempPathBuffer);
if (tempDirectoryCreated)
{
azstrncpy(m_tempDirectory, AZ::IO::MaxPathLength, workingTempPathBuffer, AZ::IO::MaxPathLength);
}
else
{
AZ_Error("AzTest", false, "Unable to create temp directory %s", workingTempPathBuffer);
}
}
}
} // Test
} // AZ
@@ -0,0 +1,16 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# Platform specific cmake file for configuring target compiler/link properties
# based on the active platform
# NOTE: functions in cmake are global, therefore adding functions to this file
# is being avoided to prevent overriding functions declared in other targets platfrom
# specific cmake files
@@ -0,0 +1,18 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../Common/WinAPI/AzTest/ColorizedOutput_WinAPI.cpp
Platform_Windows.cpp
ScopedAutoTempDirectory_Windows.cpp
AzTest_Traits_Platform.h
AzTest_Traits_Windows.h
)