Commit graph

74 commits

Author SHA1 Message Date
Zihan Chen
9151130e4d e2e_tests: Update guest kernel config and initramfs
As I'm tinkering with the first real benchmark (pgbench), a few
kernel configs are found to be missing to support psql to run in
e2e test guests. Among with previously added but not uprev-ed
KConfig changes, an uprev is prepared.

Initramfs script is also updated to match distribution behavior.

TEST=locally can pass postgres e2e benchmark

BUG=b:257303497

Change-Id: I69b44e3156d3296cbef7fa41804e8b54e4aaf0ab
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4761848
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-08-11 20:29:24 +00:00
Daniel Verkamp
dfbdd75de9 devices: virtio: use mass storage class for block devices
This is slightly different than the PCI class code used by QEMU, which
is 0x0100 (mass storage, SCSI controller). We instead use 0x0180 to
indicate a mass storage controller with a non-standardized/vendor
specific programming interface (ref: PCI Code and ID Assignment
Specification).

SCSI isn't really accurate for a virtio-blk device (our implementation
does not accept SCSI commands at all, although there is a pre-virtio-1.0
option for sending them).

The Linux virtio-blk guest driver does not care about the PCI class code
either way (it only matches on the PCI vendor+device ID range assigned
for virtio devices and uses the virtio-specific device type to
distinguish between e.g. virtio-blk and virtio-scsi), so it should be
fine to use the Other/Vendor-specific subclass code.

lspci diff:
-00:04.0 Unclassified device [00ff]: Red Hat, Inc. Virtio block device [1af4:1042] (rev 01)
+00:04.0 Mass storage controller [0180]: Red Hat, Inc. Virtio block device [1af4:1042] (rev 01)

BUG=None
TEST=lspci -vvvnnn # "Mass storage controller" for block devices

Change-Id: I7958dbb1c197fe52afb386ebb9afa9f5107a56cd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4740712
Reviewed-by: Morg <morg@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-08-09 17:58:26 +00:00
Zihan Chen
594c215bed e2e_tests: Add initramfs definition and documentation
A light weight, purely static initramfs has been added to allow
running tests that are slightly more complex. This also allow
us to inject e2e_test components (e.g. delegate) into pre-built
containers from 3rd-party sources.

TEST=VM can boot from initramfs produced by make

Change-Id: Id27faa61a54bd151187dc6231d996efaaa6ae890
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4718770
Commit-Queue: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-08-04 19:43:15 +00:00
Elie Kheirallah
6eeed23a56 devices: enable Error return when sleep/wake/snapshot fail
Devices currently printed errors and returned Ok when they failed, and
that was because errors were frequently expected.
We are at a stage where the basic devices all function properly and no
longer need to return Ok, we should hard fail if an error occurs.

BUG=b:253514925
TEST=presubmit

Change-Id: Id33c1dea603a471d815755495a269e4276a8ace8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4684441
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-08-01 01:19:59 +00:00
Shintaro Kawamura
b83a5989d9 e2e_tests: abort testing as soon as crosvm exits on booting
If crosvm fails at the early stage of setup, opening to_guest fifo
blocks forever and it takes 20 seconds to timeout.

Opening to_guest fifo should be wrapped by timeout as well as
from_guest.

Check the crosvm process status periodically to abort testing earlier.

With this change, the total e2etest execution for failure case is
reduced to 0.2s from 20s.

There is better way without panicking on timeout; interrupt the blocked
open(2) for fifo by pthread_kill(). However it is too much since this is
just a test. panicking is welcome.

BUG=b:293383846
TEST=./tools/run_tests2 --dut=vm -E 'rdeps(e2e_tests)'

Change-Id: I8735a77201f930162113efa98d655f77be8d259d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4721027
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-07-28 04:27:26 +00:00
Frederick Mayle
dc3a9018e8 base: handle EINTR in Tube recv methods
`peek_size` blocks until there is data available, so it is actually more
likely to see an EINTR than the `recv_with_fds` call that follows it.

Before, the following command failed had 5 flakes, 3 of which were
clearly caused by EINTR when recving on a tube. After, I saw no flakes.

    ./tools/run_tests --dut=vm --filter-expr="test(boot_test_vm_uring)" --repetitions 100

BUG=b:293463612

Change-Id: Ie0471a46be11d67f38d4d0a5a4793e5ca2fc1633
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4727022
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-07-28 01:30:27 +00:00
Dennis Kempin
4095c81efb Disable flaky e2e test: boot_test_vm_uring
BUG=b:293463612
TEST=CQ

Change-Id: I2ff3cf4fee109516f7f87c69058face843ac2925
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4726062
Auto-Submit: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-07-27 17:52:22 +00:00
Wang Ningyuan
bbd3bc3042 e2e_tests: Remove redundant run script
e2e_tests/run script was used as a convenience tool, and is superseded
by tools/run_tests2.

BUG=NONE
TEST=tools/presubmit

Change-Id: I52ea9d3718d005fd64506c6586624a07da66db85
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4705407
Commit-Queue: Ningyuan Wang <ningyuan@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-07-27 04:35:26 +00:00
Wang Ningyuan
6b1a35298c crosvm: virtio-net device hotplug
This CL implements PCI hotplug feature for virtio-net device. The
feature is controlled by pci-hotplug feature flag and pci-hotplug-slots
runtime flag. No behavior change to crosvm unless pci-hotplug-slots flag
is set to a nonzero value.

BUG=b:243767476
TEST=tools/presubmit
TEST=e2e_test::tap_hotplug for TAP device hotplug and removal
TEST=manual test for TAP device hotplug and removal with swap

Change-Id: I5a60314293ef8a27981d7b550a61822491c254bb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4473610
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Shin Kawamura <kawasin@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Ningyuan Wang <ningyuan@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Jason Iman <jasongustaman@chromium.org>
2023-07-27 04:35:26 +00:00
Daniel Verkamp
4bd4358aa4 Remove all remaining --features=direct code
BUG=b:279663365
TEST=tools/dev_container tools/presubmit

Change-Id: Iaa0b8176a54982044137b112039bf04f1e183c4e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4713506
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Grzegorz Jaszczyk <jaszczyk@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dmytro Maluka <dmy@semihalf.com>
2023-07-25 17:55:10 +00:00
Zihan Chen
8b39118abe e2e_tests: Add test to verify booting custom artifacts work
A hand-made initramfs and an updated kernel that supports initramfs
are uploaded alongside this CL. This test is added for the sole
purpose of letting the CQ to continously verify specifying custom
artifacts in e2e_tests is not broken. At its current speed, it's
not the slowest e2e tests we have.

TEST=CQ

BUG=b:257303497

Change-Id: I19baf495ce8af4805f76f16a5f831f86959d41a8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4697698
Commit-Queue: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-07-21 00:24:28 +00:00
Frederick Mayle
79b4364ac6 e2e_tests: remove suspend_resume test disclaimer
The simple VM in the test is fully supported now.

Change-Id: Iec0f88cc15bc42e4b069512813732df8c17cdbbd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4684831
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-07-14 21:46:53 +00:00
Elie Kheirallah
b1dee44a4b devices: vsock: add snapshot/restore support
Add snapshot restore to vsock device.

BUG=b:267691230
TEST=presubmit, e2e_tests
TEST=boot VM with vsock, snapshot, boot restored VM with vsock.

Change-Id: I3ae0c5e5099645f9a4ded6a751bb2df063c0b8e9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4610692
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-07-11 22:07:40 +00:00
Elie Kheirallah
2e707e1e65 e2e_tests: Fix snapshot/restore tests
Following this CL (https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4602373),
attempting a restore while a VM is running will cause the restore to
fail and the tests to crash as a result.
Change the tests to start a new VM with the previous snapshot config to
validate that the VM restored properly.
Enable suspend/resume tests.

BUG=N/A
TEST=presubmit + e2e_tests

Change-Id: Ifdd63fee7953cd1b7be208a093802da388322c81
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4616833
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Richard Zhang <rizhang@google.com>
2023-06-27 20:27:01 +00:00
Elie Kheirallah
5a91dd8d2b vm_control: sleep/wake devices when VM gets suspended/resumed
Currently commands Suspend and Resume to the VM will only sleep the
Vcpus but not devices. This results in a partial suspend/resume since
devices can still be running and potentially modifying the env (filling
up buffers, modifying variables). The aim of this CL is to put the
devices to sleep when the VM is put in suspended mode, and to wake the
devices when the VM goes back to resumed mode.
Added new flag to `suspend` and `resume` commands: `--full`
which does a full VM suspend.
Added new VmRequest: SuspendVm, ResumeVm.
Added suspend/resume test that also suspends/resumes devices, thus
doing a Full VM suspend/resume.
Also now tracking the state of devices before sleep, just like Vcpus

BUG=N/A
TEST=presubmit, e2e_tests
TEST=boot a VM, suspend, resume

Change-Id: Ia13fbdf7bb6765dd20bd3c67af5212e9c842b824
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4616827
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-06-27 19:31:41 +00:00
Richard Zhang
dc8d88fd80 e2e_test: virtio_pci_device: Add test for cold restore
Currently, cmds cannot be sent to the guest on cold restore
boot, so some
investigation is needed. However, this still provides a useful coverage
test for cold restoring.

This CL also updates VirtioPciDevice so that cold restore won't break
for vhost user devices by returning early for sleep
and wake if the device has not been activated.

BUG=b:280607404
TEST=snapshot_vhost_user_root test passes

Change-Id: I28a12dbb6f0f009b8253c5f679dd9963b3fd12b4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4609418
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2023-06-20 17:30:04 +00:00
Zihan Chen
8f5225c042 e2e_tests: Allow TestVM to run with custom artifacts
TestVM can now be configured to run on specific local or remote
kernel, initrd and rootfs images. This allow us to broaden e2e test
coverages to more diverse use cases.

TESTED=Relevant test case passed CQ and locally

BUG=b:257303497
BUG=b:181105093

Change-Id: I1270a189105af89259371f54b7df227b3efae380
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4451468
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-06-14 22:22:38 +00:00
Richard Zhang
1a0a8c26e2 vhost-user: Implement snapshot for device process handler
This CL also:
* re-hooked up wake and sleep calls
* Introduce VirtioDevice::is_vhost_user so we can easily branch logic
  between vhost user and non-vhost user devices
* Fixed a conflict resolution mistake where "wake" would stop non-queue
  workers

BUG=b:280607404
TEST=ran snapshot_vhost_user_root e2e_tests

Change-Id: I5abee92a0445c9575c0775502930ea16ead2fb83
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4607767
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-06-14 21:50:13 +00:00
Richard Zhang
2ef32ca115 virtio_pci_device: Implement snapshot
* Extended e2e_test to check for device name in snapshot file.
* Ignores snapshotting if iommu is present.
* Does not include snapshotting for individual device implementations.

TEST=e2e_tests and presubmits
BUG=b:280608177

Change-Id: Iecb5e44b39f71bbf5d76d09d6765710ba4953537
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4545952
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-06-07 19:01:37 +00:00
Zihan Chen
8d49ca4d61 e2e_tests: Add cgroup, unix socket, virtiofs DAX support to guest
cgroup and unix socket support are mandatory for booting with
systemd. virtiofs DAX is supported by crosvm and should be tested.

TEST=CQ
TEST=new prebuilt kernel can boot debian userspace to normal shell

Change-Id: I0b4a969f31056e777526f42b613abb66eaaf18c0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4582848
Auto-Submit: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-06-01 21:56:52 +00:00
Richard Zhang
882890f47a vhost-user: return the active Queue from stop_queue
Most of this change involves wrapping the Queue object inside an
Rc<RefCell<>>, Arc<Mutex<>>, or Rc<AsyncMutex<>>.

This is necessary for getting device suspend and resume to work.

Bug=280607608
TEST=presubmits

Change-Id: I7e3680aea2927c1fc9d971f27ebbb09ec308a634
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4545603
Commit-Queue: Richard Zhang <rizhang@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-05-19 17:56:12 +00:00
Takaya Saeki
4131e80c89 e2e_tests: fix small bugs in run_guest.sh
run_guest.sh lacks the shebang, and has a small bug of missing quotes.
This commit fixes them.

BUG=None
TEST=Confirmed that "$@" works as expected by checking the passed
arguments.

Change-Id: Ic0d5e8676b206be15b1b2f09b3b9c6de2b9d2fb3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4537378
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Takaya Saeki <takayas@chromium.org>
2023-05-17 02:56:31 +00:00
Frederick Mayle
c14d6885eb devices: virtio: block: fix kick event handling when using io_uring
There is a probably a more elegant solution where `EventAsync` provides
a `futures::stream::Stream` interface, then, instead of using
`FuturesUnordered`, we call `StreamExt::for_each_concurrent` to perform
the `process_one_chain` work.

BUG=b:282108854

Change-Id: Ic5af78e28e7ada5072790dab6af87dea796442d4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4534425
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-15 23:12:04 +00:00
Richard Zhang
84ab00303e e2e_tests: snapshot vhost user tests
This test will spin up block and net vhost user device processes. This
test will be used as a smoke test and won't run during presubmits

Also refactor functions that can be shared into the fixture crate.

BUG=b:281115884
TEST=ran test. Also verified messages get sent to vhost user devices

Change-Id: Ic7e78a8ed71290fd3c42f9e15bf59a238623c49e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4519650
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
2023-05-15 21:11:42 +00:00
Dylan Reid
1ae4e549e5 tests: Add riscv imports where needed
In working towards enabling unit tests, import the correct arch defines
for riscv64 where needed.

TEST=from dev container run:
```
cargo nextest run --workspace --no-default-features \
--exclude tpm2 \
--exclude tpm2-sys \
--exclude libvda \
--exclude libva \
--exclude ffmpeg \
--exclude vmm_vhost \
--exclude system_api \
--exclude gpu_display \
--color=always \
--no-run \
--target riscv64gc-unknown-linux-gnu
```

Change-Id: Ia7853de8ee0a11a5fdb716546a146f892229b0cb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4501091
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-05-03 16:50:25 +00:00
Daniel Verkamp
0bea3a3376 Cargo.toml: remove crosvm-direct binary
Remove the extra [[bin]] from Cargo.toml, as it is no longer used by the
chromeos-base/crosvm ebuild.

The "direct" feature is kept for now, since some of the functionality
behind that flag may still be useful (and should be moved to separate
features rather than "direct" eventually).

BUG=b:276993009
TEST=cargo build
TEST=tools/dev_container tools/presubmit

Change-Id: I78269d94913a216ebfb7f22ddc58d9cfdb6a6791
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4436629
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-17 23:54:48 +00:00
Elie Kheirallah
c2d0e8506b e2e_tests: Specify e2e_tests package for nextest run
currently running e2e_tests/run will run tests from root, and not
e2e_tests. This change specifies the package e2e_tests.

BUG=N/A
TEST=./tools/dev_container e2e_tests/run

Change-Id: I7a11d43045ab5809c9034b948c6a00db4b81ac84
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4416066
Auto-Submit: Elie Kheirallah <khei@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-04-11 23:53:01 +00:00
Daniel Verkamp
2855eaecb5 e2e_tests: remove unnecessary reference
Fixes clippy warning in Rust 1.68.

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: I4482f26ac58de31931b82da5962899afc90f5377
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4391105
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-04-11 20:44:34 +00:00
Norman Bintang
8bbe844ef7 e2e_tests: snd: Increase aplay buffer size in do_playback
Change buffer size from 2048 to 48000 bytes, and period size from
1024 to 12000 bytes. 12000 is taken from 1/4 * 48000. By default,
aplay use period size equals to 1/4 of buffer size.

There are failures that result from underruns. As the objective of this
test is to ensure correctness, using a larger buffer size to avoid
underruns is acceptable.

BUG=b:233542268
TEST=./tools/run_tests2 --dut=host

Change-Id: I5e921f7c7528d11aabd3c998575ade4c3a9a7fb9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4411220
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Norman Bintang <normanbt@chromium.org>
2023-04-11 02:57:25 +00:00
Changyuan Lyu
757e70339c device: fs/9p: add options to specify uid and gid
New options uid and gid are added to the virtiofs/virito9p device to
allow specifying the uid/gid of the virtiofs/virito9p process in its
own user namespace created by minijail.

With these options:
* An identity mapping of the current host UID/GID can be set up
  between the host and the VM.
* The crosvm process does not need CAP_SETUID/CAP_SETGID.

Background: go/crosvm-virtiofs-transparent.
If the crosvm process has no CAP_SETGID/CAP_SETUID, the
uid_map/gid_map for the virtiofs process is limited by the kernel
function new_idmap_permitted() in linux/kernel/user_namespace.c.
Say the crosvm process UID is 5000, the uid_map has to be of the form
`<uid inside> 5000 1`. Currently crosvm requires `<uid inside>` to be
0.

These two options are useful when
* crosvm cannot get capabilities,
* there is only one user in the VM accessing the shared files so
  changing uid/gid would not happen,
* Only files owned by the current host user (say 5000) are shared to
  the VM, and these files need to be owned by the same uid (5000)
  in the VM.

If a user use "uid=5000" and "uidmap=5000 5000 1", the device
process changes its uid to 5000 before starting serving requests.
Now we have an identity mapping of user 5000 inside and outside the
device's minijail sandbox, and also inside and outside the VM.

If multiple users want to access the shared
file, gid/uid options are useless. It's be better to create a new
user namespace and give CAP_SETUID/CAP_SETGID to the crosvm.

TEST=cargo test; cargo test -p devices
TEST=cargo test --package e2e_tests --test fs
BUG=b:273346109

Change-Id: I1c59530e1e8bc968a54f40633c444eb64c700e55
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4299943
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Changyuan Lyu <changyuanl@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
2023-04-10 18:47:41 +00:00
Daniel Verkamp
083dcf75f4 tree-wide: apply nightly rustfmt
BUG=None
TEST=tools/fmt --nightly

Change-Id: Ifb08dd55ccf2a74ef739d7517a64970d24a82405
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4375640
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-03-27 21:30:45 +00:00
Alexandre Courbot
23fa0fe784 e2e_tests: add "crosvm devices --vsock" integration tests
Now that the devices command supports the vsock device, add integration
tests for it.

BUG=b:217480043
TEST=cargo test -p e2e_tests --test vsock

Change-Id: I21e300b24c3fdec3a0770ff321456168ed1434b8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4337341
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Ryuichiro Chiba <chibar@chromium.org>
2023-03-22 09:23:13 +00:00
Norman Bintang
ceb7064647 e2e_tests: Add virtio-snd test
BUG=b:233542268
TEST=./tools/run_tests2 --dut=host

Change-Id: Icf429168c5bc470fa1f8cc5b6ea396f2d0b79563
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4306261
Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org>
Commit-Queue: Norman Bintang <normanbt@chromium.org>
2023-03-21 07:46:05 +00:00
Alexandre Courbot
e03fcd0bef e2e_tests: add vhost-user vsock tests
Since we are going to refactor the vhost-user vsock device, add some
integration tests to make sure we don't break anything.

BUG=b:217480043
TEST=cargo test -p e2e_tests --test vsock

Change-Id: I2a8eaa6c74f8d86aa164ebd92543fe280bc7906c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4337340
Reviewed-by: Ryuichiro Chiba <chibar@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-03-16 05:14:34 +00:00
Dennis Kempin
b96ba4c8be e2e_tests: Switch to custom kernel config and debian rootfs
We switch from the chromeos-5.10 kernel with crostini configs
to a stripped down config building the mainline 6.1 branch.

This allows us more control over the guest kernel for testing
and significantly speeds up e2e tests (~4s -> 1.2s for all
tests run with nextest).

The rootfs is switched to Debian as that's what we use elsewhere
which makes this easier to maintain.

BUG=b:256652981
TEST=presubmit

Change-Id: Ib3897b8dbf3391eefdb1eedb69ec7555f4c77344
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4326888
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-03-15 21:09:39 +00:00
Dennis Kempin
6392b09a21 e2e_tests: Use virtio-console to speed up tests
Running all tests on a local workstation would take ~4-5s currently,
switching to virtio-console will significantly speed up the VM boot
and reduces the runtime to ~2-3s.

BUG=b:256652981
TEST=presubmit

Change-Id: I4ee87c9be4955d9dd89f30a72c91a1af96edf862
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4312801
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-03-08 23:16:38 +00:00
Dennis Kempin
2bc7c926cc e2e_tests: retry instead of thread::sleep in vhost tests
Adds a few utilities to that allow us to retry closures and
wait for child processes with timeouts.
These are used to repeatedly try reading from vsocks instead of
sleeping to wait for them to be available.
This is faster and more reliable.

BUG=b:256652981
TEST=presubmit

Change-Id: I2a4c74e8c1f9b8413f7afa22cce8248e74d07092
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4316911
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Ryuichiro Chiba <chibar@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-03-08 23:10:06 +00:00
Zihan Chen
9c9fbdc24c e2e_tests: Add strace and log settings to fixture
This allowes fixture to read these settings from env and thus allow
scripts to pass in desired testing configs without requiring a
custom-built rust test harness.
Test command below run in dev container with strace package installed
can produce debug level logs and separate per-process strace results
in designated files.

TEST=CROSVM_CARGO_TEST_E2E_WRAPPER_CMD="strace -ff --output=/workspace/stracetest" CROSVM_CARGO_TEST_LOG_LEVEL_DEBUG=1 CROSVM_CARGO_TEST_LOG_FILE=/workspace/logtest.log ./tools/bench boot

BUG=b:258316090

Change-Id: I5b0eb373802722075242e33027585d702da77e59
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4297485
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-03-02 22:07:33 +00:00
Zihan Chen
2524a185b6 e2e_tests: Restructure for initial benchmark support
- Restructured to share fixture between tests and benches
- Add bench script to run benchmark target

BUG=b:257303497
BUG=b:258316090
TEST=cargo clean && ./tools/build_release && ./tools/bench boot

Change-Id: I0ea3295839889e570032e03eec033d99b7b8e553
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4064114
Commit-Queue: Zihan Chen <zihanchen@google.com>
Auto-Submit: Zihan Chen <zihanchen@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-02-23 22:11:48 +00:00
Dennis Kempin
a54a5bc81a e2e_tests: Make prebuilt version part of the file name
This prevents us from using an older version of the image if a newer
version is specified.

BUG=b:269137600
TEST=run_tests

Change-Id: I9962feebb13c69b9fb9c5fb0fba64f265d46d08e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4277626
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-02-21 23:21:45 +00:00
Dennis Kempin
2b30441772 e2e_tests: Add sleep after creating vhost user backend
If crosvm launches quickly after starting the backend, it may
find that the device socket does not exist yet. This causes
occasional test failures.

Adding a sleep stabilizes the test a little, but should be replaced
with a proper wait loop while checking for the device socket to
become available.

BUG=b:269174700
TEST=./tools/run_tests --dut=host -E"package(e2e_tests)" \
  --no-unit-tests --repetitions 10

Change-Id: Ifaba81a5fb3628d07793b1310229de4a43d2a7b6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4258306
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2023-02-21 22:54:30 +00:00
Dennis Kempin
b2ec37b33f e2e_tests: Do not capture crosvm stdout
This was useful since the libtest harness could not capture stdout
for subprocesses and we would get very noisy test results.

However, with nextest, each test is run in a separate process and
will be hidden unless the test fails.

The test log will then contain an host and guest messages interleaved,
which greatly helps debugging.

Also switches the main serial output from syslog (which prints to
stderr) to stdout.

BUG=None
TEST=None

Change-Id: Ie3b377aeaef3ef575f9232430ac7392c83060d98
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4256511
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-02-21 22:54:30 +00:00
Dennis Kempin
a5312895e7 e2e_tests: Extend exec_in_guest functionality
This is a refactoring that adds the following functionality to
exec_in_guest:

- Receive exit codes from executed commands and by default check
  if they are zero.
- Add timeouts to all communication with the guest
- Allow commands to be executed asynchronously, to allow the test
  code to perform actions while the guest command is running.
- Add anyhow error handling with contexts for more helpful error
  messages

BUG=b:269137600
BUG=b:268539201

Change-Id: Ic069c3ccae363790a124db10a0db76e4ad4384c3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4251717
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Zihan Chen <zihanchen@google.com>
2023-02-21 22:54:30 +00:00
Frederick Mayle
3379ab7e92 e2e: disable suspend_resume tests
They are flaky and that is expected since the feature is incomplete.

BUG=b:269174979

Change-Id: I929e822b7f81742a5dba0fef637d6143f18302b1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4256510
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-02-15 19:23:01 +00:00
Keiichi Watanabe
60f7474799 e2e_tests: Add virtiofs test
BUG=b:269068100
TEST=./run in e2e_tests

Change-Id: I637a6362ebc846e773fbbc0fe8223044f9e0839d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4040654
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2023-02-14 02:09:35 +00:00
Daniel Verkamp
c5bcdf29af cmdline: move restore command under snapshot
The previous command line interface had two top-level commands related
to snapshots, each with only one subcommand:

- crosvm snapshot take <snapshot-path> <control-socket>
- crosvm restore apply <snapshot-path> <control-socket>

This patch moves the `restore apply` command under `snapshot` to make it
easier to find and less redundant to have two levels of commands:

- crosvm snapshot take <snapshot-path> <control-socket>
- crosvm snapshot restore <snapshot-path> <control-socket>

The restore command is also more discoverable since it is listed in the
help for the snapshot command.

BUG=b:232437513
TEST=crosvm snapshot take /tmp/snapshot /tmp/crosvm
TEST=crosvm snapshot restore /tmp/snapshot /tmp/crosvm
TEST=cargo test -p e2e_tests suspend_resume -- --test-threads=1

Change-Id: I9c3c8662fba7631327829a118f6b53b297b2d806
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4227254
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-02-09 01:52:36 +00:00
Zihan Chen
28ce4e5423 crosvm: Uprev rust toolchain and dev container
- Rust toolchain is updated to 1.65.0
- Catapult dashboard upload tool is added to dev_container
- Bindgen is updated to latest version to support custom derive
- Derive Eq when PartialEq is derived as required by new Clippy

TEST=CQ, bindgen-all-the-things

FIXED=b:260784028
BUG=b:257303497

Change-Id: I2034cd09e0aed84d4e9b30f2e85d84d94a442ea4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4228427
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-02-08 20:26:30 +00:00
Dennis Kempin
c2ec26d7e8 e2e_tests: Clarify prebuilt download logs
This helps identify a potential deadlock by the NamedLock.

BUG=None
TEST=CQ

Change-Id: I0ef9606b6b5e36a1564ff3fee7720ae013365cc7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4228215
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-02-07 20:17:23 +00:00
Frederick Mayle
19f4b1243c devices: snapshot and restore for guest memory
`crosvm snapshot take ...` will write the contents of guest memory to a
file and `crosvm restore apply ...` will read that file to overwrite
guest memory.

To start with, the file is chosen by adding a ".mem" extension to the
snapshot file path. We should consider a better approach in the future,
maybe put them both in a tar file or have the user supply a directory
instead of a file path.

BUG=b:266514791

Change-Id: Ic05f94223fb74674bd57dcd2f848055b31eb5fdc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4215313
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-02-06 22:44:17 +00:00
Frederick Mayle
1afdc4d908 e2e_tests: suspend_resume: consume exec_command_async response
Without this, subsequent commands would fail.

BUG=b:232437513

Change-Id: Ibbe105e0e80b317cc3cd32ddd184892e1a9ab613
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4214944
Reviewed-by: Elie Kheirallah <khei@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-02-02 20:38:30 +00:00