Skip to content

Commit

Permalink
[zxcrypt] Fix tests to use fuchsia_device_ControllerRebind
Browse files Browse the repository at this point in the history
Currently the Rebind api in zxcrypt tests use the following sequence:

1. block rebind fidl api which will call device_rebind
libdriver api.
2. device_rebind schedules unbind on all the children but
does not guarantee whether the device is actually unbound and bound again.
3. The tests then issue the Bind device controller api to bind the driver again.

In the current scenario, depending on the timing of these operations, #3
will fail with ZX_ERR_ALREADY_BOUND if #2 is still in the process of unbinding.
In the case where #2 actually completes unbind #3 will succeed.

This change does the following.
1. It uses the new rebind device controller api, which takes care of
unbind and bind synchronously.
see https://fuchsia-review.googlesource.com/c/fuchsia/+/334253
2. Because we are using the rebind api, we do not need the additional
bind
3. The Rebind api has a strict requirement of clients closing the
children before callign the rebind on the parent. Made sure about that
before calling the rebind api.

Test: /system/test/sys/zxcrypt-test
Bug:40740

Change-Id: Ic1a610697343be71889f4e053f34ca0b098ddefa
  • Loading branch information
swathi540 authored and CQ bot account: commit-bot@chromium.org committed Nov 8, 2019
1 parent cd476ce commit 9453d39
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions zircon/system/utest/zxcrypt/test-device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,24 @@ bool TestDevice::Rebind() {
zxcrypt_.reset();
fvm_part_.reset();

ASSERT_EQ(ramdisk_rebind(ramdisk_), ZX_OK);
if (strlen(fvm_part_path_) != 0) {
// We need to explicitly rebind FVM here, since now that we're not
// relying on the system-wide block-watcher, the driver won't rebind by
// itself.
ASSERT_TRUE(BindFvmDriver());
fdio_t* io = fdio_unsafe_fd_to_io(ramdisk_get_block_fd(ramdisk_));
ASSERT_NONNULL(io);
zx_status_t call_status;
zx_status_t status = fuchsia_device_ControllerRebind(fdio_unsafe_borrow_channel(io), kFvmDriver,
strlen(kFvmDriver), &call_status);
fdio_unsafe_release(io);
ASSERT_OK(status);
ASSERT_OK(call_status);
fbl::unique_fd dev_root = devfs_root();
ASSERT_EQ(devmgr_integration_test::RecursiveWaitForFile(dev_root, fvm_part_path_, &fvm_part_),
ZX_OK);
parent_caller_.reset(fvm_part_.get());
} else {
ASSERT_EQ(ramdisk_rebind(ramdisk_), ZX_OK);
parent_caller_.reset(ramdisk_get_block_fd(ramdisk_));
}
ASSERT_TRUE(Connect());
Expand Down

0 comments on commit 9453d39

Please sign in to comment.