Files
WoW-Hybrid-gateway/tests/world_close_attribution_test.py

92 lines
3.9 KiB
Python

#!/usr/bin/env python3
"""A handled world-call error must not be attributed to a later pipe close."""
import os
from pathlib import Path
import subprocess
import tempfile
from wine_session_retirement_test import function
ROOT = Path(__file__).resolve().parents[1]
pipe = (ROOT / "native/wine_pipe_host.c").read_text()
close_functions = pipe[pipe.index(function(pipe, "transfer_presentation")) +
len(function(pipe, "transfer_presentation")):
pipe.index("static void private_capture_notice(")]
fixture = r"""
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "wine_pipe_host.h"
#define WINAPI
typedef long LONG;
static struct gw_pipe_control gw_wire_pipe_data;
static struct gw_pipe_world_control gw_wire_world_data;
static struct gw_pipe_world_failure gw_wire_world_failure = {.abi=1, .size=48};
static struct gw_pipe_world_call_failure gw_wire_world_call_failure = {.abi=1, .size=32};
static struct gw_pipe_world_call_phase gw_wire_world_call_phase = {.abi=1, .size=16};
static struct gw_pipe_cast_result gw_wire_cast_result;
static unsigned char incoming[8];
static uint32_t u32(const unsigned char* data){uint32_t n;memcpy(&n,data,sizeof n);return n;}
static LONG InterlockedIncrement(volatile LONG* n){return ++*n;}
static int result, close_code, closed, dropped;
static uint32_t world_phase, source, call_phase, backend;
static void pipe_note(const char* name,uint32_t value){
if(!strcmp(name,"GW_WIRE close error="))close_code=value;
else if(!strcmp(name,"GW_WIRE close world-phase="))world_phase=value;
else if(!strcmp(name,"GW_WIRE close world-source="))source=value;
else if(!strcmp(name,"GW_WIRE close call-phase="))call_phase=value;
else if(!strcmp(name,"GW_WIRE close call-backend="))backend=value;
else if(!strcmp(name,"GW_WIRE update-dropped opcode="))++dropped;
}
static void world_trace(uint32_t direction,uint32_t opcode,uint32_t size){
(void)direction;(void)opcode;(void)size;
}
static void spell_barrier_cancel(uint32_t reason){(void)reason;}
static void clear_transfer_bridge(void){}
static void gw_wire_account_detach_engine_session(void){}
static void close_connection(void* connection){assert(connection);++closed;}
static int drain_world_packets(int received){
assert(received);
if(result){
gw_wire_world_failure.phase=1;
gw_wire_world_failure.result=result;
gw_wire_world_call_phase.present=1;
gw_wire_world_call_phase.phase=4;
gw_wire_world_call_failure.present=1;
gw_wire_world_call_failure.backend_state=0x8000001b;
}
return result;
}
""" + close_functions + function(pipe, "world_packet") + r"""
int main(void){
uintptr_t methods[18]={[17]=(uintptr_t)close_connection};
uintptr_t object=(uintptr_t)methods;
gw_wire_pipe_data.connection=(uintptr_t)&object;
result=-1;
assert(world_packet(0xa9,0)==0 && dropped==1);
result=0;
assert(world_packet(0x183,0)==0 && gw_wire_world_data.last_legacy==0x183);
close_pipe(15);
assert(close_code==15 && closed==1);
assert(world_phase==0 && source==0 && call_phase==0 && backend==0);
assert(!gw_wire_world_call_failure.present && !gw_wire_world_call_phase.present);
assert(gw_wire_world_failure.abi==1 && gw_wire_world_call_phase.size==16 &&
gw_wire_world_call_failure.size==32);
gw_wire_pipe_data.closed=gw_wire_pipe_data.error=0;
result=-1;
assert(world_packet(0x183,0)!=0);
close_pipe(15);
assert(closed==2 && world_phase==1 && source==0x183 &&
call_phase==4 && backend==0x8000001b);
return 0;
}
"""
with tempfile.TemporaryDirectory(prefix="gw-world-close-") as directory:
program = Path(directory) / "fixture"
subprocess.run([os.environ.get("CC", "cc"), "-std=c11", "-Wall", "-Wextra", "-Werror",
"-I", str(ROOT / "native"), "-x", "c", "-", "-o", str(program)],
input=fixture, text=True, check=True)
subprocess.run([str(program)], cwd=directory, check=True)