Skip to content

Commit

Permalink
Output random log on autoplay test failure
Browse files Browse the repository at this point in the history
Useful to trace the issue.
  • Loading branch information
Flamefire committed Jul 8, 2024
1 parent 6eda6b8 commit 6cd9fbf
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/s25Main/autoplay/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "network/PlayerGameCommands.h"
#include "ogl/glAllocator.h"
#include "random/Random.h"
#include "random/randomIO.h"
#include "variant.h"
#include "world/GameWorld.h"
#include "world/MapLoader.h"
Expand All @@ -26,14 +27,26 @@
# include <vld.h>
#endif

#include "gameTypes/BuildingType.h"

struct Fixture : rttr::test::Fixture
{
Fixture() { libsiedler2::setAllocator(new GlAllocator); }
};
BOOST_GLOBAL_FIXTURE(Fixture);

static boost::test_tools::predicate_result verifyChecksum(const AsyncChecksum& actual, const AsyncChecksum& expected,
const bool fail = false)
{
if(!fail && (expected.randChecksum == 0 || actual == expected))
return true;
// LCOV_EXCL_START
boost::test_tools::predicate_result result(false);
result.message() << '\n' << actual << " != \n" << expected << '\n';
for(const auto& entry : RANDOM.GetAsyncLog())
result.message() << entry << '\n';
return result;
// LCOV_EXCL_STOP
}

static void playReplay(const boost::filesystem::path& replayPath)
{
Replay replay;
Expand Down Expand Up @@ -76,12 +89,10 @@ static void playReplay(const boost::filesystem::path& replayPath)
BOOST_TEST_INFO("Current GF: " << curGF);
const auto cmd = replay.ReadCommand();
visit(composeVisitor([](const Replay::ChatCommand&) {},
[&game, &checksum](const Replay::GameCommand& cmd) {
[&](const Replay::GameCommand& cmd) {
for(const gc::GameCommandPtr& gc : cmd.cmds.gcs)
gc->Execute(game.world_, cmd.player);
const AsyncChecksum& msgChecksum = cmd.cmds.checksum;
if(msgChecksum.randChecksum != 0)
BOOST_TEST_REQUIRE(msgChecksum == checksum);
BOOST_TEST_REQUIRE(verifyChecksum(checksum, cmd.cmds.checksum));
}),
cmd);
nextGF = replay.ReadGF();
Expand Down

0 comments on commit 6cd9fbf

Please sign in to comment.