zircon/system/utest/blobfs-bench/blobfs-bench.cc
// Creates a an in memory blob.
Creates a an in memory blob.
Creates a an in memory blob .
bool MakeBlob(fbl::String fs_path, size_t blob_size, unsigned int* seed,
              std::unique_ptr<BlobInfo>* out) {
  BEGIN_HELPER;
  fbl::AllocChecker ac;
  std::unique_ptr<BlobInfo> info(new (&ac) BlobInfo);
  EXPECT_EQ(ac.check(), true);
  info->data.reset(new (&ac) char[blob_size]);
  EXPECT_EQ(ac.check(), true);
  unsigned int initial_seed = rand_r(seed);
  for (size_t i = 0; i < blob_size; i++) {
    info->data[i] = static_cast<char>(rand_r(&initial_seed));
  }
  info->size_data = blob_size;
  Digest digest;
  std::unique_ptr<uint8_t[]> tree;
  ASSERT_EQ(MerkleTreeCreator::Create(info->data.get(), info->size_data, &tree, &info->size_merkle,
                                      &digest),
            ZX_OK, "Couldn't create Merkle Tree");
  info->merkle.reset(reinterpret_cast<char*>(tree.release()));
  info->path.AppendPrintf("%s/%s", fs_path.c_str(), digest.ToString().c_str());
  ASSERT_EQ(MerkleTreeVerifier::Verify(info->data.get(), info->size_data, 0, info->size_data,
                                       info->merkle.get(), info->size_merkle, digest),
            ZX_OK, "Failed to validate Merkle Tree");
  *out = std::move(info);
  END_HELPER;
}
bool MakeBlob ( fbl :: String fs_path , size_t blob_size , unsigned int * seed , std :: unique_ptr < BlobInfo > * out ) { BEGIN_HELPER ; fbl :: AllocChecker ac ; std :: unique_ptr < BlobInfo > info ( new ( & ac ) BlobInfo ) ; EXPECT_EQ ( ac . check ( ) , true ) ; info -> data . reset ( new ( & ac ) char [ blob_size ] ) ; EXPECT_EQ ( ac . check ( ) , true ) ; unsigned int initial_seed = rand_r ( seed ) ; for ( size_t i = 0 ; i < blob_size ; i ++ ) { info -> data [ i ] = static_cast < char > ( rand_r ( & initial_seed ) ) ; } info -> size_data = blob_size ; Digest digest ; std :: unique_ptr < uint8_t [ ] > tree ; ASSERT_EQ ( MerkleTreeCreator :: Create ( info -> data . get ( ) , info -> size_data , & tree , & info -> size_merkle , & digest ) , ZX_OK , " " ) ; info -> merkle . reset ( reinterpret_cast < char * > ( tree . release ( ) ) ) ; info -> path . AppendPrintf ( " " , fs_path . c_str ( ) , digest . ToString ( ) . c_str ( ) ) ; ASSERT_EQ ( MerkleTreeVerifier :: Verify ( info -> data . get ( ) , info -> size_data , 0 , info -> size_data , info -> merkle . get ( ) , info -> size_merkle , digest ) , ZX_OK , " " ) ; * out = std :: move ( info ) ; END_HELPER ; }
Creates a an in memory blob.
Creates a an in memory blob .
// Generate a Blob of random data // rand_r produces a cyclic sequence, in order to avoid hitting that cap // and generating identical blobs, we avoid consuming an element of the // sequence for each byte. We did hit this issue, which translates into // test failures. // Generate the Merkle Tree // Sanity-check the merkle tree