Files
WoW-Hybrid-gateway/tests/engine_channel_win_fixture.c
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

125 lines
8.4 KiB
C

/* Owned objects only: production queue/lock/lifetime mechanics, no game calls. */
#define GW_CHANNEL_FIXTURE 1
#include "../native/wine_channel_policy.c"
void* gw_fixture_owner;
uint32_t gw_fixture_contract_status;
static int ready=1;static unsigned sends,destroys,releases;
static void check(int value,unsigned code){if(!value)ExitProcess(code);}
int WINAPI gw_wire_native_channel_ready(void* p){return ready && p==gw_fixture_owner;}
#ifndef GW_TRANSFER_CHANNEL_FIXTURE
int WINAPI gw_wire_native_channel_transfer_ready(void* p){(void)p;return 0;}
#endif
void WINAPI gw_fixture_send(void* owner,void* buffer,unsigned char route){
struct store* s=buffer;CRITICAL_SECTION* cs=(CRITICAL_SECTION*)((char*)owner+0x70);
check(owner==gw_fixture_owner && route==0 && s->cursor==16 && s->length>=20,20);
check((uintptr_t)cs->OwningThread==GetCurrentThreadId(),21);++sends;
}
void WINAPI gw_fixture_release_store(void* buffer,void** data,uint32_t* capacity){
struct store* store=buffer;
check(data==&store->data && capacity==&store->capacity && *data && *capacity,22);
HeapFree(GetProcessHeap(),0,*data);*data=0;*capacity=0;++destroys;
}
unsigned char WINAPI gw_fixture_release(void* n,const char* source,int line,unsigned flags){
check(n && source && line==-2 && flags==0 && !((struct node*)n)->prev && !((struct node*)n)->buffer.data,23);
++releases;return (unsigned char)HeapFree(GetProcessHeap(),0,n);
}
static void reset(void){
unsigned i;unsigned char* p=(unsigned char*)&gw_wire_channel_policy;
for(i=0;i<sizeof(gw_wire_channel_policy);++i)p[i]=0;
gw_wire_channel_policy.abi=1;gw_wire_channel_policy.size=48;gw_wire_channel_policy.owner=(uint64_t)gw_fixture_owner;
sends=destroys=releases=0;
}
static struct node* append(unsigned char route,unsigned length){
void** head=(void**)((char*)gw_fixture_owner+0x200);struct node* n=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*n));
check(n!=0,24);n->requested=route;n->buffer.table=0x144c69b00ULL;
n->buffer.data=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,256);check(n->buffer.data!=0,25);
n->buffer.capacity=256;n->buffer.length=length;n->buffer.cursor=16;
n->prev=head[0];n->next=((void**)head[0])[1];((void**)head[0])[1]=n;head[0]=n;return n;
}
static DWORD WINAPI other_thread(void* owner){gw_wire_channel_poll(owner);return 0;}
#ifdef GW_PROFILE5_AUTO_FIXTURE
void fixture_auto_start(void){
unsigned char* p;void** head;struct node* n;
gw_fixture_owner=VirtualAlloc(0,4096,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
check(gw_fixture_owner!=0,70);p=gw_fixture_owner;
InitializeCriticalSection((CRITICAL_SECTION*)(p+0x70));
*(LONG*)(p+0x98)=5;*(void**)(p+0x1a0)=p;p[0x219]=1;
head=(void**)(p+0x200);head[0]=head;head[1]=(void*)((uintptr_t)head|1);
reset();gw_wire_channel_policy.owner=0;ready=0;n=append(2,21);
gw_wire_channel_poll(p);
check(!gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error &&
!sends && head[1]==n,71);
ready=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error &&
gw_wire_channel_policy.owner==(uint64_t)p && sends==1 && releases==1,72);
gw_wire_channel_policy.command=2;gw_wire_channel_poll(p);
n=append(2,21);gw_wire_channel_poll(p);
check(!gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error &&
sends==1 && head[1]==n,73);
gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error &&
sends==2 && releases==2,74);
gw_wire_channel_policy.command=2;gw_wire_channel_poll(p);
gw_wire_channel_retire_generation();n=append(2,21);gw_wire_channel_poll(p);
check(gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error &&
sends==3 && releases==3,75);
DeleteCriticalSection((CRITICAL_SECTION*)(p+0x70));VirtualFree(p,0,MEM_RELEASE);
ExitProcess(0);
}
#endif
void fixture_start(void){
unsigned i;unsigned char* p;void** head;struct node* n;HANDLE worker;
unsigned char* code=VirtualAlloc(0,4096,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE);
const unsigned char expected[]={0x90};DWORD previous;
check(code!=0,30);code[0]=0x90;check(code_status(code,expected,1)==0,31);
code[0]=0xcc;check(code_status(code,expected,1)==8,32);
check(VirtualProtect(code,4096,PAGE_READWRITE,&previous),33);
check(code_status(code,expected,1)==4,34);VirtualFree(code,0,MEM_RELEASE);
gw_fixture_owner=VirtualAlloc(0,4096,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);check(gw_fixture_owner!=0,1);
p=gw_fixture_owner;InitializeCriticalSection((CRITICAL_SECTION*)(p+0x70));*(LONG*)(p+0x98)=5;
*(void**)(p+0x1a0)=p;p[0x219]=1;head=(void**)(p+0x200);head[0]=head;head[1]=(void*)((uintptr_t)head|1);
reset();append(2,21);append(1,24);
ready=0;gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.error==3 && !sends && !destroys && !releases,2);
ready=1;reset();gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error && gw_wire_channel_policy.drained==2 &&
gw_wire_channel_policy.bytes==13 && sends==2 && destroys==2 && releases==2 && head[1]==(void*)((uintptr_t)head|1),3);
gw_wire_channel_policy.command=2;gw_wire_channel_poll(p);n=append(2,61);gw_wire_channel_poll(p);check(sends==2,4);
reset();n->prev=n;gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.error==4 && !sends && !destroys && head[1]==n,11);n->prev=head;
reset();*(void**)(p+0x1a8)=p;gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.error==3 && !sends && !destroys,12);*(void**)(p+0x1a8)=0;
reset();n->buffer.cursor=0;gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.error==4 && !sends && !destroys && !releases && head[1]==n,5);
n->buffer.cursor=16;check(finish_node(n,head),10);
reset();for(i=0;i<33;++i)append(2,20);
gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);check(sends==32 && gw_wire_channel_policy.drained==32,6);
gw_wire_channel_poll(p);check(sends==33 && releases==33 && gw_wire_channel_policy.drained==33,7);
worker=CreateThread(0,0,other_thread,p,0,0);check(worker!=0,8);WaitForSingleObject(worker,5000);CloseHandle(worker);
check(gw_wire_channel_policy.error==2 && sends==33,9);
reset();n=append(2,61);gw_fixture_contract_status=2;gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error && !sends && !destroys && head[1]==n,35);
check(gw_wire_channel_contracts.protection_deferrals>0,36);
gw_fixture_contract_status=0;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error && sends==1 && releases==1,37);
/* A real world-completion publication suspends only this opted-in owner.
* No queue is drained until all the original next-world gates pass again. */
reset();gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
gw_wire_channel_world_left(p);ready=0;gw_wire_channel_poll(p);n=append(2,61);
for(i=0;i<10;++i)gw_wire_channel_poll(p);
check(!gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error && !sends && head[1]==n,42);
ready=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.enabled && !gw_wire_channel_policy.error && sends==1 && releases==1,43);
gw_wire_channel_world_left(p);ready=0;gw_wire_channel_poll(p);
gw_wire_channel_policy.command=2;gw_wire_channel_poll(p);n=append(2,61);ready=1;gw_wire_channel_poll(p);
check(!gw_wire_channel_policy.enabled && sends==1 && head[1]==n,44);check(finish_node(n,head),45);
reset();gw_wire_channel_world_left(p);ready=0;gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.error==3 && !sends,46);ready=1; // Inactive policy cannot authorize a suspension.
reset();n=append(2,61);gw_fixture_contract_status=8;gw_wire_channel_policy.command=1;gw_wire_channel_poll(p);
check(gw_wire_channel_policy.error==8 && !sends && !destroys && head[1]==n,38);check(finish_node(n,head),39);
reset();n=append(2,61);gw_fixture_contract_status=2;gw_wire_channel_policy.command=1;
for(i=0;i<3001;++i)gw_wire_channel_poll(p);
check(gw_wire_channel_policy.error==8 && !sends && !destroys && head[1]==n,40);check(finish_node(n,head),41);
DeleteCriticalSection((CRITICAL_SECTION*)(p+0x70));VirtualFree(p,0,MEM_RELEASE);ExitProcess(0);
}