diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-02-15 13:54:24 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-02-15 14:16:17 +0000 |
commit | c0b8734987176a93588909739af143c6b0a1a6ff (patch) | |
tree | 33340f0cfc5e9e4b8691abdaa378712f3bf8ded5 /vespalib/src/tests | |
parent | e385cf1498861b27da4312828613bdabab9b2161 (diff) |
use size literals in vespalib
Diffstat (limited to 'vespalib/src/tests')
17 files changed, 73 insertions, 57 deletions
diff --git a/vespalib/src/tests/alloc/alloc_test.cpp b/vespalib/src/tests/alloc/alloc_test.cpp index 056bac58d28..c52170fc8ec 100644 --- a/vespalib/src/tests/alloc/alloc_test.cpp +++ b/vespalib/src/tests/alloc/alloc_test.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/alloc.h> #include <vespa/vespalib/util/mmap_file_allocator.h> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/size_literals.h> #include <cstddef> #include <sys/mman.h> @@ -24,11 +25,11 @@ testSwap(T & a, T & b) { void * tmpA(a.get()); void * tmpB(b.get()); - EXPECT_EQUAL(4096ul, a.size()); - EXPECT_EQUAL(8192ul, b.size()); + EXPECT_EQUAL(4_Ki, a.size()); + EXPECT_EQUAL(8_Ki, b.size()); std::swap(a, b); - EXPECT_EQUAL(4096ul, b.size()); - EXPECT_EQUAL(8192ul, a.size()); + EXPECT_EQUAL(4_Ki, b.size()); + EXPECT_EQUAL(8_Ki, a.size()); EXPECT_EQUAL(tmpA, b.get()); EXPECT_EQUAL(tmpB, a.get()); } @@ -54,30 +55,30 @@ TEST("test basics") { } { EXPECT_EXCEPTION(Alloc::allocAlignedHeap(100, 7), IllegalArgumentException, "Alloc::allocAlignedHeap(100, 7) does not support 7 alignment"); - Alloc h = Alloc::allocAlignedHeap(100, 1024); + Alloc h = Alloc::allocAlignedHeap(100, 1_Ki); EXPECT_EQUAL(100u, h.size()); EXPECT_TRUE(h.get() != nullptr); } { Alloc h = Alloc::allocMMap(100); - EXPECT_EQUAL(4096u, h.size()); + EXPECT_EQUAL(4_Ki, h.size()); EXPECT_TRUE(h.get() != nullptr); } { - Alloc a = Alloc::allocHeap(4096), b = Alloc::allocHeap(8192); + Alloc a = Alloc::allocHeap(4_Ki), b = Alloc::allocHeap(8_Ki); testSwap(a, b); } { - Alloc a = Alloc::allocMMap(4096), b = Alloc::allocMMap(8192); + Alloc a = Alloc::allocMMap(4_Ki), b = Alloc::allocMMap(8_Ki); testSwap(a, b); } { - Alloc a = Alloc::allocAlignedHeap(4096, 1024), b = Alloc::allocAlignedHeap(8192, 1024); + Alloc a = Alloc::allocAlignedHeap(4_Ki, 1_Ki), b = Alloc::allocAlignedHeap(8_Ki, 1_Ki); testSwap(a, b); } { - Alloc a = Alloc::allocHeap(4096); - Alloc b = Alloc::allocMMap(8192); + Alloc a = Alloc::allocHeap(4_Ki); + Alloc b = Alloc::allocMMap(8_Ki); testSwap(a, b); } { @@ -90,8 +91,8 @@ TEST("test basics") { TEST("test correct alignment") { { - Alloc buf = Alloc::alloc(10, MemoryAllocator::HUGEPAGE_SIZE, 1024); - EXPECT_TRUE(reinterpret_cast<ptrdiff_t>(buf.get()) % 1024 == 0); + Alloc buf = Alloc::alloc(10, MemoryAllocator::HUGEPAGE_SIZE, 1_Ki); + EXPECT_TRUE(reinterpret_cast<ptrdiff_t>(buf.get()) % 1_Ki == 0); } { @@ -215,7 +216,7 @@ TEST("mmap alloc can be extended if room") { Alloc buf = Alloc::allocMMap(100); TEST_DO(ensureRoomForExtension(buf, reserved)); - TEST_DO(verifyExtension(buf, 4096, 4096*2)); + TEST_DO(verifyExtension(buf, 4_Ki, 4_Ki*2)); } TEST("mmap alloc can not be extended if no room") { @@ -223,7 +224,7 @@ TEST("mmap alloc can not be extended if no room") { Alloc reserved = Alloc::allocMMap(100); Alloc buf = Alloc::allocMMap(100); - TEST_DO(verifyNoExtensionWhenNoRoom(buf, reserved, 4096)); + TEST_DO(verifyNoExtensionWhenNoRoom(buf, reserved, 4_Ki)); } #endif #endif @@ -240,10 +241,10 @@ TEST("heap alloc can not be shrinked") { TEST("mmap alloc can be shrinked") { Alloc buf = Alloc::allocMMap(4097); void * oldPtr = buf.get(); - EXPECT_EQUAL(8192ul, buf.size()); + EXPECT_EQUAL(8_Ki, buf.size()); EXPECT_TRUE(buf.resize_inplace(4095)); EXPECT_EQUAL(oldPtr, buf.get()); - EXPECT_EQUAL(4096ul, buf.size()); + EXPECT_EQUAL(4_Ki, buf.size()); } TEST("auto alloced heap alloc can not be shrinked") { diff --git a/vespalib/src/tests/array/array_test.cpp b/vespalib/src/tests/array/array_test.cpp index a5dfd1472a6..e5294b3243b 100644 --- a/vespalib/src/tests/array/array_test.cpp +++ b/vespalib/src/tests/array/array_test.cpp @@ -1,8 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/util/array.hpp> #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/util/array.hpp> +#include <vespa/vespalib/util/size_literals.h> #include <deque> #include <atomic> @@ -139,14 +140,14 @@ TEST("test that organic growth is by 2 in N and reserve resize are exact") EXPECT_EQUAL(512u, c.capacity()); c.push_back('j'); EXPECT_EQUAL(513u, c.size()); - EXPECT_EQUAL(1024u, c.capacity()); + EXPECT_EQUAL(1_Ki, c.capacity()); for(size_t i(513); i < 1024; i++) { c.push_back('a'); } - EXPECT_EQUAL(1024u, c.size()); - EXPECT_EQUAL(1024u, c.capacity()); + EXPECT_EQUAL(1_Ki, c.size()); + EXPECT_EQUAL(1_Ki, c.capacity()); c.reserve(1025); - EXPECT_EQUAL(1024u, c.size()); + EXPECT_EQUAL(1_Ki, c.size()); EXPECT_EQUAL(1025u, c.capacity()); c.push_back('b'); // Within, no growth EXPECT_EQUAL(1025u, c.size()); @@ -345,7 +346,7 @@ TEST_F("require that try_unreserve() succeedes if mmap can be shrinked", Unreser int *oldPtr = &f.arr[0]; f.arr.resize(512); EXPECT_TRUE(f.arr.try_unreserve(1023)); - EXPECT_EQUAL(1024u, f.arr.capacity()); + EXPECT_EQUAL(1_Ki, f.arr.capacity()); int *newPtr = &f.arr[0]; EXPECT_EQUAL(oldPtr, newPtr); } diff --git a/vespalib/src/tests/data/databuffer/databuffer_test.cpp b/vespalib/src/tests/data/databuffer/databuffer_test.cpp index f440ca1e15c..80f3e9e9b86 100644 --- a/vespalib/src/tests/data/databuffer/databuffer_test.cpp +++ b/vespalib/src/tests/data/databuffer/databuffer_test.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/data/databuffer.h> #include <iostream> @@ -28,7 +29,7 @@ Test::testBasic() EXPECT_EQUAL(256u, a.getBufSize()); EXPECT_EQUAL(a.getFreeLen(), a.getBufSize()); a.ensureFree(1000); - EXPECT_EQUAL(1024u, a.getBufSize()); + EXPECT_EQUAL(1_Ki, a.getBufSize()); EXPECT_EQUAL(a.getFreeLen(), a.getBufSize()); EXPECT_EQUAL(0u, a.getDeadLen()); EXPECT_EQUAL(0u, a.getDataLen()); diff --git a/vespalib/src/tests/datastore/array_store/array_store_test.cpp b/vespalib/src/tests/datastore/array_store/array_store_test.cpp index 72f803b441b..bf2ca9629c2 100644 --- a/vespalib/src/tests/datastore/array_store/array_store_test.cpp +++ b/vespalib/src/tests/datastore/array_store/array_store_test.cpp @@ -7,6 +7,7 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/test/insertion_operators.h> #include <vespa/vespalib/util/memory_allocator.h> +#include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/traits.h> #include <vector> @@ -35,7 +36,7 @@ struct Fixture generation_t generation; Fixture(uint32_t maxSmallArraySize, bool enable_free_lists = true) : store(ArrayStoreConfig(maxSmallArraySize, - ArrayStoreConfig::AllocSpec(16, RefT::offsetSize(), 8 * 1024, + ArrayStoreConfig::AllocSpec(16, RefT::offsetSize(), 8_Ki, ALLOC_GROW_FACTOR)).enable_free_lists(enable_free_lists)), refStore(), generation(1) @@ -403,7 +404,7 @@ TEST_F("require that address space usage is ratio between used arrays and number TEST_F("require that offset in EntryRefT is within bounds when allocating memory buffers where wanted number of bytes is not a power of 2 and less than huge page size", ByteFixture(ByteFixture::ArrayStoreType::optimizedConfigForHugePage(1023, vespalib::alloc::MemoryAllocator::HUGEPAGE_SIZE, - 4 * 1024, 8 * 1024, ALLOC_GROW_FACTOR))) + 4_Ki, 8_Ki, ALLOC_GROW_FACTOR))) { // The array store config used in this test is equivalent to the one multi-value attribute uses when initializing multi-value mapping. // See similar test in datastore_test.cpp for more details on what happens during memory allocation. diff --git a/vespalib/src/tests/datastore/array_store_config/array_store_config_test.cpp b/vespalib/src/tests/datastore/array_store_config/array_store_config_test.cpp index e90149ed08f..a2a1ee91d57 100644 --- a/vespalib/src/tests/datastore/array_store_config/array_store_config_test.cpp +++ b/vespalib/src/tests/datastore/array_store_config/array_store_config_test.cpp @@ -3,6 +3,7 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/datastore/entryref.h> #include <vespa/vespalib/datastore/array_store_config.h> +#include <vespa/vespalib/util/size_literals.h> using namespace vespalib::datastore; using AllocSpec = ArrayStoreConfig::AllocSpec; @@ -64,7 +65,7 @@ TEST_F("require that we can generate config optimized for a given huge page", Fi 4 * KB, 8 * KB)) { - EXPECT_EQUAL(1024u, f.cfg.maxSmallArraySize()); + EXPECT_EQUAL(1_Ki, f.cfg.maxSmallArraySize()); TEST_DO(f.assertSpec(0, 8 * KB)); // large arrays TEST_DO(f.assertSpec(1, 256 * KB)); TEST_DO(f.assertSpec(2, 256 * KB)); diff --git a/vespalib/src/tests/datastore/datastore/datastore_test.cpp b/vespalib/src/tests/datastore/datastore/datastore_test.cpp index 0739fd24235..2024a440627 100644 --- a/vespalib/src/tests/datastore/datastore/datastore_test.cpp +++ b/vespalib/src/tests/datastore/datastore/datastore_test.cpp @@ -5,6 +5,7 @@ #include <vespa/vespalib/gtest/gtest.h> #include <vespa/vespalib/test/insertion_operators.h> #include <vespa/vespalib/test/memory_allocator_observer.h> +#include <vespa/vespalib/util/size_literals.h> #include <vespa/log/log.h> LOG_SETUP("datastore_test"); @@ -143,8 +144,8 @@ assertMemStats(const DataStoreBase::MemStats &exp, TEST(DataStoreTest, require_that_entry_ref_is_working) { using MyRefType = EntryRefT<22>; - EXPECT_EQ(4194304u, MyRefType::offsetSize()); - EXPECT_EQ(1024u, MyRefType::numBuffers()); + EXPECT_EQ(4_Mi, MyRefType::offsetSize()); + EXPECT_EQ(1_Ki, MyRefType::numBuffers()); { MyRefType r(0, 0); EXPECT_EQ(0u, r.offset()); @@ -171,8 +172,8 @@ TEST(DataStoreTest, require_that_entry_ref_is_working) TEST(DataStoreTest, require_that_aligned_entry_ref_is_working) { using MyRefType = AlignedEntryRefT<22, 2>; // 4 byte alignement - EXPECT_EQ(4 * 4194304u, MyRefType::offsetSize()); - EXPECT_EQ(1024u, MyRefType::numBuffers()); + EXPECT_EQ(16_Mi, MyRefType::offsetSize()); + EXPECT_EQ(1_Ki, MyRefType::numBuffers()); EXPECT_EQ(0u, MyRefType::align(0)); EXPECT_EQ(4u, MyRefType::align(1)); EXPECT_EQ(4u, MyRefType::align(2)); diff --git a/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp b/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp index a0ef200ab83..e26a0931090 100644 --- a/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp +++ b/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/blockingthreadstackexecutor.h> #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/backtrace.h> +#include <vespa/vespalib/util/size_literals.h> #include <thread> using namespace vespalib; @@ -122,14 +123,14 @@ vespalib::string get_worker_stack_trace(BlockingThreadStackExecutor &executor) { VESPA_THREAD_STACK_TAG(my_stack_tag); -TEST_F("require that executor has appropriate default thread stack tag", BlockingThreadStackExecutor(1, 128*1024, 10)) { +TEST_F("require that executor has appropriate default thread stack tag", BlockingThreadStackExecutor(1, 128_Ki, 10)) { vespalib::string trace = get_worker_stack_trace(f1); if (!EXPECT_TRUE(trace.find("unnamed_blocking_executor") != vespalib::string::npos)) { fprintf(stderr, "%s\n", trace.c_str()); } } -TEST_F("require that executor thread stack tag can be set", BlockingThreadStackExecutor(1, 128*1024, 10, my_stack_tag)) { +TEST_F("require that executor thread stack tag can be set", BlockingThreadStackExecutor(1, 128_Ki, 10, my_stack_tag)) { vespalib::string trace = get_worker_stack_trace(f1); if (!EXPECT_TRUE(trace.find("my_stack_tag") != vespalib::string::npos)) { fprintf(stderr, "%s\n", trace.c_str()); @@ -139,7 +140,7 @@ TEST_F("require that executor thread stack tag can be set", BlockingThreadStackE TEST_F("require that tasks posted from internal worker thread will not block executor", TimeBomb(60)) { size_t cnt = 0; Gate fork_done; - BlockingThreadStackExecutor executor(1, 128*1024, 10); + BlockingThreadStackExecutor executor(1, 128_Ki, 10); struct IncTask : Executor::Task { size_t &cnt; IncTask(size_t &cnt_in) : cnt(cnt_in) {} diff --git a/vespalib/src/tests/executor/threadstackexecutor_test.cpp b/vespalib/src/tests/executor/threadstackexecutor_test.cpp index e860a25c83c..a830a7a6c2b 100644 --- a/vespalib/src/tests/executor/threadstackexecutor_test.cpp +++ b/vespalib/src/tests/executor/threadstackexecutor_test.cpp @@ -3,6 +3,7 @@ #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/util/backtrace.h> +#include <vespa/vespalib/util/size_literals.h> #include <atomic> using namespace vespalib; @@ -171,14 +172,14 @@ vespalib::string get_worker_stack_trace(ThreadStackExecutor &executor) { VESPA_THREAD_STACK_TAG(my_stack_tag); -TEST_F("require that executor has appropriate default thread stack tag", ThreadStackExecutor(1, 128*1024)) { +TEST_F("require that executor has appropriate default thread stack tag", ThreadStackExecutor(1, 128_Ki)) { vespalib::string trace = get_worker_stack_trace(f1); if (!EXPECT_TRUE(trace.find("unnamed_nonblocking_executor") != vespalib::string::npos)) { fprintf(stderr, "%s\n", trace.c_str()); } } -TEST_F("require that executor thread stack tag can be set", ThreadStackExecutor(1, 128*1024, my_stack_tag)) { +TEST_F("require that executor thread stack tag can be set", ThreadStackExecutor(1, 128_Ki, my_stack_tag)) { vespalib::string trace = get_worker_stack_trace(f1); if (!EXPECT_TRUE(trace.find("my_stack_tag") != vespalib::string::npos)) { fprintf(stderr, "%s\n", trace.c_str()); diff --git a/vespalib/src/tests/io/fileutil/fileutiltest.cpp b/vespalib/src/tests/io/fileutil/fileutiltest.cpp index 0aaa84c0585..6f0308a3003 100644 --- a/vespalib/src/tests/io/fileutil/fileutiltest.cpp +++ b/vespalib/src/tests/io/fileutil/fileutiltest.cpp @@ -5,6 +5,7 @@ #include <vector> #include <regex> #include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/util/size_literals.h> namespace vespalib { @@ -406,7 +407,7 @@ TEST("require that vespalib::copy works") MallocAutoPtr buffer = getAlignedBuffer(5000); memset(buffer.get(), 0, 5000); strncpy(static_cast<char*>(buffer.get()), "Hello World!\n", 14); - f.write(buffer.get(), 4096, 0); + f.write(buffer.get(), 4_Ki, 0); f.close(); std::cerr << "Simple copy\n"; // Simple copy works (4096b dividable file) diff --git a/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp b/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp index 7230f97818f..ca1d5559bce 100644 --- a/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp +++ b/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp @@ -13,6 +13,7 @@ #include <vespa/vespalib/net/socket_utils.h> #include <vespa/vespalib/data/smart_buffer.h> #include <vespa/vespalib/test/make_tls_options_for_testing.h> +#include <vespa/vespalib/util/size_literals.h> #include <sys/types.h> #include <sys/socket.h> #include <fcntl.h> @@ -38,7 +39,7 @@ bool is_blocked(int res) { } void read(CryptoSocket &socket, SmartBuffer &buffer) { - size_t chunk_size = std::max(size_t(4096), socket.min_read_buffer_size()); + size_t chunk_size = std::max(size_t(4_Ki), socket.min_read_buffer_size()); auto chunk = buffer.reserve(chunk_size); int res = socket.read(chunk.data, chunk.size); if (res > 0) { @@ -50,7 +51,7 @@ void read(CryptoSocket &socket, SmartBuffer &buffer) { void drain(CryptoSocket &socket, SmartBuffer &buffer) { int res; - size_t chunk_size = std::max(size_t(4096), socket.min_read_buffer_size()); + size_t chunk_size = std::max(size_t(4_Ki), socket.min_read_buffer_size()); do { auto chunk = buffer.reserve(chunk_size); res = socket.drain(chunk.data, chunk.size); @@ -105,7 +106,7 @@ void read_EOF(CryptoSocket &socket, SmartBuffer &read_buffer) { ASSERT_EQUAL(read_buffer.obtain().size, 0u); SingleFdSelector selector(socket.get_fd()); ASSERT_TRUE(selector.wait_readable()); - size_t chunk_size = std::max(size_t(4096), socket.min_read_buffer_size()); + size_t chunk_size = std::max(size_t(4_Ki), socket.min_read_buffer_size()); auto chunk = read_buffer.reserve(chunk_size); auto res = socket.read(chunk.data, chunk.size); while (is_blocked(res)) { @@ -205,7 +206,7 @@ void verify_handshake(CryptoSocket &socket) { void verify_crypto_socket(SocketPair &sockets, CryptoEngine &engine, bool is_server) { SocketHandle &my_handle = is_server ? sockets.server : sockets.client; my_handle.set_blocking(false); - SmartBuffer read_buffer(4096); + SmartBuffer read_buffer(4_Ki); CryptoSocket::UP my_socket = is_server ? engine.create_server_crypto_socket(std::move(my_handle)) : engine.create_client_crypto_socket(std::move(my_handle), local_spec); diff --git a/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp b/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp index 7dacbd89503..92099e9a602 100644 --- a/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp +++ b/vespalib/src/tests/net/tls/openssl_impl/openssl_impl_test.cpp @@ -12,6 +12,7 @@ #include <vespa/vespalib/net/tls/impl/openssl_tls_context_impl.h> #include <vespa/vespalib/test/make_tls_options_for_testing.h> #include <vespa/vespalib/test/peer_policy_utils.h> +#include <vespa/vespalib/util/size_literals.h> #include <stdexcept> #include <stdlib.h> @@ -83,8 +84,8 @@ struct Fixture { tls_ctx(TlsContext::create_default_context(tls_opts, AuthorizationMode::Enforce)), client(create_openssl_codec(tls_ctx, CryptoCodec::Mode::Client)), server(create_openssl_codec(tls_ctx, CryptoCodec::Mode::Server)), - client_to_server(64 * 1024), - server_to_client(64 * 1024) + client_to_server(64_Ki), + server_to_client(64_Ki) {} ~Fixture(); diff --git a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp index 97c767a17ed..3f36bbf6401 100644 --- a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp +++ b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp @@ -3,6 +3,7 @@ #include <vespa/vespalib/util/shared_string_repo.h> #include <vespa/vespalib/util/rendezvous.h> #include <vespa/vespalib/util/time.h> +#include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/stllike/hash_map.hpp> #include <vespa/vespalib/testkit/test_kit.h> @@ -18,7 +19,7 @@ using Stats = SharedStringRepo::Stats; bool verbose = false; double budget = 0.10; -size_t work_size = 4096; +size_t work_size = 4_Ki; //----------------------------------------------------------------------------- diff --git a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp index f1021ba3b09..7e8bcdcc5f4 100644 --- a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/simple_thread_bundle.h> +#include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/box.h> #include <thread> @@ -8,7 +9,7 @@ using namespace vespalib; uint64_t doWork(uint64_t data) { uint64_t value = data; - for (size_t i = 0; i < 1024 * 1024; ++i) { + for (size_t i = 0; i < 1_Mi; ++i) { value = (value << 16) + (value >> 8) + (value << 32); } return value; diff --git a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp index dc31f4b8b42..a7f6aa06e26 100644 --- a/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp +++ b/vespalib/src/tests/slime/summary-feature-benchmark/summary-feature-benchmark.cpp @@ -1,5 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/data/slime/slime.h> @@ -9,7 +10,7 @@ using namespace vespalib::slime::convenience; struct MyBuffer : public Output { std::vector<char> data; size_t used; - MyBuffer() : data(1024 * 1024), used(0) {} + MyBuffer() : data(1_Mi), used(0) {} ~MyBuffer(); WritableMemory reserve(size_t bytes) override { assert(data.size() >= (used + bytes)); diff --git a/vespalib/src/tests/stash/stash.cpp b/vespalib/src/tests/stash/stash.cpp index cea359a1bab..65de2ed8030 100644 --- a/vespalib/src/tests/stash/stash.cpp +++ b/vespalib/src/tests/stash/stash.cpp @@ -1,5 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/stash.h> #include <vespa/vespalib/util/traits.h> @@ -171,7 +172,7 @@ TEST("require that large object creation and destruction works") { Stash stash; stash.create<Large>(destructed); EXPECT_EQUAL(0u, stash.count_used()); - EXPECT_GREATER(sizeof(Large), 1024u); + EXPECT_GREATER(sizeof(Large), 1_Ki); EXPECT_FALSE(destructed); } EXPECT_TRUE(destructed); @@ -193,7 +194,7 @@ TEST("require that large objects can skip destruction") { Stash stash; stash.create<Large_NoDelete>(destructed); EXPECT_EQUAL(0u, stash.count_used()); - EXPECT_GREATER(sizeof(Large_NoDelete), 1024u); + EXPECT_GREATER(sizeof(Large_NoDelete), 1_Ki); } EXPECT_FALSE(destructed); } @@ -243,9 +244,9 @@ TEST("require that multiple chunks can be used by the stash") { EXPECT_EQUAL(100 * 512 + count * chunk_header_size(), stash.count_used()); } -TEST("require that default chunk size is 4096") { +TEST("require that default chunk size is 4_Ki") { Stash stash; - EXPECT_EQUAL(4096u, stash.get_chunk_size()); + EXPECT_EQUAL(4_Ki, stash.get_chunk_size()); } TEST("require that the chunk size can be adjusted") { @@ -460,7 +461,7 @@ void check_array(ArrayRef<float> arr, size_t expect_size) { } TEST("require that uninitialized arrays can be created") { - Stash stash(4096); + Stash stash(4_Ki); EXPECT_EQUAL(0u, stash.count_used()); ArrayRef<float> small_arr = stash.create_uninitialized_array<float>(64); TEST_DO(check_array(small_arr, 64)); diff --git a/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp b/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp index 2c1463e506a..f606b7aa39e 100644 --- a/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp +++ b/vespalib/src/tests/util/generationhandler_stress/generation_handler_stress_test.cpp @@ -2,9 +2,9 @@ #include <vespa/log/log.h> LOG_SETUP("generation_handler_stress_test"); #include <vespa/vespalib/testkit/testapp.h> - #include <vespa/vespalib/util/generationhandler.h> #include <vespa/vespalib/util/threadstackexecutor.h> +#include <vespa/vespalib/util/size_literals.h> using vespalib::Executor; using vespalib::GenerationHandler; @@ -52,8 +52,8 @@ private: Fixture::Fixture(uint32_t readThreads) : _generationHandler(), _readThreads(readThreads), - _writer(1, 128 * 1024), - _readers(readThreads, 128 * 1024), + _writer(1, 128_Ki), + _readers(readThreads, 128_Ki), _doneWriteWork(0), _doneReadWork(0), _stopRead(0), diff --git a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp b/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp index 4cbfbfebd3c..d0f319d4a0b 100644 --- a/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp +++ b/vespalib/src/tests/util/rcuvector/rcuvector_test.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/testapp.h> #include <vespa/vespalib/util/rcuvector.h> +#include <vespa/vespalib/util/size_literals.h> using namespace vespalib; @@ -241,13 +242,13 @@ struct ShrinkFixture { GenerationHolder g; RcuVectorBase<int> vec; int *oldPtr; - ShrinkFixture() : g(), vec(4096, 50, 0, g, alloc::Alloc::allocMMap()), oldPtr() + ShrinkFixture() : g(), vec(4_Ki, 50, 0, g, alloc::Alloc::allocMMap()), oldPtr() { for (size_t i = 0; i < 4000; ++i) { vec.push_back(7); } EXPECT_EQUAL(4000u, vec.size()); - EXPECT_EQUAL(4096u, vec.capacity()); + EXPECT_EQUAL(4_Ki, vec.capacity()); assertEmptyHoldList(); oldPtr = &vec[0]; } @@ -263,7 +264,7 @@ TEST_F("require that shrink() does not increase allocated memory", ShrinkFixture { f.vec.shrink(2732); EXPECT_EQUAL(2732u, f.vec.size()); - EXPECT_EQUAL(4096u, f.vec.capacity()); + EXPECT_EQUAL(4_Ki, f.vec.capacity()); TEST_DO(f.assertOldEqualNewBuffer()); TEST_DO(f.assertEmptyHoldList()); } |