diff options
Diffstat (limited to 'runtime/base')
-rw-r--r-- | runtime/base/bit_vector_test.cc | 4 | ||||
-rw-r--r-- | runtime/base/hex_dump.cc | 112 | ||||
-rw-r--r-- | runtime/base/hex_dump.h | 55 | ||||
-rw-r--r-- | runtime/base/hex_dump_test.cc | 63 | ||||
-rw-r--r-- | runtime/base/logging.cc | 86 | ||||
-rw-r--r-- | runtime/base/logging.h | 18 | ||||
-rw-r--r-- | runtime/base/mutex-inl.h | 4 | ||||
-rw-r--r-- | runtime/base/mutex.cc | 6 | ||||
-rw-r--r-- | runtime/base/mutex.h | 2 | ||||
-rw-r--r-- | runtime/base/unix_file/fd_file.cc | 16 | ||||
-rw-r--r-- | runtime/base/unix_file/fd_file.h | 4 | ||||
-rw-r--r-- | runtime/base/unix_file/mapped_file.cc | 6 | ||||
-rw-r--r-- | runtime/base/unix_file/mapped_file_test.cc | 13 | ||||
-rw-r--r-- | runtime/base/unix_file/null_file_test.cc | 6 | ||||
-rw-r--r-- | runtime/base/unix_file/random_access_file_test.h | 24 |
15 files changed, 275 insertions, 144 deletions
diff --git a/runtime/base/bit_vector_test.cc b/runtime/base/bit_vector_test.cc index d99d059..3fc9b86 100644 --- a/runtime/base/bit_vector_test.cc +++ b/runtime/base/bit_vector_test.cc @@ -25,7 +25,7 @@ TEST(BitVector, Test) { BitVector bv(kBits, false, Allocator::GetMallocAllocator()); EXPECT_EQ(1U, bv.GetStorageSize()); - EXPECT_EQ(kWordSize, bv.GetSizeOf()); + EXPECT_EQ(sizeof(uint32_t), bv.GetSizeOf()); EXPECT_FALSE(bv.IsExpandable()); EXPECT_EQ(0U, bv.NumSetBits()); @@ -70,7 +70,7 @@ TEST(BitVector, NoopAllocator) { BitVector bv(0U, false, Allocator::GetNoopAllocator(), kWords, bits); EXPECT_EQ(kWords, bv.GetStorageSize()); - EXPECT_EQ(kWords * kWordSize, bv.GetSizeOf()); + EXPECT_EQ(kWords * sizeof(uint32_t), bv.GetSizeOf()); EXPECT_EQ(bits, bv.GetRawStorage()); EXPECT_EQ(0U, bv.NumSetBits()); diff --git a/runtime/base/hex_dump.cc b/runtime/base/hex_dump.cc new file mode 100644 index 0000000..936c52b --- /dev/null +++ b/runtime/base/hex_dump.cc @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hex_dump.h" + +#include "globals.h" + +#include <string.h> + +namespace art { + +void HexDump::Dump(std::ostream& os) const { + if (byte_count_ == 0) { + return; + } + + if (address_ == NULL) { + os << "00000000:"; + return; + } + + static const char gHexDigit[] = "0123456789abcdef"; + const unsigned char* addr = reinterpret_cast<const unsigned char*>(address_); + // 01234560: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef + char out[(kBitsPerWord / 4) + /* offset */ + 1 + /* colon */ + (16 * 3) + /* 16 hex digits and space */ + 2 + /* white space */ + 16 + /* 16 characters*/ + 1 /* \0 */ ]; + size_t offset; /* offset to show while printing */ + + if (show_actual_addresses_) { + offset = reinterpret_cast<size_t>(addr); + } else { + offset = 0; + } + memset(out, ' ', sizeof(out)-1); + out[kBitsPerWord / 4] = ':'; + out[sizeof(out)-1] = '\0'; + + size_t byte_count = byte_count_; + size_t gap = offset & 0x0f; + while (byte_count > 0) { + size_t line_offset = offset & ~0x0f; + + char* hex = out; + char* asc = out + (kBitsPerWord / 4) + /* offset */ 1 + /* colon */ + (16 * 3) + /* 16 hex digits and space */ 2 /* white space */; + + for (int i = 0; i < (kBitsPerWord / 4); i++) { + *hex++ = gHexDigit[line_offset >> (kBitsPerWord - 4)]; + line_offset <<= 4; + } + hex++; + hex++; + + size_t count = std::min(byte_count, 16 - gap); + // CHECK_NE(count, 0U); + // CHECK_LE(count + gap, 16U); + + if (gap) { + /* only on first line */ + hex += gap * 3; + asc += gap; + } + + size_t i; + for (i = gap ; i < count + gap; i++) { + *hex++ = gHexDigit[*addr >> 4]; + *hex++ = gHexDigit[*addr & 0x0f]; + hex++; + if (*addr >= 0x20 && *addr < 0x7f /*isprint(*addr)*/) { + *asc++ = *addr; + } else { + *asc++ = '.'; + } + addr++; + } + for (; i < 16; i++) { + /* erase extra stuff; only happens on last line */ + *hex++ = ' '; + *hex++ = ' '; + hex++; + *asc++ = ' '; + } + + os << prefix_ << out; + + gap = 0; + byte_count -= count; + offset += count; + if (byte_count > 0) { + os << "\n"; + } + } +} + +} // namespace art diff --git a/runtime/base/hex_dump.h b/runtime/base/hex_dump.h new file mode 100644 index 0000000..8769ece --- /dev/null +++ b/runtime/base/hex_dump.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_RUNTIME_BASE_HEX_DUMP_H_ +#define ART_RUNTIME_BASE_HEX_DUMP_H_ + +#include "macros.h" + +#include <ostream> + +namespace art { + +// Prints a hex dump in this format: +// +// 01234560: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef +// 01234568: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef +class HexDump { + public: + HexDump(const void* address, size_t byte_count, bool show_actual_addresses, const char* prefix) + : address_(address), byte_count_(byte_count), show_actual_addresses_(show_actual_addresses), + prefix_(prefix) { + } + + void Dump(std::ostream& os) const; + + private: + const void* const address_; + const size_t byte_count_; + const bool show_actual_addresses_; + const char* const prefix_; + + DISALLOW_COPY_AND_ASSIGN(HexDump); +}; + +inline std::ostream& operator<<(std::ostream& os, const HexDump& rhs) { + rhs.Dump(os); + return os; +} + +} // namespace art + +#endif // ART_RUNTIME_BASE_HEX_DUMP_H_ diff --git a/runtime/base/hex_dump_test.cc b/runtime/base/hex_dump_test.cc new file mode 100644 index 0000000..d950961 --- /dev/null +++ b/runtime/base/hex_dump_test.cc @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "hex_dump.h" + +#include "globals.h" + +#include "gtest/gtest.h" + +#include <stdint.h> + +namespace art { + +TEST(HexDump, OneLine) { + const char* test_text = "0123456789abcdef"; + std::ostringstream oss; + oss << HexDump(test_text, strlen(test_text), false, ""); + EXPECT_STREQ(oss.str().c_str(), + "00000000: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 0123456789abcdef"); +} + +TEST(HexDump, MultiLine) { + const char* test_text = "0123456789abcdef0123456789ABCDEF"; + std::ostringstream oss; + oss << HexDump(test_text, strlen(test_text), false, ""); + EXPECT_STREQ(oss.str().c_str(), + "00000000: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 0123456789abcdef\n" + "00000010: 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 0123456789ABCDEF"); +} + +uint64_t g16byte_aligned_number __attribute__ ((aligned(16))); // NOLINT(whitespace/parens) +TEST(HexDump, ShowActualAddresses) { + g16byte_aligned_number = 0x6162636465666768; + std::ostringstream oss; + oss << HexDump(&g16byte_aligned_number, 8, true, ""); + // Compare ignoring pointer. + EXPECT_STREQ(oss.str().c_str() + (kBitsPerWord / 4), + ": 68 67 66 65 64 63 62 61 hgfedcba "); +} + +TEST(HexDump, Prefix) { + const char* test_text = "0123456789abcdef"; + std::ostringstream oss; + oss << HexDump(test_text, strlen(test_text), false, "test prefix: "); + EXPECT_STREQ(oss.str().c_str(), + "test prefix: 00000000: 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 " + "0123456789abcdef"); +} + +} // namespace art diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc index 3aabc8d..46b8ff2 100644 --- a/runtime/base/logging.cc +++ b/runtime/base/logging.cc @@ -161,90 +161,4 @@ LogMessage::~LogMessage() { } } -HexDump::HexDump(const void* address, size_t byte_count, bool show_actual_addresses) - : address_(address), byte_count_(byte_count), show_actual_addresses_(show_actual_addresses) { -} - -void HexDump::Dump(std::ostream& os) const { - if (byte_count_ == 0) { - return; - } - - if (address_ == NULL) { - os << "00000000:"; - return; - } - - static const char gHexDigit[] = "0123456789abcdef"; - const unsigned char* addr = reinterpret_cast<const unsigned char*>(address_); - char out[76]; /* exact fit */ - unsigned int offset; /* offset to show while printing */ - - if (show_actual_addresses_) { - offset = reinterpret_cast<int>(addr); - } else { - offset = 0; - } - memset(out, ' ', sizeof(out)-1); - out[8] = ':'; - out[sizeof(out)-1] = '\0'; - - size_t byte_count = byte_count_; - int gap = static_cast<int>(offset & 0x0f); - while (byte_count) { - unsigned int line_offset = offset & ~0x0f; - - char* hex = out; - char* asc = out + 59; - - for (int i = 0; i < 8; i++) { - *hex++ = gHexDigit[line_offset >> 28]; - line_offset <<= 4; - } - hex++; - hex++; - - int count = std::min(static_cast<int>(byte_count), 16 - gap); - CHECK_NE(count, 0); - CHECK_LE(count + gap, 16); - - if (gap) { - /* only on first line */ - hex += gap * 3; - asc += gap; - } - - int i; - for (i = gap ; i < count+gap; i++) { - *hex++ = gHexDigit[*addr >> 4]; - *hex++ = gHexDigit[*addr & 0x0f]; - hex++; - if (*addr >= 0x20 && *addr < 0x7f /*isprint(*addr)*/) { - *asc++ = *addr; - } else { - *asc++ = '.'; - } - addr++; - } - for (; i < 16; i++) { - /* erase extra stuff; only happens on last line */ - *hex++ = ' '; - *hex++ = ' '; - hex++; - *asc++ = ' '; - } - - os << out; - - gap = 0; - byte_count -= count; - offset += count; - } -} - -std::ostream& operator<<(std::ostream& os, const HexDump& rhs) { - rhs.Dump(os); - return os; -} - } // namespace art diff --git a/runtime/base/logging.h b/runtime/base/logging.h index 8e40da0..075d571 100644 --- a/runtime/base/logging.h +++ b/runtime/base/logging.h @@ -208,24 +208,6 @@ class LogMessage { DISALLOW_COPY_AND_ASSIGN(LogMessage); }; -// Prints a hex dump in this format: -// -// 01234560: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef -// 01234568: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef -class HexDump { - public: - HexDump(const void* address, size_t byte_count, bool show_actual_addresses = false); - void Dump(std::ostream& os) const; - - private: - const void* address_; - size_t byte_count_; - bool show_actual_addresses_; - - DISALLOW_COPY_AND_ASSIGN(HexDump); -}; -std::ostream& operator<<(std::ostream& os, const HexDump& rhs); - // A convenience to allow any class with a "Dump(std::ostream& os)" member function // but without an operator<< to be used as if it had an operator<<. Use like this: // diff --git a/runtime/base/mutex-inl.h b/runtime/base/mutex-inl.h index 29b3981..a7e25cb 100644 --- a/runtime/base/mutex-inl.h +++ b/runtime/base/mutex-inl.h @@ -17,6 +17,8 @@ #ifndef ART_RUNTIME_BASE_MUTEX_INL_H_ #define ART_RUNTIME_BASE_MUTEX_INL_H_ +#include <inttypes.h> + #include "mutex.h" #define ATRACE_TAG ATRACE_TAG_DALVIK @@ -96,7 +98,7 @@ class ScopedContentionRecorder { blocked_tid_(kLogLockContentions ? blocked_tid : 0), owner_tid_(kLogLockContentions ? owner_tid : 0), start_nano_time_(kLogLockContentions ? NanoTime() : 0) { - std::string msg = StringPrintf("Lock contention on %s (owner tid: %llu)", + std::string msg = StringPrintf("Lock contention on %s (owner tid: %" PRIu64 ")", mutex->GetName(), owner_tid); ATRACE_BEGIN(msg.c_str()); } diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc index 05e3a83..ff72d16 100644 --- a/runtime/base/mutex.cc +++ b/runtime/base/mutex.cc @@ -47,7 +47,7 @@ static bool ComputeRelativeTimeSpec(timespec* result_ts, const timespec& lhs, co struct AllMutexData { // A guard for all_mutexes_ that's not a mutex (Mutexes must CAS to acquire and busy wait). - AtomicInteger all_mutexes_guard; + Atomic<const BaseMutex*> all_mutexes_guard; // All created mutexes guarded by all_mutexes_guard_. std::set<BaseMutex*>* all_mutexes; AllMutexData() : all_mutexes(NULL) {} @@ -57,12 +57,12 @@ static struct AllMutexData gAllMutexData[kAllMutexDataSize]; class ScopedAllMutexesLock { public: explicit ScopedAllMutexesLock(const BaseMutex* mutex) : mutex_(mutex) { - while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(0, reinterpret_cast<int32_t>(mutex))) { + while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(0, mutex)) { NanoSleep(100); } } ~ScopedAllMutexesLock() { - while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(reinterpret_cast<int32_t>(mutex_), 0)) { + while (!gAllMutexData->all_mutexes_guard.CompareAndSwap(mutex_, 0)) { NanoSleep(100); } } diff --git a/runtime/base/mutex.h b/runtime/base/mutex.h index 1c1dcaf..63ed6cb 100644 --- a/runtime/base/mutex.h +++ b/runtime/base/mutex.h @@ -23,7 +23,7 @@ #include <iosfwd> #include <string> -#include "atomic_integer.h" +#include "atomic.h" #include "base/logging.h" #include "base/macros.h" #include "globals.h" diff --git a/runtime/base/unix_file/fd_file.cc b/runtime/base/unix_file/fd_file.cc index f48c76d..87d1c06 100644 --- a/runtime/base/unix_file/fd_file.cc +++ b/runtime/base/unix_file/fd_file.cc @@ -102,11 +102,11 @@ bool FdFile::IsOpened() const { return fd_ >= 0; } -bool FdFile::ReadFully(void* buffer, int64_t byte_count) { +bool FdFile::ReadFully(void* buffer, size_t byte_count) { char* ptr = static_cast<char*>(buffer); while (byte_count > 0) { - int bytes_read = TEMP_FAILURE_RETRY(read(fd_, ptr, byte_count)); - if (bytes_read <= 0) { + ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd_, ptr, byte_count)); + if (bytes_read == -1) { return false; } byte_count -= bytes_read; // Reduce the number of remaining bytes. @@ -115,15 +115,15 @@ bool FdFile::ReadFully(void* buffer, int64_t byte_count) { return true; } -bool FdFile::WriteFully(const void* buffer, int64_t byte_count) { +bool FdFile::WriteFully(const void* buffer, size_t byte_count) { const char* ptr = static_cast<const char*>(buffer); while (byte_count > 0) { - int bytes_read = TEMP_FAILURE_RETRY(write(fd_, ptr, byte_count)); - if (bytes_read < 0) { + ssize_t bytes_written = TEMP_FAILURE_RETRY(write(fd_, ptr, byte_count)); + if (bytes_written == -1) { return false; } - byte_count -= bytes_read; // Reduce the number of remaining bytes. - ptr += bytes_read; // Move the buffer forward. + byte_count -= bytes_written; // Reduce the number of remaining bytes. + ptr += bytes_written; // Move the buffer forward. } return true; } diff --git a/runtime/base/unix_file/fd_file.h b/runtime/base/unix_file/fd_file.h index 19e3511..01f4ca2 100644 --- a/runtime/base/unix_file/fd_file.h +++ b/runtime/base/unix_file/fd_file.h @@ -61,8 +61,8 @@ class FdFile : public RandomAccessFile { return file_path_; } void DisableAutoClose(); - bool ReadFully(void* buffer, int64_t byte_count); - bool WriteFully(const void* buffer, int64_t byte_count); + bool ReadFully(void* buffer, size_t byte_count); + bool WriteFully(const void* buffer, size_t byte_count); private: int fd_; diff --git a/runtime/base/unix_file/mapped_file.cc b/runtime/base/unix_file/mapped_file.cc index b63fdd3..bc23a74 100644 --- a/runtime/base/unix_file/mapped_file.cc +++ b/runtime/base/unix_file/mapped_file.cc @@ -101,7 +101,8 @@ int64_t MappedFile::Read(char* buf, int64_t byte_count, int64_t offset) const { errno = EINVAL; return -errno; } - int64_t read_size = std::max(0LL, std::min(byte_count, file_size_ - offset)); + int64_t read_size = std::max(static_cast<int64_t>(0), + std::min(byte_count, file_size_ - offset)); if (read_size > 0) { memcpy(buf, data() + offset, read_size); } @@ -136,7 +137,8 @@ int64_t MappedFile::Write(const char* buf, int64_t byte_count, int64_t offset) { errno = EINVAL; return -errno; } - int64_t write_size = std::max(0LL, std::min(byte_count, file_size_ - offset)); + int64_t write_size = std::max(static_cast<int64_t>(0), + std::min(byte_count, file_size_ - offset)); if (write_size > 0) { memcpy(data() + offset, buf, write_size); } diff --git a/runtime/base/unix_file/mapped_file_test.cc b/runtime/base/unix_file/mapped_file_test.cc index 3dda02f..49750f4 100644 --- a/runtime/base/unix_file/mapped_file_test.cc +++ b/runtime/base/unix_file/mapped_file_test.cc @@ -65,7 +65,7 @@ TEST_F(MappedFileTest, OpenClose) { ASSERT_TRUE(file.Open(good_path_, MappedFile::kReadOnlyMode)); EXPECT_GE(file.Fd(), 0); EXPECT_TRUE(file.IsOpened()); - EXPECT_EQ(kContent.size(), file.size()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.size())); EXPECT_EQ(0, file.Close()); EXPECT_EQ(-1, file.Fd()); EXPECT_FALSE(file.IsOpened()); @@ -86,7 +86,7 @@ TEST_F(MappedFileTest, CanUseAfterMapReadOnly) { EXPECT_FALSE(file.IsMapped()); EXPECT_TRUE(file.MapReadOnly()); EXPECT_TRUE(file.IsMapped()); - EXPECT_EQ(kContent.size(), file.size()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.size())); ASSERT_TRUE(file.data()); EXPECT_EQ(0, memcmp(kContent.c_str(), file.data(), file.size())); EXPECT_EQ(0, file.Flush()); @@ -113,7 +113,7 @@ TEST_F(MappedFileTest, CanWriteNewData) { ASSERT_TRUE(file.Open(new_path, MappedFile::kReadWriteMode)); EXPECT_TRUE(file.MapReadWrite(kContent.size())); EXPECT_TRUE(file.IsMapped()); - EXPECT_EQ(kContent.size(), file.size()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.size())); ASSERT_TRUE(file.data()); memcpy(file.data(), kContent.c_str(), kContent.size()); EXPECT_EQ(0, file.Close()); @@ -200,15 +200,16 @@ TEST_F(MappedFileTest, WriteMappedReadWrite) { // A zero-length write is a no-op. EXPECT_EQ(0, file.Write(kContent.c_str(), 0, 0)); // But the file size is as given when mapped. - EXPECT_EQ(kContent.size(), file.GetLength()); + EXPECT_EQ(kContent.size(), static_cast<uint64_t>(file.GetLength())); // Data written past the end are discarded. EXPECT_EQ(kContent.size() - 1, - file.Write(kContent.c_str(), kContent.size(), 1)); + static_cast<uint64_t>(file.Write(kContent.c_str(), kContent.size(), 1))); EXPECT_EQ(0, memcmp(kContent.c_str(), file.data() + 1, kContent.size() - 1)); // Data can be overwritten. - EXPECT_EQ(kContent.size(), file.Write(kContent.c_str(), kContent.size(), 0)); + EXPECT_EQ(kContent.size(), + static_cast<uint64_t>(file.Write(kContent.c_str(), kContent.size(), 0))); EXPECT_EQ(0, memcmp(kContent.c_str(), file.data(), kContent.size())); } diff --git a/runtime/base/unix_file/null_file_test.cc b/runtime/base/unix_file/null_file_test.cc index 0f20acd..410fdfc 100644 --- a/runtime/base/unix_file/null_file_test.cc +++ b/runtime/base/unix_file/null_file_test.cc @@ -48,7 +48,7 @@ TEST_F(NullFileTest, GetLength) { NullFile f; // The length is always 0. ASSERT_EQ(0, f.GetLength()); - ASSERT_EQ(content.size(), f.Write(content.data(), content.size(), 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 0))); ASSERT_EQ(0, f.GetLength()); } @@ -58,8 +58,8 @@ TEST_F(NullFileTest, Write) { // You can't write at a negative offset... ASSERT_EQ(-EINVAL, f.Write(content.data(), content.size(), -128)); // But you can write anywhere else... - ASSERT_EQ(content.size(), f.Write(content.data(), content.size(), 0)); - ASSERT_EQ(content.size(), f.Write(content.data(), content.size(), 128)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 0))); + ASSERT_EQ(content.size(), static_cast<uint64_t>(f.Write(content.data(), content.size(), 128))); // ...though the file will remain empty. ASSERT_EQ(0, f.GetLength()); } diff --git a/runtime/base/unix_file/random_access_file_test.h b/runtime/base/unix_file/random_access_file_test.h index 9d8550d..3152788 100644 --- a/runtime/base/unix_file/random_access_file_test.h +++ b/runtime/base/unix_file/random_access_file_test.h @@ -71,7 +71,7 @@ class RandomAccessFileTest : public testing::Test { ASSERT_EQ(0, file->Read(buf, 123, 0)); const std::string content("hello"); - ASSERT_EQ(content.size(), file->Write(content.data(), content.size(), 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), 0))); TestReadContent(content, file.get()); } @@ -83,21 +83,21 @@ class RandomAccessFileTest : public testing::Test { ASSERT_EQ(-EINVAL, file->Read(buf.get(), 0, -123)); // Reading too much gets us just what's in the file. - ASSERT_EQ(content.size(), file->Read(buf.get(), buf_size, 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Read(buf.get(), buf_size, 0))); ASSERT_EQ(std::string(buf.get(), content.size()), content); // We only get as much as we ask for. const size_t short_request = 2; ASSERT_LT(short_request, content.size()); - ASSERT_EQ(short_request, file->Read(buf.get(), short_request, 0)); + ASSERT_EQ(short_request, static_cast<uint64_t>(file->Read(buf.get(), short_request, 0))); ASSERT_EQ(std::string(buf.get(), short_request), content.substr(0, short_request)); // We don't have to start at the beginning. const int non_zero_offset = 2; ASSERT_GT(non_zero_offset, 0); - ASSERT_EQ(short_request, - file->Read(buf.get(), short_request, non_zero_offset)); + ASSERT_EQ(short_request, static_cast<uint64_t>(file->Read(buf.get(), short_request, + non_zero_offset))); ASSERT_EQ(std::string(buf.get(), short_request), content.substr(non_zero_offset, short_request)); @@ -109,8 +109,8 @@ class RandomAccessFileTest : public testing::Test { void TestSetLength() { const std::string content("hello"); UniquePtr<RandomAccessFile> file(MakeTestFile()); - ASSERT_EQ(content.size(), file->Write(content.data(), content.size(), 0)); - ASSERT_EQ(content.size(), file->GetLength()); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), 0))); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->GetLength())); // Can't give a file a negative length. ASSERT_EQ(-EINVAL, file->SetLength(-123)); @@ -143,20 +143,20 @@ class RandomAccessFileTest : public testing::Test { ASSERT_EQ(0, file->GetLength()); // We can write data. - ASSERT_EQ(content.size(), file->Write(content.data(), content.size(), 0)); - ASSERT_EQ(content.size(), file->GetLength()); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), 0))); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->GetLength())); std::string new_content; ASSERT_TRUE(ReadString(file.get(), &new_content)); ASSERT_EQ(new_content, content); // We can read it back. char buf[256]; - ASSERT_EQ(content.size(), file->Read(buf, sizeof(buf), 0)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Read(buf, sizeof(buf), 0))); ASSERT_EQ(std::string(buf, content.size()), content); // We can append data past the end. - ASSERT_EQ(content.size(), - file->Write(content.data(), content.size(), file->GetLength() + 1)); + ASSERT_EQ(content.size(), static_cast<uint64_t>(file->Write(content.data(), content.size(), + file->GetLength() + 1))); int64_t new_length = 2*content.size() + 1; ASSERT_EQ(file->GetLength(), new_length); ASSERT_TRUE(ReadString(file.get(), &new_content)); |