Files
WoW-Hybrid-gateway/tests/engine_spell_locator_ready_test.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

90 lines
7.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "native/engine_spell_locator_ready.h"
#define MAIN_BASE ((uintptr_t)UINT64_C(0x140000000))
#define BUCKETS ((uintptr_t)UINT64_C(0x30000000))
#define NODE_BASE ((uintptr_t)UINT64_C(0x31000000))
#define NODE(n) (NODE_BASE+(uintptr_t)(n)*32u)
#define CHECK(x) do { if(!(x)){fprintf(stderr,"FAIL line %d: %s\n",__LINE__,#x);exit(1);} }while(0)
struct item { uint64_t next; uint32_t id,marker; };
struct mock {
unsigned char asserted;
uint64_t count,pointer,head;
struct item nodes[70];
size_t node_count, calls;
int mutation,head_reads,map_reads,prereq_reads,node_reads[70];
uintptr_t unreadable;
};
static void put32(unsigned char *p,uint32_t x){size_t i;for(i=0;i<4;++i)p[i]=(unsigned char)(x>>(i*8));}
static void put64(unsigned char *p,uint64_t x){size_t i;for(i=0;i<8;++i)p[i]=(unsigned char)(x>>(i*8));}
static int mock_read(void *context,uintptr_t at,void *output,size_t size)
{
struct mock *m=(struct mock*)context;unsigned char raw[16]={0};size_t index;
++m->calls;
if(at==m->unreadable)return 0;
if(at==MAIN_BASE+(uintptr_t)GW_SPELL_LOCATOR_PROVIDER_RVA&&size==8){
put64(raw,0); /* Unavailable startup provider remains pending. */
}else if(at==MAIN_BASE+(uintptr_t)GW_SPELL_LOCATOR_ASSERTED_RVA&&size==1){
++m->prereq_reads;raw[0]=(unsigned char)((m->mutation==4&&m->prereq_reads==2)?0:m->asserted);
}else if(at==MAIN_BASE+(uintptr_t)GW_SPELL_LOCATOR_MAP_RVA&&size==16){
++m->map_reads;put64(raw,(m->mutation==3&&m->map_reads==2)?2:m->count);put64(raw+8,m->pointer);
}else if(at>=BUCKETS&&(uint64_t)(at-BUCKETS)<m->count*8&&size==8){
++m->head_reads;put64(raw,(m->mutation==1&&m->head_reads==2)?NODE(1):m->head);
}else if(at>=NODE_BASE&&(at-NODE_BASE)%32u==0&&size==16){
index=(size_t)((at-NODE_BASE)/32u);if(index>=m->node_count)return 0;
++m->node_reads[index];put64(raw,m->nodes[index].next);put32(raw+8,m->nodes[index].id);
put32(raw+12,(m->mutation==2&&index==0&&m->node_reads[index]==2)?0:m->nodes[index].marker);
}else return 0;
memcpy(output,raw,size);return 1;
}
static struct mock fixture(void)
{
struct mock m;memset(&m,0,sizeof(m));m.asserted=1;m.count=1;m.pointer=BUCKETS;m.head=NODE(0);m.node_count=3;
m.nodes[0]=(struct item){NODE(1),45595,11};m.nodes[1]=(struct item){NODE(2),51602,22};m.nodes[2]=(struct item){0,23922,33};return m;
}
static int run(struct mock *m,uint32_t const *ids,size_t n,gw_spell_locator_diagnostics *d)
{return gw_spell_locators_available(MAIN_BASE,ids,n,mock_read,m,d);}
int main(void)
{
uint32_t ids[3]={45595,51602,23922};gw_spell_locator_diagnostics d;struct mock m;size_t i;int result;
uint32_t many[GW_SPELL_LOCATOR_MAX_IDS];
m=fixture();CHECK(run(&m,ids,3,&d)==1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_READY);CHECK(d.ready_ids==3&&d.checked_ids==3);CHECK(d.read_bytes<1024);
m=fixture();m.nodes[0].marker=0;CHECK(run(&m,ids,3,&d)==0);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_ZERO&&d.problem_spell_id==45595&&d.ready_ids==0);
m=fixture();m.nodes[0].marker=UINT32_MAX;m.nodes[1].marker=UINT32_C(0x80000000);CHECK(run(&m,ids,3,&d)==1);
m=fixture();m.head=0;CHECK(run(&m,ids,3,&d)==0);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_PROVIDER_PENDING&&d.problem_spell_id==45595);
m=fixture();m.nodes[0].id=123;CHECK(run(&m,ids,3,&d)==0);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_PROVIDER_PENDING);
m=fixture();m.asserted=0;CHECK(run(&m,ids,3,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_UNSUPPORTED_PREREQUISITE&&d.read_calls==1);
for(i=1;i<=4;++i){m=fixture();m.mutation=(int)i;CHECK(run(&m,ids,1,&d)==0);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_CHANGED);}
m=fixture();m.unreadable=NODE(0);CHECK(run(&m,ids,3,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_UNREADABLE);
m=fixture();m.nodes[0].id=123;m.nodes[0].next=NODE(0);CHECK(run(&m,ids,3,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_CYCLE);
m=fixture();m.node_count=65;for(i=0;i<65;++i)m.nodes[i]=(struct item){i==64?0:NODE(i+1),123,1};CHECK(run(&m,ids,1,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_CHAIN_LIMIT);
m=fixture();m.node_count=64;for(i=0;i<64;++i)m.nodes[i]=(struct item){i==63?0:NODE(i+1),123,1};CHECK(run(&m,ids,1,&d)==0);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_PROVIDER_PENDING&&d.nodes_examined==64);
m=fixture();m.node_count=64;for(i=0;i<64;++i)m.nodes[i]=(struct item){i==63?0:NODE(i+1),i==63?45595u:123u,1};CHECK(run(&m,ids,1,&d)==1);
for(i=0;i<3;++i){m=fixture();m.count=i==0?0:(i==1?3:(uint64_t)GW_SPELL_LOCATOR_BUCKET_CAP+1);CHECK(run(&m,ids,1,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_BAD_MAP);}
m=fixture();m.count=GW_SPELL_LOCATOR_BUCKET_CAP;CHECK(run(&m,ids,1,&d)==1);
m=fixture();m.pointer=BUCKETS+1;CHECK(run(&m,ids,1,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_BAD_POINTER);
m=fixture();m.pointer=UINT64_C(0x00007ffffffffff8);m.count=2;CHECK(run(&m,ids,1,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_BAD_POINTER);
m=fixture();m.head=NODE(0)+1;CHECK(run(&m,ids,1,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_BAD_POINTER);
m=fixture();CHECK(gw_spell_locators_available(MAIN_BASE+1,ids,1,mock_read,&m,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_BAD_MAIN_RANGE&&m.calls==0);
m=fixture();CHECK(gw_spell_locators_available(0,ids,1,mock_read,&m,&d)==-1);CHECK(m.calls==0);
m=fixture();{uint32_t bad=0;CHECK(run(&m,&bad,1,&d)==-1);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_BAD_INPUT&&m.calls==0);bad=UINT32_C(0x80000000);CHECK(run(&m,&bad,1,&d)==-1);}
m=fixture();CHECK(run(&m,NULL,1,&d)==-1);CHECK(run(&m,ids,GW_SPELL_LOCATOR_MAX_IDS+1,&d)==-1);CHECK(m.calls==0);
CHECK(gw_spell_locators_available(0,NULL,0,NULL,NULL,&d)==1);CHECK(d.read_calls==0&&d.reason==GW_SPELL_LOCATOR_REASON_READY);
m=fixture();CHECK(gw_spell_locators_available(MAIN_BASE,ids,3,mock_read,&m,NULL)==1);
m=fixture();for(i=0;i<GW_SPELL_LOCATOR_MAX_IDS;++i)many[i]=45595;CHECK(run(&m,many,GW_SPELL_LOCATOR_MAX_IDS,&d)==1);CHECK(d.ready_ids==GW_SPELL_LOCATOR_MAX_IDS);
m=fixture();m.node_count=64;for(i=0;i<64;++i)m.nodes[i]=(struct item){i==63?0:NODE(i+1),i==63?45595u:123u,1};result=run(&m,many,GW_SPELL_LOCATOR_MAX_IDS,&d);CHECK(result==0&&d.reason==GW_SPELL_LOCATOR_REASON_BUDGET);CHECK(d.work_steps<=GW_SPELL_LOCATOR_WORK_CAP&&d.read_bytes<=GW_SPELL_LOCATOR_READ_CAP);
{struct gw_spell_locator_reader reader;unsigned char out[16];m=fixture();gw_spell_locator_reset(&d);d.read_bytes=GW_SPELL_LOCATOR_READ_CAP-1;reader=(struct gw_spell_locator_reader){mock_read,&m,&d};CHECK(gw_spell_locator_read(&reader,BUCKETS,out,8)==0);CHECK(d.reason==GW_SPELL_LOCATOR_REASON_BUDGET&&m.calls==0);gw_spell_locator_reset(&d);d.work_steps=GW_SPELL_LOCATOR_WORK_CAP;CHECK(gw_spell_locator_read(&reader,BUCKETS,out,8)==0);CHECK(m.calls==0);}
CHECK(gw_spell_locator_hash(UINT32_C(0x0))==UINT64_C(0x0));
CHECK(gw_spell_locator_hash(UINT32_C(0xb21b))==UINT64_C(0xfc53ac1f492ef301));
CHECK(gw_spell_locator_hash(UINT32_C(0xc992))==UINT64_C(0x8dd5677a5f4a1f01));
CHECK(gw_spell_locator_hash(UINT32_C(0x5d72))==UINT64_C(0x9fbb9c659e71e10d));
CHECK(gw_spell_locator_hash(UINT32_C(0x7fffffff))==UINT64_C(0x8a662c1a93a26b91));
CHECK(gw_spell_locator_hash(UINT32_C(0x80000000))==UINT64_C(0xc4ca27146b0a922f));
CHECK(gw_spell_locator_hash(UINT32_C(0xffffffff))==UINT64_C(0x64b5720b4b825f21));
/* Signed32 finalizer witness values are generated from the existing qualified Python port. */
puts("PASS 25 pure mock groups: marker/absence/prerequisite/stability/bounds/cycles/budgets; no process access");
return 0;
}