src/bringup/bin/bootsvc/integration_test/integration-test.cc
// Make sure the fuchsia.boot.Items service works
Make sure the fuchsia.boot.Items service works
Make sure the fuchsia . boot . Items service works
TEST(BootsvcIntegrationTest, BootItems) {
  zx::channel local, remote;
  zx_status_t status = zx::channel::create(0, &local, &remote);
  ASSERT_EQ(ZX_OK, status);
  status = fdio_service_connect(kItemsPath, remote.release());
  ASSERT_EQ(ZX_OK, status);
  uint32_t types[] = {
      ZBI_TYPE_CRASHLOG,
      ZBI_TYPE_PLATFORM_ID,
      ZBI_TYPE_DRV_BOARD_INFO,
      ZBI_TYPE_STORAGE_RAMDISK,
      ZBI_TYPE_SERIAL_NUMBER,
  };
  for (uint32_t type : types) {
    zx::vmo payload;
    uint32_t length;
    status = fuchsia_boot_ItemsGet(local.get(), type, 0, payload.reset_and_get_address(), &length);
    ASSERT_EQ(ZX_OK, status);
#ifdef __x64_64__
    if (type == ZBI_TYPE_CRASHLOG) {
      ASSERT_TRUE(payload.is_valid());
      fbl::String path = fbl::StringPrintf("/boot/%s", bootsvc::kLastPanicFilePath);
      fbl::unique_fd fd(open(path.data(), O_RDONLY));
      ASSERT_TRUE(fd.is_valid());
      auto file_buf = std::make_unique<uint8_t[]>(length);
      auto payload_buf = std::make_unique<uint8_t[]>(length);
      ASSERT_EQ(length, read(fd.get(), file_buf.get(), length));
      ASSERT_EQ(ZX_OK, payload.read(payload_buf.get(), 0, length));
      ASSERT_BYTES_EQ(file_buf.get(), payload_buf.get(), length, "");
    }
#endif
    if (type == ZBI_TYPE_SERIAL_NUMBER) {
      ASSERT_TRUE(payload.is_valid());
      ASSERT_GE(length, 0);
      std::string serial_no(length, '\0');
      ASSERT_OK(payload.read(serial_no.data(), 0, length));
      EXPECT_EQ(length, serial_no.size());
    }
  }
}
TEST ( BootsvcIntegrationTest , BootItems ) { zx :: channel local , remote ; zx_status_t status = zx :: channel :: create ( 0 , & local , & remote ) ; ASSERT_EQ ( ZX_OK , status ) ; status = fdio_service_connect ( kItemsPath , remote . release ( ) ) ; ASSERT_EQ ( ZX_OK , status ) ; uint32_t types [ ] = { ZBI_TYPE_CRASHLOG , ZBI_TYPE_PLATFORM_ID , ZBI_TYPE_DRV_BOARD_INFO , ZBI_TYPE_STORAGE_RAMDISK , ZBI_TYPE_SERIAL_NUMBER , } ; for ( uint32_t type : types ) { zx :: vmo payload ; uint32_t length ; status = fuchsia_boot_ItemsGet ( local . get ( ) , type , 0 , payload . reset_and_get_address ( ) , & length ) ; ASSERT_EQ ( ZX_OK , status ) ; #ifdef __x64_64__ if ( type == ZBI_TYPE_CRASHLOG ) { ASSERT_TRUE ( payload . is_valid ( ) ) ; fbl :: String path = fbl :: StringPrintf ( " " , bootsvc :: kLastPanicFilePath ) ; fbl :: unique_fd fd ( open ( path . data ( ) , O_RDONLY ) ) ; ASSERT_TRUE ( fd . is_valid ( ) ) ; auto file_buf = std :: make_unique < uint8_t [ ] > ( length ) ; auto payload_buf = std :: make_unique < uint8_t [ ] > ( length ) ; ASSERT_EQ ( length , read ( fd . get ( ) , file_buf . get ( ) , length ) ) ; ASSERT_EQ ( ZX_OK , payload . read ( payload_buf . get ( ) , 0 , length ) ) ; ASSERT_BYTES_EQ ( file_buf . get ( ) , payload_buf . get ( ) , length , " " ) ; } #endif if ( type == ZBI_TYPE_SERIAL_NUMBER ) { ASSERT_TRUE ( payload . is_valid ( ) ) ; ASSERT_GE ( length , 0 ) ; std :: string serial_no ( length , ' \0 ' ) ; ASSERT_OK ( payload . read ( serial_no . data ( ) , 0 , length ) ) ; EXPECT_EQ ( length , serial_no . size ( ) ) ; } } }
Make sure the fuchsia.boot.Items service works
Make sure the fuchsia . boot . Items service works
// Check that we can open the fuchsia.boot.Items service. // Check that we can get the following boot item types. // clang-format off // clang-format on // (The following is only implemented on x64 at this time, so we only test // it there.) // If we see a ZBI_TYPE_CRASHLOG item, then the kernel should have // translated it into a VMO file, and bootsvc should have put it at the // path below.