src/devices/coordinator/composite-device-tests.cc
TEST_F(CompositeTestCase, DevfsNotifications) {
  zx::channel watcher;
  {
    zx::channel remote;
    ASSERT_OK(zx::channel::create(0, &watcher, &remote));
    ASSERT_OK(devfs_watch(coordinator()->root_device()->self, std::move(remote),
                          fuchsia_io_WATCH_MASK_ADDED));
  }

  size_t device_indexes[2];
  uint32_t protocol_id[] = {
      ZX_PROTOCOL_GPIO,
      ZX_PROTOCOL_I2C,
  };
  static_assert(fbl::count_of(protocol_id) == fbl::count_of(device_indexes));

  const char* kCompositeDevName = "composite-dev";
  ASSERT_NO_FATAL_FAILURES(BindCompositeDefineComposite(platform_bus(), protocol_id,
                                                        fbl::count_of(protocol_id),
                                                        nullptr /* props */, 0, kCompositeDevName));
  // Add the devices to construct the composite out of.
  for (size_t i = 0; i < fbl::count_of(device_indexes); ++i) {
    char name[32];
    snprintf(name, sizeof(name), "device-%zu", i);
    ASSERT_NO_FATAL_FAILURES(
        AddDevice(platform_bus(), name, protocol_id[i], "", &device_indexes[i]));
  }

  zx::channel composite_remote_coordinator;
  zx::channel composite_remote_controller;
  size_t component_device_indexes[fbl::count_of(device_indexes)];
  ASSERT_NO_FATAL_FAILURES(CheckCompositeCreation(
      kCompositeDevName, device_indexes, fbl::count_of(device_indexes), component_device_indexes,
      &composite_remote_coordinator, &composite_remote_controller));

  uint8_t msg[fuchsia_io_MAX_FILENAME + 2];
  uint32_t msg_len = 0;
  ASSERT_OK(watcher.read(0, msg, nullptr, sizeof(msg), 0, &msg_len, nullptr));
  ASSERT_EQ(msg_len, 2 + strlen(kCompositeDevName));
  ASSERT_EQ(msg[0], fuchsia_io_WATCH_EVENT_ADDED);
  ASSERT_EQ(msg[1], strlen(kCompositeDevName));
  ASSERT_BYTES_EQ(reinterpret_cast<const uint8_t*>(kCompositeDevName), msg + 2, msg[1]);
}
// Make sure we receive devfs notifications when composite devices appear
Make sure we receive devfs notifications when composite devices appear
Make sure we receive devfs notifications when composite devices appear
TEST_F(CompositeTestCase, DevfsNotifications) {
  zx::channel watcher;
  {
    zx::channel remote;
    ASSERT_OK(zx::channel::create(0, &watcher, &remote));
    ASSERT_OK(devfs_watch(coordinator()->root_device()->self, std::move(remote),
                          fuchsia_io_WATCH_MASK_ADDED));
  }
  size_t device_indexes[2];
  uint32_t protocol_id[] = {
      ZX_PROTOCOL_GPIO,
      ZX_PROTOCOL_I2C,
  };
  static_assert(fbl::count_of(protocol_id) == fbl::count_of(device_indexes));
  const char* kCompositeDevName = "composite-dev";
  ASSERT_NO_FATAL_FAILURES(BindCompositeDefineComposite(platform_bus(), protocol_id,
                                                        fbl::count_of(protocol_id),
                                                        nullptr , 0, kCompositeDevName));
  for (size_t i = 0; i < fbl::count_of(device_indexes); ++i) {
    char name[32];
    snprintf(name, sizeof(name), "device-%zu", i);
    ASSERT_NO_FATAL_FAILURES(
        AddDevice(platform_bus(), name, protocol_id[i], "", &device_indexes[i]));
  }
  zx::channel composite_remote_coordinator;
  zx::channel composite_remote_controller;
  size_t component_device_indexes[fbl::count_of(device_indexes)];
  ASSERT_NO_FATAL_FAILURES(CheckCompositeCreation(
      kCompositeDevName, device_indexes, fbl::count_of(device_indexes), component_device_indexes,
      &composite_remote_coordinator, &composite_remote_controller));
  uint8_t msg[fuchsia_io_MAX_FILENAME + 2];
  uint32_t msg_len = 0;
  ASSERT_OK(watcher.read(0, msg, nullptr, sizeof(msg), 0, &msg_len, nullptr));
  ASSERT_EQ(msg_len, 2 + strlen(kCompositeDevName));
  ASSERT_EQ(msg[0], fuchsia_io_WATCH_EVENT_ADDED);
  ASSERT_EQ(msg[1], strlen(kCompositeDevName));
  ASSERT_BYTES_EQ(reinterpret_cast<const uint8_t*>(kCompositeDevName), msg + 2, msg[1]);
}
TEST_F ( CompositeTestCase , DevfsNotifications ) { zx :: channel watcher ; { zx :: channel remote ; ASSERT_OK ( zx :: channel :: create ( 0 , & watcher , & remote ) ) ; ASSERT_OK ( devfs_watch ( coordinator ( ) -> root_device ( ) -> self , std :: move ( remote ) , fuchsia_io_WATCH_MASK_ADDED ) ) ; } size_t device_indexes [ 2 ] ; uint32_t protocol_id [ ] = { ZX_PROTOCOL_GPIO , ZX_PROTOCOL_I2C , } ; static_assert ( fbl :: count_of ( protocol_id ) == fbl :: count_of ( device_indexes ) ) ; const char * kCompositeDevName = " " ; ASSERT_NO_FATAL_FAILURES ( BindCompositeDefineComposite ( platform_bus ( ) , protocol_id , fbl :: count_of ( protocol_id ) , nullptr , 0 , kCompositeDevName ) ) ; for ( size_t i = 0 ; i < fbl :: count_of ( device_indexes ) ; ++ i ) { char name [ 32 ] ; snprintf ( name , sizeof ( name ) , " " , i ) ; ASSERT_NO_FATAL_FAILURES ( AddDevice ( platform_bus ( ) , name , protocol_id [ i ] , " " , & device_indexes [ i ] ) ) ; } zx :: channel composite_remote_coordinator ; zx :: channel composite_remote_controller ; size_t component_device_indexes [ fbl :: count_of ( device_indexes ) ] ; ASSERT_NO_FATAL_FAILURES ( CheckCompositeCreation ( kCompositeDevName , device_indexes , fbl :: count_of ( device_indexes ) , component_device_indexes , & composite_remote_coordinator , & composite_remote_controller ) ) ; uint8_t msg [ fuchsia_io_MAX_FILENAME + 2 ] ; uint32_t msg_len = 0 ; ASSERT_OK ( watcher . read ( 0 , msg , nullptr , sizeof ( msg ) , 0 , & msg_len , nullptr ) ) ; ASSERT_EQ ( msg_len , 2 + strlen ( kCompositeDevName ) ) ; ASSERT_EQ ( msg [ 0 ] , fuchsia_io_WATCH_EVENT_ADDED ) ; ASSERT_EQ ( msg [ 1 ] , strlen ( kCompositeDevName ) ) ; ASSERT_BYTES_EQ ( reinterpret_cast < const uint8_t * > ( kCompositeDevName ) , msg + 2 , msg [ 1 ] ) ; }
Make sure we receive devfs notifications when composite devices appear
Make sure we receive devfs notifications when composite devices appear
/* props */ // Add the devices to construct the composite out of.