Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/tests/D3D12Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@

namespace gpgmm::d3d12 {

D3D12_MESSAGE_SEVERITY GetMessageSeverity(LogSeverity logSeverity) {
switch (logSeverity) {
case LogSeverity::Error:
return D3D12_MESSAGE_SEVERITY_ERROR;
case LogSeverity::Warning:
return D3D12_MESSAGE_SEVERITY_WARNING;
case LogSeverity::Info:
return D3D12_MESSAGE_SEVERITY_INFO;
case LogSeverity::Debug:
return D3D12_MESSAGE_SEVERITY_MESSAGE;
default:
UNREACHABLE();
return {};
}
}

void D3D12TestBase::SetUp() {
GPGMMTestBase::SetUp();

Expand Down Expand Up @@ -71,7 +87,7 @@ namespace gpgmm::d3d12 {
desc.Flags |= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH;
}

desc.MinLogLevel = GetDefaultLogLevel();
desc.MinLogLevel = GetMessageSeverity(GetLogLevel());

if (IsDumpAllEventsEnabled()) {
desc.RecordOptions.Flags |= EVENT_RECORD_FLAG_ALL_EVENTS;
Expand Down Expand Up @@ -138,12 +154,4 @@ namespace gpgmm::d3d12 {
#endif
}

D3D12_MESSAGE_SEVERITY D3D12TestBase::GetDefaultLogLevel() const {
#if defined(NDEBUG)
return D3D12_MESSAGE_SEVERITY_WARNING;
#else
return D3D12_MESSAGE_SEVERITY_MESSAGE;
#endif
}

} // namespace gpgmm::d3d12
2 changes: 2 additions & 0 deletions src/tests/D3D12Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace gpgmm::d3d12 {
class ResourceAllocator;
class ResourceAllocation;

D3D12_MESSAGE_SEVERITY GetMessageSeverity(LogSeverity logSeverity);

class D3D12TestBase : public GPGMMTestBase {
public:
void SetUp();
Expand Down
35 changes: 34 additions & 1 deletion src/tests/GPGMMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ bool GPGMMTestBase::IsDumpAllEventsEnabled() const {
return gTestEnv->IsDumpAllEventsEnabled();
}

gpgmm::LogSeverity GPGMMTestBase::GetLogLevel() const {
return gTestEnv->GetLogLevel();
}

// static
std::vector<MEMORY_ALLOCATION_EXPECT> GPGMMTestBase::GenerateTestAllocations(uint64_t alignment) {
return {
Expand Down Expand Up @@ -101,9 +105,34 @@ GPGMMTestEnvironment::GPGMMTestEnvironment(int argc, char** argv) {
continue;
}

constexpr const char kLogLevel[] = "--log-level";
size_t arglen = sizeof(kLogLevel) - 1;
if (strncmp(argv[i], kLogLevel, arglen) == 0) {
const char* level = argv[i] + arglen;
if (level[0] != '\0') {
if (strcmp(level, "=DEBUG") == 0) {
mLogLevel = gpgmm::LogSeverity::Debug;
} else if (strcmp(level, "=INFO") == 0) {
mLogLevel = gpgmm::LogSeverity::Info;
} else if (strcmp(level, "=WARN") == 0) {
mLogLevel = gpgmm::LogSeverity::Warning;
} else if (strcmp(level, "=ERROR") == 0) {
mLogLevel = gpgmm::LogSeverity::Error;
} else {
gpgmm::ErrorLog() << "Invalid log message level " << level << ".\n";
UNREACHABLE();
}
} else {
mLogLevel = gpgmm::LogSeverity::Warning;
}
continue;
}

if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
gpgmm::InfoLog() << "Global options:\n"
<< " --dump: Record all events to disk.\n";
<< " --dump: Record all events to disk.\n"
<< " --log-level=[DEBUG|INFO|WARN|ERROR]: Log severity "
"level for log messages.\n";
continue;
}
}
Expand All @@ -120,3 +149,7 @@ void GPGMMTestEnvironment::SetUp() {
bool GPGMMTestEnvironment::IsDumpAllEventsEnabled() const {
return mIsDumpAllEventsEnabled;
}

gpgmm::LogSeverity GPGMMTestEnvironment::GetLogLevel() const {
return mLogLevel;
}
8 changes: 8 additions & 0 deletions src/tests/GPGMMTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class GPGMMTestBase {
gpgmm::DebugPlatform* GetDebugPlatform();

bool IsDumpAllEventsEnabled() const;
gpgmm::LogSeverity GetLogLevel() const;

static std::vector<MEMORY_ALLOCATION_EXPECT> GenerateTestAllocations(uint64_t alignment);
};
Expand All @@ -77,9 +78,16 @@ class GPGMMTestEnvironment : public testing::Environment {
void SetUp() override;

bool IsDumpAllEventsEnabled() const;
gpgmm::LogSeverity GetLogLevel() const;

private:
bool mIsDumpAllEventsEnabled = false;

#if defined(NDEBUG)
gpgmm::LogSeverity mLogLevel = gpgmm::LogSeverity::Warning;
#else
gpgmm::LogSeverity mLogLevel = gpgmm::LogSeverity::Info;
#endif
};

#endif // TESTS_GPGMMTEST_H_
28 changes: 6 additions & 22 deletions src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,6 @@ namespace {
return (args.isMember("Description") && args.isMember("ID"));
}

D3D12_MESSAGE_SEVERITY GetMessageSeverity(gpgmm::LogSeverity logSeverity) {
switch (logSeverity) {
case gpgmm::LogSeverity::Error:
return D3D12_MESSAGE_SEVERITY_ERROR;
case gpgmm::LogSeverity::Warning:
return D3D12_MESSAGE_SEVERITY_WARNING;
case gpgmm::LogSeverity::Info:
return D3D12_MESSAGE_SEVERITY_INFO;
case gpgmm::LogSeverity::Debug:
return D3D12_MESSAGE_SEVERITY_MESSAGE;
default:
UNREACHABLE();
return D3D12_MESSAGE_SEVERITY_MESSAGE;
}
}

} // namespace

class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWithParams {
Expand Down Expand Up @@ -324,7 +308,7 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
residencyDesc.EvictBatchSize = snapshot["EvictBatchSize"].asUInt64();
residencyDesc.InitialFenceValue = snapshot["InitialFenceValue"].asUInt64();

if (envParams.LogLevel <= gpgmm::LogSeverity::Warning &&
if (GetLogLevel() <= gpgmm::LogSeverity::Warning &&
residencyDesc.IsUMA != snapshot["IsUMA"].asBool() &&
iterationIndex == 0) {
gpgmm::WarningLog()
Expand All @@ -339,7 +323,7 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
static_cast<EVENT_RECORD_FLAGS_TYPE>(envParams.CaptureEventMask);
residencyDesc.RecordOptions.TraceFile = traceFile.path;
residencyDesc.RecordOptions.MinMessageLevel =
GetMessageSeverity(envParams.LogLevel);
GetMessageSeverity(GetLogLevel());

// Keep recording across multiple playback iterations to ensure all
// events will be captured instead of overwritten per iteration.
Expand All @@ -349,7 +333,7 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
}
}

residencyDesc.MinLogLevel = GetMessageSeverity(envParams.LogLevel);
residencyDesc.MinLogLevel = GetMessageSeverity(GetLogLevel());

ComPtr<ResidencyManager> residencyManager;
ASSERT_SUCCEEDED(ResidencyManager::CreateResidencyManager(
Expand Down Expand Up @@ -421,7 +405,7 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
static_cast<EVENT_RECORD_FLAGS_TYPE>(envParams.CaptureEventMask);
allocatorDesc.RecordOptions.TraceFile = traceFile.path;
allocatorDesc.RecordOptions.MinMessageLevel =
GetMessageSeverity(envParams.LogLevel);
GetMessageSeverity(GetLogLevel());

// Keep recording across multiple playback iterations to ensure all
// events will be captured instead of overwritten per iteration.
Expand All @@ -431,9 +415,9 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
}
}

allocatorDesc.MinLogLevel = GetMessageSeverity(envParams.LogLevel);
allocatorDesc.MinLogLevel = GetMessageSeverity(GetLogLevel());

if (envParams.LogLevel <= gpgmm::LogSeverity::Warning &&
if (GetLogLevel() <= gpgmm::LogSeverity::Warning &&
allocatorDesc.ResourceHeapTier !=
snapshot["ResourceHeapTier"].asInt() &&
iterationIndex == 0) {
Expand Down
42 changes: 0 additions & 42 deletions src/tests/capture_replay_tests/GPGMMCaptureReplayTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ namespace {

GPGMMCaptureReplayTestEnvironment* gTestEnv = nullptr;

std::string LogSeverityToString(const gpgmm::LogSeverity& severity) {
switch (severity) {
case gpgmm::LogSeverity::Debug:
return "DEBUG";
case gpgmm::LogSeverity::Info:
return "INFO";
case gpgmm::LogSeverity::Warning:
return "WARN";
case gpgmm::LogSeverity::Error:
return "ERROR";
default:
UNREACHABLE();
return "";
}
}

std::string AllocatorProfileToString(const AllocatorProfile& profile) {
switch (profile) {
case AllocatorProfile::ALLOCATOR_PROFILE_MAX_PERFORMANCE:
Expand Down Expand Up @@ -116,29 +100,6 @@ GPGMMCaptureReplayTestEnvironment::GPGMMCaptureReplayTestEnvironment(int argc, c
continue;
}

constexpr const char kLogLevel[] = "--log-level";
arglen = sizeof(kLogLevel) - 1;
if (strncmp(argv[i], kLogLevel, arglen) == 0) {
const char* level = argv[i] + arglen;
if (level[0] != '\0') {
if (strcmp(level, "=DEBUG") == 0) {
mParams.LogLevel = gpgmm::LogSeverity::Debug;
} else if (strcmp(level, "=INFO") == 0) {
mParams.LogLevel = gpgmm::LogSeverity::Info;
} else if (strcmp(level, "=WARN") == 0) {
mParams.LogLevel = gpgmm::LogSeverity::Warning;
} else if (strcmp(level, "=ERROR") == 0) {
mParams.LogLevel = gpgmm::LogSeverity::Error;
} else {
gpgmm::ErrorLog() << "Invalid log message level " << level << ".\n";
UNREACHABLE();
}
} else {
mParams.LogLevel = gpgmm::LogSeverity::Warning;
}
continue;
}

constexpr const char kPlaybackFile[] = "--playback-file=";
arglen = sizeof(kPlaybackFile) - 1;
if (strncmp(argv[i], kPlaybackFile, arglen) == 0) {
Expand Down Expand Up @@ -170,8 +131,6 @@ GPGMMCaptureReplayTestEnvironment::GPGMMCaptureReplayTestEnvironment(int argc, c
<< "Playback options:"
<< " [--iterations=X]\n"
<< " --iterations: Number of times to run playback.\n"
<< " --log-level=[DEBUG|INFO|WARN|ERROR]: Log severity "
"level for log messages.\n"
<< " --capture-mask: Event mask to record during capture.\n"
<< " --playback-file: Path to captured file to playback.\n"
<< " --same-caps: Captured device must be compatible with playback device.\n"
Expand Down Expand Up @@ -201,7 +160,6 @@ void GPGMMCaptureReplayTestEnvironment::PrintCaptureReplaySettings() const {
gpgmm::InfoLog() << "Playback settings\n"
"-----------------\n"
<< "Iterations per test: " << mParams.Iterations << "\n"
<< "Log level: " << LogSeverityToString(mParams.LogLevel) << "\n"
<< "Must use same caps: " << (mParams.IsSameCapsRequired ? "true" : "false")
<< "\n"
<< "No Allocations: "
Expand Down
5 changes: 1 addition & 4 deletions src/tests/capture_replay_tests/GPGMMCaptureReplayTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "tests/GPGMMTest.h"

#include "gpgmm/utils/Log.h"

#include <regex>
#include <string>

Expand All @@ -44,8 +42,7 @@ enum class AllocatorProfile {
};

struct TestEnviromentParams {
uint64_t Iterations = 1; // Number of test iterations to run.
gpgmm::LogSeverity LogLevel = gpgmm::LogSeverity::Info; // Level of logging.
uint64_t Iterations = 1; // Number of test iterations to run.
int CaptureEventMask = 0;

bool IsSameCapsRequired = false; // Caps of test device must match capture caps.
Expand Down
2 changes: 1 addition & 1 deletion src/tests/end2end/D3D12ResidencyManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test
residencyDesc.Adapter = mAdapter;
residencyDesc.Device = mDevice;

residencyDesc.MinLogLevel = GetDefaultLogLevel();
residencyDesc.MinLogLevel = GetMessageSeverity(GetLogLevel());

if (IsDumpAllEventsEnabled()) {
residencyDesc.RecordOptions.Flags |= EVENT_RECORD_FLAG_ALL_EVENTS;
Expand Down