first commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "atom_bridge.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
static uint64_t now(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC,&t); return (uint64_t)t.tv_sec*1000+(uint64_t)t.tv_nsec/1000000; }
|
||||
int main(int argc,char **argv) {
|
||||
uint32_t s[24],h=0; uint16_t data[2]={42,43}; unsigned ok=0,err=0;
|
||||
int uncertain=0,last=0; uint64_t start=now(); struct timespec pause={0,1000000};
|
||||
if(argc!=4) return 2;
|
||||
uint16_t port=(uint16_t)atoi(argv[1]); uint8_t f=(uint8_t)atoi(argv[2]);
|
||||
#define CALL(cmd) ab_call(cmd,h,0x7f000001u,port,1,f,0,2,data,2,s,24,now(),100,80,20)
|
||||
if(CALL(AB_OPEN)) return 2;
|
||||
h=s[0]; if(CALL(AB_CONFIGURE) || CALL(AB_ENABLE)) return 2;
|
||||
while(now()-start<1500 && ok<(unsigned)atoi(argv[3])) {
|
||||
if(CALL(AB_TICK)) return 2;
|
||||
if(s[3]) {
|
||||
if(f<=4 && CALL(AB_COPY_READ)) return 2;
|
||||
ok++; if(CALL(AB_ACK)) return 2;
|
||||
}
|
||||
if(s[4]) { err++; last=(int)s[5]; uncertain|=(int)s[9]; if(CALL(AB_ACK)) return 2; }
|
||||
if(s[1]==3 && ok<(unsigned)atoi(argv[3])) {
|
||||
if(CALL(AB_REQUEST_TIMEOUT) || CALL(AB_SUBMIT)) return 2;
|
||||
}
|
||||
nanosleep(&pause,0);
|
||||
}
|
||||
printf("%u %u %u %d %d %u %u\n",ok,err,s[11],uncertain,last,data[0],data[1]);
|
||||
CALL(AB_CLOSE); return ok==(unsigned)atoi(argv[3])?0:1;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "atom_mb.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
static uint64_t now(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC,&t); return (uint64_t)t.tv_sec*1000+(uint64_t)t.tv_nsec/1000000; }
|
||||
int main(int argc,char **argv) {
|
||||
am_client c; uint64_t start=now(); unsigned successes=0,errors=0; int uncertain=0,last=0;
|
||||
struct timespec pause={0,1000000}; uint16_t values[2]={42,43};
|
||||
if(argc!=4 || !am_init(&c,"127.0.0.1",(uint16_t)atoi(argv[1]))) return 2;
|
||||
c.retry_delay_ms=20; c.response_timeout_ms=80; c.connect_timeout_ms=100;
|
||||
am_enable(&c,1,start);
|
||||
while(now()-start<1500 && successes<(unsigned)atoi(argv[3])) {
|
||||
uint64_t t=now(); am_tick(&c,t);
|
||||
if(c.done) { successes++; c.done=0; }
|
||||
if(c.error) { errors++; last=c.result; uncertain|=c.write_uncertain; c.error=0; }
|
||||
if(c.state==AM_READY && successes<(unsigned)atoi(argv[3])) {
|
||||
int f=atoi(argv[2]); am_request(&c,1,(uint8_t)f,0,2,values,t);
|
||||
}
|
||||
nanosleep(&pause,0);
|
||||
}
|
||||
printf("%u %u %u %d %d %u %u\n",successes,errors,c.reconnects,uncertain,last,c.data[0],c.data[1]);
|
||||
am_close(&c); return successes==(unsigned)atoi(argv[3])?0:1;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "atom_bridge.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#define CALL(cmd,h) ab_call(cmd,h,0x7f000001u,502,1,3,0,2,NULL,0,status,24,100,2000,1000,1000)
|
||||
int main(void) {
|
||||
uint32_t status[24],handles[16],old,newh; unsigned i;
|
||||
assert(ab_call(AB_OPEN,0,0,502,0,0,0,0,NULL,0,status,23,0,0,0,0)==AB_BAD_CAPACITY);
|
||||
for(i=0;i<16;i++) { assert(CALL(AB_OPEN,0)==0); handles[i]=status[0]; assert(handles[i]); }
|
||||
assert(CALL(AB_OPEN,0)==AB_POOL_FULL);
|
||||
old=handles[0]; assert(CALL(AB_CLOSE,old)==0); assert(CALL(AB_TICK,old)==AB_BAD_HANDLE);
|
||||
assert(CALL(AB_OPEN,0)==0); newh=status[0]; assert(newh!=old);
|
||||
assert(CALL(AB_CONFIGURE,newh)==0); assert(CALL(AB_ENABLE,newh)==0);
|
||||
assert(CALL(AB_REQUEST_TIMEOUT,newh)==0); assert(status[22]==1000);
|
||||
assert(CALL(AB_CONFIGURE,newh)==2); assert(CALL(AB_SUBMIT,newh)==3);
|
||||
assert(CALL(AB_DISABLE,newh)==0); assert(CALL(AB_COPY_READ,newh)==1);
|
||||
ab_shutdown(); assert(CALL(AB_TICK,newh)==AB_BAD_HANDLE);
|
||||
puts("PASS bridge: capacity, pool limit, stale handles, configure, offline submission, shutdown");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import socket, struct, subprocess, threading, time, sys
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
DRIVER=ROOT/'tests'/(sys.argv[1] if len(sys.argv)>1 else 'driver')
|
||||
def exact(s,n):
|
||||
b=b''
|
||||
while len(b)<n:
|
||||
part=s.recv(n-len(b))
|
||||
if not part: raise EOFError
|
||||
b+=part
|
||||
return b
|
||||
def run(mode, function=3):
|
||||
listener=socket.socket(); listener.bind(('127.0.0.1',0)); listener.listen(); listener.settimeout(2)
|
||||
issues=[]
|
||||
def server():
|
||||
first=True
|
||||
try:
|
||||
while True:
|
||||
try: s,_=listener.accept()
|
||||
except (socket.timeout,OSError): break
|
||||
with s:
|
||||
s.settimeout(2)
|
||||
while True:
|
||||
try:
|
||||
h=exact(s,7); p=exact(s,struct.unpack('>H',h[4:6])[0]-1)
|
||||
except (EOFError,ConnectionError,socket.timeout): break
|
||||
if first and mode in ('close','timeout','bad_tid','bad_length','write_drop'):
|
||||
first=False
|
||||
if mode=='timeout': time.sleep(.12)
|
||||
elif mode=='bad_tid': s.sendall(b'\xff\xff'+h[2:4]+b'\x00\x07'+h[6:7]+b'\x03\x04\x00\x2a\x00\x2b')
|
||||
elif mode=='bad_length': s.sendall(h[:4]+b'\xff\xff'+h[6:7])
|
||||
break
|
||||
if first and mode=='exception': reply=bytes([p[0]|128,2]); first=False
|
||||
elif function==16: reply=p[:5]
|
||||
elif function==1: reply=b'\x01\x01\x03'
|
||||
else: reply=b'\x03\x04\x00\x2a\x00\x2b'
|
||||
packet=h[:4]+struct.pack('>H',len(reply)+1)+h[6:7]+reply
|
||||
if mode=='fragment':
|
||||
for b in packet: s.sendall(bytes([b])); time.sleep(.001)
|
||||
else: s.sendall(packet)
|
||||
except Exception as e: issues.append(e)
|
||||
worker=threading.Thread(target=server); worker.start()
|
||||
try:
|
||||
p=subprocess.run([str(DRIVER),str(listener.getsockname()[1]),str(function),'2'],capture_output=True,text=True,timeout=4)
|
||||
assert p.returncode==0,(mode,p.stdout,p.stderr)
|
||||
ok,err,reconnect,uncertain,last,a,b=map(int,p.stdout.split())
|
||||
assert ok==2
|
||||
if function==3: assert (a,b)==(42,43)
|
||||
if function==1: assert (a,b)==(1,1)
|
||||
if mode in ('close','timeout','bad_tid','bad_length','write_drop'): assert err>=1 and reconnect>=1
|
||||
if mode=='exception': assert err==1 and reconnect==0 and last==9
|
||||
if mode=='write_drop': assert uncertain==1
|
||||
print('PASS',mode,p.stdout.strip())
|
||||
finally:
|
||||
listener.close(); worker.join(3)
|
||||
assert not issues,issues
|
||||
for mode in ('normal','fragment','close','timeout','bad_tid','bad_length','exception'): run(mode)
|
||||
run('write_drop',16)
|
||||
run('coils',1)
|
||||
Reference in New Issue
Block a user