[DTrace-devel] [PATCH 1/2] Test curcpu->cpu_id

Kris Van Hees kris.van.hees at oracle.com
Tue Aug 25 18:43:36 PDT 2020


On Tue, Aug 25, 2020 at 05:55:26PM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> The built-in variable curcpu is exercised only very mildly in
> the test suite.  In test/unittest/variables/bvar/tst.curcpu.d,
> we check only if 'curcpu' can be accessed and is not -1.  In
> test/unittest/sched/tst.var-curcpu.d, curcpu->cpu_id is
> printed but the value is not checked.
> 
> Add test/unittest/variables/bvar/tst.curcpu_cpu_id.sh to check
> the curcpu->cpu_id value.
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>

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

... with very small changes listed below...

> ---
>  .../variables/bvar/tst.curcpu_cpu_id.sh       | 61 +++++++++++++++++++
>  1 file changed, 61 insertions(+)
>  create mode 100755 test/unittest/variables/bvar/tst.curcpu_cpu_id.sh
> 
> diff --git a/test/unittest/variables/bvar/tst.curcpu_cpu_id.sh b/test/unittest/variables/bvar/tst.curcpu_cpu_id.sh
> new file mode 100755
> index 00000000..d5992d29
> --- /dev/null
> +++ b/test/unittest/variables/bvar/tst.curcpu_cpu_id.sh
> @@ -0,0 +1,61 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2020, 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.
> +#
> +
> +##
> +#
> +# ASSERTION:
> +# The cpucpu->cpu_id field matches the CPU.
> +#
> +# SECTION: Variables/Built-in Variables/curcpu
> +#
> +##
> +
> +dtrace=$1
> +
> +# Testing turns off default CPU ID output for more reproducible results.
> +# For this test, however, we want that CPU ID output.
> +unset _DTRACE_TESTING
> +
> +# Feed DTrace output into awk script to process results.
> +$dtrace $dt_flags -n '
> +profile-3 {
> +	trace(curcpu->cpu_id);
> +}
> +
> +profile-2 {

I would make this a tick-2 probe so we don't have to create as many timer
events as there are CPUs for the end condition, and instead get away with
a single timer.

> +	exit(0);
> +}
> +' | awk '
> +BEGIN {
> +        nevents = 0;
> +        nerrors = 0;
> +        ID = -1;
> +}
> +
> +{ print }
> +
> +$3 == ":profile-3" {
> +        nevents++;
> +        if (NF != 4) { nerrors++; print; print "ERROR: not 4 fields" };
> +        if ($1 != $4) { nerrors++; print; print "ERROR: CPU ID and cpu_id differ" };
> +        if (used[$1] != 0) { nerrors++; print; print "ERROR: CPU ID repeated" };
> +        used[$1] += 1;

used[$1]++; since that is really the most common idiom for an increment by 1.

> +        if (ID == -1) { ID = $2 };
> +        if (ID != $2) { nerrors++; print; print "ERROR: probe ID changed" };
> +}
> +
> +END {
> +        if (nevents == 0) { print "NO EVENTS"; exit(1) };
> +        if (nerrors != 0) { print "FOUND ERRORS"; exit(1) };
> +        print "success";
> +        exit(0);
> +}
> +'
> +
> +exit $?
> +
> -- 
> 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