Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# perf_probe :: Reject invalid options (exclusive)
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
18TEST_RESULT=0
19
20if ! check_kprobes_available; then
21 print_overall_skipped
22 exit 2
23fi
24
25# Check for presence of DWARF
26$CMD_PERF check feature -q dwarf
27[ $? -ne 0 ] && HINT_FAIL="Some of the tests need DWARF to run"
28
29### missing argument
30
31# some options require an argument
32for opt in '-a' '-d' '-L' '-V'; do
33 ! $CMD_PERF probe $opt 2> $LOGS_DIR/invalid_options_missing_argument$opt.err
34 PERF_EXIT_CODE=$?
35
36 ../common/check_all_patterns_found.pl "Error: switch .* requires a value" < $LOGS_DIR/invalid_options_missing_argument$opt.err
37 CHECK_EXIT_CODE=$?
38
39 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "missing argument for $opt"
40 (( TEST_RESULT += $? ))
41done
42
43
44### unnecessary argument
45
46# some options may omit the argument
47for opt in '-F' '-l'; do
48 $CMD_PERF probe -F > /dev/null 2> $LOGS_DIR/invalid_options_unnecessary_argument$opt.err
49 PERF_EXIT_CODE=$?
50
51 test ! -s $LOGS_DIR/invalid_options_unnecessary_argument$opt.err
52 CHECK_EXIT_CODE=$?
53
54 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "unnecessary argument for $opt"
55 (( TEST_RESULT += $? ))
56done
57
58
59### mutually exclusive options
60
61# some options are mutually exclusive
62test -e $LOGS_DIR/invalid_options_mutually_exclusive.log && rm -f $LOGS_DIR/invalid_options_mutually_exclusive.log
63for opt in '-a xxx -d xxx' '-a xxx -L foo' '-a xxx -V foo' '-a xxx -l' '-a xxx -F' \
64 '-d xxx -L foo' '-d xxx -V foo' '-d xxx -l' '-d xxx -F' \
65 '-L foo -V bar' '-L foo -l' '-L foo -F' '-V foo -l' '-V foo -F' '-l -F'; do
66 ! $CMD_PERF probe $opt > /dev/null 2> $LOGS_DIR/aux.log
67 PERF_EXIT_CODE=$?
68
69 ../common/check_all_patterns_found.pl "Error: switch .+ cannot be used with switch .+" < $LOGS_DIR/aux.log
70 CHECK_EXIT_CODE=$?
71
72 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "mutually exclusive options :: $opt"
73 (( TEST_RESULT += $? ))
74
75 # gather the logs
76 cat $LOGS_DIR/aux.log | grep "Error" >> $LOGS_DIR/invalid_options_mutually_exclusive.log
77done
78
79
80# print overall results
81print_overall_results "$TEST_RESULT" $HINT_FAIL
82exit $?