bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 bpf-next] selftests/bpf: Add an option for a debug shell in vmtest.sh
@ 2021-03-23  1:47 KP Singh
  2021-03-26  4:48 ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: KP Singh @ 2021-03-23  1:47 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Florent Revest, Brendan Jackman

The newly introduced -s command line option starts an interactive shell.
If a command is specified, the shell is started after the command
finishes executing. It's useful to have a shell especially when
debugging failing tests or developing new tests.

Since the user may terminate the VM forcefully, an extra "sync" is added
after the execution of the command to persist any logs from the command
into the log file.

Signed-off-by: KP Singh <kpsingh@kernel.org>
---
 tools/testing/selftests/bpf/vmtest.sh | 39 +++++++++++++++++++--------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/tools/testing/selftests/bpf/vmtest.sh b/tools/testing/selftests/bpf/vmtest.sh
index 22554894db99..8889b3f55236 100755
--- a/tools/testing/selftests/bpf/vmtest.sh
+++ b/tools/testing/selftests/bpf/vmtest.sh
@@ -24,15 +24,15 @@ 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:
 
 	$0 -- ./test_progs -t test_lsm
 
-If no command is specified, "${DEFAULT_COMMAND}" will be run by
-default.
+If no command is specified and a debug shell (-s) is not requested,
+"${DEFAULT_COMMAND}" will be run by default.
 
 If you build your kernel using KBUILD_OUTPUT= or O= options, these
 can be passed as environment variables to the script:
@@ -49,6 +49,9 @@ 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, start an interactive
+			shell. If <command> is specified, the shell runs after
+			the command finishes executing
 EOF
 }
 
@@ -149,6 +152,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
 
@@ -162,9 +166,10 @@ EOF
 
 	fi
 
-	sudo bash -c "cat >${init_script}" <<EOF
-#!/bin/bash
+	sudo bash -c "echo '#!/bin/bash' > ${init_script}"
 
+	if [[ "${command}" != "" ]]; then
+		sudo bash -c "cat >>${init_script}" <<EOF
 # Have a default value in the exit status file
 # incase the VM is forcefully stopped.
 echo "130" > "/root/${EXIT_STATUS_FILE}"
@@ -175,9 +180,12 @@ echo "130" > "/root/${EXIT_STATUS_FILE}"
 	stdbuf -oL -eL ${command}
 	echo "\$?" > "/root/${EXIT_STATUS_FILE}"
 } 2>&1 | tee "/root/${LOG_FILE}"
-poweroff -f
+# Ensure that the logs are written to disk
+sync
 EOF
+	fi
 
+	sudo bash -c "echo ${exit_command} >> ${init_script}"
 	sudo chmod a+x "${init_script}"
 	unmount_image
 }
@@ -277,8 +285,10 @@ main()
 	local kernel_bzimage="${kernel_checkout}/${X86_BZIMAGE}"
 	local command="${DEFAULT_COMMAND}"
 	local update_image="no"
+	local exit_command="poweroff -f"
+	local debug_shell="no"
 
-	while getopts 'hkid:j:' opt; do
+	while getopts 'hskid:j:' opt; do
 		case ${opt} in
 		i)
 			update_image="yes"
@@ -289,6 +299,11 @@ main()
 		j)
 			NUM_COMPILE_JOBS="$OPTARG"
 			;;
+		s)
+			command=""
+			debug_shell="yes"
+			exit_command="bash"
+			;;
 		h)
 			usage
 			exit 0
@@ -307,7 +322,7 @@ main()
 	done
 	shift $((OPTIND -1))
 
-	if [[ $# -eq 0 ]]; then
+	if [[ $# -eq 0  && "${debug_shell}" == "no" ]]; then
 		echo "No command specified, will run ${DEFAULT_COMMAND} in the vm"
 	else
 		command="$@"
@@ -355,10 +370,12 @@ 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}"
+	if [[ "${command}" != "" ]]; then
+		copy_logs
+		echo "Logs saved in ${OUTPUT_DIR}/${LOG_FILE}"
+	fi
 }
 
 catch()
-- 
2.31.0.rc2.261.g7f71774620-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 bpf-next] selftests/bpf: Add an option for a debug shell in vmtest.sh
  2021-03-23  1:47 [PATCH v2 bpf-next] selftests/bpf: Add an option for a debug shell in vmtest.sh KP Singh
@ 2021-03-26  4:48 ` Andrii Nakryiko
  2021-03-29 13:45   ` KP Singh
  0 siblings, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2021-03-26  4:48 UTC (permalink / raw)
  To: KP Singh
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Florent Revest, Brendan Jackman

On Mon, Mar 22, 2021 at 6:47 PM KP Singh <kpsingh@kernel.org> wrote:
>
> The newly introduced -s command line option starts an interactive shell.
> If a command is specified, the shell is started after the command
> finishes executing. It's useful to have a shell especially when
> debugging failing tests or developing new tests.
>
> Since the user may terminate the VM forcefully, an extra "sync" is added
> after the execution of the command to persist any logs from the command
> into the log file.
>
> Signed-off-by: KP Singh <kpsingh@kernel.org>
> ---

I run:

./vmtest.sh -s

And I get test_progs executed, not bash. What do I do wrong?...

>  tools/testing/selftests/bpf/vmtest.sh | 39 +++++++++++++++++++--------
>  1 file changed, 28 insertions(+), 11 deletions(-)
>

[...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 bpf-next] selftests/bpf: Add an option for a debug shell in vmtest.sh
  2021-03-26  4:48 ` Andrii Nakryiko
@ 2021-03-29 13:45   ` KP Singh
  2021-03-31  5:17     ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: KP Singh @ 2021-03-29 13:45 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Florent Revest, Brendan Jackman

On Fri, Mar 26, 2021 at 5:48 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Mar 22, 2021 at 6:47 PM KP Singh <kpsingh@kernel.org> wrote:
> >
> > The newly introduced -s command line option starts an interactive shell.
> > If a command is specified, the shell is started after the command
> > finishes executing. It's useful to have a shell especially when
> > debugging failing tests or developing new tests.
> >
> > Since the user may terminate the VM forcefully, an extra "sync" is added
> > after the execution of the command to persist any logs from the command
> > into the log file.
> >
> > Signed-off-by: KP Singh <kpsingh@kernel.org>
> > ---
>
> I run:
>
> ./vmtest.sh -s
>
> And I get test_progs executed, not bash. What do I do wrong?...

It does not seem to happen for me [classic, works on my machine :P]

tools/testing/selftests/bpf$ ./vmtest.sh -s
[...]
+ /etc/rcS.d/S50-startup
bash: cannot set terminal process group (84): Inappropriate ioctl for device
bash: no job control in this shell
[root@(none) /]#

To help debug this:

Can you check the contents of /etc/rcS.d/S50-startup on the image,
here's what mine looks like:

[root@(none) /]# cat /etc/rcS.d/S50-startup
#!/bin/bash
bash

2. Also, can you delete the cache in the home directory
(~/.bpf_selftests by default) and try again?

>
> >  tools/testing/selftests/bpf/vmtest.sh | 39 +++++++++++++++++++--------
> >  1 file changed, 28 insertions(+), 11 deletions(-)
> >
>
> [...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 bpf-next] selftests/bpf: Add an option for a debug shell in vmtest.sh
  2021-03-29 13:45   ` KP Singh
@ 2021-03-31  5:17     ` Andrii Nakryiko
  2021-03-31 19:33       ` Andrii Nakryiko
  0 siblings, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2021-03-31  5:17 UTC (permalink / raw)
  To: KP Singh
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Florent Revest, Brendan Jackman

On Mon, Mar 29, 2021 at 6:46 AM KP Singh <kpsingh@kernel.org> wrote:
>
> On Fri, Mar 26, 2021 at 5:48 AM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> >
> > On Mon, Mar 22, 2021 at 6:47 PM KP Singh <kpsingh@kernel.org> wrote:
> > >
> > > The newly introduced -s command line option starts an interactive shell.
> > > If a command is specified, the shell is started after the command
> > > finishes executing. It's useful to have a shell especially when
> > > debugging failing tests or developing new tests.
> > >
> > > Since the user may terminate the VM forcefully, an extra "sync" is added
> > > after the execution of the command to persist any logs from the command
> > > into the log file.
> > >
> > > Signed-off-by: KP Singh <kpsingh@kernel.org>
> > > ---
> >
> > I run:
> >
> > ./vmtest.sh -s
> >
> > And I get test_progs executed, not bash. What do I do wrong?...
>
> It does not seem to happen for me [classic, works on my machine :P]
>
> tools/testing/selftests/bpf$ ./vmtest.sh -s
> [...]
> + /etc/rcS.d/S50-startup
> bash: cannot set terminal process group (84): Inappropriate ioctl for device
> bash: no job control in this shell
> [root@(none) /]#
>
> To help debug this:
>
> Can you check the contents of /etc/rcS.d/S50-startup on the image,
> here's what mine looks like:
>
> [root@(none) /]# cat /etc/rcS.d/S50-startup
> #!/bin/bash
> bash

Couldn't do it, because it would only run test_progs, no matter which
command I specified (that didn't happen before, strange). E.g.,
running `./vmtest.sh -- cat /etc/rcS.d/S50-startup` gives this:

starting pid 83, tty '': '/etc/init.d/rcS'
[    1.070838] random: fast init done
+ for path in /etc/rcS.d/S*
+ '[' -x /etc/rcS.d/S10-mount ']'
+ /etc/rcS.d/S10-mount
+ /bin/mount proc /proc -t proc
+ /bin/mount devtmpfs /dev -t devtmpfs
mount: mounting devtmpfs on /dev failed: Resource busy
+ true
+ /bin/mount sysfs /sys -t sysfs
+ /bin/mount bpffs /sys/fs/bpf -t bpf
+ /bin/mount debugfs /sys/kernel/debug -t debugfs
+ echo 'Listing currently mounted file systems'
Listing currently mounted file systems
+ /bin/mount
/dev/root on / type ext4 (rw,relatime)
devtmpfs on /dev type devtmpfs
(rw,relatime,size=1004288k,nr_inodes=251072,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
none on /sys/fs/bpf type bpf (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
+ for path in /etc/rcS.d/S*
+ '[' -x /etc/rcS.d/S40-network ']'
+ /etc/rcS.d/S40-network
+ ip link set lo up
+ for path in /etc/rcS.d/S*
+ '[' -x /etc/rcS.d/S50-startup ']'
+ /etc/rcS.d/S50-startup
./test_progs

And there was a bunch of messages like this before kernel started:

error: Macro %global is a built-in (%define)
error: Macro %global is a built-in (%define)
warning: file /etc/rpm/macros.perl: 2 invalid macro definitions

Don't know if related.

>
> 2. Also, can you delete the cache in the home directory
> (~/.bpf_selftests by default) and try again?
>

But this solved the issue. So must be something in cached data.

> >
> > >  tools/testing/selftests/bpf/vmtest.sh | 39 +++++++++++++++++++--------
> > >  1 file changed, 28 insertions(+), 11 deletions(-)
> > >
> >
> > [...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 bpf-next] selftests/bpf: Add an option for a debug shell in vmtest.sh
  2021-03-31  5:17     ` Andrii Nakryiko
@ 2021-03-31 19:33       ` Andrii Nakryiko
  0 siblings, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2021-03-31 19:33 UTC (permalink / raw)
  To: KP Singh
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Florent Revest, Brendan Jackman

On Tue, Mar 30, 2021 at 10:17 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Mar 29, 2021 at 6:46 AM KP Singh <kpsingh@kernel.org> wrote:
> >
> > On Fri, Mar 26, 2021 at 5:48 AM Andrii Nakryiko
> > <andrii.nakryiko@gmail.com> wrote:
> > >
> > > On Mon, Mar 22, 2021 at 6:47 PM KP Singh <kpsingh@kernel.org> wrote:
> > > >
> > > > The newly introduced -s command line option starts an interactive shell.
> > > > If a command is specified, the shell is started after the command
> > > > finishes executing. It's useful to have a shell especially when
> > > > debugging failing tests or developing new tests.
> > > >
> > > > Since the user may terminate the VM forcefully, an extra "sync" is added
> > > > after the execution of the command to persist any logs from the command
> > > > into the log file.
> > > >
> > > > Signed-off-by: KP Singh <kpsingh@kernel.org>
> > > > ---
> > >
> > > I run:
> > >
> > > ./vmtest.sh -s
> > >
> > > And I get test_progs executed, not bash. What do I do wrong?...
> >
> > It does not seem to happen for me [classic, works on my machine :P]
> >
> > tools/testing/selftests/bpf$ ./vmtest.sh -s
> > [...]
> > + /etc/rcS.d/S50-startup
> > bash: cannot set terminal process group (84): Inappropriate ioctl for device
> > bash: no job control in this shell
> > [root@(none) /]#
> >
> > To help debug this:
> >
> > Can you check the contents of /etc/rcS.d/S50-startup on the image,
> > here's what mine looks like:
> >
> > [root@(none) /]# cat /etc/rcS.d/S50-startup
> > #!/bin/bash
> > bash
>
> Couldn't do it, because it would only run test_progs, no matter which
> command I specified (that didn't happen before, strange). E.g.,
> running `./vmtest.sh -- cat /etc/rcS.d/S50-startup` gives this:
>
> starting pid 83, tty '': '/etc/init.d/rcS'
> [    1.070838] random: fast init done
> + for path in /etc/rcS.d/S*
> + '[' -x /etc/rcS.d/S10-mount ']'
> + /etc/rcS.d/S10-mount
> + /bin/mount proc /proc -t proc
> + /bin/mount devtmpfs /dev -t devtmpfs
> mount: mounting devtmpfs on /dev failed: Resource busy
> + true
> + /bin/mount sysfs /sys -t sysfs
> + /bin/mount bpffs /sys/fs/bpf -t bpf
> + /bin/mount debugfs /sys/kernel/debug -t debugfs
> + echo 'Listing currently mounted file systems'
> Listing currently mounted file systems
> + /bin/mount
> /dev/root on / type ext4 (rw,relatime)
> devtmpfs on /dev type devtmpfs
> (rw,relatime,size=1004288k,nr_inodes=251072,mode=755)
> proc on /proc type proc (rw,relatime)
> sysfs on /sys type sysfs (rw,relatime)
> none on /sys/fs/bpf type bpf (rw,relatime)
> debugfs on /sys/kernel/debug type debugfs (rw,relatime)
> + for path in /etc/rcS.d/S*
> + '[' -x /etc/rcS.d/S40-network ']'
> + /etc/rcS.d/S40-network
> + ip link set lo up
> + for path in /etc/rcS.d/S*
> + '[' -x /etc/rcS.d/S50-startup ']'
> + /etc/rcS.d/S50-startup
> ./test_progs
>
> And there was a bunch of messages like this before kernel started:
>
> error: Macro %global is a built-in (%define)
> error: Macro %global is a built-in (%define)
> warning: file /etc/rpm/macros.perl: 2 invalid macro definitions
>
> Don't know if related.
>
> >
> > 2. Also, can you delete the cache in the home directory
> > (~/.bpf_selftests by default) and try again?
> >
>
> But this solved the issue. So must be something in cached data.
>

I've applied it to bpf-next, thanks!

> > >
> > > >  tools/testing/selftests/bpf/vmtest.sh | 39 +++++++++++++++++++--------
> > > >  1 file changed, 28 insertions(+), 11 deletions(-)
> > > >
> > >
> > > [...]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-31 19:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23  1:47 [PATCH v2 bpf-next] selftests/bpf: Add an option for a debug shell in vmtest.sh KP Singh
2021-03-26  4:48 ` Andrii Nakryiko
2021-03-29 13:45   ` KP Singh
2021-03-31  5:17     ` Andrii Nakryiko
2021-03-31 19:33       ` Andrii Nakryiko

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).