next chapter
This commit is contained in:
1 parent
9385583955
commit
c98eccc057
21 files changed
+1054
-11
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#include "simulation.hpp"
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace model = ota::rollback;
|
||||
|
||||
namespace {
|
||||
|
||||
void usage(std::ostream &output) {
|
||||
output << "Usage: rollback-simulate [all|SCENARIO|--help]\nScenarios:\n";
|
||||
for (const auto &scenario: model::scenarios()) output << " " << scenario << '\n';
|
||||
}
|
||||
|
||||
void run(const std::string &scenario) {
|
||||
const auto result = model::run_scenario(scenario);
|
||||
std::cout << scenario << ": " << model::name(result.phase)
|
||||
<< "; running=" << (result.running == model::Slot::A ? "A" : "B")
|
||||
<< "; boots=" << result.boots_requested
|
||||
<< "; attempts-left=" << result.attempts_left
|
||||
<< "; records-lost=" << result.records_lost
|
||||
<< "; failed-release-blocked=" << (result.blocked_releases.count(result.failed_release) != 0)
|
||||
<< "; " << result.recovery_reason << '\n';
|
||||
}
|
||||
|
||||
}// namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc == 2 && std::string(argv[1]) == "--help") {
|
||||
usage(std::cout);
|
||||
return 0;
|
||||
}
|
||||
if (argc > 2) {
|
||||
usage(std::cerr);
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
const std::string requested = argc == 2 ? argv[1] : "all";
|
||||
if (requested == "all") {
|
||||
for (const auto &scenario: model::scenarios()) run(scenario);
|
||||
} else
|
||||
run(requested);
|
||||
} catch (const std::exception &error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
usage(std::cerr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user