Add cellular owner checkpoint codec
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 41s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 31s
Foundation / checks (network) (push) Failing after 3m3s
Foundation / checks (client) (push) Failing after 4m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 41s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 31s
Foundation / checks (network) (push) Failing after 3m3s
Foundation / checks (client) (push) Failing after 4m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#include "evo/server/lifecycle/cellular_lives.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <span>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace evo::server;
|
||||
@@ -27,6 +31,19 @@ Inventory founder_price(std::uint64_t count) {
|
||||
return funding;
|
||||
}
|
||||
|
||||
std::uint64_t checksum(std::span<const std::uint8_t> bytes) {
|
||||
std::uint64_t value = 14695981039346656037ULL;
|
||||
for (const auto byte : bytes)
|
||||
value = (value ^ byte) * 1099511628211ULL;
|
||||
return value;
|
||||
}
|
||||
|
||||
void refresh_checksum(std::vector<std::uint8_t>& bytes) {
|
||||
const auto value = checksum(std::span{bytes}.first(bytes.size() - 8));
|
||||
for (unsigned i = 0; i < 8; ++i)
|
||||
bytes[bytes.size() - 8 + i] = static_cast<std::uint8_t>(value >> (i * 8U));
|
||||
}
|
||||
|
||||
void owner_advances_and_closes_death_atomically() {
|
||||
auto primitive = PrimitiveLives::create({90, 1, 7, 17, founder_price(2), {{0, 0}, {20, 0}}});
|
||||
CHECK(primitive);
|
||||
@@ -71,6 +88,27 @@ void owner_advances_and_closes_death_atomically() {
|
||||
CHECK(owner.habitat().patches()[0].stock == (Inventory{{0}, {}}));
|
||||
CHECK(owner.current_total() == owner.opening_total());
|
||||
|
||||
const auto saved = owner.snapshot();
|
||||
CHECK(saved.size() <= max_cellular_lives_bytes);
|
||||
auto recovered = CellularLives::restore(saved, 90, 1, 7, owner.tick());
|
||||
CHECK(recovered && (*recovered)->snapshot() == saved);
|
||||
CHECK(!CellularLives::restore(saved, 91, 1, 7, owner.tick()));
|
||||
CHECK(!CellularLives::restore(saved, 90, 1, 7, owner.tick() + 1));
|
||||
auto damaged = saved;
|
||||
damaged[100] ^= 1;
|
||||
const auto damaged_result = CellularLives::restore(damaged, 90, 1, 7, owner.tick());
|
||||
CHECK(!damaged_result && damaged_result.error() == CellularLivesError::checksum);
|
||||
auto unsupported = saved;
|
||||
unsupported[8] = static_cast<std::uint8_t>(cellular_lives_format + 1);
|
||||
refresh_checksum(unsupported);
|
||||
const auto unsupported_result =
|
||||
CellularLives::restore(unsupported, 90, 1, 7, owner.tick());
|
||||
CHECK(!unsupported_result && unsupported_result.error() == CellularLivesError::version);
|
||||
auto outside = saved;
|
||||
std::fill(outside.begin() + 300, outside.begin() + 308, uint8_t{0xff});
|
||||
refresh_checksum(outside);
|
||||
CHECK(!CellularLives::restore(outside, 90, 1, 7, owner.tick()));
|
||||
|
||||
std::size_t steps{};
|
||||
while (!owner.lives().empty() && steps < 2'000) {
|
||||
std::vector<CellularLifeIntent> idle;
|
||||
@@ -78,7 +116,10 @@ void owner_advances_and_closes_death_atomically() {
|
||||
for (const auto& life : owner.lives())
|
||||
idle.push_back({life.identity.life, {}});
|
||||
const auto advanced = owner.advance_tick(idle);
|
||||
CHECK(advanced && owner.current_total() == owner.opening_total());
|
||||
const auto replayed = (*recovered)->advance_tick(idle);
|
||||
CHECK(advanced && replayed && *advanced == *replayed);
|
||||
CHECK(owner.snapshot() == (*recovered)->snapshot());
|
||||
CHECK(owner.current_total() == owner.opening_total());
|
||||
++steps;
|
||||
}
|
||||
CHECK(owner.lives().empty() && owner.corpses().size() == 2 && steps < 2'000);
|
||||
@@ -94,6 +135,13 @@ void owner_advances_and_closes_death_atomically() {
|
||||
second_lineage->died.value == owner.corpses()[1].died_tick);
|
||||
CHECK(owner.heat().energy.value != 0);
|
||||
CHECK(owner.current_total() == owner.opening_total());
|
||||
const auto terminal_snapshot = owner.snapshot();
|
||||
auto terminal_recovery = CellularLives::restore(terminal_snapshot, 90, 1, 7, owner.tick());
|
||||
CHECK(terminal_recovery && (*terminal_recovery)->snapshot() == terminal_snapshot);
|
||||
CHECK((*terminal_recovery)->lives().empty() &&
|
||||
std::ranges::equal((*terminal_recovery)->corpses(), owner.corpses()));
|
||||
CHECK((*terminal_recovery)->heat() == owner.heat());
|
||||
CHECK((*terminal_recovery)->archive().organism(101) == owner.archive().organism(101));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user