* [PATCH 3/9] perf test: new testsuite: perf annotate tests
@ 2015-12-07 18:53 Michael Petlan
2015-12-15 12:03 ` Jiri Olsa
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Michael Petlan @ 2015-12-07 18:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Jiri Olsa; +Cc: linux-perf-users@vger.kernel.org
This commit adds tests for perf annotate tool.
The structure of the base_something dirs is the following:
base_something/
settings.sh
- a script mentioned to be sourced within the tests
setup.sh
- if present, necessary for setup of the subset
test_*.sh
- various tests of the subset
cleanup.sh
- a cleanup script that should remove logs, etc.
All the tests should be stand-alone. So if needed, it is enough to
cd to the proper base_directory and run the test. Sometimes, setup
is needed to be run first.
Example:
cd testsuite/base_annotate
./setup.sh
./test_basic.sh
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
tools/perf/testsuite/base_annotate/cleanup.sh | 22 +++
.../perf/testsuite/base_annotate/examples/Makefile | 13 ++
tools/perf/testsuite/base_annotate/examples/load.c | 24 +++
tools/perf/testsuite/base_annotate/settings.sh | 15 ++
tools/perf/testsuite/base_annotate/setup.sh | 35 +++++
tools/perf/testsuite/base_annotate/test_basic.sh | 169 +++++++++++++++++++++
6 files changed, 278 insertions(+)
create mode 100755 tools/perf/testsuite/base_annotate/cleanup.sh
create mode 100644 tools/perf/testsuite/base_annotate/examples/Makefile
create mode 100644 tools/perf/testsuite/base_annotate/examples/load.c
create mode 100644 tools/perf/testsuite/base_annotate/settings.sh
create mode 100755 tools/perf/testsuite/base_annotate/setup.sh
create mode 100755 tools/perf/testsuite/base_annotate/test_basic.sh
diff --git a/tools/perf/testsuite/base_annotate/cleanup.sh b/tools/perf/testsuite/base_annotate/cleanup.sh
new file mode 100755
index 0000000..616873a
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/cleanup.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+#
+# cleanup.sh of perf annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+
+make -s -C examples clean
+
+find . -name \*.log | xargs -r rm
+find . -name \*.err | xargs -r rm
+rm -f perf.data
+
+print_results 0 0 "clean-up logs"
+exit $?
diff --git a/tools/perf/testsuite/base_annotate/examples/Makefile b/tools/perf/testsuite/base_annotate/examples/Makefile
new file mode 100644
index 0000000..0ae9638
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/examples/Makefile
@@ -0,0 +1,13 @@
+CC=gcc
+CFLAGS=-g -O0
+
+SRCS = $(wildcard *.c)
+PROGS = $(patsubst %.c,%,$(SRCS))
+
+all: $(PROGS)
+
+%: %.c
+ $(CC) $(CFLAGS) -o $@ $<
+
+clean:
+ rm -f $(PROGS)
diff --git a/tools/perf/testsuite/base_annotate/examples/load.c b/tools/perf/testsuite/base_annotate/examples/load.c
new file mode 100644
index 0000000..c8f30d1
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/examples/load.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int main (int argc, char *argv[])
+{
+ long from, i, j = 20L;
+
+ if (argc > 1)
+ from = atol (argv[1]);
+ else
+ from = 20L;
+
+ for (i = 1L; j; ++i)
+ {
+ for (j = from; j > 0L; --j)
+ if (i % j)
+ break;
+ }
+
+ printf ("%ld\n", --i);
+
+ return 0;
+}
diff --git a/tools/perf/testsuite/base_annotate/settings.sh b/tools/perf/testsuite/base_annotate/settings.sh
new file mode 100644
index 0000000..77567ce
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/settings.sh
@@ -0,0 +1,15 @@
+#
+# settings.sh of perf_annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+# Description:
+# FIXME
+#
+#
+
+export TEST_NAME="perf_annotate"
+export MY_ARCH=`arch`
+export MY_HOSTNAME=`hostname`
+export MY_KERNEL_VERSION=`uname -r`
+export MY_CPUS_ONLINE=`nproc`
+export MY_CPUS_AVAILABLE=`cat /proc/cpuinfo | grep processor | wc -l`
diff --git a/tools/perf/testsuite/base_annotate/setup.sh b/tools/perf/testsuite/base_annotate/setup.sh
new file mode 100755
index 0000000..1a1bc41
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/setup.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+#
+# setup.sh of perf annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+# Description:
+#
+# FIXME - build C program
+#
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+
+make -s -C examples
+print_results $? 0 "building the example code"
+TEST_RESULT=$?
+
+# record some data
+$CMD_PERF record examples/load > /dev/null 2> setup_record.log
+PERF_EXIT_CODE=$?
+
+# check the perf record output
+../common/check_all_lines_matched.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < setup_record.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "record data"
+(( TEST_RESULT += $? ))
+
+print_overall_results $TEST_RESULT
+exit $?
diff --git a/tools/perf/testsuite/base_annotate/test_basic.sh b/tools/perf/testsuite/base_annotate/test_basic.sh
new file mode 100755
index 0000000..84adf65
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/test_basic.sh
@@ -0,0 +1,169 @@
+#!/bin/bash
+
+#
+# test_basic of perf annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+# Description:
+#
+# This test tests basic functionality of perf annotate command.
+#
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+TEST_RESULT=0
+
+
+### help message
+
+if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then
+ # test that a help message is shown and looks reasonable
+ $CMD_PERF annotate --help > basic_helpmsg.log
+ PERF_EXIT_CODE=$?
+
+ ../common/check_all_patterns_found.pl "PERF-ANNOTATE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" "SEE ALSO" < basic_helpmsg.log
+ CHECK_EXIT_CODE=$?
+ ../common/check_all_patterns_found.pl "perf\-annotate \- Read perf.data .* display annotated code" < basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+ ../common/check_all_patterns_found.pl "input" "dsos" "symbol" "force" "verbose" "dump-raw-trace" "vmlinux" "modules" < basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+ ../common/check_all_patterns_found.pl "print-line" "full-paths" "stdio" "tui" "cpu" "source" "symfs" "disassembler-style" < basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+ ../common/check_all_patterns_found.pl "objdump" "skip-missing" "group" < basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+
+ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "help message"
+ (( TEST_RESULT += $? ))
+else
+ print_testcase_skipped "help message"
+fi
+
+
+### basic execution
+
+# annotate...
+$CMD_PERF annotate --stdio > basic_annotate.log 2> basic_annotate.err
+PERF_EXIT_CODE=$?
+
+# check the annotate output; default option means both source and assembly
+REGEX_HEADER="Percent.*Source code.*Disassembly\sof"
+REGEX_LINE="$RE_NUMBER\s+:\s+$RE_NUMBER_HEX\s*:.*"
+REGEX_SECTION__TEXT="Disassembly of section \.text:"
+# check for the basic structure
+../common/check_all_patterns_found.pl "$REGEX_HEADER load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < basic_annotate.log
+CHECK_EXIT_CODE=$?
+# check for the source code presence
+../common/check_all_patterns_found.pl "main" "from = atol" "from = 20L;" "for\s*\(i = 1L; j; \+\+i\)" "return 0;" < basic_annotate.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "basic execution - annotate"
+(( TEST_RESULT += $? ))
+
+
+### dso filter
+
+# '--dso SOME_DSO' limits the annotation to SOME_DSO only
+$CMD_PERF annotate --stdio --dso load > basic_dso.log 2> basic_dso.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "$REGEX_HEADER load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < basic_dso.log
+CHECK_EXIT_CODE=$?
+# check for the source code presence
+../common/check_all_patterns_found.pl "main\(" "from = atol" "from = 20L;" "for\s*\(i = 1L; j; \+\+i\)" "return 0;" < basic_dso.log
+(( CHECK_EXIT_CODE += $? ))
+# check whether the '--dso' option cuts the output to one dso only
+test `grep -c "Disassembly" basic_dso.log` -eq 2
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "dso filter"
+(( TEST_RESULT += $? ))
+
+
+### no-source
+
+# '--no-source' should show only the assembly code
+$CMD_PERF annotate --stdio --no-source --dso load > basic_nosource.log 2> basic_nosource.err
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "$REGEX_HEADER load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < basic_nosource.log
+CHECK_EXIT_CODE=$?
+# the C source should not be there
+../common/check_no_patterns_found.pl "from = atol" "from = 20L;" "for\s*\(i = 1L; j; \+\+i\)" "return 0;" < basic_nosource.log
+(( CHECK_EXIT_CODE += $? ))
+# check whether the '--dso' option cuts the output to one dso only
+test `grep -c "Disassembly" basic_dso.log` -eq 2
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "no-source"
+(( TEST_RESULT += $? ))
+
+
+### full-paths
+
+# '-P' should print full paths of DSOs
+$CMD_PERF annotate --stdio --dso load -P > basic_fullpaths.log 2> basic_fullpaths.err
+PERF_EXIT_CODE=$?
+
+FULLPATH="`pwd`/examples"
+../common/check_all_patterns_found.pl "$REGEX_HEADER $FULLPATH/load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < basic_fullpaths.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "full-paths"
+(( TEST_RESULT += $? ))
+
+
+### print-line
+
+# '--print-line' should print inline the source lines
+$CMD_PERF annotate --stdio --dso load -P --print-line > basic_printline.log 2> basic_printline.err
+PERF_EXIT_CODE=$?
+
+FULLPATH="`pwd`/examples"
+../common/check_all_patterns_found.pl "$FULLPATH/load\.c:$RE_NUMBER\s+$REGEX_LINE" "$REGEX_SECTION__TEXT" < basic_printline.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "print-line"
+(( TEST_RESULT += $? ))
+
+
+### redirected input
+
+# '-i dir/perf.data' should point to some other perf.data file
+mv perf.data examples/
+$CMD_PERF annotate --stdio --dso load -i examples/perf.data > basic_input.log 2> basic_input.err
+PERF_EXIT_CODE=$?
+
+# the output should be the same as before
+diff -q basic_input.log basic_dso.log
+CHECK_EXIT_CODE=$?
+diff -q basic_input.err basic_dso.err
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "redirected input"
+(( TEST_RESULT += $? ))
+
+
+### execution without perf.data
+
+# check for error message
+! $CMD_PERF annotate > basic_nodata.log 2> basic_nodata.err
+PERF_EXIT_CODE=$?
+
+REGEX_NO_DATA="failed to open perf.data: No such file or directory"
+../common/check_all_lines_matched.pl "$REGEX_NO_DATA" < basic_nodata.err
+CHECK_EXIT_CODE=$?
+test ! -s basic_nodata.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "execution without data"
+(( TEST_RESULT += $? ))
+mv examples/perf.data ./
+
+
+# print overall resutls
+print_overall_results "$TEST_RESULT"
+exit $?
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/9] perf test: new testsuite: perf annotate tests
2015-12-07 18:53 [PATCH 3/9] perf test: new testsuite: perf annotate tests Michael Petlan
@ 2015-12-15 12:03 ` Jiri Olsa
2015-12-15 12:03 ` Jiri Olsa
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Jiri Olsa @ 2015-12-15 12:03 UTC (permalink / raw)
To: Michael Petlan; +Cc: Arnaldo Carvalho de Melo, linux-perf-users@vger.kernel.org
On Mon, Dec 07, 2015 at 07:53:14PM +0100, Michael Petlan wrote:
SNIP
>
> diff --git a/tools/perf/testsuite/base_annotate/cleanup.sh b/tools/perf/testsuite/base_annotate/cleanup.sh
> new file mode 100755
> index 0000000..616873a
> --- /dev/null
> +++ b/tools/perf/testsuite/base_annotate/cleanup.sh
> @@ -0,0 +1,22 @@
> +#!/bin/bash
> +
> +#
> +# cleanup.sh of perf annotate test
> +# Author: Michael Petlan <mpetlan@redhat.com>
> +#
> +#
> +
> +# include working environment
> +. ../common/init.sh
> +. ./settings.sh
> +
> +THIS_TEST_NAME=`basename $0 .sh`
> +
> +make -s -C examples clean
> +
> +find . -name \*.log | xargs -r rm
> +find . -name \*.err | xargs -r rm
> +rm -f perf.data
> +
> +print_results 0 0 "clean-up logs"
could the test work over some temporary directory,
so it has its data stored in there?
it helps with paralel tests running and
is little bit cleaner solution
thanks,
jirka
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/9] perf test: new testsuite: perf annotate tests
2015-12-07 18:53 [PATCH 3/9] perf test: new testsuite: perf annotate tests Michael Petlan
2015-12-15 12:03 ` Jiri Olsa
@ 2015-12-15 12:03 ` Jiri Olsa
2015-12-15 12:04 ` Jiri Olsa
2015-12-15 12:04 ` Jiri Olsa
3 siblings, 0 replies; 7+ messages in thread
From: Jiri Olsa @ 2015-12-15 12:03 UTC (permalink / raw)
To: Michael Petlan; +Cc: Arnaldo Carvalho de Melo, linux-perf-users@vger.kernel.org
On Mon, Dec 07, 2015 at 07:53:14PM +0100, Michael Petlan wrote:
> This commit adds tests for perf annotate tool.
>
> The structure of the base_something dirs is the following:
>
> base_something/
> settings.sh
> - a script mentioned to be sourced within the tests
> setup.sh
> - if present, necessary for setup of the subset
> test_*.sh
> - various tests of the subset
> cleanup.sh
> - a cleanup script that should remove logs, etc.
>
> All the tests should be stand-alone. So if needed, it is enough to
> cd to the proper base_directory and run the test. Sometimes, setup
> is needed to be run first.
>
> Example:
>
> cd testsuite/base_annotate
> ./setup.sh
> ./test_basic.sh
hum, would it be better to allow running separate tests via
perf test suite like:
$ perf test suite base_annotate
you'd need pass argv,argc into tests functions,
which shouldn't be big deal
jirka
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/9] perf test: new testsuite: perf annotate tests
2015-12-07 18:53 [PATCH 3/9] perf test: new testsuite: perf annotate tests Michael Petlan
2015-12-15 12:03 ` Jiri Olsa
2015-12-15 12:03 ` Jiri Olsa
@ 2015-12-15 12:04 ` Jiri Olsa
2015-12-15 12:04 ` Jiri Olsa
3 siblings, 0 replies; 7+ messages in thread
From: Jiri Olsa @ 2015-12-15 12:04 UTC (permalink / raw)
To: Michael Petlan; +Cc: Arnaldo Carvalho de Melo, linux-perf-users@vger.kernel.org
On Mon, Dec 07, 2015 at 07:53:14PM +0100, Michael Petlan wrote:
SNIP
> +
> + ../common/check_all_patterns_found.pl "PERF-ANNOTATE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" "SEE ALSO" < basic_helpmsg.log
> + CHECK_EXIT_CODE=$?
> + ../common/check_all_patterns_found.pl "perf\-annotate \- Read perf.data .* display annotated code" < basic_helpmsg.log
> + (( CHECK_EXIT_CODE += $? ))
> + ../common/check_all_patterns_found.pl "input" "dsos" "symbol" "force" "verbose" "dump-raw-trace" "vmlinux" "modules" < basic_helpmsg.log
> + (( CHECK_EXIT_CODE += $? ))
> + ../common/check_all_patterns_found.pl "print-line" "full-paths" "stdio" "tui" "cpu" "source" "symfs" "disassembler-style" < basic_helpmsg.log
> + (( CHECK_EXIT_CODE += $? ))
> + ../common/check_all_patterns_found.pl "objdump" "skip-missing" "group" < basic_helpmsg.log
> + (( CHECK_EXIT_CODE += $? ))
I know it's probably PITA, but would it make sense to preceed
each line with the actuall line you are expecting? like:
###
# perf-annotate - Read perf.data (created by perf record) and display annotated code
#
../common/check_all_patterns_found.pl "perf\-annotate \- Read perf.data .* display annotated code" < basic_helpmsg.log
(( CHECK_EXIT_CODE += $? ))
###
# Disassembly of section load0:
# │ Disassembly of section load0:
# 16.67 │ xor %eax,%eax
#
../common/check_all_patterns_found.pl "$REGEX_HEADER load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < basic_annotate.log
CHECK_EXIT_CODE=$?
###
# from = atol (argv[1]);
#
../common/check_all_patterns_found.pl "main" "from = atol" "from = 20L;" "for\s*\(i = 1L; j; \+\+i\)" "return 0;" < basic_annotate.log
(( CHECK_EXIT_CODE += $? ))
or some other way that would make it easy to find out what
the check is looking for in general
thanks,
jirka
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/9] perf test: new testsuite: perf annotate tests
2015-12-07 18:53 [PATCH 3/9] perf test: new testsuite: perf annotate tests Michael Petlan
` (2 preceding siblings ...)
2015-12-15 12:04 ` Jiri Olsa
@ 2015-12-15 12:04 ` Jiri Olsa
2015-12-16 11:51 ` Michael Petlan
3 siblings, 1 reply; 7+ messages in thread
From: Jiri Olsa @ 2015-12-15 12:04 UTC (permalink / raw)
To: Michael Petlan; +Cc: Arnaldo Carvalho de Melo, linux-perf-users@vger.kernel.org
On Mon, Dec 07, 2015 at 07:53:14PM +0100, Michael Petlan wrote:
SNIP
> diff --git a/tools/perf/testsuite/base_annotate/setup.sh b/tools/perf/testsuite/base_annotate/setup.sh
> new file mode 100755
> index 0000000..1a1bc41
> --- /dev/null
> +++ b/tools/perf/testsuite/base_annotate/setup.sh
> @@ -0,0 +1,35 @@
> +#!/bin/bash
> +
> +#
> +# setup.sh of perf annotate test
> +# Author: Michael Petlan <mpetlan@redhat.com>
> +#
> +# Description:
> +#
> +# FIXME - build C program
> +#
> +#
> +
> +# include working environment
> +. ../common/init.sh
> +. ./settings.sh
> +
> +THIS_TEST_NAME=`basename $0 .sh`
> +
> +make -s -C examples
> +print_results $? 0 "building the example code"
> +TEST_RESULT=$?
> +
> +# record some data
> +$CMD_PERF record examples/load > /dev/null 2> setup_record.log
> +PERF_EXIT_CODE=$?
> +
> +# check the perf record output
> +../common/check_all_lines_matched.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < setup_record.log
> +CHECK_EXIT_CODE=$?
> +
> +print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "record data"
> +(( TEST_RESULT += $? ))
> +
> +print_overall_results $TEST_RESULT
so setup.sh script is already running some tests?
I thought it's just for seting up the test data
or whatever environment the testcase needs..
jirka
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/9] perf test: new testsuite: perf annotate tests
2015-12-15 12:04 ` Jiri Olsa
@ 2015-12-16 11:51 ` Michael Petlan
0 siblings, 0 replies; 7+ messages in thread
From: Michael Petlan @ 2015-12-16 11:51 UTC (permalink / raw)
To: Jiri Olsa; +Cc: Arnaldo Carvalho de Melo, linux-perf-users@vger.kernel.org
On Tue, 2015-12-15 at 13:04 +0100, Jiri Olsa wrote:
> On Mon, Dec 07, 2015 at 07:53:14PM +0100, Michael Petlan wrote:
>
> SNIP
>
> > diff --git a/tools/perf/testsuite/base_annotate/setup.sh b/tools/perf/testsuite/base_annotate/setup.sh
> > new file mode 100755
> > index 0000000..1a1bc41
> > --- /dev/null
> > +++ b/tools/perf/testsuite/base_annotate/setup.sh
> > @@ -0,0 +1,35 @@
> > +#!/bin/bash
> > +
> > +#
> > +# setup.sh of perf annotate test
> > +# Author: Michael Petlan <mpetlan@redhat.com>
> > +#
> > +# Description:
> > +#
> > +# FIXME - build C program
> > +#
> > +#
> > +
> > +# include working environment
> > +. ../common/init.sh
> > +. ./settings.sh
> > +
> > +THIS_TEST_NAME=`basename $0 .sh`
> > +
> > +make -s -C examples
> > +print_results $? 0 "building the example code"
> > +TEST_RESULT=$?
> > +
> > +# record some data
> > +$CMD_PERF record examples/load > /dev/null 2> setup_record.log
> > +PERF_EXIT_CODE=$?
> > +
> > +# check the perf record output
> > +../common/check_all_lines_matched.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < setup_record.log
> > +CHECK_EXIT_CODE=$?
> > +
> > +print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "record data"
> > +(( TEST_RESULT += $? ))
> > +
> > +print_overall_results $TEST_RESULT
>
> so setup.sh script is already running some tests?
>
> I thought it's just for seting up the test data
> or whatever environment the testcase needs..
>
> jirka
It is setting up the test data or whatever environment the testcase
needs, but it of course self-checks its success or fail. If make fails,
it will be counted and it will be seen in the logs. The same about the
sample perf.data recording - if it fails, it is good to know it within
the setup phase.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-perf-users" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <cover.1458134357.git.mpetlan@redhat.com>]
* [PATCH 3/9] perf test: new testsuite: perf annotate tests
[not found] <cover.1458134357.git.mpetlan@redhat.com>
@ 2016-03-16 13:54 ` Michael Petlan
0 siblings, 0 replies; 7+ messages in thread
From: Michael Petlan @ 2016-03-16 13:54 UTC (permalink / raw)
To: linux-perf-users; +Cc: acme, Jiri Olsa
This commit adds tests for perf annotate tool.
The structure of the base_something dirs is the following:
base_something/
settings.sh
- a script mentioned to be sourced within the tests
setup.sh
- if present, necessary for setup of the subset
test_*.sh
- various tests of the subset
cleanup.sh
- a cleanup script that should remove logs, etc.
All the tests should be stand-alone. So if needed, it is enough to
cd to the proper base_directory and run the test. Sometimes, setup
is needed to be run first.
Example:
cd testsuite/base_annotate
./setup.sh
./test_basic.sh
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
---
tools/perf/testsuite/base_annotate/cleanup.sh | 24 +++
.../perf/testsuite/base_annotate/examples/Makefile | 16 ++
tools/perf/testsuite/base_annotate/examples/load.c | 24 +++
tools/perf/testsuite/base_annotate/settings.sh | 31 ++++
tools/perf/testsuite/base_annotate/setup.sh | 35 +++++
tools/perf/testsuite/base_annotate/test_basic.sh | 169 +++++++++++++++++++++
6 files changed, 299 insertions(+)
create mode 100755 tools/perf/testsuite/base_annotate/cleanup.sh
create mode 100644 tools/perf/testsuite/base_annotate/examples/Makefile
create mode 100644 tools/perf/testsuite/base_annotate/examples/load.c
create mode 100644 tools/perf/testsuite/base_annotate/settings.sh
create mode 100755 tools/perf/testsuite/base_annotate/setup.sh
create mode 100755 tools/perf/testsuite/base_annotate/test_basic.sh
diff --git a/tools/perf/testsuite/base_annotate/cleanup.sh b/tools/perf/testsuite/base_annotate/cleanup.sh
new file mode 100755
index 0000000..dd66675
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/cleanup.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+#
+# cleanup.sh of perf annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+if [ -n "$PERFSUITE_RUN_DIR" ]; then
+ print_overall_skipped
+ exit 0
+fi
+
+make -s -C examples clean
+find . -name \*.log | xargs -r rm
+find . -name \*.err | xargs -r rm
+rm -f perf.data*
+
+print_overall_results 0
+exit $?
diff --git a/tools/perf/testsuite/base_annotate/examples/Makefile b/tools/perf/testsuite/base_annotate/examples/Makefile
new file mode 100644
index 0000000..3248b6c
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/examples/Makefile
@@ -0,0 +1,16 @@
+CC=gcc
+CFLAGS=-g -O0
+
+SRCS = $(wildcard *.c)
+PROGS = $(patsubst %.c,%,$(SRCS))
+
+all: $(PROGS)
+ifneq "$(MAKE_TARGET_DIR)x" 'x'
+ mv $(PROGS) $(MAKE_TARGET_DIR)/
+endif
+
+%: %.c
+ $(CC) $(CFLAGS) -o $@ $<
+
+clean:
+ rm -f $(PROGS)
diff --git a/tools/perf/testsuite/base_annotate/examples/load.c b/tools/perf/testsuite/base_annotate/examples/load.c
new file mode 100644
index 0000000..c8f30d1
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/examples/load.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int main (int argc, char *argv[])
+{
+ long from, i, j = 20L;
+
+ if (argc > 1)
+ from = atol (argv[1]);
+ else
+ from = 20L;
+
+ for (i = 1L; j; ++i)
+ {
+ for (j = from; j > 0L; --j)
+ if (i % j)
+ break;
+ }
+
+ printf ("%ld\n", --i);
+
+ return 0;
+}
diff --git a/tools/perf/testsuite/base_annotate/settings.sh b/tools/perf/testsuite/base_annotate/settings.sh
new file mode 100644
index 0000000..398ed27
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/settings.sh
@@ -0,0 +1,31 @@
+#
+# settings.sh of perf_annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+# Description:
+# FIXME
+#
+#
+
+export TEST_NAME="perf_annotate"
+export MY_ARCH=`arch`
+export MY_HOSTNAME=`hostname`
+export MY_KERNEL_VERSION=`uname -r`
+export MY_CPUS_ONLINE=`nproc`
+export MY_CPUS_AVAILABLE=`cat /proc/cpuinfo | grep -P "processor\s" | wc -l`
+
+if [ -n "$PERFSUITE_RUN_DIR" ]; then
+ # when $PERFSUITE_RUN_DIR is set to something, all the logs and temp files will be placed there
+ # --> the $PERFSUITE_RUN_DIR/perf_something/examples and $PERFSUITE_RUN_DIR/perf_something/logs
+ # dirs will be used for that
+ export PERFSUITE_RUN_DIR=`readlink -f $PERFSUITE_RUN_DIR`
+ export CURRENT_TEST_DIR="$PERFSUITE_RUN_DIR/$TEST_NAME"
+ export MAKE_TARGET_DIR="$CURRENT_TEST_DIR/examples"
+ test -d "$MAKE_TARGET_DIR" || mkdir -p "$MAKE_TARGET_DIR"
+ export LOGS_DIR="$PERFSUITE_RUN_DIR/$TEST_NAME/logs"
+ test -d "$LOGS_DIR" || mkdir -p "$LOGS_DIR"
+else
+ # when $PERFSUITE_RUN_DIR is not set, logs will be placed here
+ export CURRENT_TEST_DIR="."
+ export LOGS_DIR="."
+fi
diff --git a/tools/perf/testsuite/base_annotate/setup.sh b/tools/perf/testsuite/base_annotate/setup.sh
new file mode 100755
index 0000000..54b1e17
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/setup.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+#
+# setup.sh of perf annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+# Description:
+#
+# FIXME - build C program
+#
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+
+make -s -C examples
+print_results $? 0 "building the example code"
+TEST_RESULT=$?
+
+# record some data
+$CMD_PERF record -o $CURRENT_TEST_DIR/perf.data $CURRENT_TEST_DIR/examples/load > /dev/null 2> $LOGS_DIR/setup_record.log
+PERF_EXIT_CODE=$?
+
+# check the perf record output
+../common/check_all_lines_matched.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup_record.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "record data"
+(( TEST_RESULT += $? ))
+
+print_overall_results $TEST_RESULT
+exit $?
diff --git a/tools/perf/testsuite/base_annotate/test_basic.sh b/tools/perf/testsuite/base_annotate/test_basic.sh
new file mode 100755
index 0000000..196c38b
--- /dev/null
+++ b/tools/perf/testsuite/base_annotate/test_basic.sh
@@ -0,0 +1,169 @@
+#!/bin/bash
+
+#
+# test_basic of perf annotate test
+# Author: Michael Petlan <mpetlan@redhat.com>
+#
+# Description:
+#
+# This test tests basic functionality of perf annotate command.
+#
+#
+
+# include working environment
+. ../common/init.sh
+. ./settings.sh
+
+THIS_TEST_NAME=`basename $0 .sh`
+TEST_RESULT=0
+
+
+### help message
+
+if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then
+ # test that a help message is shown and looks reasonable
+ $CMD_PERF annotate --help > $LOGS_DIR/basic_helpmsg.log
+ PERF_EXIT_CODE=$?
+
+ ../common/check_all_patterns_found.pl "PERF-ANNOTATE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" "SEE ALSO" < $LOGS_DIR/basic_helpmsg.log
+ CHECK_EXIT_CODE=$?
+ ../common/check_all_patterns_found.pl "perf\-annotate \- Read perf.data .* display annotated code" < $LOGS_DIR/basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+ ../common/check_all_patterns_found.pl "input" "dsos" "symbol" "force" "verbose" "dump-raw-trace" "vmlinux" "modules" < $LOGS_DIR/basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+ ../common/check_all_patterns_found.pl "print-line" "full-paths" "stdio" "tui" "cpu" "source" "symfs" "disassembler-style" < $LOGS_DIR/basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+ ../common/check_all_patterns_found.pl "objdump" "skip-missing" "group" < $LOGS_DIR/basic_helpmsg.log
+ (( CHECK_EXIT_CODE += $? ))
+
+ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "help message"
+ (( TEST_RESULT += $? ))
+else
+ print_testcase_skipped "help message"
+fi
+
+
+### basic execution
+
+# annotate...
+( cd $CURRENT_TEST_DIR ; $CMD_PERF annotate --stdio > $LOGS_DIR/basic_annotate.log 2> $LOGS_DIR/basic_annotate.err )
+PERF_EXIT_CODE=$?
+
+# check the annotate output; default option means both source and assembly
+REGEX_HEADER="Percent.*Source code.*Disassembly\sof"
+REGEX_LINE="$RE_NUMBER\s+:\s+$RE_NUMBER_HEX\s*:.*"
+REGEX_SECTION__TEXT="Disassembly of section \.text:"
+# check for the basic structure
+../common/check_all_patterns_found.pl "$REGEX_HEADER load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < $LOGS_DIR/basic_annotate.log
+CHECK_EXIT_CODE=$?
+# check for the source code presence
+../common/check_all_patterns_found.pl "main" "from = atol" "from = 20L;" "for\s*\(i = 1L; j; \+\+i\)" "return 0;" < $LOGS_DIR/basic_annotate.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "basic execution - annotate"
+(( TEST_RESULT += $? ))
+
+
+### dso filter
+
+# '--dso SOME_DSO' limits the annotation to SOME_DSO only
+( cd $CURRENT_TEST_DIR ; $CMD_PERF annotate --stdio --dso load > $LOGS_DIR/basic_dso.log 2> $LOGS_DIR/basic_dso.err )
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "$REGEX_HEADER load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < $LOGS_DIR/basic_dso.log
+CHECK_EXIT_CODE=$?
+# check for the source code presence
+../common/check_all_patterns_found.pl "main\s*\(" "from = atol" "from = 20L;" "for\s*\(i = 1L; j; \+\+i\)" "return 0;" < $LOGS_DIR/basic_dso.log
+(( CHECK_EXIT_CODE += $? ))
+# check whether the '--dso' option cuts the output to one dso only
+test `grep -c "Disassembly" $LOGS_DIR/basic_dso.log` -ge 2 # FIXME wrong
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "dso filter"
+(( TEST_RESULT += $? ))
+
+
+### no-source
+
+# '--no-source' should show only the assembly code
+( cd $CURRENT_TEST_DIR ; $CMD_PERF annotate --stdio --no-source --dso load > $LOGS_DIR/basic_nosource.log 2> $LOGS_DIR/basic_nosource.err )
+PERF_EXIT_CODE=$?
+
+../common/check_all_patterns_found.pl "$REGEX_HEADER load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < $LOGS_DIR/basic_nosource.log
+CHECK_EXIT_CODE=$?
+# the C source should not be there
+../common/check_no_patterns_found.pl "from = atol" "from = 20L;" "for\s*\(i = 1L; j; \+\+i\)" "return 0;" < $LOGS_DIR/basic_nosource.log
+(( CHECK_EXIT_CODE += $? ))
+# check whether the '--dso' option cuts the output to one dso only
+test `grep -c "Disassembly" $LOGS_DIR/basic_nosource.log` -ge 2 # FIXME wrong
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "no-source"
+(( TEST_RESULT += $? ))
+
+
+### full-paths
+
+# '-P' should print full paths of DSOs
+( cd $CURRENT_TEST_DIR ; $CMD_PERF annotate --stdio --dso load -P > $LOGS_DIR/basic_fullpaths.log 2> $LOGS_DIR/basic_fullpaths.err )
+PERF_EXIT_CODE=$?
+
+FULLPATH=`readlink -f $CURRENT_TEST_DIR/examples`
+../common/check_all_patterns_found.pl "$REGEX_HEADER $FULLPATH/load" "$REGEX_LINE" "$REGEX_SECTION__TEXT" < $LOGS_DIR/basic_fullpaths.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "full-paths"
+(( TEST_RESULT += $? ))
+
+
+### print-line
+
+# '--print-line' should print inline the source lines
+( cd $CURRENT_TEST_DIR ; $CMD_PERF annotate --stdio --dso load -P --print-line > $LOGS_DIR/basic_printline.log 2> $LOGS_DIR/basic_printline.err )
+PERF_EXIT_CODE=$?
+
+FULLPATH="`pwd`/examples"
+../common/check_all_patterns_found.pl "$FULLPATH/load\.c:$RE_NUMBER\s+$REGEX_LINE" "$REGEX_SECTION__TEXT" < $LOGS_DIR/basic_printline.log
+CHECK_EXIT_CODE=$?
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "print-line"
+(( TEST_RESULT += $? ))
+
+
+### redirected input
+
+# '-i dir/perf.data' should point to some other perf.data file
+mv $CURRENT_TEST_DIR/perf.data $CURRENT_TEST_DIR/examples/
+$CMD_PERF annotate --stdio --dso load -i $CURRENT_TEST_DIR/examples/perf.data > $LOGS_DIR/basic_input.log 2> $LOGS_DIR/basic_input.err
+PERF_EXIT_CODE=$?
+
+# the output should be the same as before
+diff -q $LOGS_DIR/basic_input.log $LOGS_DIR/basic_dso.log
+CHECK_EXIT_CODE=$?
+diff -q $LOGS_DIR/basic_input.err $LOGS_DIR/basic_dso.err
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "redirected input"
+(( TEST_RESULT += $? ))
+
+
+### execution without perf.data
+
+# check for error message
+! $CMD_PERF annotate > $LOGS_DIR/basic_nodata.log 2> $LOGS_DIR/basic_nodata.err
+PERF_EXIT_CODE=$?
+
+REGEX_NO_DATA="failed to open perf.data: No such file or directory"
+../common/check_all_lines_matched.pl "$REGEX_NO_DATA" < $LOGS_DIR/basic_nodata.err
+CHECK_EXIT_CODE=$?
+test ! -s $LOGS_DIR/basic_nodata.log
+(( CHECK_EXIT_CODE += $? ))
+
+print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "execution without data"
+(( TEST_RESULT += $? ))
+mv $CURRENT_TEST_DIR/examples/perf.data $CURRENT_TEST_DIR/
+
+
+# print overall resutls
+print_overall_results "$TEST_RESULT"
+exit $?
--
1.8.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-03-16 13:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-07 18:53 [PATCH 3/9] perf test: new testsuite: perf annotate tests Michael Petlan
2015-12-15 12:03 ` Jiri Olsa
2015-12-15 12:03 ` Jiri Olsa
2015-12-15 12:04 ` Jiri Olsa
2015-12-15 12:04 ` Jiri Olsa
2015-12-16 11:51 ` Michael Petlan
[not found] <cover.1458134357.git.mpetlan@redhat.com>
2016-03-16 13:54 ` Michael Petlan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).