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

bootconfig/tracing/ktest: Add ktest examples of testing bootconfig

bootconfig is a new feature that appends scripts onto the initrd, and the
kernel executes the scripts as an extended kernel command line.

Need to add tests to test that the happened. To test the bootconfig
properly, the initrd needs to be updated and the kernel rebooted. ktest is
the perfect solution to perform these tests.

Add a example bootconfig.conf in the tools/testing/ktest/examples/include
and example bootconfig scripts in tools/testing/ktest/examples/bootconfig
and also include verifier scripts that ktest will install on the target
and run to make sure that the bootconfig options in the scripts took place
after the target rebooted with the new initrd update.

Link: https://lkml.kernel.org/r/20210618112647.6a81dec5@oasis.local.home

Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

+385
+49
tools/testing/ktest/examples/bootconfigs/boottrace.bconf
··· 1 + ftrace.event { 2 + task.task_newtask { 3 + filter = "pid < 128" 4 + enable 5 + } 6 + kprobes.vfs_read { 7 + probes = "vfs_read $arg1 $arg2" 8 + filter = "common_pid < 200" 9 + enable 10 + } 11 + synthetic.initcall_latency { 12 + fields = "unsigned long func", "u64 lat" 13 + actions = "hist:keys=func.sym,lat:vals=lat:sort=lat" 14 + } 15 + initcall.initcall_start { 16 + actions = "hist:keys=func:ts0=common_timestamp.usecs" 17 + } 18 + initcall.initcall_finish { 19 + actions = "hist:keys=func:lat=common_timestamp.usecs-$ts0:onmatch(initcall.initcall_start).initcall_latency(func,$lat)" 20 + } 21 + } 22 + 23 + ftrace.instance { 24 + foo { 25 + tracer = "function" 26 + ftrace.filters = "user_*" 27 + cpumask = 1 28 + options = nosym-addr 29 + buffer_size = 512KB 30 + trace_clock = mono 31 + event.signal.signal_deliver.actions=snapshot 32 + } 33 + bar { 34 + tracer = "function" 35 + ftrace.filters = "kernel_*" 36 + cpumask = 2 37 + trace_clock = x86-tsc 38 + } 39 + } 40 + 41 + ftrace.alloc_snapshot 42 + 43 + kernel { 44 + trace_options = sym-addr 45 + trace_event = "initcall:*" 46 + trace_buf_size = 1M 47 + ftrace = function 48 + ftrace_filter = "vfs*" 49 + }
+1
tools/testing/ktest/examples/bootconfigs/config-bootconfig
··· 1 + CONFIG_CMDLINE="bootconfig"
+15
tools/testing/ktest/examples/bootconfigs/functiongraph.bconf
··· 1 + ftrace { 2 + tracing_on = 0 # off by default 3 + tracer = function_graph 4 + event.kprobes { 5 + start_event { 6 + probes = "pci_proc_init" 7 + actions = "traceon" 8 + } 9 + end_event { 10 + probes = "pci_proc_init%return" 11 + actions = "traceoff" 12 + } 13 + } 14 + } 15 +
+33
tools/testing/ktest/examples/bootconfigs/tracing.bconf
··· 1 + ftrace { 2 + tracer = function_graph; 3 + options = event-fork, sym-addr, stacktrace; 4 + buffer_size = 1M; 5 + alloc_snapshot; 6 + trace_clock = global; 7 + events = "task:task_newtask", "initcall:*"; 8 + event.sched.sched_process_exec { 9 + filter = "pid < 128"; 10 + } 11 + instance.bar { 12 + event.kprobes { 13 + myevent { 14 + probes = "vfs_read $arg2 $arg3"; 15 + } 16 + myevent2 { 17 + probes = "vfs_write $arg2 +0($arg2):ustring $arg3"; 18 + } 19 + myevent3 { 20 + probes = "initrd_load"; 21 + } 22 + enable 23 + } 24 + } 25 + instance.foo { 26 + tracer = function; 27 + tracing_on = false; 28 + }; 29 + } 30 + kernel { 31 + ftrace_dump_on_oops = "orig_cpu" 32 + traceoff_on_warning 33 + }
+84
tools/testing/ktest/examples/bootconfigs/verify-boottrace.sh
··· 1 + #!/bin/sh 2 + 3 + cd /sys/kernel/tracing 4 + 5 + compare_file() { 6 + file="$1" 7 + val="$2" 8 + content=`cat $file` 9 + if [ "$content" != "$val" ]; then 10 + echo "FAILED: $file has '$content', expected '$val'" 11 + exit 1 12 + fi 13 + } 14 + 15 + compare_file_partial() { 16 + file="$1" 17 + val="$2" 18 + content=`cat $file | sed -ne "/^$val/p"` 19 + if [ -z "$content" ]; then 20 + echo "FAILED: $file does not contain '$val'" 21 + cat $file 22 + exit 1 23 + fi 24 + } 25 + 26 + file_contains() { 27 + file=$1 28 + val="$2" 29 + 30 + if ! grep -q "$val" $file ; then 31 + echo "FAILED: $file does not contain $val" 32 + cat $file 33 + exit 1 34 + fi 35 + } 36 + 37 + compare_mask() { 38 + file=$1 39 + val="$2" 40 + 41 + content=`cat $file | sed -ne "/^[0 ]*$val/p"` 42 + if [ -z "$content" ]; then 43 + echo "FAILED: $file does not have mask '$val'" 44 + cat $file 45 + exit 1 46 + fi 47 + } 48 + 49 + compare_file "events/task/task_newtask/filter" "pid < 128" 50 + compare_file "events/task/task_newtask/enable" "1" 51 + 52 + compare_file "events/kprobes/vfs_read/filter" "common_pid < 200" 53 + compare_file "events/kprobes/vfs_read/enable" "1" 54 + 55 + compare_file_partial "events/synthetic/initcall_latency/trigger" "hist:keys=func.sym,lat:vals=hitcount,lat:sort=lat" 56 + compare_file_partial "events/synthetic/initcall_latency/enable" "0" 57 + 58 + compare_file_partial "events/initcall/initcall_start/trigger" "hist:keys=func:vals=hitcount:ts0=common_timestamp.usecs" 59 + compare_file_partial "events/initcall/initcall_start/enable" "1" 60 + 61 + compare_file_partial "events/initcall/initcall_finish/trigger" 'hist:keys=func:vals=hitcount:lat=common_timestamp.usecs-\$ts0:sort=hitcount:size=2048:clock=global:onmatch(initcall.initcall_start).initcall_latency(func,\$lat)' 62 + compare_file_partial "events/initcall/initcall_finish/enable" "1" 63 + 64 + compare_file "instances/foo/current_tracer" "function" 65 + file_contains "instances/foo/set_ftrace_filter" "^user" 66 + compare_file "instances/foo/buffer_size_kb" "512" 67 + compare_mask "instances/foo/tracing_cpumask" "1" 68 + compare_file "instances/foo/options/sym-addr" "0" 69 + file_contains "instances/foo/trace_clock" '\[mono\]' 70 + compare_file_partial "instances/foo/events/signal/signal_deliver/trigger" "snapshot" 71 + 72 + compare_file "instances/bar/current_tracer" "function" 73 + file_contains "instances/bar/set_ftrace_filter" "^kernel" 74 + compare_mask "instances/bar/tracing_cpumask" "2" 75 + file_contains "instances/bar/trace_clock" '\[x86-tsc\]' 76 + 77 + file_contains "snapshot" "Snapshot is allocated" 78 + compare_file "options/sym-addr" "1" 79 + compare_file "events/initcall/enable" "1" 80 + compare_file "buffer_size_kb" "1027" 81 + compare_file "current_tracer" "function" 82 + file_contains "set_ftrace_filter" '^vfs' 83 + 84 + exit 0
+61
tools/testing/ktest/examples/bootconfigs/verify-functiongraph.sh
··· 1 + #!/bin/sh 2 + 3 + cd /sys/kernel/tracing 4 + 5 + compare_file() { 6 + file="$1" 7 + val="$2" 8 + content=`cat $file` 9 + if [ "$content" != "$val" ]; then 10 + echo "FAILED: $file has '$content', expected '$val'" 11 + exit 1 12 + fi 13 + } 14 + 15 + compare_file_partial() { 16 + file="$1" 17 + val="$2" 18 + content=`cat $file | sed -ne "/^$val/p"` 19 + if [ -z "$content" ]; then 20 + echo "FAILED: $file does not contain '$val'" 21 + cat $file 22 + exit 1 23 + fi 24 + } 25 + 26 + file_contains() { 27 + file=$1 28 + val="$2" 29 + 30 + if ! grep -q "$val" $file ; then 31 + echo "FAILED: $file does not contain $val" 32 + cat $file 33 + exit 1 34 + fi 35 + } 36 + 37 + compare_mask() { 38 + file=$1 39 + val="$2" 40 + 41 + content=`cat $file | sed -ne "/^[0 ]*$val/p"` 42 + if [ -z "$content" ]; then 43 + echo "FAILED: $file does not have mask '$val'" 44 + cat $file 45 + exit 1 46 + fi 47 + } 48 + 49 + 50 + compare_file "tracing_on" "0" 51 + compare_file "current_tracer" "function_graph" 52 + 53 + compare_file_partial "events/kprobes/start_event/enable" "1" 54 + compare_file_partial "events/kprobes/start_event/trigger" "traceon" 55 + file_contains "kprobe_events" 'start_event.*pci_proc_init' 56 + 57 + compare_file_partial "events/kprobes/end_event/enable" "1" 58 + compare_file_partial "events/kprobes/end_event/trigger" "traceoff" 59 + file_contains "kprobe_events" '^r.*end_event.*pci_proc_init' 60 + 61 + exit 0
+72
tools/testing/ktest/examples/bootconfigs/verify-tracing.sh
··· 1 + #!/bin/sh 2 + 3 + cd /sys/kernel/tracing 4 + 5 + compare_file() { 6 + file="$1" 7 + val="$2" 8 + content=`cat $file` 9 + if [ "$content" != "$val" ]; then 10 + echo "FAILED: $file has '$content', expected '$val'" 11 + exit 1 12 + fi 13 + } 14 + 15 + compare_file_partial() { 16 + file="$1" 17 + val="$2" 18 + content=`cat $file | sed -ne "/^$val/p"` 19 + if [ -z "$content" ]; then 20 + echo "FAILED: $file does not contain '$val'" 21 + cat $file 22 + exit 1 23 + fi 24 + } 25 + 26 + file_contains() { 27 + file=$1 28 + val="$2" 29 + 30 + if ! grep -q "$val" $file ; then 31 + echo "FAILED: $file does not contain $val" 32 + cat $file 33 + exit 1 34 + fi 35 + } 36 + 37 + compare_mask() { 38 + file=$1 39 + val="$2" 40 + 41 + content=`cat $file | sed -ne "/^[0 ]*$val/p"` 42 + if [ -z "$content" ]; then 43 + echo "FAILED: $file does not have mask '$val'" 44 + cat $file 45 + exit 1 46 + fi 47 + } 48 + 49 + compare_file "current_tracer" "function_graph" 50 + compare_file "options/event-fork" "1" 51 + compare_file "options/sym-addr" "1" 52 + compare_file "options/stacktrace" "1" 53 + compare_file "buffer_size_kb" "1024" 54 + file_contains "snapshot" "Snapshot is allocated" 55 + file_contains "trace_clock" '\[global\]' 56 + 57 + compare_file "events/initcall/enable" "1" 58 + compare_file "events/task/task_newtask/enable" "1" 59 + compare_file "events/sched/sched_process_exec/filter" "pid < 128" 60 + compare_file "events/kprobes/enable" "1" 61 + 62 + compare_file "instances/bar/events/kprobes/myevent/enable" "1" 63 + compare_file "instances/bar/events/kprobes/myevent2/enable" "1" 64 + compare_file "instances/bar/events/kprobes/myevent3/enable" "1" 65 + 66 + compare_file "instances/foo/current_tracer" "function" 67 + compare_file "instances/foo/tracing_on" "0" 68 + 69 + compare_file "/proc/sys/kernel/ftrace_dump_on_oops" "2" 70 + compare_file "/proc/sys/kernel/traceoff_on_warning" "1" 71 + 72 + exit 0
+69
tools/testing/ktest/examples/include/bootconfig.conf
··· 1 + # bootconfig.conf 2 + # 3 + # Tests to test some bootconfig scripts 4 + 5 + # List where on the target machine the initrd is used 6 + INITRD := /boot/initramfs-test.img 7 + 8 + # Install bootconfig on the target machine and define the path here. 9 + BOOTCONFIG := /usr/bin/bootconfig 10 + 11 + # Currenty we just build the .config in the BUILD_DIR 12 + BUILD_TYPE := oldconfig 13 + 14 + # Helper macro to run bootconfig on the target 15 + # SSH is defined in include/defaults.conf 16 + ADD_BOOTCONFIG := ${SSH} "${BOOTCONFIG} -d ${INITRD} && ${BOOTCONFIG} -a /tmp/${BOOTCONFIG_FILE} ${INITRD}" 17 + 18 + # This copies a bootconfig script to the target and then will 19 + # add it to the initrd. SSH_USER is defined in include/defaults.conf 20 + # and MACHINE is defined in the example configs. 21 + BOOTCONFIG_TEST_PREP = scp ${BOOTCONFIG_PATH}${BOOTCONFIG_FILE} ${SSH_USER}@${MACHINE}:/tmp && ${ADD_BOOTCONFIG} 22 + 23 + # When a test is complete, remove the bootconfig from the initrd. 24 + CLEAR_BOOTCONFIG := ${SSH} "${BOOTCONFIG} -d ${INITRD}" 25 + 26 + # Run a verifier on the target after it had booted, to make sure that the 27 + # bootconfig script did what it was expected to do 28 + DO_TEST = scp ${BOOTCONFIG_PATH}${BOOTCONFIG_VERIFY} ${SSH_USER}@${MACHINE}:/tmp && ${SSH} /tmp/${BOOTCONFIG_VERIFY} 29 + 30 + # Comment this out to not run the boot configs 31 + RUN_BOOTCONFIG := 1 32 + 33 + TEST_START IF DEFINED RUN_BOOTCONFIG 34 + TEST_TYPE = test 35 + TEST_NAME = bootconfig boottrace 36 + # Just testing the bootconfig on initrd, no need to build the kernel 37 + BUILD_TYPE = nobuild 38 + BOOTCONFIG_FILE = boottrace.bconf 39 + BOOTCONFIG_VERIFY = verify-boottrace.sh 40 + ADD_CONFIG = ${ADD_CONFIG} ${BOOTCONFIG_PATH}/config-bootconfig 41 + PRE_TEST = ${BOOTCONFIG_TEST_PREP} 42 + PRE_TEST_DIE = 1 43 + TEST = ${DO_TEST} 44 + POST_TEST = ${CLEAR_BOOTCONFIG} 45 + 46 + TEST_START IF DEFINED RUN_BOOTCONFIG 47 + TEST_TYPE = test 48 + TEST_NAME = bootconfig function graph 49 + BUILD_TYPE = nobuild 50 + BOOTCONFIG_FILE = functiongraph.bconf 51 + BOOTCONFIG_VERIFY = verify-functiongraph.sh 52 + ADD_CONFIG = ${ADD_CONFIG} ${BOOTCONFIG_PATH}/config-bootconfig 53 + PRE_TEST = ${BOOTCONFIG_TEST_PREP} 54 + PRE_TEST_DIE = 1 55 + TEST = ${DO_TEST} 56 + POST_TEST = ${CLEAR_BOOTCONFIG} 57 + 58 + TEST_START IF DEFINED RUN_BOOTCONFIG 59 + TEST_TYPE = test 60 + TEST_NAME = bootconfig tracing 61 + BUILD_TYPE = nobuild 62 + BOOTCONFIG_FILE = tracing.bconf 63 + BOOTCONFIG_VERIFY = verify-tracing.sh 64 + ADD_CONFIG = ${ADD_CONFIG} ${BOOTCONFIG_PATH}/config-bootconfig 65 + PRE_TEST = ${BOOTCONFIG_TEST_PREP} 66 + PRE_TEST_DIE = 1 67 + TEST = ${DO_TEST} 68 + POST_TEST = ${CLEAR_BOOTCONFIG} 69 +
+1
tools/testing/ktest/examples/kvm.conf
··· 90 90 INCLUDE include/tests.conf 91 91 INCLUDE include/bisect.conf 92 92 INCLUDE include/min-config.conf 93 + INCLUDE include/bootconfig.conf