50 lines
1.8 KiB
C++
50 lines
1.8 KiB
C++
#include "simulation.hpp"
|
|
|
|
#include <exception>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
namespace model = ota::installation;
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc == 2 && std::string(argv[1]) == "--help") {
|
|
std::cout << "Usage: installation-simulate [all|--help]\n";
|
|
return 0;
|
|
}
|
|
if (argc > 2 || (argc == 2 && std::string(argv[1]) != "all")) {
|
|
std::cerr << "Usage: installation-simulate [all|--help]\n";
|
|
return 1;
|
|
}
|
|
try {
|
|
for (int cut = 0; cut <= model::installation_steps; ++cut) {
|
|
model::Storage storage;
|
|
{
|
|
model::Installer installer(storage);
|
|
for (int step = 0; step < cut; ++step) model::perform_step(installer, step);
|
|
}
|
|
model::Installer restarted(storage);
|
|
const auto action = restarted.recover();
|
|
std::cout << "Reset after " << cut << " steps: boot=" << model::boot_choice(storage.boot)
|
|
<< "; " << model::name(action) << '\n';
|
|
}
|
|
for (const auto result: {model::WriteResult::OldRecord, model::WriteResult::NewRecord, model::WriteResult::InvalidRecord}) {
|
|
model::Storage storage;
|
|
{
|
|
model::Installer installer(storage);
|
|
for (int step = 0; step < 5; ++step) model::perform_step(installer, step);
|
|
try {
|
|
installer.request_trial(result);
|
|
} catch (const std::runtime_error &error) {
|
|
std::cout << error.what() << '\n';
|
|
}
|
|
}
|
|
model::Installer restarted(storage);
|
|
std::cout << "Boot-state write outcome: " << model::name(restarted.recover()) << '\n';
|
|
}
|
|
} catch (const std::exception &error) {
|
|
std::cerr << error.what() << '\n';
|
|
return 1;
|
|
}
|
|
}
|