Skip to content

Commit

Permalink
Reduce code duplication in TestPutOverwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHogan committed Jan 21, 2021
1 parent 39a48ab commit 35a5026
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/buffer_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void SetFirstFreeBufferId(SharedMemoryContext *context, DeviceID device_id,
}

std::atomic<u32> *GetAvailableBuffersArray(SharedMemoryContext *context,
DeviceID device_id) {
DeviceID device_id) {
BufferPool *pool = GetBufferPoolFromContext(context);
std::atomic<u32> *result =
(std::atomic<u32> *)(context->shm_base +
Expand Down
14 changes: 11 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,29 @@ target_compile_definitions(bp_test
#------------------------------------------------------------------------------

add_executable(config_parser_test config_parser_test.cc)
target_link_libraries(config_parser_test hermes)
target_link_libraries(config_parser_test hermes
$<$<BOOL:${HERMES_RPC_THALLIUM}>:thallium>)

add_test(NAME TestConfigParser
COMMAND config_parser_test ${CMAKE_CURRENT_SOURCE_DIR}/data/hermes.conf)
target_compile_definitions(config_parser_test
PRIVATE $<$<BOOL:${HERMES_RPC_THALLIUM}>:HERMES_RPC_THALLIUM>)

#------------------------------------------------------------------------------
# Memory Management tests
#------------------------------------------------------------------------------

add_executable(mem memory_test.cc)
target_link_libraries(mem hermes)
target_link_libraries(mem hermes $<$<BOOL:${HERMES_RPC_THALLIUM}>:thallium>)
add_test(NAME TestMemoryManagement COMMAND mem)
target_compile_definitions(mem
PRIVATE $<$<BOOL:${HERMES_RPC_THALLIUM}>:HERMES_RPC_THALLIUM>)

add_executable(stb_map stb_map_test.cc)
target_link_libraries(stb_map hermes ${LIBRT} MPI::MPI_CXX)
target_link_libraries(stb_map hermes ${LIBRT}
$<$<BOOL:${HERMES_RPC_THALLIUM}>:thallium> MPI::MPI_CXX)
target_compile_definitions(stb_map
PRIVATE $<$<BOOL:${HERMES_RPC_THALLIUM}>:HERMES_RPC_THALLIUM>)
add_test(NAME TestSTBMapWithHeap COMMAND stb_map)

#------------------------------------------------------------------------------
Expand Down
17 changes: 2 additions & 15 deletions test/bucket_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,14 @@ void TestPutOverwrite(std::shared_ptr<hapi::Hermes> hermes) {
hapi::Status status = bucket.Put(blob_name, blob, ctx);
Assert(status == 0);

hapi::Blob retrieved_blob;
size_t retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx);
Assert(blob_size == retrieved_size);
retrieved_blob.resize(retrieved_size);
retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx);
Assert(blob_size == retrieved_size);
Assert(retrieved_blob == blob);

retrieved_blob.clear();
hermes::testing::GetAndVerifyBlob(bucket, blob_name, blob);

// NOTE(chogan): Overwrite the data
size_t new_size = KILOBYTES(9);
hapi::Blob new_blob(new_size, 'z');
status = bucket.Put(blob_name, new_blob, ctx);

retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx);
Assert(retrieved_size == new_size);
retrieved_blob.resize(retrieved_size);
retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx);
Assert(retrieved_size == new_size);
Assert(retrieved_blob == new_blob);
hermes::testing::GetAndVerifyBlob(bucket, blob_name, new_blob);

bucket.Destroy(ctx);
}
Expand Down
18 changes: 16 additions & 2 deletions test/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <map>

#include "hermes_types.h"
#include "bucket.h"

namespace hermes {
namespace testing {
Expand Down Expand Up @@ -43,6 +44,8 @@ void Assert(bool expr, const char *file, int lineno, const char *message) {
}
}

#define Assert(expr) hermes::testing::Assert((expr), __FILE__, __LINE__, #expr)

struct TargetViewState {
std::vector<hermes::u64> bytes_capacity;
std::vector<hermes::u64> bytes_available;
Expand Down Expand Up @@ -143,9 +146,20 @@ void PrintNodeState(TargetViewState &node_state) {
}
}

void GetAndVerifyBlob(api::Bucket &bucket, const std::string &blob_name,
const api::Blob &expected) {
api::Context ctx;
api::Blob retrieved_blob;
size_t expected_size = expected.size();
size_t retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx);
Assert(expected_size == retrieved_size);
retrieved_blob.resize(retrieved_size);
retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx);
Assert(expected_size == retrieved_size);
Assert(retrieved_blob == expected);
}

} // namespace testing
} // namespace hermes

#define Assert(expr) hermes::testing::Assert((expr), __FILE__, __LINE__, #expr)

#endif // HERMES_TEST_UTILS_H_

0 comments on commit 35a5026

Please sign in to comment.