Skip to contentSkip to conversation

selftests/bpf: Add an option for a debug shell in vmtest.sh

PATCH Superseded KP Singh 2 participants 4 messages Mar 22, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

KP Singh

author
#0 lore raw

PATCH 1/1 selftests/bpf: Add an option for a debug shell in vmtest.sh

The newly introduced -s command line option starts an interactive shell after running the intended command in instead of powering off the VM. It's useful to have a shell especially when debugging failing tests or developing new tests.

---
 tools/testing/selftests/bpf/vmtest.sh | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/vmtest.sh +11 -4
index 22554894db99..3f248e755755 100755
@@ -24,7 +24,7 @@ EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status"
 usage()
 {
 	cat <<EOF
-Usage: $0 [-i] [-d <output_dir>] -- [<command>]
+Usage: $0 [-i] [-s] [-d <output_dir>] -- [<command>]
 
 <command> is the command you would normally run when you are in
 tools/testing/selftests/bpf. e.g:
@@ -49,6 +49,8 @@ Options:
 	-d)		Update the output directory (default: ${OUTPUT_DIR})
 	-j)		Number of jobs for compilation, similar to -j in make
 			(default: ${NUM_COMPILE_JOBS})
+	-s)		Instead of powering off the VM, run an interactive debug
+			shell after <command> finishes.
 EOF
 }
 
@@ -149,6 +151,7 @@ update_init_script()
 	local init_script_dir="${OUTPUT_DIR}/${MOUNT_DIR}/etc/rcS.d"
 	local init_script="${init_script_dir}/S50-startup"
 	local command="$1"
+	local exit_command="$2"
 
 	mount_image
 
@@ -175,7 +178,7 @@ echo "130" > "/root/${EXIT_STATUS_FILE}"
 	stdbuf -oL -eL ${command}
 	echo "\$?" > "/root/${EXIT_STATUS_FILE}"
 } 2>&1 | tee "/root/${LOG_FILE}"
-poweroff -f
+${exit_command}
 EOF
 
 	sudo chmod a+x "${init_script}"
@@ -277,8 +280,9 @@ main()
 	local kernel_bzimage="${kernel_checkout}/${X86_BZIMAGE}"
 	local command="${DEFAULT_COMMAND}"
 	local update_image="no"
+	local exit_command="poweroff -f"
 
-	while getopts 'hkid:j:' opt; do
+	while getopts 'hskid:j:' opt; do
 		case ${opt} in
 		i)
 			update_image="yes"
@@ -289,6 +293,9 @@ main()
 		j)
 			NUM_COMPILE_JOBS="$OPTARG"
 			;;
+		s)
+			exit_command="bash"
+			;;
 		h)
 			usage
 			exit 0
@@ -355,7 +362,7 @@ main()
 	fi
 
 	update_selftests "${kernel_checkout}" "${make_command}"
-	update_init_script "${command}"
+	update_init_script "${command}" "${exit_command}"
 	run_vm "${kernel_bzimage}"
 	copy_logs
 	echo "Logs saved in ${OUTPUT_DIR}/${LOG_FILE}"
Signature · 1 line
2.31.0.rc2.261.g7f71774620-goog
#1 lore raw
Quoted 16 lines · KP Singh

The newly introduced -s command line option starts an interactive shell after running the intended command in instead of powering off the VM. It's useful to have a shell especially when debugging failing tests or developing new tests.

---
 tools/testing/selftests/bpf/vmtest.sh | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/vmtest.sh +0 -0
index 22554894db99..3f248e755755 100755

tools/testing/selftests/bpf/vmtest.sh EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status" · line 27

Quoted 5 lines
tools/testing/selftests/bpf/vmtest.sh +1 -1
@@ -24,7 +24,7 @@ EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status"
 usage()
 {
        cat <<EOF
-Usage: $0 [-i] [-d <output_dir>] -- [<command>]
+Usage: $0 [-i] [-s] [-d <output_dir>] -- [<command>]

wouldn't it make more sense to just run bash without any default commands, if -s is specified? So "shell mode" gets you into shell. Then you can run whatever you want.

Quoted 62 lines
tools/testing/selftests/bpf/vmtest.sh +10 -4
 <command> is the command you would normally run when you are in
 tools/testing/selftests/bpf. e.g:
@@ -49,6 +49,8 @@ Options:
        -d)             Update the output directory (default: ${OUTPUT_DIR})
        -j)             Number of jobs for compilation, similar to -j in make
                        (default: ${NUM_COMPILE_JOBS})
+       -s)             Instead of powering off the VM, run an interactive debug
+                       shell after <command> finishes.
 EOF
 }
 
@@ -149,6 +151,7 @@ update_init_script()
        local init_script_dir="${OUTPUT_DIR}/${MOUNT_DIR}/etc/rcS.d"
        local init_script="${init_script_dir}/S50-startup"
        local command="$1"
+       local exit_command="$2"
 
        mount_image
 
@@ -175,7 +178,7 @@ echo "130" > "/root/${EXIT_STATUS_FILE}"
        stdbuf -oL -eL ${command}
        echo "\$?" > "/root/${EXIT_STATUS_FILE}"
 } 2>&1 | tee "/root/${LOG_FILE}"
-poweroff -f
+${exit_command}
 EOF
 
        sudo chmod a+x "${init_script}"
@@ -277,8 +280,9 @@ main()
        local kernel_bzimage="${kernel_checkout}/${X86_BZIMAGE}"
        local command="${DEFAULT_COMMAND}"
        local update_image="no"
+       local exit_command="poweroff -f"
 
-       while getopts 'hkid:j:' opt; do
+       while getopts 'hskid:j:' opt; do
                case ${opt} in
                i)
                        update_image="yes"
@@ -289,6 +293,9 @@ main()
                j)
                        NUM_COMPILE_JOBS="$OPTARG"
                        ;;
+               s)
+                       exit_command="bash"
+                       ;;
                h)
                        usage
                        exit 0
@@ -355,7 +362,7 @@ main()
        fi
 
        update_selftests "${kernel_checkout}" "${make_command}"
-       update_init_script "${command}"
+       update_init_script "${command}" "${exit_command}"
        run_vm "${kernel_bzimage}"
        copy_logs
        echo "Logs saved in ${OUTPUT_DIR}/${LOG_FILE}"
--

2.31.0.rc2.261.g7f71774620-goog

author
#2 lore raw
Quoted 13 lines · Andrii Nakryiko
Quoted 11 lines · KP Singh

The newly introduced -s command line option starts an interactive shell after running the intended command in instead of powering off the VM. It's useful to have a shell especially when debugging failing tests or developing new tests.

---
 tools/testing/selftests/bpf/vmtest.sh | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Quoted 15 lines

tools/testing/selftests/bpf/vmtest.sh EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status" · line 27

Quoted 10 lines
tools/testing/selftests/bpf/vmtest.sh +1 -1
index 22554894db99..3f248e755755 100755
@@ -24,7 +24,7 @@ EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status"
 usage()
 {
        cat <<EOF
-Usage: $0 [-i] [-d <output_dir>] -- [<command>]
+Usage: $0 [-i] [-s] [-d <output_dir>] -- [<command>]

wouldn't it make more sense to just run bash without any default commands, if -s is specified? So "shell mode" gets you into shell. Then you can run whatever you want.

Yep, that would be better indeed. Will send an updated v2.

#3 lore raw
Quoted 32 lines · KP Singh
Quoted 13 lines · Andrii Nakryiko
Quoted 11 lines · KP Singh

The newly introduced -s command line option starts an interactive shell after running the intended command in instead of powering off the VM. It's useful to have a shell especially when debugging failing tests or developing new tests.

---
 tools/testing/selftests/bpf/vmtest.sh | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Quoted 15 lines

tools/testing/selftests/bpf/vmtest.sh EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status" · line 27

Quoted 10 lines
tools/testing/selftests/bpf/vmtest.sh +1 -1
index 22554894db99..3f248e755755 100755
@@ -24,7 +24,7 @@ EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status"
 usage()
 {
        cat <<EOF
-Usage: $0 [-i] [-d <output_dir>] -- [<command>]
+Usage: $0 [-i] [-s] [-d <output_dir>] -- [<command>]

wouldn't it make more sense to just run bash without any default commands, if -s is specified? So "shell mode" gets you into shell. Then you can run whatever you want.

Quoted 1 line

Yep, that would be better indeed. Will send an updated v2.

Cool. If it's not too hard, it still makes sense to run <command> in bash, if it was specified explicitly.