-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the PDI wrapper (#743)
- Loading branch information
1 parent
63eb62b
commit 852fbff
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (C) The DDC development team, see COPYRIGHT.md file | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
cmake_minimum_required(VERSION 3.22) | ||
|
||
include(GoogleTest) | ||
|
||
add_executable(pdi_tests ../main.cpp pdi.cpp) | ||
set_property(TARGET pdi_tests PROPERTY ENABLE_EXPORTS TRUE) | ||
target_compile_features(pdi_tests PUBLIC cxx_std_17) | ||
target_link_libraries(pdi_tests PUBLIC GTest::gtest DDC::core DDC::pdi) | ||
gtest_discover_tests(pdi_tests DISCOVERY_MODE PRE_TEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright (C) The DDC development team, see COPYRIGHT.md file | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <cstddef> | ||
#include <string> | ||
|
||
#include <ddc/ddc.hpp> | ||
#include <ddc/pdi.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <paraconf.h> | ||
#include <pdi.h> | ||
|
||
namespace { | ||
|
||
struct DDimX | ||
{ | ||
}; | ||
|
||
struct DDimY | ||
{ | ||
}; | ||
|
||
} // namespace | ||
|
||
extern "C" { | ||
|
||
void test_ddc_expose() | ||
{ | ||
// pdi_chunk_label_rank | ||
void* pdi_chunk_label_rank_ptr; | ||
ASSERT_EQ(PDI_access("pdi_chunk_label_rank", &pdi_chunk_label_rank_ptr, PDI_IN), PDI_OK); | ||
std::size_t const* const pdi_chunk_label_rank | ||
= static_cast<std::size_t*>(pdi_chunk_label_rank_ptr); | ||
EXPECT_EQ(*pdi_chunk_label_rank, 2); | ||
|
||
// pdi_chunk_label_extents | ||
void* pdi_chunk_label_extents_ptr; | ||
ASSERT_EQ(PDI_access("pdi_chunk_label_extents", &pdi_chunk_label_extents_ptr, PDI_IN), PDI_OK); | ||
std::size_t const* const pdi_chunk_label_extents | ||
= static_cast<std::size_t*>(pdi_chunk_label_extents_ptr); | ||
ASSERT_EQ(pdi_chunk_label_extents[0], 3); | ||
ASSERT_EQ(pdi_chunk_label_extents[1], 5); | ||
|
||
// pdi_chunk_label | ||
void* pdi_chunk_label_ptr; | ||
ASSERT_EQ(PDI_access("pdi_chunk_label", &pdi_chunk_label_ptr, PDI_IN), PDI_OK); | ||
int const* const pdi_chunk_label = static_cast<int*>(pdi_chunk_label_ptr); | ||
for (std::size_t i = 0; i < pdi_chunk_label_extents[0]; ++i) { | ||
for (std::size_t j = 0; j < pdi_chunk_label_extents[1]; ++j) { | ||
EXPECT_EQ(pdi_chunk_label[pdi_chunk_label_extents[1] * i + j], 3); | ||
} | ||
} | ||
|
||
EXPECT_EQ(PDI_reclaim("pdi_chunk_label_rank"), PDI_OK); | ||
EXPECT_EQ(PDI_reclaim("pdi_chunk_label_extents"), PDI_OK); | ||
EXPECT_EQ(PDI_reclaim("pdi_chunk_label"), PDI_OK); | ||
|
||
// nb_event_called | ||
void* nb_event_called_ptr; | ||
ASSERT_EQ(PDI_access("nb_event_called", &nb_event_called_ptr, PDI_INOUT), PDI_OK); | ||
int* const nb_event_called = static_cast<int*>(nb_event_called_ptr); | ||
*nb_event_called += 1; | ||
|
||
EXPECT_EQ(PDI_reclaim("nb_event_called"), PDI_OK); | ||
} | ||
} | ||
|
||
TEST(Pdi, ChunkAndChunkSpan) | ||
{ | ||
std::string const pdi_cfg = R"PDI_CFG( | ||
metadata: | ||
pdi_chunk_label_rank: size_t | ||
pdi_chunk_label_extents: | ||
type: array | ||
subtype: size_t | ||
size: $pdi_chunk_label_rank | ||
data: | ||
pdi_chunk_label: | ||
type: array | ||
subtype: int | ||
size: [ '$pdi_chunk_label_extents[0]', '$pdi_chunk_label_extents[1]' ] | ||
nb_event_called: int | ||
plugins: | ||
user_code: | ||
on_event: | ||
some_event: | ||
test_ddc_expose: {} | ||
)PDI_CFG"; | ||
|
||
PC_tree_t pdi_conf = PC_parse_string(pdi_cfg.c_str()); | ||
PDI_init(pdi_conf); | ||
|
||
PDI_errhandler(PDI_NULL_HANDLER); | ||
|
||
{ | ||
ddc::DiscreteDomain<DDimX, DDimY> const | ||
ddom_xy(ddc::DiscreteElement<DDimX, DDimY>(7, 11), | ||
ddc::DiscreteVector<DDimX, DDimY>(3, 5)); | ||
|
||
ddc::Chunk chunk("ddc_chunk_label", ddom_xy, ddc::HostAllocator<int>()); | ||
ddc::parallel_fill(chunk, 3); | ||
|
||
int nb_event_called = 0; | ||
|
||
ddc::PdiEvent("some_event") | ||
.with("pdi_chunk_label", chunk) | ||
.and_with("nb_event_called", nb_event_called); | ||
|
||
ddc::PdiEvent("some_event") | ||
.with("pdi_chunk_label", chunk.span_view()) | ||
.and_with("nb_event_called", nb_event_called); | ||
|
||
ddc::PdiEvent("some_event") | ||
.with("pdi_chunk_label", chunk.span_cview()) | ||
.and_with("nb_event_called", nb_event_called); | ||
|
||
EXPECT_EQ(nb_event_called, 3); | ||
} | ||
|
||
PDI_finalize(); | ||
PC_tree_destroy(&pdi_conf); | ||
} |