crosvm/tests
Iliyan Malchev 2c1417b43a Serial: add input path overriding stdin for --serial
Allowing the input to be specified for file-based serial ports allows
the user of pipes as input/output. That enables kgdb over serial.

TEST=
Build a kernel with support for gdb

```
make x86_64_defconfig
make kvmconfig
./scripts/config --enable GDB_SCRIPTS
./scripts/config --enable KGDB
./scripts/config --enable KGDB_SERIAL_CONSOLE
./scripts/config --enable KGDB_LOW_LEVEL_TRAP
./scripts/config --enable KGDB_KDB
./scripts/config --enable KDB_KEYBOARD
./scripts/config --enable GDB_SCRIPTS
./scripts/config --set-val KDB_CONTINUE_CATASTROPHIC 0
make -j33
```

Setup devices for PTYs

To make sure crosvm doesn't create an ordinary file if socat is started
after it, create these named pipes first:

```
mkfifo ~/console_{in,out} ~/kgdb_{in,out}
```

Set up two PTYs: ~/kgdb for the debugger, and ~/serial for the console.
PTY ~/kgdb connects to ~/kgdb{in,out}, and ~/serial connects to
~/console{in,out}

```
socat -d -d -d \
    'PIPE:$HOME/console_out,rdonly=1,nonblock=1,ignoreeof=1!!PIPE:$HOME/console_in,wronly=1' \
    PTY,link=$HOME/serial,ctty,raw,echo=0

socat -d -d -d \
    'PIPE:$HOME/kgdb_out,rdonly=1,nonblock=1,ignoreeof=1!!PIPE:$HOME/kgdb_in,wronly=1' \
    PTY,link=$HOME/kgdb,ctty,raw,echo=0
```

Start crosvm with serial ports pointed at ~/console{in,out} and ~/kgdb{in,out}.

```
cargo run run -p 'init=/bin/sh panic=0 kgdboc=ttyS1,115200 kgdbwait kgdbcon' \
    --serial type=file,path=$HOME/console_out,num=1,console=true,stdin=false,input=$HOME/console_in \
    --serial type=file,path=$HOME/kgdb_out,input=$HOME/kgdb_in,num=2,console=false,stdin=false \
    -r ~/rootfs.img \
    ~/src/linux/arch/x86/boot/bzImage
```

Start GDB

```
gdb vmlinux -ex "target remote /home/dgreid/kgdb"
```

To break into gdb, open up the serial console, mount /proc and send a SysRq

```
minicom -D ~/serial
mount -t proc none /proc
echo g > /proc/sysrq-trigger
```

Change-Id: I18a9c1087d38301df49de08eeae2f8559b03463a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2151856
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-04-19 22:22:46 +00:00
..
boot.rs Serial: add input path overriding stdin for --serial 2020-04-19 22:22:46 +00:00
mini_plugin_template.c add support for accessing debug registers in the plugin process 2018-02-12 22:42:35 -08:00
plugin.policy crosvm: pre-cache answers to plugin get calls 2019-10-31 06:18:09 +00:00
plugin_adder.c allow non-dirty log memory regions from the plugin process 2018-02-12 22:42:37 -08:00
plugin_async_write.c crosvm: add plugin API for async writes 2019-11-06 23:01:15 +00:00
plugin_dirty_log.c allow non-dirty log memory regions from the plugin process 2018-02-12 22:42:37 -08:00
plugin_enable_cap.c crosvm: add handling for hyperv exits 2020-03-05 19:01:24 +00:00
plugin_extensions.c allow plugin to query for KVM extensions 2018-02-12 22:42:40 -08:00
plugin_hint.c crosvm: pre-cache answers to plugin get calls 2019-10-31 06:18:09 +00:00
plugin_ioevent.c allow non-dirty log memory regions from the plugin process 2018-02-12 22:42:37 -08:00
plugin_irqfd.c allow non-dirty log memory regions from the plugin process 2018-02-12 22:42:37 -08:00
plugin_msr_index_list.c plugin: allow retrieving list of supported MSRs 2018-07-31 16:37:06 -07:00
plugin_net_config.c plugin: add missing #include <string.h> in test 2019-10-22 00:09:26 +00:00
plugin_supported_cpuid.c crosvm: support kvm's hyper-v cpuid ioctl 2020-02-20 02:12:01 +00:00
plugin_vcpu_pause.c tests: avoid internal error in pause test 2020-02-19 23:05:34 +00:00
plugin_vm_state.c plugin: allow retrieving and setting VM clock 2019-01-22 21:05:18 -08:00
plugins.rs crosvm: Apply cargo fix for some clippy errors 2020-04-15 18:01:32 +00:00
vfs_crypto.c devices: fs: Support fs crypto ioctls 2019-12-10 03:10:57 +00:00