Copilot commented on code in PR #14100:
URL: https://github.com/apache/trafficserver/pull/14100#discussion_r4604366422


##########
tests/uranium_tests/ats_probe/test_eventloop_probe.py:
##########
@@ -0,0 +1,106 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+from pathlib import Path
+import os
+import re
+import shutil
+import subprocess
+import threading
+import time
+
+import pytest
+
+from tools.uranium.services import ATS, Curl, ProcessService, ServiceFactory
+
+TEST_DIRECTORY = Path(__file__).parent
+SCRIPT = TEST_DIRECTORY / "eventloop_probe.bt"
+STALL_MS = 2000
+REPORT = re.compile(r"watchdog_thread_awake pid=(\d+) index=(\d+) tid=(\d+) 
awake_ms=(\d+)")
+
+
+def tracer_command() -> tuple[str, ...]:
+    """Run bpftrace directly as root or through passwordless sudo."""
+
+    if shutil.which("bpftrace") is None:
+        pytest.skip("bpftrace is required")
+    if os.geteuid() == 0:
+        return ("bpftrace", str(SCRIPT))
+    if shutil.which("sudo") is not None:
+        result = subprocess.run(("sudo", "-n", "true"), capture_output=True, 
text=True, check=False)
+        if result.returncode == 0:
+            return ("sudo", "-n", "bpftrace", str(SCRIPT))
+    pytest.skip("event loop probe tracing requires root or passwordless sudo")
+
+
+def wait_for_trace(pattern: re.Pattern[str], timeout: float, *, _tracer: 
ProcessService) -> re.Match[str]:
+    """Wait for a line in the live tracer output.
+
+    :param pattern: Expression to find in the accumulated bpftrace output.
+    :param timeout: Maximum number of seconds to wait.
+
+    :param _tracer: Test-local tracer configured by the test.
+    """
+
+    deadline = time.monotonic() + timeout
+    while time.monotonic() < deadline:
+        if match := pattern.search(_tracer.output):
+            return match
+        if not _tracer.is_running:
+            pytest.skip(f"bpftrace cannot attach to the ATS 
probes:\n{_tracer.output}")

Review Comment:
   This helper is also used after the tracer has printed its ready marker, 
while waiting for the sleep and watchdog events. If bpftrace exits unexpectedly 
during those waits, the test is marked skipped instead of failing, so a failed 
tracing run silently loses its assertions. Please restrict environment-related 
skips to the initial attachment check and fail if the tracer terminates after 
readiness.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to