Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf testsuite probe: Add test for invalid options

Test if various incompatible options are correctly handled-rejected.
It is run as a part of perftool-testsuite_probe test case.

Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240702110849.31904-8-vmolnaro@redhat.com
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Veronika Molnarova and committed by
Arnaldo Carvalho de Melo
83b6815d adc1dd00

+79
+79
tools/perf/tests/shell/base_probe/test_invalid_options.sh
··· 1 + #!/bin/bash 2 + 3 + # SPDX-License-Identifier: GPL-2.0 4 + 5 + # 6 + # test_invalid_options of perf_probe test 7 + # Author: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> 8 + # Author: Michael Petlan <mpetlan@redhat.com> 9 + # 10 + # Description: 11 + # 12 + # This test checks whether the invalid and incompatible options are reported 13 + # 14 + 15 + # include working environment 16 + . ../common/init.sh 17 + 18 + TEST_RESULT=0 19 + 20 + if ! check_kprobes_available; then 21 + print_overall_skipped 22 + exit 0 23 + fi 24 + 25 + 26 + ### missing argument 27 + 28 + # some options require an argument 29 + for opt in '-a' '-d' '-L' '-V'; do 30 + ! $CMD_PERF probe $opt 2> $LOGS_DIR/invalid_options_missing_argument$opt.err 31 + PERF_EXIT_CODE=$? 32 + 33 + ../common/check_all_patterns_found.pl "Error: switch .* requires a value" < $LOGS_DIR/invalid_options_missing_argument$opt.err 34 + CHECK_EXIT_CODE=$? 35 + 36 + print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "missing argument for $opt" 37 + (( TEST_RESULT += $? )) 38 + done 39 + 40 + 41 + ### unnecessary argument 42 + 43 + # some options may omit the argument 44 + for opt in '-F' '-l'; do 45 + $CMD_PERF probe -F > /dev/null 2> $LOGS_DIR/invalid_options_unnecessary_argument$opt.err 46 + PERF_EXIT_CODE=$? 47 + 48 + test ! -s $LOGS_DIR/invalid_options_unnecessary_argument$opt.err 49 + CHECK_EXIT_CODE=$? 50 + 51 + print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "unnecessary argument for $opt" 52 + (( TEST_RESULT += $? )) 53 + done 54 + 55 + 56 + ### mutually exclusive options 57 + 58 + # some options are mutually exclusive 59 + test -e $LOGS_DIR/invalid_options_mutually_exclusive.log && rm -f $LOGS_DIR/invalid_options_mutually_exclusive.log 60 + for opt in '-a xxx -d xxx' '-a xxx -L foo' '-a xxx -V foo' '-a xxx -l' '-a xxx -F' \ 61 + '-d xxx -L foo' '-d xxx -V foo' '-d xxx -l' '-d xxx -F' \ 62 + '-L foo -V bar' '-L foo -l' '-L foo -F' '-V foo -l' '-V foo -F' '-l -F'; do 63 + ! $CMD_PERF probe $opt > /dev/null 2> $LOGS_DIR/aux.log 64 + PERF_EXIT_CODE=$? 65 + 66 + ../common/check_all_patterns_found.pl "Error: switch .+ cannot be used with switch .+" < $LOGS_DIR/aux.log 67 + CHECK_EXIT_CODE=$? 68 + 69 + print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "mutually exclusive options :: $opt" 70 + (( TEST_RESULT += $? )) 71 + 72 + # gather the logs 73 + cat $LOGS_DIR/aux.log | grep "Error" >> $LOGS_DIR/invalid_options_mutually_exclusive.log 74 + done 75 + 76 + 77 + # print overall results 78 + print_overall_results "$TEST_RESULT" 79 + exit $?