[DTrace-devel] [PATCH 07/16] cpc: Import tests from Solaris

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


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

On Thu, Jan 26, 2023 at 09:23:20PM -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>
> ---
>  .../cpc/err.D_PDESC_ZERO.lowfrequency.d       |  45 ++++++++
>  .../cpc/err.D_PDESC_ZERO.malformedoverflow.d  |  40 +++++++
>  .../cpc/err.D_PDESC_ZERO.nonexistentevent.d   |  40 +++++++
>  test/unittest/cpc/err.cpcvscpustatpart1.ksh   |  78 +++++++++++++
>  test/unittest/cpc/err.cpcvscpustatpart2.ksh   |  70 ++++++++++++
>  test/unittest/cpc/err.cputrackfailtostart.ksh |  77 +++++++++++++
>  test/unittest/cpc/err.cputrackterminates.ksh  |  70 ++++++++++++
>  test/unittest/cpc/err.toomanyenablings.d      |  55 +++++++++
>  test/unittest/cpc/tst.allcpus.ksh             | 107 ++++++++++++++++++
>  test/unittest/cpc/tst.genericevent.d          |  48 ++++++++
>  test/unittest/cpc/tst.platformevent.ksh       |  81 +++++++++++++
>  11 files changed, 711 insertions(+)
>  create mode 100644 test/unittest/cpc/err.D_PDESC_ZERO.lowfrequency.d
>  create mode 100644 test/unittest/cpc/err.D_PDESC_ZERO.malformedoverflow.d
>  create mode 100644 test/unittest/cpc/err.D_PDESC_ZERO.nonexistentevent.d
>  create mode 100755 test/unittest/cpc/err.cpcvscpustatpart1.ksh
>  create mode 100755 test/unittest/cpc/err.cpcvscpustatpart2.ksh
>  create mode 100755 test/unittest/cpc/err.cputrackfailtostart.ksh
>  create mode 100755 test/unittest/cpc/err.cputrackterminates.ksh
>  create mode 100644 test/unittest/cpc/err.toomanyenablings.d
>  create mode 100755 test/unittest/cpc/tst.allcpus.ksh
>  create mode 100644 test/unittest/cpc/tst.genericevent.d
>  create mode 100755 test/unittest/cpc/tst.platformevent.ksh
> 
> diff --git a/test/unittest/cpc/err.D_PDESC_ZERO.lowfrequency.d b/test/unittest/cpc/err.D_PDESC_ZERO.lowfrequency.d
> new file mode 100644
> index 00000000..1015a251
> --- /dev/null
> +++ b/test/unittest/cpc/err.D_PDESC_ZERO.lowfrequency.d
> @@ -0,0 +1,45 @@
> +/*
> + * CDDL HEADER START
> + *
> + * The contents of this file are subject to the terms of the
> + * Common Development and Distribution License (the "License").
> + * You may not use this file except in compliance with the License.
> + *
> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> + * or http://www.opensolaris.org/os/licensing.
> + * See the License for the specific language governing permissions
> + * and limitations under the License.
> + *
> + * When distributing Covered Code, include this CDDL HEADER in each
> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> + * If applicable, add the following below this CDDL HEADER, with the
> + * fields enclosed by brackets "[]" replaced with your own identifying
> + * information: Portions Copyright [yyyy] [name of copyright owner]
> + *
> + * CDDL HEADER END
> + */
> +
> +/*
> + * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> + * Use is subject to license terms.
> + */
> +
> +/*
> + * Test to check that attempting to enable a valid event with a frequency
> + * lower than the default platform limit will fail.
> + *
> + * This test will fail if:
> + *	1) The system under test does not define the 'PAPI_tot_ins' event.
> + *	2) The 'dcpc-min-overflow' variable in dcpc.conf has been modified.
> + */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +	exit(0);
> +}
> +
> +cpc:::PAPI_tot_ins-all-100
> +{
> +}
> diff --git a/test/unittest/cpc/err.D_PDESC_ZERO.malformedoverflow.d b/test/unittest/cpc/err.D_PDESC_ZERO.malformedoverflow.d
> new file mode 100644
> index 00000000..f9b78094
> --- /dev/null
> +++ b/test/unittest/cpc/err.D_PDESC_ZERO.malformedoverflow.d
> @@ -0,0 +1,40 @@
> +/*
> + * CDDL HEADER START
> + *
> + * The contents of this file are subject to the terms of the
> + * Common Development and Distribution License (the "License").
> + * You may not use this file except in compliance with the License.
> + *
> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> + * or http://www.opensolaris.org/os/licensing.
> + * See the License for the specific language governing permissions
> + * and limitations under the License.
> + *
> + * When distributing Covered Code, include this CDDL HEADER in each
> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> + * If applicable, add the following below this CDDL HEADER, with the
> + * fields enclosed by brackets "[]" replaced with your own identifying
> + * information: Portions Copyright [yyyy] [name of copyright owner]
> + *
> + * CDDL HEADER END
> + */
> +
> +/*
> + * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> + * Use is subject to license terms.
> + */
> +
> +/*
> + * Tests that specifying an overflow value containing extraneous characters
> + * (only digits are allowed) will fail.
> + */
> +
> +BEGIN
> +{
> +	exit(0);
> +}
> +
> +cpc:::PAPI_tot_ins-all-10000bonehead
> +{
> +	@[probename] = count();
> +}
> diff --git a/test/unittest/cpc/err.D_PDESC_ZERO.nonexistentevent.d b/test/unittest/cpc/err.D_PDESC_ZERO.nonexistentevent.d
> new file mode 100644
> index 00000000..73f9575f
> --- /dev/null
> +++ b/test/unittest/cpc/err.D_PDESC_ZERO.nonexistentevent.d
> @@ -0,0 +1,40 @@
> +/*
> + * CDDL HEADER START
> + *
> + * The contents of this file are subject to the terms of the
> + * Common Development and Distribution License (the "License").
> + * You may not use this file except in compliance with the License.
> + *
> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> + * or http://www.opensolaris.org/os/licensing.
> + * See the License for the specific language governing permissions
> + * and limitations under the License.
> + *
> + * When distributing Covered Code, include this CDDL HEADER in each
> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> + * If applicable, add the following below this CDDL HEADER, with the
> + * fields enclosed by brackets "[]" replaced with your own identifying
> + * information: Portions Copyright [yyyy] [name of copyright owner]
> + *
> + * CDDL HEADER END
> + */
> +
> +/*
> + * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> + * Use is subject to license terms.
> + */
> +
> +/*
> + * Tests that attempting to enable a probe containing a non existent event
> + * will fail.
> + */
> +
> +BEGIN
> +{
> +	exit(0);
> +}
> +
> +cpc:::PAPI_cpc_bad-all-10000
> +{
> +	@[probename] = count();
> +}
> diff --git a/test/unittest/cpc/err.cpcvscpustatpart1.ksh b/test/unittest/cpc/err.cpcvscpustatpart1.ksh
> new file mode 100755
> index 00000000..767d493a
> --- /dev/null
> +++ b/test/unittest/cpc/err.cpcvscpustatpart1.ksh
> @@ -0,0 +1,78 @@
> +#!/bin/ksh
> +#
> +# CDDL HEADER START
> +#
> +# The contents of this file are subject to the terms of the
> +# Common Development and Distribution License (the "License").
> +# You may not use this file except in compliance with the License.
> +#
> +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> +# or http://www.opensolaris.org/os/licensing.
> +# See the License for the specific language governing permissions
> +# and limitations under the License.
> +#
> +# When distributing Covered Code, include this CDDL HEADER in each
> +# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> +# If applicable, add the following below this CDDL HEADER, with the
> +# fields enclosed by brackets "[]" replaced with your own identifying
> +# information: Portions Copyright [yyyy] [name of copyright owner]
> +#
> +# CDDL HEADER END
> +#
> +
> +#
> +# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> +# Use is subject to license terms.
> +#
> +
> +
> +#
> +# This tests that cpustat(1) should fail to start if the cpc provider
> +# is already calling the shots.
> +#
> +# This script will fail if:
> +#       1) The system under test does not define the 'PAPI_tot_ins'
> +#       generic event.
> +
> +script()
> +{
> +	$dtrace -o $dtraceout -s /dev/stdin <<EOF
> +	#pragma D option bufsize=128k
> +
> +	cpc:::PAPI_tot_ins-all-10000
> +	{
> +		@[probename] = count();
> +	}
> +EOF
> +}
> +
> +if [ $# != 1 ]; then
> +	echo expected one argument: '<'dtrace-path'>'
> +	exit 2
> +fi
> +
> +dtrace=$1
> +dtraceout=/tmp/dtrace.out.$$
> +script 2>/dev/null &
> +timeout=15
> +
> +#
> +# Sleep while the above script fires into life. To guard against dtrace dying
> +# and us sleeping forever we allow 15 secs for this to happen. This should be
> +# enough for even the slowest systems.
> +#
> +while [ ! -f $dtraceout ]; do
> +	sleep 1
> +	timeout=$(($timeout-1))
> +	if [ $timeout -eq 0 ]; then
> +		echo "dtrace failed to start. Exiting."
> +		exit 1
> +	fi
> +done
> +
> +cpustat -c PAPI_tot_ins 1 5
> +status=$?
> +
> +rm $dtraceout
> +
> +exit $status
> diff --git a/test/unittest/cpc/err.cpcvscpustatpart2.ksh b/test/unittest/cpc/err.cpcvscpustatpart2.ksh
> new file mode 100755
> index 00000000..584469c3
> --- /dev/null
> +++ b/test/unittest/cpc/err.cpcvscpustatpart2.ksh
> @@ -0,0 +1,70 @@
> +#!/bin/ksh -p
> +#
> +# CDDL HEADER START
> +#
> +# The contents of this file are subject to the terms of the
> +# Common Development and Distribution License (the "License").
> +# You may not use this file except in compliance with the License.
> +#
> +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> +# or http://www.opensolaris.org/os/licensing.
> +# See the License for the specific language governing permissions
> +# and limitations under the License.
> +#
> +# When distributing Covered Code, include this CDDL HEADER in each
> +# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> +# If applicable, add the following below this CDDL HEADER, with the
> +# fields enclosed by brackets "[]" replaced with your own identifying
> +# information: Portions Copyright [yyyy] [name of copyright owner]
> +#
> +# CDDL HEADER END
> +#
> +
> +#
> +# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> +# Use is subject to license terms.
> +#
> +
> +
> +#
> +# This tests that enablings from the cpc provider will fail if cpustat(1) is
> +# already master of the universe.
> +#
> +# This script will fail if:
> +#       1) The system under test does not define the 'PAPI_tot_ins'
> +#       generic event.
> +
> +script()
> +{
> +        $dtrace -s /dev/stdin <<EOF
> +        #pragma D option bufsize=128k
> +
> +        BEGIN
> +        {
> +                exit(0);
> +        }
> +
> +        cpc:::PAPI_tot_ins-all-10000
> +        {
> +                @[probename] = count();
> +        }
> +EOF
> +}
> +
> +if [ $# != 1 ]; then
> +        echo expected one argument: '<'dtrace-path'>'
> +        exit 2
> +fi
> +
> +dtrace=$1
> +dtraceout=/tmp/dtrace.out.$$
> +
> +cpustat -c PAPI_tot_ins 1 20 &
> +pid=$!
> +sleep 5
> +script 2>/dev/null
> +
> +status=$?
> +
> +kill $pid
> +exit $status
> diff --git a/test/unittest/cpc/err.cputrackfailtostart.ksh b/test/unittest/cpc/err.cputrackfailtostart.ksh
> new file mode 100755
> index 00000000..f62b83d5
> --- /dev/null
> +++ b/test/unittest/cpc/err.cputrackfailtostart.ksh
> @@ -0,0 +1,77 @@
> +#!/bin/ksh
> +#
> +# CDDL HEADER START
> +#
> +# The contents of this file are subject to the terms of the
> +# Common Development and Distribution License (the "License").
> +# You may not use this file except in compliance with the License.
> +#
> +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> +# or http://www.opensolaris.org/os/licensing.
> +# See the License for the specific language governing permissions
> +# and limitations under the License.
> +#
> +# When distributing Covered Code, include this CDDL HEADER in each
> +# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> +# If applicable, add the following below this CDDL HEADER, with the
> +# fields enclosed by brackets "[]" replaced with your own identifying
> +# information: Portions Copyright [yyyy] [name of copyright owner]
> +#
> +# CDDL HEADER END
> +#
> +
> +#
> +# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> +# Use is subject to license terms.
> +
> +#
> +# This script ensures that cputrack(1M) will fail to start when the cpc
> +# provider has active enablings.
> +#
> +# The script will fail if:
> +#	1) The system under test does not define the 'PAPI_tot_ins' event.
> +#
> +
> +script()
> +{
> +        $dtrace -o $dtraceout -s /dev/stdin <<EOF
> +        #pragma D option bufsize=128k
> +
> +        cpc:::PAPI_tot_ins-all-10000
> +        {
> +                @[probename] = count();
> +        }
> +EOF
> +}
> +
> +
> +if [ $# != 1 ]; then
> +        echo expected one argument: '<'dtrace-path'>'
> +        exit 2
> +fi
> +
> +dtrace=$1
> +dtraceout=/tmp/dtrace.out.$$
> +script 2>/dev/null &
> +timeout=15
> +
> +#
> +# Sleep while the above script fires into life. To guard against dtrace dying
> +# and us sleeping forever we allow 15 secs for this to happen. This should be
> +# enough for even the slowest systems.
> +#
> +while [ ! -f $dtraceout ]; do
> +        sleep 1
> +        timeout=$(($timeout-1))
> +        if [ $timeout -eq 0 ]; then
> +                echo "dtrace failed to start. Exiting."
> +                exit 1
> +        fi
> +done
> +
> +cputrack -c PAPI_tot_ins sleep 10
> +status=$?
> +
> +rm $dtraceout
> +
> +exit $status
> diff --git a/test/unittest/cpc/err.cputrackterminates.ksh b/test/unittest/cpc/err.cputrackterminates.ksh
> new file mode 100755
> index 00000000..58d1e798
> --- /dev/null
> +++ b/test/unittest/cpc/err.cputrackterminates.ksh
> @@ -0,0 +1,70 @@
> +#!/bin/ksh
> +#
> +# CDDL HEADER START
> +#
> +# The contents of this file are subject to the terms of the
> +# Common Development and Distribution License (the "License").
> +# You may not use this file except in compliance with the License.
> +#
> +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> +# or http://www.opensolaris.org/os/licensing.
> +# See the License for the specific language governing permissions
> +# and limitations under the License.
> +#
> +# When distributing Covered Code, include this CDDL HEADER in each
> +# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> +# If applicable, add the following below this CDDL HEADER, with the
> +# fields enclosed by brackets "[]" replaced with your own identifying
> +# information: Portions Copyright [yyyy] [name of copyright owner]
> +#
> +# CDDL HEADER END
> +#
> +
> +#
> +# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> +# Use is subject to license terms.
> +
> +#
> +# This script ensures that cputrack(1) will terminate when the cpc provider
> +# kicks into life.
> +#
> +# The script will fail if:
> +#	1) The system under test does not define the 'PAPI_tot_ins' event.
> +#
> +
> +script()
> +{
> +	$dtrace -s /dev/stdin <<EOF
> +	#pragma D option bufsize=128k
> +
> +	cpc:::PAPI_tot_ins-all-10000
> +	{
> +		@[probename] = count();
> +	}
> +
> +	tick-1s
> +	/n++ > 10/
> +	{
> +		exit(0);
> +	}
> +EOF
> +}
> +
> +if [ $# != 1 ]; then
> +        echo expected one argument: '<'dtrace-path'>'
> +        exit 2
> +fi
> +
> +dtrace=$1
> +
> +cputrack -c PAPI_tot_ins sleep 20 &
> +cputrack_pid=$!
> +sleep 5
> +script 2>/dev/null &
> +
> +wait $cputrack_pid
> +status=$?
> +
> +rm $dtraceout
> +
> +exit $status
> diff --git a/test/unittest/cpc/err.toomanyenablings.d b/test/unittest/cpc/err.toomanyenablings.d
> new file mode 100644
> index 00000000..a50bd71a
> --- /dev/null
> +++ b/test/unittest/cpc/err.toomanyenablings.d
> @@ -0,0 +1,55 @@
> +/*
> + * CDDL HEADER START
> + *
> + * The contents of this file are subject to the terms of the
> + * Common Development and Distribution License (the "License").
> + * You may not use this file except in compliance with the License.
> + *
> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> + * or http://www.opensolaris.org/os/licensing.
> + * See the License for the specific language governing permissions
> + * and limitations under the License.
> + *
> + * When distributing Covered Code, include this CDDL HEADER in each
> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> + * If applicable, add the following below this CDDL HEADER, with the
> + * fields enclosed by brackets "[]" replaced with your own identifying
> + * information: Portions Copyright [yyyy] [name of copyright owner]
> + *
> + * CDDL HEADER END
> + */
> +
> +/*
> + * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> + * Use is subject to license terms.
> + */
> +
> +/*
> + * Test to check that attempting to enable too many probes will fail.
> + *
> + * This test will fail if:
> + *	1) We ever execute on a platform which is capable of programming 10
> + *	'PAPI_tot_ins' events simultaneously (which no current platforms are
> + *	capable of doing).
> + *	2) The system under test does not define the 'PAPI_tot_ins' event.
> + */
> +
> +#pragma D option quiet
> +
> +BEGIN
> +{
> +	exit(0);
> +}
> +
> +cpc:::PAPI_tot_ins-all-10000,
> +cpc:::PAPI_tot_ins-all-10001,
> +cpc:::PAPI_tot_ins-all-10002,
> +cpc:::PAPI_tot_ins-all-10003,
> +cpc:::PAPI_tot_ins-all-10004,
> +cpc:::PAPI_tot_ins-all-10005,
> +cpc:::PAPI_tot_ins-all-10006,
> +cpc:::PAPI_tot_ins-all-10007,
> +cpc:::PAPI_tot_ins-all-10008,
> +cpc:::PAPI_tot_ins-all-10009
> +{
> +}
> diff --git a/test/unittest/cpc/tst.allcpus.ksh b/test/unittest/cpc/tst.allcpus.ksh
> new file mode 100755
> index 00000000..7f026c9e
> --- /dev/null
> +++ b/test/unittest/cpc/tst.allcpus.ksh
> @@ -0,0 +1,107 @@
> +#!/bin/ksh
> +#
> +# CDDL HEADER START
> +#
> +# The contents of this file are subject to the terms of the
> +# Common Development and Distribution License (the "License").
> +# You may not use this file except in compliance with the License.
> +#
> +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> +# or http://www.opensolaris.org/os/licensing.
> +# See the License for the specific language governing permissions
> +# and limitations under the License.
> +#
> +# When distributing Covered Code, include this CDDL HEADER in each
> +# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> +# If applicable, add the following below this CDDL HEADER, with the
> +# fields enclosed by brackets "[]" replaced with your own identifying
> +# information: Portions Copyright [yyyy] [name of copyright owner]
> +#
> +# CDDL HEADER END
> +#
> +
> +#
> +# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> +# Use is subject to license terms.
> +#
> +
> +#
> +# This script verifies that we can fire a probe on each CPU that is in
> +# an online state.
> +#
> +# The script will fail if:
> +#       1) The system under test does not define the 'PAPI_tot_ins' event.
> +#
> +
> +if [ $# != 1 ]; then
> +        echo expected one argument: '<'dtrace-path'>'
> +        exit 2
> +fi
> +
> +dtrace=$1
> +numproc=`psrinfo | tail -1 | cut -f1`
> +cpu=0
> +dtraceout=/var/tmp/dtrace.out.$$
> +scriptout=/var/tmp/script.out.$$
> +
> +spin()
> +{
> +	while [ 1 ]; do
> +		:
> +	done
> +}
> +
> +script()
> +{
> +        $dtrace -o $dtraceout -s /dev/stdin <<EOF
> +	#pragma D option bufsize=128k
> +	#pragma D option quiet
> +
> +        cpc:::PAPI_tot_ins-user-10000
> +	/cpus[cpu] != 1/
> +        {
> +		cpus[cpu] = 1;
> +		@a[cpu] = count();
> +        }
> +
> +	tick-1s
> +	/n++ > 10/
> +	{
> +		printa(@a);
> +		exit(0);
> +	}
> +EOF
> +}
> +
> +echo "" > $scriptout
> +while [ $cpu -le $numproc ]
> +do
> +	if [ "`psrinfo -s $cpu 2> /dev/null`" -eq 1 ]; then
> +		printf "%9d %16d\n" $cpu 1 >> $scriptout
> +		spin &
> +		allpids[$cpu]=$!
> +		pbind -b $cpu $!
> +	fi
> +	cpu=$(($cpu+1))
> +done
> +echo "" >> $scriptout
> +
> +script
> +
> +diff $dtraceout $scriptout >/dev/null 2>&1
> +status=$?
> +
> +# kill off the spinner processes
> +cpu=0
> +while [ $cpu -le $numproc ]
> +do
> +	if [ "`psrinfo -s $cpu 2> /dev/null`" -eq 1 ]; then
> +		kill ${allpids[$cpu]}
> +	fi
> +	cpu=$(($cpu+1))
> +done
> +
> +rm $dtraceout
> +rm $scriptout
> +
> +exit $status
> diff --git a/test/unittest/cpc/tst.genericevent.d b/test/unittest/cpc/tst.genericevent.d
> new file mode 100644
> index 00000000..7ebf844e
> --- /dev/null
> +++ b/test/unittest/cpc/tst.genericevent.d
> @@ -0,0 +1,48 @@
> +/*
> + * CDDL HEADER START
> + *
> + * The contents of this file are subject to the terms of the
> + * Common Development and Distribution License (the "License").
> + * You may not use this file except in compliance with the License.
> + *
> + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> + * or http://www.opensolaris.org/os/licensing.
> + * See the License for the specific language governing permissions
> + * and limitations under the License.
> + *
> + * When distributing Covered Code, include this CDDL HEADER in each
> + * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> + * If applicable, add the following below this CDDL HEADER, with the
> + * fields enclosed by brackets "[]" replaced with your own identifying
> + * information: Portions Copyright [yyyy] [name of copyright owner]
> + *
> + * CDDL HEADER END
> + */
> +/*
> + * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> + * Use is subject to license terms.
> + */
> +
> +/*
> + * Test that we can successfully enable a probe using a generic event.
> + * Currently, all platforms implement 'PAPI_tot_ins' so we'll use that.
> + * Note that this test will fail if the system under test does not
> + * implement that event.
> + *
> + * This test will fail if:
> + *	1) The system under test does not define the 'PAPI_tot_ins' event.
> + */
> +
> +#pragma D option quiet
> +#pragma D option bufsize=128k
> +
> +cpc:::PAPI_tot_ins-all-10000
> +{
> +	@[probename] = count();
> +}
> +
> +tick-1s
> +/n++ > 10/
> +{
> +	exit(0);
> +}
> diff --git a/test/unittest/cpc/tst.platformevent.ksh b/test/unittest/cpc/tst.platformevent.ksh
> new file mode 100755
> index 00000000..96d1ab8c
> --- /dev/null
> +++ b/test/unittest/cpc/tst.platformevent.ksh
> @@ -0,0 +1,81 @@
> +#!/bin/ksh
> +#
> +# CDDL HEADER START
> +#
> +# The contents of this file are subject to the terms of the
> +# Common Development and Distribution License (the "License").
> +# You may not use this file except in compliance with the License.
> +#
> +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
> +# or http://www.opensolaris.org/os/licensing.
> +# See the License for the specific language governing permissions
> +# and limitations under the License.
> +#
> +# When distributing Covered Code, include this CDDL HEADER in each
> +# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
> +# If applicable, add the following below this CDDL HEADER, with the
> +# fields enclosed by brackets "[]" replaced with your own identifying
> +# information: Portions Copyright [yyyy] [name of copyright owner]
> +#
> +# CDDL HEADER END
> +#
> +
> +#
> +# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
> +# Use is subject to license terms.
> +#
> +
> +#
> +# This script ensures that we can enable a probe which specifies a platform
> +# specific event.
> +#
> +
> +if [ $# != 1 ]; then
> +        print -u2 "expected one argument: <dtrace-path>"
> +        exit 2
> +fi
> +
> +dtrace=$1
> +
> +get_event()
> +{
> +        perl /dev/stdin /dev/stdout << EOF
> +        open CPUSTAT, '/usr/sbin/cpustat -h |'
> +            or die  "Couldn't run cpustat: \$!\n";
> +        while (<CPUSTAT>) {
> +                if (/(\s+)event\[*[0-9]-*[0-9]*\]*:/ && !/PAPI/) {
> +                        @a = split(/ /, \$_);
> +                        \$event = \$a[\$#a-1];
> +                }
> +        }
> +
> +        close CPUSTAT;
> +        print "\$event\n";
> +EOF
> +}
> +
> +script()
> +{
> +        $dtrace -s /dev/stdin << EOD
> +        #pragma D option quiet
> +        #pragma D option bufsize=128k
> +
> +        cpc:::$1-all-10000
> +        {
> +                @[probename] = count();
> +        }
> +
> +        tick-1s
> +        /n++ > 5/
> +        {
> +                exit(0);
> +        }
> +EOD
> +}
> +
> +event=$(get_event)
> +script $event
> +
> +status=$?
> +
> +exit $status
> -- 
> 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