Skip to content

Commit

Permalink
cpc: Add mode tests
Browse files Browse the repository at this point in the history
CPC probes can specify modes: all, user, and kernel.  These tests check
"all" against "perf stat" results.  They check "user" and "kernel" by
using workloads that are known to be user-space- or kernel-intensive.

An extra utility is added to support these tests:

  * cpc_get_events.sh composes a list of events to test on
    the current system

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Feb 26, 2023
1 parent a7c1483 commit e379031
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 1 deletion.
68 changes: 68 additions & 0 deletions test/unittest/cpc/tst.mode_kernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/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.

# Test CPC provider with modes (all, user, kernel) with a
# kernel-space-intensive workload.

# @@reinvoke-failure: 2

utils=`pwd`/test/utils

dtrace=$1
tmpfile=$tmpdir/tst.mode_kernel.$$
mkdir $tmpfile
cd $tmpfile

target=workload_kernel

# run tests
declare -A actual
status=0
for eventname in `$utils/cpc_get_events.sh`; do

# the DTrace CPC provider needs '-' turned into '_'
Deventname=`echo $eventname | tr '-' '_'`

# determine number of iterations for target number of seconds
nsecs=1
niters=`$utils/workload_get_iterations.sh $target $nsecs`
if [ $niters -lt 0 ]; then
echo "workload_get_iterations.sh failed with $target"
exit 1
fi

# determine expected count
expect=`$utils/perf_count_event.sh $eventname $target $niters`

# sample events (with DTrace)
period=$(($expect / 20))
echo $niters iterations for $Deventname with period $period
for mode in all user kernel; do
$dtrace $dt_flags -qn $Deventname-$mode-$period'
/pid == $target/
{
@ = sum('$period');
}' -c "$utils/$target $niters" > tmp.txt
if [[ $? -ne 0 ]]; then
echo ERROR running DTrace for $Deventname-$mode-$period
cat tmp.txt
exit 1
fi
actual[$mode]=`cat tmp.txt`
if [ -z ${actual[$mode]} ]; then
actual[$mode]=0
fi
done

# report
margin=$(($expect / 4))
$utils/check_result.sh ${actual[all]} $expect $margin; status=$(($status + $?))
$utils/check_result.sh ${actual[user]} 0 $margin; status=$(($status + $?))
$utils/check_result.sh ${actual[kernel]} $expect $margin; status=$(($status + $?))
done

exit $status
68 changes: 68 additions & 0 deletions test/unittest/cpc/tst.mode_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/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.

# Test CPC provider with modes (all, user, kernel) with a
# user-space-intensive workload.

# @@reinvoke-failure: 2

utils=`pwd`/test/utils

dtrace=$1
tmpfile=$tmpdir/tst.mode_user.$$
mkdir $tmpfile
cd $tmpfile

target=workload_user

# run tests
declare -A actual
status=0
for eventname in `$utils/cpc_get_events.sh`; do

# the DTrace CPC provider needs '-' turned into '_'
Deventname=`echo $eventname | tr '-' '_'`

# determine number of iterations for target number of seconds
nsecs=1
niters=`$utils/workload_get_iterations.sh $target $nsecs`
if [ $niters -lt 0 ]; then
echo "workload_get_iterations.sh failed with $target"
exit 1
fi

# determine expected count
expect=`$utils/perf_count_event.sh $eventname $target $niters`

# sample events (with DTrace)
period=$(($expect / 20))
echo $niters iterations for $Deventname with period $period
for mode in all user kernel; do
$dtrace $dt_flags -qn $Deventname-$mode-$period'
/pid == $target/
{
@ = sum('$period');
}' -c "$utils/$target $niters" > tmp.txt
if [[ $? -ne 0 ]]; then
echo ERROR running DTrace for $Deventname-$mode-$period
cat tmp.txt
exit 1
fi
actual[$mode]=`cat tmp.txt`
if [ -z ${actual[$mode]} ]; then
actual[$mode]=0
fi
done

# report
margin=$(($expect / 4))
$utils/check_result.sh ${actual[all]} $expect $margin; status=$(($status + $?))
$utils/check_result.sh ${actual[user]} $expect $margin; status=$(($status + $?))
$utils/check_result.sh ${actual[kernel]} 0 $margin; status=$(($status + $?))
done

exit $status
2 changes: 1 addition & 1 deletion test/utils/Build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# http://oss.oracle.com/licenses/upl.

TEST_UTILS = baddof badioctl workload_kernel workload_user showUSDT print-stack-layout
TEST_SCRIPTS = check_result.sh perf_count_event.sh workload_analyze_loop.sh workload_get_iterations.sh
TEST_SCRIPTS = check_result.sh cpc_get_events.sh perf_count_event.sh workload_analyze_loop.sh workload_get_iterations.sh

define test-util-template
CMDS += $(1)
Expand Down
18 changes: 18 additions & 0 deletions test/utils/cpc_get_events.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/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.

# Form a list of events to test on this system.
# Use at least cpu-clock but also try "perf list" for some others.

eventnamelist="cpu-clock"
for eventname in branches instructions; do
if perf list hw | grep -qw $eventname; then
eventnamelist="$eventnamelist $eventname"
fi
done

echo $eventnamelist

0 comments on commit e379031

Please sign in to comment.