@@ -122,8 +122,27 @@ def generate_context_binary(
122122 shell = True ,
123123 executable = "/bin/bash" ,
124124 capture_output = True ,
125+ text = True ,
126+ env = _qnn_subprocess_env (qnn_sdk , target ),
125127 )
126- assert os .path .isfile (f"{ artifact_dir } /model_ctx.bin" ), print (result .stderr )
128+ assert os .path .isfile (f"{ artifact_dir } /model_ctx.bin" ), (
129+ f"Failed to generate context binary at { artifact_dir } /model_ctx.bin. "
130+ f"returncode={ result .returncode } \n "
131+ f"stdout:\n { result .stdout } \n "
132+ f"stderr:\n { result .stderr } "
133+ )
134+
135+
136+ def _qnn_subprocess_env (qnn_sdk : str , target : str ) -> Dict [str , str ]:
137+ """Return an env dict with LD_LIBRARY_PATH set so QNN SDK prebuilt
138+ binaries (e.g. qnn-context-binary-utility) can resolve their bundled
139+ libc++.so.1, which is shipped at $QNN_SDK_ROOT/lib/<target>/.
140+ """
141+ env = os .environ .copy ()
142+ qnn_lib_dir = f"{ qnn_sdk } /lib/{ target } "
143+ existing = env .get ("LD_LIBRARY_PATH" , "" )
144+ env ["LD_LIBRARY_PATH" ] = f"{ qnn_lib_dir } :{ existing } " if existing else qnn_lib_dir
145+ return env
127146
128147
129148def validate_context_binary (ctx_bin : bytes ):
@@ -149,8 +168,15 @@ def validate_context_binary(ctx_bin: bytes):
149168 shell = True ,
150169 executable = "/bin/bash" ,
151170 capture_output = True ,
171+ text = True ,
172+ env = _qnn_subprocess_env (qnn_sdk , target ),
173+ )
174+ assert os .path .isfile (f"{ tmp_dir } /ctx.json" ), (
175+ f"qnn-context-binary-utility failed to produce ctx.json. "
176+ f"returncode={ result .returncode } \n "
177+ f"stdout:\n { result .stdout } \n "
178+ f"stderr:\n { result .stderr } "
152179 )
153- assert os .path .isfile (f"{ tmp_dir } /ctx.json" ), print (result .stderr )
154180
155181
156182class TestQNN (unittest .TestCase ):
0 commit comments