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


##########
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:
   Changed: if bpftrace exits at any point after it starts, the test now fails 
and shows bpftrace's output. It skips only when bpftrace is missing or the run 
has no privilege.



-- 
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