Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omnet/blob/main/cmd/tkad/test/faults.py # omnet aien-dev/omnet Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omnet / cmd / tkad / test / faults.py` 207 lines ยท 9128 bytes Raw Blame History 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: Apache-2.0 3 """Compile test-only syscall-boundary fault variants; never production switches.""" 4 import base64 5 import hashlib 6 import json 7 import pathlib 8 import socket 9 import struct 10 import subprocess 11 import sys 12 import tempfile 13 import time 14 15 root, binary = map(pathlib.Path, sys.argv[1:]) 16 source = pathlib.Path(str(binary) + ".om").read_text() 17 omc = subprocess.check_output(["sh",str(root/"tools/omc.sh")],text=True).strip() 18 fixture = json.loads((root/"cmd/tkad/test/fixture.json").read_text()) 19 write_needle = "fn stwr fd int b view uchar 65536 off ulong n ulong to long\nret write fd b off n\nend" 20 sync_needle = "fn stsync fd int to long\nret fsync fd\nend" 21 assert source.count(write_needle)==1 and source.count(sync_needle)==1 22 23 24 def build(label, needle, replacement): 25 p = subprocess.run([omc],input=source.replace(needle,replacement).encode(),capture_output=True) 26 assert p.returncode==0,p.stderr.decode() 27 path=root/"build"/("tkad-fault-"+label);path.write_bytes(p.stdout);path.chmod(0o700) 28 return path 29 30 31 def start(binary, state, init=False): 32 p=subprocess.Popen([str(binary),str(state)]+(["--init"] if init else []),stdout=subprocess.PIPE,stderr=subprocess.PIPE) 33 deadline=time.monotonic()+10 34 while time.monotonic()0 182 return base64.b64encode(bytes([raw[0]+1])+raw[1:]+pad+b"\x5a"+struct.pack(">I",n)+bytes(n)).decode() 183 184 185 with tempfile.TemporaryDirectory(prefix="tkad-registry-capacity-") as name: 186 state=pathlib.Path(name);p=start(raw_store,state,True) 187 for i in (0,1): 188 assert rpc(state,9,dict(NodeID=i+1,NodeKey=fixture["nodes"][i],RotationPubkey=fixture["rotations"][i]))[0]==200 189 common=dict(Version=131,NodeKey=fixture["nodes"][0]) 190 try: 191 assert rpc(state,1,dict(common,GenesisAUM=fixture["genesis"]),1)[0]==200 192 assert rpc(state,2,dict(common,Signatures={"1":fixture["signatures"][0],"2":fixture["signatures"][1]}),1)[0]==200 193 assert rpc(state,9,dict(NodeID=3,NodeKey=fixture["nodes"][2],RotationPubkey=fixture["rotations"][2]))[0]==200 194 assert rpc(state,7,dict(Version=131,NodeKey=fixture["nodes"][2],Signature=padded(fixture["signatures"][2],30000)),3)[0]==200 195 first=rpc(state,11,{})[1] 196 assert len(first["Nodes"])==3 and first["Nodes"][2]["KeySignature"]==padded(fixture["signatures"][2],30000),first 197 # A second individually valid signature would push the registry past the 198 # map response limit; the candidate must be rejected, never committed. 199 assert rpc(state,7,dict(common,Signature=padded(fixture["signatures"][0],30000)),1)[0]==413 200 assert rpc(state,11,{})[1]==first,"rejected candidate cannot change the registry" 201 finally:p.kill();p.communicate(timeout=10) 202 p=start(raw_store,state) 203 try: 204 assert rpc(state,11,{})[1]==first,"over-capacity rejection is durable, registry still readable" 205 finally:p.kill();p.communicate(timeout=10) 206 print("PASS tkad registry capacity guard: ignored CBOR padding rejected 413, registry unchanged and readable") 207