883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
79 lines
3.3 KiB
Python
79 lines
3.3 KiB
Python
"""The opt-in observer identifies only validated single-push target pages."""
|
|
import pathlib
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class SpellHotfixTraceTest(unittest.TestCase):
|
|
def test_real_splitter_validates_and_observer_filters_pages(self):
|
|
source = r'''
|
|
#include <stdint.h>
|
|
#include "native/hotfix_request_split.h"
|
|
#include "native/spell_hotfix_trace.h"
|
|
static uint32_t seen[4], count;
|
|
static int emit(void *p, const unsigned char *b, uint32_t n) {
|
|
(void)p; uint32_t id=gw_spell_hotfix_trace_push(b,n);
|
|
if(id) seen[count++]=id;
|
|
return 0;
|
|
}
|
|
static void put32(unsigned char *p,uint32_t x) {
|
|
p[0]=x;p[1]=x>>8;p[2]=x>>16;p[3]=x>>24;
|
|
}
|
|
int main(void) {
|
|
unsigned char req[32]={0};
|
|
put32(req,70334);put32(req+8,5);
|
|
put32(req+12,878652721);put32(req+16,123);
|
|
put32(req+20,867881837);put32(req+24,878652721);
|
|
put32(req+28,1700860167);
|
|
if(gw_hotfix_split_request(req,sizeof(req),emit,0)) return 1;
|
|
if(count!=3 || seen[0]!=878652721 || seen[1]!=867881837 || seen[2]!=1700860167) return 2;
|
|
count=0;put32(req+8,6);
|
|
if(!gw_hotfix_split_request(req,sizeof(req),emit,0) || count) return 3;
|
|
return gw_spell_hotfix_trace_push(req,15)!=0;
|
|
}'''
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = pathlib.Path(directory)
|
|
(path / 'test.c').write_text(source)
|
|
subprocess.run(['cc', '-std=c99', '-Wall', '-Wextra', '-Werror', '-I', str(ROOT),
|
|
str(path / 'test.c'), '-o', str(path / 'test')], check=True)
|
|
subprocess.run([str(path / 'test')], check=True)
|
|
|
|
|
|
def test_initial_known_validates_shape_and_reports_only_membership(self):
|
|
source = r'''
|
|
#include <stdint.h>
|
|
#include "native/spell_hotfix_trace.h"
|
|
static void put32(unsigned char *p,uint32_t x) {
|
|
p[0]=x;p[1]=x>>8;p[2]=x>>16;p[3]=x>>24;
|
|
}
|
|
int main(void) {
|
|
unsigned char b[389]={0x80};uint32_t count=0,mask=0;
|
|
/* Exact src/world.cpp initial writer: marker, count, zero, IDs. */
|
|
put32(b+1,95);put32(b+9,23922);put32(b+9+93*4,45595);put32(b+9+94*4,51602);
|
|
if(gw_spell_hotfix_trace_initial(b,sizeof(b),&count,&mask) || count!=95 || mask!=7) return 1;
|
|
put32(b+9+93*4,75);put32(b+9+94*4,75);
|
|
if(gw_spell_hotfix_trace_initial(b,sizeof(b),&count,&mask) || count!=95 || mask!=1) return 2;
|
|
count=123;mask=123;
|
|
if(!gw_spell_hotfix_trace_initial(b,sizeof(b)-1,&count,&mask) || count!=123 || mask!=123) return 3;
|
|
b[0]=0;if(!gw_spell_hotfix_trace_initial(b,sizeof(b),&count,&mask))return 4;b[0]=0x80;
|
|
b[5]=1;if(!gw_spell_hotfix_trace_initial(b,sizeof(b),&count,&mask))return 5;b[5]=0;
|
|
put32(b+1,4097);if(!gw_spell_hotfix_trace_initial(b,sizeof(b),&count,&mask))return 6;
|
|
put32(b+1,0);if(gw_spell_hotfix_trace_initial(b,9,&count,&mask)||count||mask)return 7;
|
|
if(!gw_spell_hotfix_trace_initial(0,9,&count,&mask))return 8;
|
|
return 0;
|
|
}
|
|
'''
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
path = pathlib.Path(directory)
|
|
(path / 'test.c').write_text(source)
|
|
subprocess.run(['cc', '-std=c99', '-Wall', '-Wextra', '-Werror', '-I', str(ROOT),
|
|
str(path / 'test.c'), '-o', str(path / 'test')], check=True)
|
|
subprocess.run([str(path / 'test')], check=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|