@@ -174,6 +174,60 @@ pub async fn cleanup_global_test_process() -> anyhow::Result<()> {
174174 Ok ( ( ) )
175175}
176176
177+ #[ tokio:: test]
178+ async fn test_special_pid_in_if_condition ( ) -> anyhow:: Result < ( ) > {
179+ init ( ) ;
180+ ensure_global_cleanup_registered ( ) ;
181+
182+ let opt_level = OptimizationLevel :: Debug ;
183+ let test_pid = get_global_test_pid_with_opt ( opt_level) . await ?;
184+
185+ // Use $pid in an expression: it should equal the traced process PID
186+ let script_content = format ! (
187+ "trace sample_program.c:16 {{\n if $pid == {} {{ print \" PID_OK\" ; }} else {{ print \" PID_BAD\" ; }}\n }}\n " ,
188+ test_pid
189+ ) ;
190+
191+ let ( exit_code, stdout, stderr) =
192+ run_ghostscope_with_script_opt ( & script_content, 3 , opt_level) . await ?;
193+
194+ assert_eq ! ( exit_code, 0 , "stderr={}" , stderr) ;
195+ assert ! (
196+ stdout. contains( "PID_OK" ) ,
197+ "Expected PID_OK in output. STDOUT: {}" ,
198+ stdout
199+ ) ;
200+
201+ Ok ( ( ) )
202+ }
203+
204+ #[ tokio:: test]
205+ async fn test_special_tid_and_timestamp_print ( ) -> anyhow:: Result < ( ) > {
206+ init ( ) ;
207+ ensure_global_cleanup_registered ( ) ;
208+
209+ let opt_level = OptimizationLevel :: Debug ;
210+ let _ = get_global_test_pid_with_opt ( opt_level) . await ?;
211+
212+ // Just print them to ensure they compile, evaluate and render
213+ let script_content = r#"
214+ trace sample_program.c:16 {
215+ print "TST:{} {}", $tid, $timestamp;
216+ }
217+ "# ;
218+
219+ let ( exit_code, stdout, stderr) =
220+ run_ghostscope_with_script_opt ( script_content, 3 , opt_level) . await ?;
221+
222+ assert_eq ! ( exit_code, 0 , "stderr={}" , stderr) ;
223+ assert ! (
224+ stdout. contains( "TST:" ) ,
225+ "Expected TST: with tid/timestamp in output. STDOUT: {}" ,
226+ stdout
227+ ) ;
228+ Ok ( ( ) )
229+ }
230+
177231// Global cleanup registration - only runs once when the first test calls it
178232static GLOBAL_CLEANUP_REGISTERED : Once = Once :: new ( ) ;
179233
0 commit comments