blob: 3f25cf779d41c4351cff817f96e65575cfabc889 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/ddk/binding.h>
#include <lib/zx/vmo.h>
#include <zxtest/zxtest.h>
#include "coordinator.h"
#include "coordinator_test_utils.h"
#include "driver.h"
#include "multiple_device_test.h"
class AutobindTest : public MultipleDeviceTestCase {
void SetUp() {
ASSERT_NO_FATAL_FAILURE(MultipleDeviceTestCase::SetUp());
auto bind_program = std::make_unique<zx_bind_inst_t[]>(1);
bind_program[0] = BI_MATCH();
auto drv = std::make_unique<Driver>();
drv->name = "always_match";
drv->binding = std::move(bind_program);
drv->binding_size = sizeof(zx_bind_inst_t);
drv->bytecode_version = 1;
drv->libname = "<always_match.so>";
// Borrow a DSO VMO from another driver, because we need an executable VMO (or else duplicating
// it to send to the driver host will fail)
fprintf(stderr, "libname: %s", coordinator().fragment_driver()->libname.c_str());
ASSERT_OK(coordinator().LibnameToVmo(coordinator().fragment_driver()->libname, &drv->dso_vmo));
coordinator().DriverAdded(drv.release(), "0.1");
coordinator_loop()->RunUntilIdle();
}
};
TEST_F(AutobindTest, SkipAutobindFlag) {
size_t device_index;
ASSERT_NO_FATAL_FAILURE(AddDeviceSkipAutobind(platform_bus()->device, "skip_autobind",
ZX_PROTOCOL_PCI, &device_index));
coordinator_loop()->RunUntilIdle();
// If autobind erroneously ran, we'd have a pending message for telling the driver host
ASSERT_FALSE(device(device_index)->HasPendingMessages());
}
TEST_F(AutobindTest, NoSkipAutobindFlag) {
size_t device_index;
ASSERT_NO_FATAL_FAILURE(AddDevice(platform_bus()->device, "no_skip_autobind", ZX_PROTOCOL_PCI,
/* driver */ "", &device_index));
coordinator_loop()->RunUntilIdle();
ASSERT_TRUE(device(device_index)->HasPendingMessages());
}