29 lines
1.9 KiB
Python
29 lines
1.9 KiB
Python
"""Real event queue/lifecycle/plan bodies; allocation faults and paused deadlines."""
|
|
import re
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
GAME=ROOT/'src/server/game/src'
|
|
|
|
class CubeRestore(unittest.TestCase):
|
|
def test_real_event_ownership_paused_expiry_and_inventory_commit(self):
|
|
def body(name):
|
|
return re.sub(r'^#include[^\n]*\n','',(GAME/name).read_bytes().decode('latin1'),flags=re.M)
|
|
item=(GAME/'item.cpp').read_text()
|
|
unique='EVENTFUNC(unique_expire_event)'+item.split('EVENTFUNC(unique_expire_event)',1)[1].split('\nEVENTFUNC(timer_based_on_wear_expire_event)',1)[0]
|
|
real='EVENTFUNC(real_time_expire_event)'+item.split('EVENTFUNC(real_time_expire_event)',1)[1].split('\nvoid CItem::StartRealTimeExpireEvent()',1)[0]
|
|
source='\n'.join(['#include "tests/features/fixtures/cube_restore_platform.h"',body('event_queue.cpp'),body('event.cpp'),unique,real,'#include "src/server/game/src/port_cube_lifecycle.inc"',body('port_cube_restore.cpp'),'#include "tests/features/fixtures/cube_restore_cases.inc"'])
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
cpp=Path(folder)/'restore.cpp';exe=Path(folder)/'restore';cpp.write_text(source)
|
|
subprocess.run(['c++','-std=c++17','-fsanitize=address,undefined','-fno-sanitize-recover=all','-I'+str(ROOT),'-I'+str(ROOT/'src/extern/include'),str(cpp),'-o',str(exe)],check=True)
|
|
subprocess.run([str(exe)],check=True)
|
|
for at in range(1,4):subprocess.run([str(exe),'event-fail',str(at)],check=True)
|
|
measure=subprocess.check_output([str(exe),'prepare-fail','0'],text=True)
|
|
count=int(re.search(r'ALLOCATIONS (\d+)',measure).group(1))
|
|
self.assertGreater(count,10)
|
|
for at in range(1,count+1):subprocess.run([str(exe),'prepare-fail',str(at)],check=True)
|
|
|
|
if __name__=='__main__':unittest.main()
|