Skip to content

Commit

Permalink
#2027: Tests: Add test to reproduce Non-copyable invoke call
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobDomagala committed Dec 7, 2022
1 parent 3deaeaa commit 24cfffe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/unit/objgroup/test_objgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ TEST_F(TestObjGroup, test_proxy_invoke) {

EXPECT_EQ(accumulate_result, 11);
EXPECT_EQ(proxy.get()->recv_, 2);

// Non-copyable (and without default constructor)
NonCopyableStruct s{20};
auto const result = proxy[this_node]
.invoke<
decltype(&MyObjA::modifyNonCopyableStruct),
&MyObjA::modifyNonCopyableStruct>(std::move(s));

EXPECT_EQ(result.val, 10);
EXPECT_EQ(proxy.get()->recv_, 3);
}

TEST_F(TestObjGroup, test_pending_send) {
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/objgroup/test_objgroup_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//@HEADER
*/

#include <memory>
#if !defined INCLUDED_UNIT_OBJGROUP_TEST_OBJGROUP_COMMON_H
#define INCLUDED_UNIT_OBJGROUP_TEST_OBJGROUP_COMMON_H

Expand All @@ -64,6 +65,16 @@ struct SysMsg : vt::collective::ReduceTMsg<int> {
{}
};

struct NonCopyableStruct {
NonCopyableStruct(const NonCopyableStruct&) = delete;
NonCopyableStruct& operator=(const NonCopyableStruct&) = delete;

NonCopyableStruct(NonCopyableStruct&&) = default;
NonCopyableStruct& operator=(NonCopyableStruct&&) = default;

int val = 20;
};

struct MyObjA {

MyObjA() : id_(++next_id) {}
Expand Down Expand Up @@ -97,6 +108,13 @@ struct MyObjA {
return std::accumulate(std::begin(vec), std::end(vec), 0);
}

NonCopyableStruct modifyNonCopyableStruct(NonCopyableStruct i) {
recv_++;
i.val = 10;

return i;
}

int id_ = -1;
int recv_ = 0;
static int next_id;
Expand Down

0 comments on commit 24cfffe

Please sign in to comment.