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/spark-supervisor/blob/main/tests/mutants.py # spark-supervisor Process supervisor and health monitor for sovereign daemons 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 `spark-supervisor / tests / mutants.py` 51 lines ยท 4206 bytes Raw Blame History 1 #!/usr/bin/env python3 2 """Test-only source fault injector. Each compiled mutant must fail its behavioral oracle. 3 The real-kernel runner contains mutants inside its independent parent memory/pids ceilings. 4 """ 5 import os, pathlib, shutil, subprocess, tempfile 6 here=pathlib.Path(__file__).resolve().parents[1] 7 omc=os.environ['OMC'] 8 # name, behavioral module/case, edits (file, exact old bytes, exact replacement) 9 mutants=[ 10 ('declared-environment','environment',[('om/services.om','ret execenv pk 0 get gu GPK environment 0 n','ret execprog pk 0 get gu GPK')]), 11 ('restart-always','policies',[('om/supervise.om','if wis 1 walways\nput srs i 2','if wis 1 walways\nput srs i 0')]), 12 ('restart-on-failure','policies',[('om/supervise.om','if wis 1 wonfail\nput srs i 1','if wis 1 wonfail\nput srs i 2')]), 13 ('restart-never','policies',[('om/supervise.om','if wis 1 sxNever\nput srs i 0','if wis 1 sxNever\nput srs i 1')]), 14 ('bounded-backoff','policies',[('om/supervise.om','d = get sbmx i\nend\nput sbk','d = d\nend\nput sbk')]), 15 ('ordered-start','order_health',[('om/services.om','fn sxReady i ulong to bool\n','fn sxReady i ulong to bool\nif eq i i\nret true\nend\n')]), 16 ('http-health','order_health',[('om/services.om','if not sxHttp i','if false')]), 17 ('reverse-stop','order_health',[('om/services.om','if not sxHasLiveDependent i','if true')]), 18 ('one-status-line','order_health',[('om/supervise.om','fn ostline i ulong to void\noname i','fn ostline i ulong to void\nostr fnone')]), 19 ('rotation-bound','logs_stop',[('om/supervise.om','room = sub get slmx i get sls i','room = n')]), 20 ('stop-grace','logs_stop',[('om/supervise.om','sendterm i\nsetst i 3','sendkill i\nsetst i 3')]), 21 ('whole-group-stop','logs_stop',[('om/supervise.om','r = killpid neg int get spid i 9','r = killpid int get spid i 9'),('om/services.om','r = killpid neg int pid 9','r = killpid int pid 9')]), 22 ('honest-missing-trigger','missing_trigger',[('om/contract.om','change-trigger=MISSING_IMPLEMENTATION','change-trigger=ENABLED')]), 23 ('explicit-reload','missing_trigger',[('om/supervise.om','if and aveq d vall verbis k d vreload\nrescan','if and aveq d vall verbis k d vreload\nsxShutdownStep')]), 24 ('fail-closed','fail_closed',[('om/limits.om','fn cgLimited i ulong to bool\n','fn cgLimited i ulong to bool\nif eq i i\nret false\nend\n')]), 25 ('memory-enforcement','limits',[('om/limits.om','r = cgSet cgMemory memory','r = long 0')]), 26 ('pids-enforcement','limits',[('om/limits.om','r = cgSet cgPids tasks','r = long 0')]), 27 ('cpu-weight','limits',[('om/limits.om','r = cgSet cgWeight weight','r = cgSet cgWeight 100')]), 28 ('oom-marker','limits',[('om/contract.om','LIMIT_OOM_KILLED\\n','OOM_UNREPORTED\\n')]), 29 ('exit-status','limits',[('om/limited.om','ret int shr st 8','ret 0')]), 30 ] 31 import sys 32 only=set(sys.argv[1:]) 33 if only: mutants=[m for m in mutants if m[0] in only]; assert len(mutants)==len(only),'unknown mutant name' 34 root=pathlib.Path(tempfile.mkdtemp(prefix='aien-mutants.')) 35 for name, case, edits in mutants: 36 tree=root/name 37 shutil.copytree(here/'om',tree/'om') 38 (tree/'tools').mkdir();shutil.copy2(here/'tools/build.sh',tree/'tools/build.sh') 39 for path,old,new in edits: 40 target=tree/path; data=target.read_text(); assert data.count(old)==1,(name,path,data.count(old)); target.write_text(data.replace(old,new)) 41 env=dict(os.environ,OMC=str(pathlib.Path(omc).resolve())) 42 log=root/(name+'.log') 43 with log.open('wb') as output: 44 built=subprocess.run(['sh',str(tree/'tools/build.sh')],env=env,stdout=output,stderr=output,timeout=60) 45 assert built.returncode==0,('mutant did not compile',name,str(log)) 46 env['SUPERVISE_BIN']=str(tree/'out/aien-supervise') 47 command=['sh',str(here/'tests/limits.sh')] if case=='limits' else ['python3',str(here/'tests/contract.py'),case] 48 observed=subprocess.run(command,env=env,stdout=output,stderr=output,timeout=75) 49 assert observed.returncode not in (0,3),('mutant survived or NOT_RUN',name,observed.returncode,str(log)) 50 print('MUTANT KILLED',name,'oracle_exit='+str(observed.returncode),'log='+str(log),flush=True) 51 print('MUTANTS PASS killed='+str(len(mutants))+' total='+str(len(mutants))+' dir='+str(root))