okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
407ea8192
main
1"""Tests for serve/server.py's effort_end_args (#458): "effort_position": "end" is used when the engine binary knows 2--tail-role-token. With the Intel launcher (sycl/serve/strata-sycl.sh) as the configured exe, the check reads the 3binary the launcher runs (STRATA_SYCL_BIN, default build-sycl-aot/strata), not the shell script, which never names 4the option. Fake files in a temp repo - nothing is built or run. 5 6python -m unittest tools.test_effort_end_args 7""" 8from __future__import annotations 9 10import contextlib 11import io 12import os 13import sys 14import tempfile 15import unittest 16from pathlib import Path 17from unittest import mock 18 19ROOT = Path (__file__ ).resolve ().parents [1 ] 20sys .path .insert (0 ,str (ROOT )) 21from serve import server as S # noqa: E402 22 23 24class Tok : 25def encode (self ,text ,parse_special = False ): 26return [42 ]if text == "system" else [1 ,2 ] 27 28 29ENGINE_WITH = b"\x7fELF ... --tail-role-token ... --serve ..." 30ENGINE_WITHOUT = b"\x7fELF ... --serve ..." 31 32 33class EffortEndArgs (unittest .TestCase ): 34def setUp (self ): 35self .tmp = tempfile .TemporaryDirectory () 36self .repo = Path (self .tmp .name )/ "engine-repo" 37 (self .repo / "sycl" / "serve" ).mkdir (parents = True ) 38self .launcher = self .repo / "sycl" / "serve" / "strata-sycl.sh" 39self .launcher .write_text ("#!/usr/bin/env bash\nexec ${STRATA_SYCL_BIN:-build-sycl-aot/strata}\n" ) 40 (self .repo / "build-sycl-aot" ).mkdir () 41 42def tearDown (self ): 43self .tmp .cleanup () 44 45def call (self ,cfg ,exe ): 46with contextlib .redirect_stdout (io .StringIO ()),mock .patch .dict (os .environ , {},clear = False ): 47os .environ .pop ("STRATA_SYCL_BIN" ,None ) 48return S .effort_end_args (cfg ,str (exe ),Tok ()) 49 50def test_sycl_launcher_reads_the_binary (self ): 51 (self .repo / "build-sycl-aot" / "strata" ).write_bytes (ENGINE_WITH ) 52self .assertEqual (self .call ({"effort_position" :"end" },self .launcher ), ["--tail-role-token" ,"42" ]) 53 54def test_sycl_binary_without_the_option (self ): 55 (self .repo / "build-sycl-aot" / "strata" ).write_bytes (ENGINE_WITHOUT ) 56self .assertIsNone (self .call ({"effort_position" :"end" },self .launcher )) 57 58def test_sycl_bin_from_the_config_env (self ): 59 (self .repo / "build-sycl-aot" / "strata" ).write_bytes (ENGINE_WITHOUT ) 60 (self .repo / "other" ).mkdir () 61 (self .repo / "other" / "strata" ).write_bytes (ENGINE_WITH ) 62cfg = {"effort_position" :"end" ,"env" : {"STRATA_SYCL_BIN" :"other/strata" }} 63self .assertEqual (self .call (cfg ,self .launcher ), ["--tail-role-token" ,"42" ]) 64 65def test_sycl_binary_missing_falls_back_to_the_launcher (self ): 66self .assertIsNone (self .call ({"effort_position" :"end" },self .launcher )) 67 68def test_a_plain_engine_is_read_as_before (self ): 69exe = Path (self .tmp .name )/ "strata" 70exe .write_bytes (ENGINE_WITH ) 71self .assertEqual (self .call ({"effort_position" :"end" },exe ), ["--tail-role-token" ,"42" ]) 72exe .write_bytes (ENGINE_WITHOUT ) 73self .assertIsNone (self .call ({"effort_position" :"end" },exe )) 74 75def test_start_is_the_default (self ): 76 (self .repo / "build-sycl-aot" / "strata" ).write_bytes (ENGINE_WITH ) 77self .assertIsNone (self .call ({},self .launcher )) 78self .assertIsNone (self .call ({"effort_position" :"start" },self .launcher )) 79 80 81if __name__ == "__main__" : 82unittest .main ()