Integrate ROM-dependent testing framework into YAZE
- Added a new RomDependentTestSuite to facilitate testing functionalities that rely on the currently loaded ROM, enhancing test coverage. - Updated EditorManager to register the new test suite and manage the current ROM for dependent tests. - Enhanced the IntegratedTestSuite to first check for a loaded ROM before proceeding with tests, improving robustness. - Improved the TestManager UI to indicate ROM loading status and provide feedback for running ROM-dependent tests. - Updated CMake configuration to include the new test suite header, ensuring proper integration into the build system.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#ifndef YAZE_APP_TEST_TEST_MANAGER_H
|
||||
#define YAZE_APP_TEST_TEST_MANAGER_H
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "app/rom.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
|
||||
@@ -21,22 +22,10 @@ namespace yaze {
|
||||
namespace test {
|
||||
|
||||
// Test execution status
|
||||
enum class TestStatus {
|
||||
kNotRun,
|
||||
kRunning,
|
||||
kPassed,
|
||||
kFailed,
|
||||
kSkipped
|
||||
};
|
||||
enum class TestStatus { kNotRun, kRunning, kPassed, kFailed, kSkipped };
|
||||
|
||||
// Test categories for organization
|
||||
enum class TestCategory {
|
||||
kUnit,
|
||||
kIntegration,
|
||||
kUI,
|
||||
kPerformance,
|
||||
kMemory
|
||||
};
|
||||
enum class TestCategory { kUnit, kIntegration, kUI, kPerformance, kMemory };
|
||||
|
||||
// Individual test result
|
||||
struct TestResult {
|
||||
@@ -57,27 +46,35 @@ struct TestResults {
|
||||
size_t failed_tests = 0;
|
||||
size_t skipped_tests = 0;
|
||||
std::chrono::milliseconds total_duration{0};
|
||||
|
||||
|
||||
void AddResult(const TestResult& result) {
|
||||
individual_results.push_back(result);
|
||||
total_tests++;
|
||||
switch (result.status) {
|
||||
case TestStatus::kPassed: passed_tests++; break;
|
||||
case TestStatus::kFailed: failed_tests++; break;
|
||||
case TestStatus::kSkipped: skipped_tests++; break;
|
||||
default: break;
|
||||
case TestStatus::kPassed:
|
||||
passed_tests++;
|
||||
break;
|
||||
case TestStatus::kFailed:
|
||||
failed_tests++;
|
||||
break;
|
||||
case TestStatus::kSkipped:
|
||||
skipped_tests++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
total_duration += result.duration;
|
||||
}
|
||||
|
||||
|
||||
void Clear() {
|
||||
individual_results.clear();
|
||||
total_tests = passed_tests = failed_tests = skipped_tests = 0;
|
||||
total_duration = std::chrono::milliseconds{0};
|
||||
}
|
||||
|
||||
|
||||
float GetPassRate() const {
|
||||
return total_tests > 0 ? static_cast<float>(passed_tests) / total_tests : 0.0f;
|
||||
return total_tests > 0 ? static_cast<float>(passed_tests) / total_tests
|
||||
: 0.0f;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -91,7 +88,7 @@ class TestSuite {
|
||||
virtual void DrawConfiguration() {}
|
||||
virtual bool IsEnabled() const { return enabled_; }
|
||||
virtual void SetEnabled(bool enabled) { enabled_ = enabled; }
|
||||
|
||||
|
||||
protected:
|
||||
bool enabled_ = true;
|
||||
};
|
||||
@@ -109,41 +106,40 @@ struct ResourceStats {
|
||||
class TestManager {
|
||||
public:
|
||||
static TestManager& Get();
|
||||
|
||||
|
||||
// Core test execution
|
||||
absl::Status RunAllTests();
|
||||
absl::Status RunTestsByCategory(TestCategory category);
|
||||
absl::Status RunTestSuite(const std::string& suite_name);
|
||||
|
||||
|
||||
// Test suite management
|
||||
void RegisterTestSuite(std::unique_ptr<TestSuite> suite);
|
||||
std::vector<std::string> GetTestSuiteNames() const;
|
||||
TestSuite* GetTestSuite(const std::string& name);
|
||||
|
||||
|
||||
// Results access
|
||||
const TestResults& GetLastResults() const { return last_results_; }
|
||||
void ClearResults() { last_results_.Clear(); }
|
||||
|
||||
|
||||
// Configuration
|
||||
void SetMaxConcurrentTests(size_t max_concurrent) {
|
||||
max_concurrent_tests_ = max_concurrent;
|
||||
void SetMaxConcurrentTests(size_t max_concurrent) {
|
||||
max_concurrent_tests_ = max_concurrent;
|
||||
}
|
||||
void SetTestTimeout(std::chrono::seconds timeout) {
|
||||
test_timeout_ = timeout;
|
||||
}
|
||||
|
||||
void SetTestTimeout(std::chrono::seconds timeout) { test_timeout_ = timeout; }
|
||||
|
||||
// Resource monitoring
|
||||
void UpdateResourceStats();
|
||||
const std::vector<ResourceStats>& GetResourceHistory() const {
|
||||
return resource_history_;
|
||||
const std::vector<ResourceStats>& GetResourceHistory() const {
|
||||
return resource_history_;
|
||||
}
|
||||
|
||||
|
||||
// UI Testing (ImGui Test Engine integration)
|
||||
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
|
||||
ImGuiTestEngine* GetUITestEngine() { return ui_test_engine_; }
|
||||
void InitializeUITesting();
|
||||
void StopUITesting(); // Stop test engine while ImGui context is valid
|
||||
void DestroyUITestingContext(); // Destroy test engine after ImGui context is destroyed
|
||||
void DestroyUITestingContext(); // Destroy test engine after ImGui context is
|
||||
// destroyed
|
||||
void ShutdownUITesting(); // Complete shutdown (calls both Stop and Destroy)
|
||||
#else
|
||||
void* GetUITestEngine() { return nullptr; }
|
||||
@@ -152,54 +148,61 @@ class TestManager {
|
||||
void DestroyUITestingContext() {}
|
||||
void ShutdownUITesting() {}
|
||||
#endif
|
||||
|
||||
|
||||
// Status queries
|
||||
bool IsTestRunning() const { return is_running_; }
|
||||
const std::string& GetCurrentTestName() const { return current_test_name_; }
|
||||
float GetProgress() const { return progress_; }
|
||||
|
||||
|
||||
// UI Interface
|
||||
void DrawTestDashboard();
|
||||
|
||||
|
||||
// ROM-dependent testing
|
||||
void SetCurrentRom(Rom* rom) { current_rom_ = rom; }
|
||||
Rom* GetCurrentRom() const { return current_rom_; }
|
||||
|
||||
private:
|
||||
TestManager();
|
||||
~TestManager();
|
||||
|
||||
|
||||
// Test execution helpers
|
||||
absl::Status ExecuteTestSuite(TestSuite* suite);
|
||||
void UpdateProgress();
|
||||
|
||||
|
||||
// Resource monitoring helpers
|
||||
void CollectResourceStats();
|
||||
void TrimResourceHistory();
|
||||
|
||||
|
||||
// Member variables
|
||||
std::vector<std::unique_ptr<TestSuite>> test_suites_;
|
||||
std::unordered_map<std::string, TestSuite*> suite_lookup_;
|
||||
|
||||
|
||||
TestResults last_results_;
|
||||
bool is_running_ = false;
|
||||
std::string current_test_name_;
|
||||
float progress_ = 0.0f;
|
||||
|
||||
|
||||
// Configuration
|
||||
size_t max_concurrent_tests_ = 1;
|
||||
std::chrono::seconds test_timeout_{30};
|
||||
|
||||
|
||||
// Resource monitoring
|
||||
std::vector<ResourceStats> resource_history_;
|
||||
static constexpr size_t kMaxResourceHistorySize = 1000;
|
||||
|
||||
|
||||
// UI Testing
|
||||
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
|
||||
ImGuiTestEngine* ui_test_engine_ = nullptr;
|
||||
#endif
|
||||
|
||||
|
||||
// UI State
|
||||
bool show_dashboard_ = false;
|
||||
bool show_resource_monitor_ = false;
|
||||
std::string test_filter_;
|
||||
TestCategory category_filter_ = TestCategory::kUnit;
|
||||
|
||||
// ROM-dependent testing
|
||||
Rom* current_rom_ = nullptr;
|
||||
};
|
||||
|
||||
// Utility functions for test result formatting
|
||||
|
||||
Reference in New Issue
Block a user