diff --git a/implementations/caching/CachingBlockStore.cpp b/implementations/caching/CachingBlockStore.cpp index e2c9d5bf..bf4aef78 100644 --- a/implementations/caching/CachingBlockStore.cpp +++ b/implementations/caching/CachingBlockStore.cpp @@ -5,6 +5,7 @@ #include #include +#include using cpputils::dynamic_pointer_move; using cpputils::Data; @@ -47,7 +48,7 @@ optional> CachingBlockStore::load(const Key &key) { void CachingBlockStore::remove(cpputils::unique_ref block) { auto cached_block = dynamic_pointer_move(block); - assert(cached_block != none); + ASSERT(cached_block != none, "Passed block is not a CachedBlock"); auto baseBlock = (*cached_block)->releaseBlock(); auto baseNewBlock = dynamic_pointer_move(baseBlock); if (baseNewBlock != none) { diff --git a/implementations/caching/NewBlock.cpp b/implementations/caching/NewBlock.cpp index 5cae9b8c..59fe7176 100644 --- a/implementations/caching/NewBlock.cpp +++ b/implementations/caching/NewBlock.cpp @@ -1,5 +1,6 @@ #include "NewBlock.h" #include "CachingBlockStore.h" +#include using cpputils::Data; using boost::none; @@ -24,7 +25,7 @@ const void *NewBlock::data() const { } void NewBlock::write(const void *source, uint64_t offset, uint64_t size) { - assert(offset <= _data.size() && offset + size <= _data.size()); + ASSERT(offset <= _data.size() && offset + size <= _data.size(), "Write outside of valid area"); std::memcpy((uint8_t*)_data.data()+offset, source, size); _dataChanged = true; } @@ -34,7 +35,7 @@ void NewBlock::writeToBaseBlockIfChanged() { if (_baseBlock == none) { //TODO _data.copy() necessary? auto newBase = _blockStore->tryCreateInBaseStore(key(), _data.copy()); - assert(newBase != boost::none); //TODO What if tryCreate fails due to a duplicate key? We should ensure we don't use duplicate keys. + ASSERT(newBase != boost::none, "Couldn't create base block"); //TODO What if tryCreate fails due to a duplicate key? We should ensure we don't use duplicate keys. _baseBlock = std::move(*newBase); } else { (*_baseBlock)->write(_data.data(), 0, _data.size()); @@ -52,7 +53,7 @@ void NewBlock::remove() { void NewBlock::flush() { writeToBaseBlockIfChanged(); - assert(_baseBlock != none); + ASSERT(_baseBlock != none, "At this point, the base block should already have been created but wasn't"); (*_baseBlock)->flush(); } diff --git a/implementations/caching/cache/Cache.h b/implementations/caching/cache/Cache.h index 64038881..ddfa2b76 100644 --- a/implementations/caching/cache/Cache.h +++ b/implementations/caching/cache/Cache.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace blockstore { namespace caching { @@ -66,10 +67,10 @@ boost::optional Cache::pop(const Key &key) { template void Cache::push(const Key &key, Value value) { std::lock_guard lock(_mutex); - assert(_cachedBlocks.size() <= MAX_ENTRIES); + ASSERT(_cachedBlocks.size() <= MAX_ENTRIES, "Cache too full"); if (_cachedBlocks.size() == MAX_ENTRIES) { _cachedBlocks.pop(); - assert(_cachedBlocks.size() == MAX_ENTRIES-1); + ASSERT(_cachedBlocks.size() == MAX_ENTRIES-1, "Removing entry from cache didn't work"); } _cachedBlocks.push(key, CacheEntry(std::move(value))); } diff --git a/implementations/encrypted/EncryptedBlock.h b/implementations/encrypted/EncryptedBlock.h index 6eba0afe..0a7dce7c 100644 --- a/implementations/encrypted/EncryptedBlock.h +++ b/implementations/encrypted/EncryptedBlock.h @@ -11,6 +11,7 @@ #include #include #include "ciphers/Cipher.h" +#include namespace blockstore { namespace encrypted { @@ -123,7 +124,7 @@ const void *EncryptedBlock::data() const { template void EncryptedBlock::write(const void *source, uint64_t offset, uint64_t count) { - assert(offset <= size() && offset + count <= size()); //Also check offset < size() because of possible overflow in the addition + ASSERT(offset <= size() && offset + count <= size(), "Write outside of valid area"); //Also check offset < size() because of possible overflow in the addition std::memcpy((uint8_t*)_plaintextWithHeader.data()+HEADER_LENGTH+offset, source, count); _dataChanged = true; } diff --git a/implementations/encrypted/EncryptedBlockStore.h b/implementations/encrypted/EncryptedBlockStore.h index a574a3d7..f3fe7b23 100644 --- a/implementations/encrypted/EncryptedBlockStore.h +++ b/implementations/encrypted/EncryptedBlockStore.h @@ -69,7 +69,7 @@ boost::optional> EncryptedBlockStore::load(c template void EncryptedBlockStore::remove(cpputils::unique_ref block) { auto encryptedBlock = cpputils::dynamic_pointer_move>(block); - assert(encryptedBlock != boost::none); + ASSERT(encryptedBlock != boost::none, "Block is not an EncryptedBlock"); auto baseBlock = (*encryptedBlock)->releaseBlock(); return _baseBlockStore->remove(std::move(baseBlock)); } diff --git a/implementations/inmemory/InMemoryBlock.cpp b/implementations/inmemory/InMemoryBlock.cpp index fcbf152d..77ba5b0f 100644 --- a/implementations/inmemory/InMemoryBlock.cpp +++ b/implementations/inmemory/InMemoryBlock.cpp @@ -1,6 +1,7 @@ #include "InMemoryBlock.h" #include "InMemoryBlockStore.h" #include +#include using std::make_shared; using std::istream; @@ -29,7 +30,7 @@ const void *InMemoryBlock::data() const { } void InMemoryBlock::write(const void *source, uint64_t offset, uint64_t size) { - assert(offset <= _data->size() && offset + size <= _data->size()); //Also check offset < _data->size() because of possible overflow in the addition + ASSERT(offset <= _data->size() && offset + size <= _data->size(), "Write outside of valid area"); //Also check offset < _data->size() because of possible overflow in the addition std::memcpy((uint8_t*)_data->data()+offset, source, size); } diff --git a/implementations/inmemory/InMemoryBlockStore.cpp b/implementations/inmemory/InMemoryBlockStore.cpp index 3540d5d4..6a97dd7b 100644 --- a/implementations/inmemory/InMemoryBlockStore.cpp +++ b/implementations/inmemory/InMemoryBlockStore.cpp @@ -1,6 +1,7 @@ #include "InMemoryBlock.h" #include "InMemoryBlockStore.h" #include +#include using std::make_unique; using std::string; @@ -44,7 +45,7 @@ void InMemoryBlockStore::remove(unique_ref block) { Key key = block->key(); cpputils::destruct(std::move(block)); int numRemoved = _blocks.erase(key.ToString()); - assert(1==numRemoved); + ASSERT(1==numRemoved, "Didn't find block to remove"); } uint64_t InMemoryBlockStore::numBlocks() const { diff --git a/implementations/ondisk/OnDiskBlock.cpp b/implementations/ondisk/OnDiskBlock.cpp index 15db611d..07ad3f77 100644 --- a/implementations/ondisk/OnDiskBlock.cpp +++ b/implementations/ondisk/OnDiskBlock.cpp @@ -4,6 +4,7 @@ #include "OnDiskBlock.h" #include "OnDiskBlockStore.h" #include "../../utils/FileDoesntExistException.h" +#include using std::istream; using std::ostream; @@ -34,7 +35,7 @@ const void *OnDiskBlock::data() const { } void OnDiskBlock::write(const void *source, uint64_t offset, uint64_t size) { - assert(offset <= _data.size() && offset + size <= _data.size()); //Also check offset < _data->size() because of possible overflow in the addition + ASSERT(offset <= _data.size() && offset + size <= _data.size(), "Write outside of valid area"); //Also check offset < _data->size() because of possible overflow in the addition std::memcpy((uint8_t*)_data.data()+offset, source, size); _dataChanged = true; } @@ -76,7 +77,7 @@ optional> OnDiskBlock::CreateOnDisk(const bf::path &root void OnDiskBlock::RemoveFromDisk(const bf::path &rootdir, const Key &key) { auto filepath = rootdir / key.ToString(); - assert(bf::is_regular_file(filepath)); + ASSERT(bf::is_regular_file(filepath), "Block not found on disk"); bf::remove(filepath); } diff --git a/implementations/parallelaccess/ParallelAccessBlockStore.cpp b/implementations/parallelaccess/ParallelAccessBlockStore.cpp index fece925b..cd951f53 100644 --- a/implementations/parallelaccess/ParallelAccessBlockStore.cpp +++ b/implementations/parallelaccess/ParallelAccessBlockStore.cpp @@ -3,6 +3,7 @@ #include "ParallelAccessBlockStoreAdapter.h" #include #include +#include using std::string; using std::mutex; @@ -48,7 +49,7 @@ optional> ParallelAccessBlockStore::load(const Key &key) { void ParallelAccessBlockStore::remove(unique_ref block) { Key key = block->key(); auto block_ref = dynamic_pointer_move(block); - assert(block_ref != none); + ASSERT(block_ref != none, "Block is not a BlockRef"); return _parallelAccessStore.remove(key, std::move(*block_ref)); } diff --git a/implementations/testfake/FakeBlock.cpp b/implementations/testfake/FakeBlock.cpp index 354553e8..03fb975b 100644 --- a/implementations/testfake/FakeBlock.cpp +++ b/implementations/testfake/FakeBlock.cpp @@ -1,6 +1,7 @@ #include "FakeBlock.h" #include "FakeBlockStore.h" #include +#include using std::shared_ptr; using std::istream; @@ -27,7 +28,7 @@ const void *FakeBlock::data() const { } void FakeBlock::write(const void *source, uint64_t offset, uint64_t size) { - assert(offset <= _data->size() && offset + size <= _data->size()); //Also check offset < _data->size() because of possible overflow in the addition + ASSERT(offset <= _data->size() && offset + size <= _data->size(), "Write outside of valid area"); //Also check offset < _data->size() because of possible overflow in the addition std::memcpy((uint8_t*)_data->data()+offset, source, size); _dataChanged = true; } diff --git a/implementations/testfake/FakeBlockStore.cpp b/implementations/testfake/FakeBlockStore.cpp index aa311091..e03f7754 100644 --- a/implementations/testfake/FakeBlockStore.cpp +++ b/implementations/testfake/FakeBlockStore.cpp @@ -1,5 +1,6 @@ #include "FakeBlock.h" #include "FakeBlockStore.h" +#include using std::make_shared; using std::string; @@ -42,7 +43,7 @@ void FakeBlockStore::remove(unique_ref block) { Key key = block->key(); cpputils::destruct(std::move(block)); int numRemoved = _blocks.erase(key.ToString()); - assert(numRemoved == 1); + ASSERT(numRemoved == 1, "Block not found"); } unique_ref FakeBlockStore::makeFakeBlockFromData(const Key &key, const Data &data, bool dirty) { @@ -55,11 +56,11 @@ void FakeBlockStore::updateData(const Key &key, const Data &data) { auto found = _blocks.find(key.ToString()); if (found == _blocks.end()) { auto insertResult = _blocks.emplace(key.ToString(), data.copy()); - assert(true == insertResult.second); + ASSERT(true == insertResult.second, "Inserting didn't work"); found = insertResult.first; } Data &stored_data = found->second; - assert(data.size() == stored_data.size()); + ASSERT(data.size() == stored_data.size(), "Wrong data size in block"); std::memcpy(stored_data.data(), data.data(), data.size()); } diff --git a/test/implementations/caching/cache/testutils/MinimalValueType.h b/test/implementations/caching/cache/testutils/MinimalValueType.h index 9e48e43e..60d9fa4c 100644 --- a/test/implementations/caching/cache/testutils/MinimalValueType.h +++ b/test/implementations/caching/cache/testutils/MinimalValueType.h @@ -4,6 +4,7 @@ #include #include +#include // This is a not-default-constructible non-copyable but moveable Value type class MinimalValueType { @@ -19,13 +20,13 @@ public: } ~MinimalValueType() { - assert(!_isDestructed); + ASSERT(!_isDestructed, "Object was already destructed before"); --instances; _isDestructed = true; } int value() const { - assert(!_isMoved && !_isDestructed); + ASSERT(!_isMoved && !_isDestructed, "Object is invalid"); return _value; } diff --git a/utils/BlockStoreUtils.cpp b/utils/BlockStoreUtils.cpp index 2c358344..a304c91e 100644 --- a/utils/BlockStoreUtils.cpp +++ b/utils/BlockStoreUtils.cpp @@ -2,6 +2,7 @@ #include "BlockStoreUtils.h" #include #include +#include using cpputils::Data; using cpputils::unique_ref; @@ -16,7 +17,7 @@ unique_ref copyToNewBlock(BlockStore *blockStore, const Block &block) { } void copyTo(Block *target, const Block &source) { - assert(target->size() == source.size()); + ASSERT(target->size() == source.size(), "Can't copy block data when blocks have different sizes"); target->write(source.data(), 0, source.size()); }