[DTrace-devel] [PATCH 02/16] cpc: Add simple tests

Kris Van Hees kris.van.hees at oracle.com
Fri Feb 24 00:50:08 UTC 2023


Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

On Thu, Jan 26, 2023 at 09:23:15PM -0500, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  test/unittest/cpc/tst.cpu_clock.d    | 47 ++++++++++++++++++++++++++++
>  test/unittest/cpc/tst.cpu_clock2.d   | 42 +++++++++++++++++++++++++
>  test/unittest/cpc/tst.cpu_clock2.r   |  1 +
>  test/unittest/cpc/tst.cpu_clock2.r.p | 28 +++++++++++++++++
>  test/unittest/cpc/tst.list_cpc.sh    | 43 +++++++++++++++++++++++++
>  5 files changed, 161 insertions(+)
>  create mode 100644 test/unittest/cpc/tst.cpu_clock.d
>  create mode 100644 test/unittest/cpc/tst.cpu_clock2.d
>  create mode 100644 test/unittest/cpc/tst.cpu_clock2.r
>  create mode 100755 test/unittest/cpc/tst.cpu_clock2.r.p
>  create mode 100755 test/unittest/cpc/tst.list_cpc.sh
> 
> diff --git a/test/unittest/cpc/tst.cpu_clock.d b/test/unittest/cpc/tst.cpu_clock.d
> new file mode 100644
> index 00000000..f1fbcf10
> --- /dev/null
> +++ b/test/unittest/cpc/tst.cpu_clock.d
> @@ -0,0 +1,47 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2023, 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.
> + */
> +
> +/* @@reinvoke-failure: 2 */
> +
> +/*
> + * This test is probably unstable due to possible kernel throttling issues.
> + * But on my ARM OL9 VM, it looks particularly bad due to emitting 14
> + * probes and then just stopping for a long time.
> + */
> +/* @@tags: unstable */
> +
> +#pragma D option quiet
> +
> +/* count quickly (each 0.05 sec) */
> +cpc:::cpu_clock-all-50000000
> +/cpu == 0/
> +{
> +	n++;
> +}
> +
> +/* we expect 40 counts after 2 secs */
> +/* (possibly, there could be far fewer due to kernel throttling) */
> +cpc:::cpu_clock-all-2000000000
> +/cpu == 0 && (n < 20 || n > 42)/
> +{
> +	printf("count is out of range: %d (expect 40)\n", n);
> +	exit(1);
> +}
> +
> +cpc:::cpu_clock-all-2000000000
> +/cpu == 0/
> +{
> +	printf("count is in range: %d\n", n);
> +	exit(0);
> +}
> +
> +/* or time out */
> +tick-5s
> +{
> +	printf("time out: count is %d\n", n);
> +	exit(1);
> +}
> diff --git a/test/unittest/cpc/tst.cpu_clock2.d b/test/unittest/cpc/tst.cpu_clock2.d
> new file mode 100644
> index 00000000..4e0259d9
> --- /dev/null
> +++ b/test/unittest/cpc/tst.cpu_clock2.d
> @@ -0,0 +1,42 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2023, 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.
> + */
> +
> +/* @@runtest-opts: -qC */
> +
> +/*
> + * Depending on how the kernel was configured, throttling can introduce
> + * occasional large gaps between cpu_clock firings.  So, measure these
> + * gaps.  None should be too low, but a few may be too high.
> + */
> +
> +#define PERIOD 50000000
> +
> +long long lasttime[int];
> +
> +cpc:::cpu_clock-all-PERIOD
> +{
> +	currtime[cpu] = timestamp;
> +}
> +
> +cpc:::cpu_clock-all-PERIOD
> +/lasttime[cpu] != 0/
> +{
> +	this->gap = currtime[cpu] - lasttime[cpu];
> +	@["number"] = sum(1);
> +	@["low" ] = sum(this->gap <  9 * (PERIOD / 10) ? 1 : 0);
> +	@["high"] = sum(this->gap > 15 * (PERIOD / 10) ? 1 : 0);
> +}
> +
> +cpc:::cpu_clock-all-PERIOD
> +{
> +	lasttime[cpu] = currtime[cpu];
> +}
> +
> +tick-5s
> +{
> +	exit(0);
> +}
> diff --git a/test/unittest/cpc/tst.cpu_clock2.r b/test/unittest/cpc/tst.cpu_clock2.r
> new file mode 100644
> index 00000000..2e9ba477
> --- /dev/null
> +++ b/test/unittest/cpc/tst.cpu_clock2.r
> @@ -0,0 +1 @@
> +success
> diff --git a/test/unittest/cpc/tst.cpu_clock2.r.p b/test/unittest/cpc/tst.cpu_clock2.r.p
> new file mode 100755
> index 00000000..c2628b69
> --- /dev/null
> +++ b/test/unittest/cpc/tst.cpu_clock2.r.p
> @@ -0,0 +1,28 @@
> +#!/usr/bin/gawk -f
> +
> +BEGIN { number = low = high = -1; }
> +
> +/number/ { number = $2 }
> +/low/ { low = $2 }
> +/high/ { high = $2 }
> +
> +END {
> +        if (number == -1 || low == -1 || high == -1) {
> +                printf("missing data\n");
> +                exit(1);
> +        }
> +        if (number < 20 ) {
> +                printf("too few data\n");
> +                exit(1);
> +        }
> +        if (low != 0 ) {
> +                printf("some data too low\n");
> +                exit(1);
> +        }
> +        if (high > number / 10 ) {
> +                printf("too much data too high\n");
> +                exit(1);
> +        }
> +        printf("success\n");
> +        exit(0);
> +}
> diff --git a/test/unittest/cpc/tst.list_cpc.sh b/test/unittest/cpc/tst.list_cpc.sh
> new file mode 100755
> index 00000000..4455ea49
> --- /dev/null
> +++ b/test/unittest/cpc/tst.list_cpc.sh
> @@ -0,0 +1,43 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2023, 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.
> +
> +dtrace=$1
> +tmpfile=$tmpdir/tst.list_cpc.$$
> +mkdir $tmpfile
> +cd $tmpfile
> +
> +$dtrace $dt_flags -lP cpc > out.txt 2> err.txt
> +if [ $? -ne 0 ]; then
> +	echo "DTrace error"
> +	echo "==== out.txt"
> +	cat out.txt
> +	echo "==== err.txt"
> +	cat err.txt
> +	exit 1
> +fi
> +
> +awk '
> +BEGIN { cpu_clock = task_clock = 0 }
> +$2 == "cpc" && index($3, "perf_count_sw_cpu_clock-") { cpu_clock = 1; next }
> +$2 == "cpc" && index($3, "perf_count_sw_task_clock-") { task_clock = 1; next }
> +END {
> +	if (cpu_clock && task_clock) exit(0);
> +	if (cpu_clock == 0) { print "missing CPU clock" }
> +	if (task_clock == 0) { print "missing task clock" }
> +	exit(1);
> +}' out.txt
> +
> +if [ $? -ne 0 ]; then
> +	echo "unexpected results"
> +	echo "==== out.txt"
> +	cat out.txt
> +	echo "==== err.txt"
> +	cat err.txt
> +	exit 1
> +fi
> +
> +exit 0
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list