Linux DTrace development list
 help / color / mirror / Atom feed
From: Alan Maguire <almagui@kernel.org>
To: kris.van.hees@oracle.com
Cc: alan.maguire@oracle.com, dtrace-devel@oss.oracle.com,
	dtrace@lists.linux.dev
Subject: Re: [PATCH v5 11/11] test: Add a test for the PCP ManagedDTraceScript interface
Date: Tue, 20 Oct 2026 16:49:03 +0100	[thread overview]
Message-ID: <8fcbc041-a175-4af9-a13d-c81006b83bba@kernel.org> (raw)
In-Reply-To: <asPQNnYoMDTJviCl@kvh-deb-bpf>

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

> 
> This should either add a dependency on python and pcp for the testsuite,
> or there should be a .x file to exclude this test when python and pcp
> are not available.  As it is now, not having PCP on the system will
> cause the test to fail.

The earlier python tests introduce a test.x for python availability, so
that should cover this test too. There is a test for pcp availability
below, see:

> +if ! "$DTRACE_PYTHON" -c 'import dtrace, cpmapi, cpmda, pcp.pmapi, pcp.pmda' \
> +    >/dev/null 2>&1; then
> +    echo "DTrace or PCP Python bindings are unavailable"
> +    exit 2
> +fi
> +

...but the exit 2 triggers a fail IIRC; something like the attached should
work I think..

[-- Attachment #2: 0001-test-Add-a-test-for-the-PCP-ManagedDTraceScript-inte.patch --]
[-- Type: text/x-patch, Size: 3600 bytes --]

From 37b5be874e207f244e92c64720ffbce0febaa2a1 Mon Sep 17 00:00:00 2001
From: Alan Maguire <alan.maguire@oracle.com>
Date: Tue, 18 Aug 2026 11:28:51 +0100
Subject: [PATCH 1/2] test: Add a test for the PCP ManagedDTraceScript
 interface

Since tests cannot rely on a full PCP configuration, do
limited testing of a ManagedDTraceScript, ensuring that
we can create it, start it and that it collects data.

Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 test/unittest/python/tst.pcp.sh | 63 +++++++++++++++++++++++++++++++++
 test/unittest/python/tst.pcp.x  | 16 +++++++++
 2 files changed, 79 insertions(+)
 create mode 100755 test/unittest/python/tst.pcp.sh
 create mode 100755 test/unittest/python/tst.pcp.x

diff --git a/test/unittest/python/tst.pcp.sh b/test/unittest/python/tst.pcp.sh
new file mode 100755
index 00000000..cd8c03b4
--- /dev/null
+++ b/test/unittest/python/tst.pcp.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+#
+# Test the PCP ManagedDTraceScript with a real DTrace session.
+# @@timeout: 60
+
+if [ $# -ne 1 ]; then
+    echo "usage: $0 <dtrace>" >&2
+    exit 2
+fi
+
+tmpdir=$(mktemp -d)
+cleanup() { rm -rf "$tmpdir"; }
+trap cleanup EXIT
+
+cat >"$tmpdir/test.py" <<'EOF'
+#!/usr/bin/env python3
+import importlib.machinery
+import importlib.util
+import time
+
+loader = importlib.machinery.SourceFileLoader("pmdadtrace", "pcp/pmdadtrace.python")
+spec = importlib.util.spec_from_loader("pmdadtrace", loader)
+pmdadtrace = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(pmdadtrace)
+
+created = []
+script = pmdadtrace.ManagedDTraceScript(
+    "tick_test", "profile:::tick-1s /$1 == 1/ { @ticks = count(); }", False,
+    {"quiet": True}, ".", None, None, [], ["1"], 0,
+    print,
+)
+script._data_callbacks = {
+    "create_metric": lambda entry: created.append(("metric", entry.metric)),
+    "create_instance": lambda entry: created.append(
+        ("instance", entry.metric, entry.instance)
+    ),
+    "update_instance": lambda entry: None,
+    "remove_instance": lambda entry: None,
+    "refresh_metrics": lambda: None,
+}
+
+ok, error = script.start()
+if not ok:
+    raise SystemExit(f"unable to start ManagedDTraceScript: {error}")
+time.sleep(15)
+script.stop()
+
+entries = script.latest_aggregations()
+if script.state() == "error":
+    raise SystemExit(f"ManagedDTraceScript failed: {script.last_error()}")
+if not any(entry.metric.endswith(".ticks") for entry in entries.values()):
+    raise SystemExit(f"tick aggregation was not published: {entries}")
+if not any(item[0] == "instance" for item in created):
+    raise SystemExit(f"tick metric instance was not created: {created}")
+EOF
+
+chmod +x "$tmpdir/test.py"
+timeout 60 "$DTRACE_PYTHON" "$tmpdir/test.py"
diff --git a/test/unittest/python/tst.pcp.x b/test/unittest/python/tst.pcp.x
new file mode 100755
index 00000000..8a05441e
--- /dev/null
+++ b/test/unittest/python/tst.pcp.x
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
+# Licensed under the Universal Permissive License v 1.0 as shown at
+# http://oss.oracle.com/licenses/upl.
+#
+# Skip the PCP test when the PCP Python bindings are not installed.
+#
+
+if ! "$DTRACE_PYTHON" -c 'import cpmapi, cpmda, pcp.pmapi, pcp.pmda' >/dev/null 2>&1; then
+	echo "PCP Python bindings are unavailable"
+	exit 2
+fi
+
+exit 0
-- 
2.55.0


      reply	other threads:[~2026-10-20 15:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21 16:10 [PATCH v5 00/11] Add python, PCP support via libdtrace interfaces Alan Maguire
2026-08-21 16:10 ` [PATCH v5 01/11] libdtrace: Support multiple DTrace handles per process Alan Maguire
2026-10-07  9:26   ` Kris Van Hees
2026-08-21 16:10 ` [PATCH v5 02/11] libdtrace: share vmlinux BTF/CTF globally to support faster startup Alan Maguire
2026-10-07 10:05   ` Kris Van Hees
2026-08-21 16:10 ` [PATCH v5 03/11] libdtrace: avoid BTF probes for ranged built-in modules Alan Maguire
2026-10-07 10:20   ` Kris Van Hees
2026-10-20  9:58     ` Alan Maguire
2026-08-21 16:10 ` [PATCH v5 04/11] libdtrace: Add aggregation key/value computation APIs Alan Maguire
2026-10-07 10:51   ` Kris Van Hees
2026-08-21 16:10 ` [PATCH v5 05/11] python: Add cpython bindings for libdtrace Alan Maguire
2026-10-05 16:23   ` Kris Van Hees
2026-08-21 16:10 ` [PATCH v5 06/11] dtrace.spec: add python bindings packaging Alan Maguire
2026-08-21 16:10 ` [PATCH v5 07/11] runtest.sh: Prepare Python bindings for in-tree testing Alan Maguire
2026-08-21 16:10 ` [PATCH v5 08/11] test: add tests for python bindings Alan Maguire
2026-08-21 16:10 ` [PATCH v5 09/11] dtrace: Add a PCP PMDA to expose DTrace data as metrics Alan Maguire
2026-08-21 16:10 ` [PATCH v5 10/11] dtrace.spec: Add PCP PMDA packaging pcp-pmda-dtrace Alan Maguire
2026-08-21 16:10 ` [PATCH v5 11/11] test: Add a test for the PCP ManagedDTraceScript interface Alan Maguire
2026-10-05 16:28   ` Kris Van Hees
2026-10-20 15:49     ` Alan Maguire [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8fcbc041-a175-4af9-a13d-c81006b83bba@kernel.org \
    --to=almagui@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    --cc=kris.van.hees@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox