src/virtualization/lib/guest_interaction/test/server_integration_test.cc
// Create a file large enough that it needs to be fragmented when it is sent
// to and received from the guest and then send it to and retrieve it from the
// guest.
// TODO(fxbug.dev/43569): Flaky.
Create a file large enough that it needs to be fragmented when it is sent
to and received from the guest and then send it to and retrieve it from the
guest.
Create a file large enough that it needs to be fragmented when it is sent to and received from the guest and then send it to and retrieve it from the guest .
TEST_F(GuestInteractionTest, DISABLED_GrpcPutGetTest) {
  CreateEnvironment();
  LaunchDebianGuest();
  fuchsia::virtualization::HostVsockEndpointPtr ep;
  realm_->GetHostVsockEndpoint(ep.NewRequest());
  zx::socket local_socket, remote_socket;
  zx_status_t status = zx::socket::create(ZX_SOCKET_STREAM, &local_socket, &remote_socket);
  ASSERT_EQ(status, ZX_OK);
  bool connect_complete = false;
  ep->Connect(cid_, GUEST_INTERACTION_PORT, std::move(remote_socket),
              [&connect_complete, &status](zx_status_t connect_status) {
                status = connect_status;
                connect_complete = true;
              });
  RunLoopUntil([&connect_complete] { return connect_complete; });
  ASSERT_EQ(status, ZX_OK);
  int32_t vsock_fd = ConvertSocketToNonBlockingFd(std::move(local_socket));
  ASSERT_GE(vsock_fd, 0);
  ClientImpl<PosixPlatform> client(vsock_fd);
  char test_file[] = "/data/test_file.txt";
  char guest_destination[] = "/root/new/directory/test_file.txt";
  char host_verification_file[] = "/data/verification_file.txt";
  std::string file_contents;
  for (int i = 0; i < 2 * CHUNK_SIZE; i++) {
    file_contents.push_back(i % ('z' - 'A') + 'A');
  }
  fbl::unique_fd fd = fbl::unique_fd(open(test_file, O_WRONLY | O_TRUNC | O_CREAT));
  uint32_t bytes_written = 0;
  while (bytes_written < file_contents.size()) {
    ssize_t write_size = write(fd.get(), file_contents.c_str() + bytes_written,
                               file_contents.size() - bytes_written);
    ASSERT_TRUE(write_size > 0);
    bytes_written += write_size;
  }
  zx::channel put_local, put_remote;
  zx::channel::create(0, &put_local, &put_remote);
  zx_status_t open_status =
      fdio_open(test_file, fuchsia::io::OPEN_RIGHT_READABLE, put_local.release());
  ASSERT_EQ(open_status, ZX_OK);
  zx_status_t transfer_status = ZX_ERR_IO;
  client.Put(std::move(put_remote), guest_destination, [&](zx_status_t put_result) {
    transfer_status = put_result;
    client.Stop();
  });
  client.Run();
  ASSERT_EQ(transfer_status, ZX_OK);
  zx::channel get_local, get_remote;
  zx::channel::create(0, &get_local, &get_remote);
  open_status = fdio_open(host_verification_file,
                          fuchsia::io::OPEN_RIGHT_WRITABLE | fuchsia::io::OPEN_FLAG_CREATE |
                              fuchsia::io::OPEN_FLAG_TRUNCATE,
                          get_local.release());
  ASSERT_EQ(open_status, ZX_OK);
  transfer_status = ZX_ERR_IO;
  client.Get(guest_destination, std::move(get_remote), [&](zx_status_t get_result) {
    transfer_status = get_result;
    client.Stop();
  });
  client.Run();
  ASSERT_EQ(transfer_status, OperationStatus::OK);
  std::string verification_string;
  char output_buf[kBufferSize];
  fd.reset(open(host_verification_file, O_RDONLY));
  while (true) {
    size_t read_size = read(fd.get(), output_buf, kBufferSize);
    if (read_size <= 0)
      break;
    verification_string.append(std::string(output_buf, read_size));
  }
  ASSERT_EQ(verification_string, file_contents);
}
TEST_F ( GuestInteractionTest , DISABLED_GrpcPutGetTest ) { CreateEnvironment ( ) ; LaunchDebianGuest ( ) ; fuchsia :: virtualization :: HostVsockEndpointPtr ep ; realm_ -> GetHostVsockEndpoint ( ep . NewRequest ( ) ) ; zx :: socket local_socket , remote_socket ; zx_status_t status = zx :: socket :: create ( ZX_SOCKET_STREAM , & local_socket , & remote_socket ) ; ASSERT_EQ ( status , ZX_OK ) ; bool connect_complete = false ; ep -> Connect ( cid_ , GUEST_INTERACTION_PORT , std :: move ( remote_socket ) , [ & connect_complete , & status ] ( zx_status_t connect_status ) { status = connect_status ; connect_complete = true ; } ) ; RunLoopUntil ( [ & connect_complete ] { return connect_complete ; } ) ; ASSERT_EQ ( status , ZX_OK ) ; int32_t vsock_fd = ConvertSocketToNonBlockingFd ( std :: move ( local_socket ) ) ; ASSERT_GE ( vsock_fd , 0 ) ; ClientImpl < PosixPlatform > client ( vsock_fd ) ; char test_file [ ] = " " ; char guest_destination [ ] = " " ; char host_verification_file [ ] = " " ; std :: string file_contents ; for ( int i = 0 ; i < 2 * CHUNK_SIZE ; i ++ ) { file_contents . push_back ( i % ( ' ' - ' ' ) + ' ' ) ; } fbl :: unique_fd fd = fbl :: unique_fd ( open ( test_file , O_WRONLY | O_TRUNC | O_CREAT ) ) ; uint32_t bytes_written = 0 ; while ( bytes_written < file_contents . size ( ) ) { ssize_t write_size = write ( fd . get ( ) , file_contents . c_str ( ) + bytes_written , file_contents . size ( ) - bytes_written ) ; ASSERT_TRUE ( write_size > 0 ) ; bytes_written += write_size ; } zx :: channel put_local , put_remote ; zx :: channel :: create ( 0 , & put_local , & put_remote ) ; zx_status_t open_status = fdio_open ( test_file , fuchsia :: io :: OPEN_RIGHT_READABLE , put_local . release ( ) ) ; ASSERT_EQ ( open_status , ZX_OK ) ; zx_status_t transfer_status = ZX_ERR_IO ; client . Put ( std :: move ( put_remote ) , guest_destination , [ & ] ( zx_status_t put_result ) { transfer_status = put_result ; client . Stop ( ) ; } ) ; client . Run ( ) ; ASSERT_EQ ( transfer_status , ZX_OK ) ; zx :: channel get_local , get_remote ; zx :: channel :: create ( 0 , & get_local , & get_remote ) ; open_status = fdio_open ( host_verification_file , fuchsia :: io :: OPEN_RIGHT_WRITABLE | fuchsia :: io :: OPEN_FLAG_CREATE | fuchsia :: io :: OPEN_FLAG_TRUNCATE , get_local . release ( ) ) ; ASSERT_EQ ( open_status , ZX_OK ) ; transfer_status = ZX_ERR_IO ; client . Get ( guest_destination , std :: move ( get_remote ) , [ & ] ( zx_status_t get_result ) { transfer_status = get_result ; client . Stop ( ) ; } ) ; client . Run ( ) ; ASSERT_EQ ( transfer_status , OperationStatus :: OK ) ; std :: string verification_string ; char output_buf [ kBufferSize ] ; fd . reset ( open ( host_verification_file , O_RDONLY ) ) ; while ( true ) { size_t read_size = read ( fd . get ( ) , output_buf , kBufferSize ) ; if ( read_size <= 0 ) break ; verification_string . append ( std :: string ( output_buf , read_size ) ) ; } ASSERT_EQ ( verification_string , file_contents ) ; }
Create a file large enough that it needs to be fragmented when it is sent
to and received from the guest and then send it to and retrieve it from the
guest.
Create a file large enough that it needs to be fragmented when it is sent to and received from the guest and then send it to and retrieve it from the guest .
// Connect the gRPC client to the guest under test. // Write a file of gibberish that the test can send over to the guest. // Push the test file to the guest // Copy back the file that was sent to the guest. // Verify the contents that were communicated through stdin.