Skip to content

Commit

Permalink
test: Add test for modpath
Browse files Browse the repository at this point in the history
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 4256450 commit 9fd37fb
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/unittest/options/err.D_PRAGMA_OPTSET.modpath.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

/*
* ASSERTION: Option modpath cannot be used from within a D program.
*
* SECTION: Options and Tunables/Consumer Options
*/

#pragma D option modpath=/nonexistent/directory

BEGIN
{
exit(0);
}
2 changes: 2 additions & 0 deletions test/unittest/options/err.D_PRAGMA_OPTSET.modpath.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- @@stderr --
dtrace: failed to compile script test/unittest/options/err.D_PRAGMA_OPTSET.modpath.d: [D_PRAGMA_OPTSET] line 14: failed to set option 'modpath' to '/nonexistent/directory': Option cannot be used from within a D program
14 changes: 14 additions & 0 deletions test/unittest/options/tst.modpath.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FUNCTION:NAME
:BEGIN

sanity check on DTrace passed
DTrace correctly fails when modpath is an empty directory
FUNCTION:NAME
:BEGIN

DTrace works with modpath and a linked CTF archive
-- @@stderr --
dtrace: description 'BEGIN ' matched 1 probe
dtrace: description 'BEGIN ' matched 1 probe
dtrace: could not enable tracing: Module does not contain any CTF data
dtrace: description 'BEGIN ' matched 1 probe
47 changes: 47 additions & 0 deletions test/unittest/options/tst.modpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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

DIRNAME="$tmpdir/modpath.$$.$RANDOM"
mkdir -p $DIRNAME
cd $DIRNAME

# create the directory where the CTF archive will end up
mkdir -p mydirectory/kernel

# sanity check that DTrace works
$dtrace $dt_flags -n 'BEGIN {exit(0)}'
if [ $? -ne 0 ]; then
echo ERROR: sanity check on DTrace failed
exit 1
else
echo sanity check on DTrace passed
fi

# verify that modpath directs us to the (empty) directory
$dtrace $dt_flags -xmodpath=mydirectory -n 'BEGIN {exit(0)}'
if [ $? -ne 0 ]; then
echo DTrace correctly fails when modpath is an empty directory
else
echo ERROR: DTrace unexpectedly passes with modpath set to empty directory
exit 1
fi

# link a CTF archive to our directory
ln -s /lib/modules/$(uname -r)/kernel/vmlinux.ctfa mydirectory/kernel/vmlinux.ctfa

# verify that modpath now works
$dtrace $dt_flags -xmodpath=mydirectory -n 'BEGIN {exit(0)}'
if [ $? -ne 0 ]; then
echo ERROR: DTrace somehow fails
exit 1
else
echo DTrace works with modpath and a linked CTF archive
exit 0
fi

0 comments on commit 9fd37fb

Please sign in to comment.