Add configurable crash-site salvage; record Workshop 0.0.146
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""Exercise the production worker's preparation, finite-slot and stop rules."""
|
||||
from policy_harness import ROOT, body, run
|
||||
step = body(ROOT / 'addons/core/Scripts/Game/ERR/00_Core/ERR_CrashSites.c', 'protected void Step(')
|
||||
step = step.replace('protected void Step', 'void Step').replace('Replication.IsServer()', 'Replication::IsServer()').replace('ERR_GameMode.Get()', 'ERR_GameMode::Get()').replace('ERR_MissionRules.Terminal', 'ERR_MissionRules::Terminal').replace('m_Mode.', 'm_Mode->').replace('System.GetTickCount()', '0').replace('LogLevel.WARNING', '0')
|
||||
run(r'''
|
||||
#include <cassert>
|
||||
using vector = int;
|
||||
void Print(const char*,int){}
|
||||
namespace Replication { bool server=true; bool IsServer(){return server;} }
|
||||
namespace ERR_MissionRules { bool Terminal(int phase){return phase==2;} }
|
||||
struct ERR_GameMode { int phase=0; bool Active(){return phase==1;} int Phase(){return phase;} static ERR_GameMode* Get(); } mode;
|
||||
ERR_GameMode* ERR_GameMode::Get(){return &mode;}
|
||||
struct Worker {
|
||||
ERR_GameMode* m_Mode=&mode;
|
||||
bool m_Stopped=false, m_Pending=false, ready=true, surveyed=true, created=true;
|
||||
int m_Consumed=0,m_Target=2,m_Attempts=0,m_Skipped=0,spawns=0,fills=0;
|
||||
void Stop(){m_Stopped=true;}
|
||||
bool Ready(){return ready;}
|
||||
bool Survey(vector&,float&){return surveyed;}
|
||||
bool Create(vector,float){spawns++;m_Pending=created;return created;}
|
||||
void Fill(){fills++;m_Pending=false;}
|
||||
''' + step + r'''
|
||||
};
|
||||
int main(){
|
||||
Worker waiting;
|
||||
for(int i=0;i<1000;i++)waiting.Step();
|
||||
assert(!waiting.m_Stopped && waiting.m_Attempts==0 && waiting.spawns==0);
|
||||
mode.phase=1;waiting.ready=false;
|
||||
for(int i=0;i<1000;i++)waiting.Step();
|
||||
assert(!waiting.m_Stopped && waiting.m_Attempts==0);
|
||||
waiting.ready=true;
|
||||
for(int i=0;i<1000;i++)waiting.Step();
|
||||
assert(waiting.spawns==2 && waiting.fills==2 && waiting.m_Consumed==2 && waiting.m_Stopped);
|
||||
Worker disabled;disabled.m_Target=0;disabled.Step();assert(disabled.spawns==0&&disabled.m_Stopped);
|
||||
Worker impossible;impossible.surveyed=false;
|
||||
for(int i=0;i<4001;i++)impossible.Step();
|
||||
assert(impossible.spawns==0&&impossible.m_Skipped==2&&impossible.m_Stopped);
|
||||
Worker failed;failed.created=false;
|
||||
for(int i=0;i<10;i++)failed.Step();
|
||||
assert(failed.spawns==2&&failed.m_Skipped==2&&failed.m_Stopped);
|
||||
Worker client;Replication::server=false;client.Step();assert(client.spawns==0&&client.m_Stopped);
|
||||
Replication::server=true;mode.phase=2;Worker ended;ended.Step();assert(ended.spawns==0&&ended.m_Stopped);
|
||||
}
|
||||
''')
|
||||
print('PASS: crash worker waits through preparation, bounds failed searches, consumes slots once, never refills, and stops on clients/end')
|
||||
Reference in New Issue
Block a user