mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-30 08:11:01 +00:00
Separate application and emulator settings
This commit is contained in:
@@ -38,7 +38,30 @@ namespace test
|
||||
return env;
|
||||
}
|
||||
|
||||
inline windows_emulator create_sample_emulator(emulator_settings settings, const bool reproducible = false,
|
||||
struct sample_configuration
|
||||
{
|
||||
bool reproducible{false};
|
||||
bool print_time{false};
|
||||
};
|
||||
|
||||
inline application_settings get_sample_app_settings(const sample_configuration& config)
|
||||
{
|
||||
application_settings settings{.application = "C:\\test-sample.exe"};
|
||||
|
||||
if (config.print_time)
|
||||
{
|
||||
settings.arguments.emplace_back(u"-time");
|
||||
}
|
||||
|
||||
if (config.reproducible)
|
||||
{
|
||||
settings.arguments.emplace_back(u"-reproducible");
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
inline windows_emulator create_sample_emulator(emulator_settings settings, const sample_configuration& config = {},
|
||||
emulator_callbacks callbacks = {})
|
||||
{
|
||||
const auto is_verbose = enable_verbose_logging();
|
||||
@@ -49,29 +72,27 @@ namespace test
|
||||
// settings.verbose_calls = true;
|
||||
}
|
||||
|
||||
if (reproducible)
|
||||
{
|
||||
settings.arguments = {u"-reproducible"};
|
||||
}
|
||||
|
||||
settings.application = "c:/test-sample.exe";
|
||||
settings.emulation_root = get_emulator_root();
|
||||
|
||||
settings.port_mappings[28970] = static_cast<uint16_t>(getpid());
|
||||
settings.path_mappings["C:\\a.txt"] =
|
||||
std::filesystem::temp_directory_path() / ("emulator-test-file-" + std::to_string(getpid()) + ".txt");
|
||||
|
||||
return windows_emulator{std::move(settings), std::move(callbacks)};
|
||||
return windows_emulator{
|
||||
get_sample_app_settings(config),
|
||||
settings,
|
||||
std::move(callbacks),
|
||||
};
|
||||
}
|
||||
|
||||
inline windows_emulator create_sample_emulator(const bool reproducible = false)
|
||||
inline windows_emulator create_sample_emulator(const sample_configuration& config = {})
|
||||
{
|
||||
emulator_settings settings{
|
||||
.disable_logging = true,
|
||||
.use_relative_time = true,
|
||||
};
|
||||
|
||||
return create_sample_emulator(std::move(settings), reproducible);
|
||||
return create_sample_emulator(std::move(settings), config);
|
||||
}
|
||||
|
||||
inline void bisect_emulation(windows_emulator& emu)
|
||||
|
||||
@@ -2,9 +2,17 @@
|
||||
|
||||
namespace test
|
||||
{
|
||||
namespace
|
||||
{
|
||||
auto create_reproducible_sample_emulator()
|
||||
{
|
||||
return create_sample_emulator({.reproducible = true});
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SerializationTest, ResettingEmulatorWorks)
|
||||
{
|
||||
auto emu = create_sample_emulator(true);
|
||||
auto emu = create_reproducible_sample_emulator();
|
||||
|
||||
utils::buffer_serializer start_state{};
|
||||
emu.serialize(start_state);
|
||||
@@ -31,7 +39,7 @@ namespace test
|
||||
|
||||
TEST(SerializationTest, SerializedDataIsReproducible)
|
||||
{
|
||||
auto emu1 = create_sample_emulator(true);
|
||||
auto emu1 = create_reproducible_sample_emulator();
|
||||
emu1.start();
|
||||
|
||||
ASSERT_TERMINATED_SUCCESSFULLY(emu1);
|
||||
@@ -55,7 +63,7 @@ namespace test
|
||||
|
||||
TEST(SerializationTest, EmulationIsReproducible)
|
||||
{
|
||||
auto emu1 = create_sample_emulator(true);
|
||||
auto emu1 = create_reproducible_sample_emulator();
|
||||
emu1.start();
|
||||
|
||||
ASSERT_TERMINATED_SUCCESSFULLY(emu1);
|
||||
@@ -63,7 +71,7 @@ namespace test
|
||||
utils::buffer_serializer serializer1{};
|
||||
emu1.serialize(serializer1);
|
||||
|
||||
auto emu2 = create_sample_emulator(true);
|
||||
auto emu2 = create_reproducible_sample_emulator();
|
||||
emu2.start();
|
||||
|
||||
ASSERT_TERMINATED_SUCCESSFULLY(emu2);
|
||||
@@ -76,7 +84,7 @@ namespace test
|
||||
|
||||
TEST(SerializationTest, DeserializedEmulatorBehavesLikeSource)
|
||||
{
|
||||
auto emu = create_sample_emulator(true);
|
||||
auto emu = create_reproducible_sample_emulator();
|
||||
emu.start({}, 100);
|
||||
|
||||
utils::buffer_serializer serializer{};
|
||||
|
||||
@@ -7,16 +7,18 @@ namespace test
|
||||
std::string output_buffer{};
|
||||
|
||||
emulator_callbacks callbacks{
|
||||
.stdout_callback = [&output_buffer](const std::string_view data) { output_buffer.append(data); },
|
||||
.stdout_callback =
|
||||
[&output_buffer](const std::string_view data) {
|
||||
output_buffer.append(data); //
|
||||
},
|
||||
};
|
||||
|
||||
const emulator_settings settings{
|
||||
.arguments = {u"-time"},
|
||||
.disable_logging = true,
|
||||
.use_relative_time = false,
|
||||
};
|
||||
|
||||
auto emu = create_sample_emulator(settings, false, callbacks);
|
||||
auto emu = create_sample_emulator(settings, {.print_time = true}, std::move(callbacks));
|
||||
emu.start();
|
||||
|
||||
constexpr auto prefix = "Time: "sv;
|
||||
|
||||
Reference in New Issue
Block a user