Test: fix build error.

This commit is contained in:
Victor Costan 2022-09-29 09:46:03 -07:00
parent 9758c9dfd7
commit a505476792
4 changed files with 10 additions and 9 deletions

View File

@ -2041,7 +2041,7 @@ size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
std::string* compressed) { std::string* compressed) {
// Compute the number of bytes to be compressed. // Compute the number of bytes to be compressed.
size_t uncompressed_length = 0; size_t uncompressed_length = 0;
for (int i = 0; i < iov_cnt; ++i) { for (size_t i = 0; i < iov_cnt; ++i) {
uncompressed_length += iov[i].iov_len; uncompressed_length += iov[i].iov_len;
} }

View File

@ -158,21 +158,22 @@ void BM_UIOVecSource(benchmark::State& state) {
std::string contents = std::string contents =
ReadTestDataFile(kTestDataFiles[file_index].filename, ReadTestDataFile(kTestDataFiles[file_index].filename,
kTestDataFiles[file_index].size_limit); kTestDataFiles[file_index].size_limit);
std::vector<char> contents_copy(contents.begin(), contents.end());
// Create `iovec`s of the `contents`. // Create `iovec`s of the `contents`.
const int kNumEntries = 10; const int kNumEntries = 10;
struct iovec iov[kNumEntries]; struct iovec iov[kNumEntries];
size_t used_so_far = 0; size_t used_so_far = 0;
for (int i = 0; i < kNumEntries; ++i) { for (int i = 0; i < kNumEntries; ++i) {
iov[i].iov_base = contents.data() + used_so_far; iov[i].iov_base = contents_copy.data() + used_so_far;
if (used_so_far == contents.size()) { if (used_so_far == contents_copy.size()) {
iov[i].iov_len = 0; iov[i].iov_len = 0;
continue; continue;
} }
if (i == kNumEntries - 1) { if (i == kNumEntries - 1) {
iov[i].iov_len = contents.size() - used_so_far; iov[i].iov_len = contents_copy.size() - used_so_far;
} else { } else {
iov[i].iov_len = contents.size() / kNumEntries; iov[i].iov_len = contents_copy.size() / kNumEntries;
} }
used_so_far += iov[i].iov_len; used_so_far += iov[i].iov_len;
} }

View File

@ -169,7 +169,7 @@ struct iovec* GetIOVec(const std::string& input, char*& buf, size_t& num) {
int VerifyIOVecSource(const std::string& input) { int VerifyIOVecSource(const std::string& input) {
std::string compressed; std::string compressed;
std::string copy = input; std::vector<char> copy(input.begin(), input.end());
char* buf = copy.data(); char* buf = copy.data();
size_t num = 0; size_t num = 0;
struct iovec* iov = GetIOVec(input, buf, num); struct iovec* iov = GetIOVec(input, buf, num);
@ -567,8 +567,8 @@ TEST(Snappy, FourByteOffset) {
TEST(Snappy, IOVecSourceEdgeCases) { TEST(Snappy, IOVecSourceEdgeCases) {
// Validate that empty leading, trailing, and in-between iovecs are handled: // Validate that empty leading, trailing, and in-between iovecs are handled:
// [] [] ['a'] [] ['b'] []. // [] [] ['a'] [] ['b'] [].
std::string data = "ab"; char data[3] = "ab";
char* buf = data.data(); char* buf = data;
size_t used_so_far = 0; size_t used_so_far = 0;
static const int kLengths[] = {0, 0, 1, 0, 1, 0}; static const int kLengths[] = {0, 0, 1, 0, 1, 0};
struct iovec iov[ARRAYSIZE(kLengths)]; struct iovec iov[ARRAYSIZE(kLengths)];

@ -1 +1 @@
Subproject commit bf585a2789e30585b4e3ce6baf11ef2750b54677 Subproject commit 49aa374da96199d64fd3de9673b6f405bbc3de3e