| 1 | """Mock-WM suite catalog, checked against a separate Python state model.""" |
| 2 | from pathlib import Path |
| 3 | import hashlib,importlib.util,json |
| 4 | from model import expected |
| 5 | from workloads import WORKLOADS |
| 6 | |
| 7 | ROOT = Path(__file__).resolve().parents[2] |
| 8 | HERE = Path(__file__).resolve().parent |
| 9 | spec = importlib.util.spec_from_file_location('_shared_benchmark_catalog', ROOT/'bench/native/catalog.py') |
| 10 | shared = importlib.util.module_from_spec(spec);spec.loader.exec_module(shared) |
| 11 | SEEDS = (0, 1, 2, 3) |
| 12 | SCALING_CASES = ('wm-callback-chain', 'wm-focus-cycle') |
| 13 | |
| 14 | def expected_values(name): |
| 15 | return [expected(name.removeprefix('wm-'), seed) for seed in SEEDS] |
| 16 | |
| 17 | def vile_source(case, root): |
| 18 | setup = case['vile_setup'].replace('@FIXTURE_ROOT@', json.dumps(str(root/'bench/wm/fixtures'))) |
| 19 | return setup + '\n' + (root/case['source']).read_text() |
| 20 | |
| 21 | def guile_wrapper(case, root): |
| 22 | case = dict(case, guile_setup=case['guile_setup'].replace('@FIXTURE_ROOT@', json.dumps(str(root/'bench/wm/fixtures')))) |
| 23 | return shared.guile_wrapper(case, root) |
| 24 | |
| 25 | def validate_catalog(record, root): |
| 26 | assert record['schema_version']==3 and record['seed_values']==list(SEEDS) |
| 27 | assert len(record['cases'])==len(WORKLOADS)==12 |
| 28 | for path, digest in record['dependencies'].items(): |
| 29 | assert hashlib.sha256((root/path).read_bytes()).hexdigest()==digest,path |
| 30 | common=(root/'bench/wm/common.scm').read_text() |
| 31 | for case in record['cases']: |
| 32 | category, body=WORKLOADS[case['name'].removeprefix('wm-')] |
| 33 | assert case['category']==category and case['definitions']==common+'\n'+body |
| 34 | assert case['expected_by_seed']==expected_values(case['name']) |
| 35 | assert len(set(case['expected_by_seed']))==4 |
| 36 | assert case['batch_calls']==4 and case['warmup_calls']==5 |
| 37 | data=(case['definitions']+'\n'+shared.batch_source(case)).encode() |
| 38 | assert (root/case['source']).read_bytes()==data,case['name'] |
| 39 | assert hashlib.sha256(data).hexdigest()==case['source_sha256'],case['name'] |
| 40 | |
| 41 | def generate(): |
| 42 | common=(HERE/'common.scm').read_text();cases=[] |
| 43 | for name,(category,body) in WORKLOADS.items(): |
| 44 | name='wm-'+name;values=expected_values(name) |
| 45 | case=dict(name=name,category=category,definitions=common+'\n'+body, |
| 46 | expected=values[0],expected_by_seed=values,batch_calls=4,warmup_calls=5, |
| 47 | source='bench/wm/'+name+'.scm', |
| 48 | vile_setup='(define wm-fixture-root @FIXTURE_ROOT@) (define wm-config-environment (interaction-environment))', |
| 49 | guile_setup='(define-module (vile benchmarks '+name+') #:use-module (guile))\n(define wm-fixture-root @FIXTURE_ROOT@) (define wm-config-environment (current-module))', |
| 50 | oracle='Independent Python dictionary-state model checks every state field and client geometry through the common checksum protocol.') |
| 51 | data=(case['definitions']+'\n'+shared.batch_source(case)).encode() |
| 52 | (ROOT/case['source']).write_bytes(data);case['source_sha256']=hashlib.sha256(data).hexdigest();cases.append(case) |
| 53 | dependencies=[HERE/'common.scm',HERE/'model.py',HERE/'workloads.py',*sorted((HERE/'fixtures').glob('*.scm'))] |
| 54 | record=dict(schema_version=3,suite='mock-window-manager-v1',seed_values=list(SEEDS),cases=cases, |
| 55 | original_cases_path='bench/wm/model.py',original_cases_sha256=hashlib.sha256((HERE/'model.py').read_bytes()).hexdigest(), |
| 56 | dependencies={str(p.relative_to(ROOT)):hashlib.sha256(p.read_bytes()).hexdigest() for p in dependencies}) |
| 57 | (HERE/'cases.json').write_text(json.dumps(record,indent=2)+'\n');validate_catalog(record,ROOT) |
| 58 | print('Generated and checked',len(cases),'WM cases with four seed oracles each.') |
| 59 | |
| 60 | if __name__=='__main__':generate() |
| 61 | |