Linux DTrace development list
 help / color / mirror / Atom feed
From: Kris Van Hees <kris.van.hees@oracle.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH v5 11/11] test: Add a test for the PCP ManagedDTraceScript interface
Date: Mon, 5 Oct 2026 16:28:38 +0000	[thread overview]
Message-ID: <asPQNnYoMDTJviCl@kvh-deb-bpf> (raw)
In-Reply-To: <20260821161100.41710-12-alan.maguire@oracle.com>

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.

On Fri, Aug 21, 2026 at 05:10:59PM +0100, Alan Maguire wrote:
> 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 | 69 +++++++++++++++++++++++++++++++++
>  1 file changed, 69 insertions(+)
>  create mode 100755 test/unittest/python/tst.pcp.sh
> 
> diff --git a/test/unittest/python/tst.pcp.sh b/test/unittest/python/tst.pcp.sh
> new file mode 100755
> index 00000000..acc68854
> --- /dev/null
> +++ b/test/unittest/python/tst.pcp.sh
> @@ -0,0 +1,69 @@
> +#!/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
> +
> +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
> +
> +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"
> -- 
> 2.43.5
> 

      reply	other threads:[~2026-10-05 16:30 UTC|newest]

Thread overview: 18+ 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-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 [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=asPQNnYoMDTJviCl@kvh-deb-bpf \
    --to=kris.van.hees@oracle.com \
    --cc=alan.maguire@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    /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