okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6e1085c1d
main
1#!/usr/bin/env python3 2"""Run the unchanged P40 workload/graders, isolating generated Python with bubblewrap. 3 4All arguments are forwarded to the original bench.py. Requires Linux and bwrap. 5""" 6import importlib .util 7import pathlib 8import resource 9import subprocess 10import sys 11 12ROOT = pathlib .Path (__file__ ).resolve ().parents [4 ] 13SOURCE = ROOT / 'bench/results/2026-10-05-community-2x-p40/scripts/bench.py' 14spec = importlib .util .spec_from_file_location ('p40_bench' ,SOURCE ) 15bench = importlib .util .module_from_spec (spec ) 16spec .loader .exec_module (bench ) 17original_run = subprocess .run 18 19 20def limits (): 21resource .setrlimit (resource .RLIMIT_AS , (512 * 1024 ** 2 ,512 * 1024 ** 2 )) 22resource .setrlimit (resource .RLIMIT_CPU , (15 ,15 )) 23resource .setrlimit (resource .RLIMIT_FSIZE , (1024 ** 2 ,1024 ** 2 )) 24 25 26def isolated_run (command ,** kwargs ): 27if len (command )== 3 and command [:2 ]== [sys .executable ,'-I' ]: 28command = ['bwrap' ,'--unshare-all' ,'--die-with-parent' ,'--new-session' , 29'--ro-bind' ,'/usr' ,'/usr' ,'--ro-bind' ,'/lib' ,'/lib' , 30'--ro-bind' ,'/lib64' ,'/lib64' ,'--proc' ,'/proc' ,'--dev' ,'/dev' , 31'--tmpfs' ,'/tmp' ,'--ro-bind' ,command [2 ],'/solution.py' , 32'--chdir' ,'/tmp' ,'/usr/bin/python3' ,'-I' ,'/solution.py' ] 33kwargs ['preexec_fn' ]= limits 34return original_run (command ,** kwargs ) 35 36 37# Only the code grader invokes subprocess.run. Task construction and grading stay upstream's. 38bench .subprocess .run = isolated_run 39if __name__ == '__main__' : 40bench .main ()