Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft e2e test #219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class SocketPartyCommunicationAgentFactory final
if (id == myId_) {
throw std::runtime_error("No need to talk to myself!");
} else {
auto serverId = id < myId_ ? id : myId_;
auto iter = partyInfos_.find(serverId);
auto iter = partyInfos_.find(id);
if (iter == partyInfos_.end()) {
throw std::runtime_error("Don't know how to connect to this party!");
}
Expand Down
45 changes: 42 additions & 3 deletions fbpcf/engine/communication/test/AgentFactoryCreationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

#pragma once

#include <fbpcf/engine/communication/SocketPartyCommunicationAgentFactory.h>
#include <iostream>
#include <memory>
#include "fbpcf/engine/communication/InMemoryPartyCommunicationAgentFactory.h"
#include "folly/Random.h"

namespace fbpcf::engine::communication {

Expand All @@ -18,7 +21,7 @@ getInMemoryAgentFactory(int numberOfParty) {
int,
std::shared_ptr<InMemoryPartyCommunicationAgentFactory::HostInfo>>>(
numberOfParty);
std::vector<std::unique_ptr<IPartyCommunicationAgentFactory>> rst;
std::vector<std::unique_ptr<IPartyCommunicationAgentFactory>> result;

for (int i = 0; i < numberOfParty; i++) {
for (int j = i + 1; j < numberOfParty; j++) {
Expand All @@ -30,10 +33,46 @@ getInMemoryAgentFactory(int numberOfParty) {
}
}
for (int i = 0; i < numberOfParty; i++) {
rst.push_back(std::make_unique<InMemoryPartyCommunicationAgentFactory>(
result.push_back(std::make_unique<InMemoryPartyCommunicationAgentFactory>(
i, std::move(maps[i])));
}
return rst;
return result;
}

inline std::vector<std::unique_ptr<IPartyCommunicationAgentFactory>>
getSocketAgentFactory(int numberOfParty) {
auto maps = std::vector<
std::map<int, SocketPartyCommunicationAgentFactory::PartyInfo>>(
numberOfParty);
for (int i = 0; i < numberOfParty; i++) {
int port = 5000 + folly::Random::rand32() % 1000;
for (int j = i; j < numberOfParty; j++) {
SocketPartyCommunicationAgentFactory::PartyInfo partyInfo = {
"localhost", port};
if (i == j) {
continue;
}
maps[j].emplace(i, partyInfo);
maps[i].emplace(j, partyInfo);
}
}

std::vector<std::unique_ptr<IPartyCommunicationAgentFactory>> result;
for (int i = 0; i < numberOfParty; i++) {
auto m = maps[i];
std::cerr << "entry " << i << "\n";
for (auto const& x : m) {
std::cerr << x.first << ":[" << x.second.address << "," << x.second.portNo
<< "]";
}
std::cerr << "\n";
}

for (int i = 0; i < numberOfParty; i++) {
result.push_back(
std::make_unique<SocketPartyCommunicationAgentFactory>(i, maps[i]));
}
return result;
}

} // namespace fbpcf::engine::communication
24 changes: 14 additions & 10 deletions fbpcf/engine/communication/test/PartyCommunicationAgentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ TEST(SocketPartyCommunicationAgentTest, testSendAndReceiveWithTls) {
* stress runs, we get errors when trying to bind to the
* same port multiple times.
*/
std::map<int, SocketPartyCommunicationAgentFactory::PartyInfo> partyInfo = {
{0, {"127.0.0.1", intDistro(defEngine)}},
{1, {"127.0.0.1", intDistro(defEngine)}}};
auto port = intDistro(defEngine);
std::map<int, SocketPartyCommunicationAgentFactory::PartyInfo> partyInfo0 = {
{1, {"127.0.0.1", port}}};
std::map<int, SocketPartyCommunicationAgentFactory::PartyInfo> partyInfo1 = {
{0, {"127.0.0.1", port}}};

auto factory0 = std::make_unique<SocketPartyCommunicationAgentFactory>(
0, partyInfo, true, createdDir);
0, partyInfo0, true, createdDir);
auto factory1 = std::make_unique<SocketPartyCommunicationAgentFactory>(
1, partyInfo, true, createdDir);
1, partyInfo1, true, createdDir);

int size = 1048576; // 1024 ^ 2
auto thread0 = std::thread(testAgentFactory, 0, size, std::move(factory0));
Expand All @@ -97,14 +99,16 @@ TEST(SocketPartyCommunicationAgentTest, testSendAndReceiveWithoutTls) {
std::default_random_engine defEngine(rd());
std::uniform_int_distribution<int> intDistro(10000, 25000);

std::map<int, SocketPartyCommunicationAgentFactory::PartyInfo> partyInfo = {
{0, {"127.0.0.1", intDistro(defEngine)}},
{1, {"127.0.0.1", intDistro(defEngine)}}};
auto port = intDistro(defEngine);
std::map<int, SocketPartyCommunicationAgentFactory::PartyInfo> partyInfo0 = {
{1, {"127.0.0.1", port}}};
std::map<int, SocketPartyCommunicationAgentFactory::PartyInfo> partyInfo1 = {
{0, {"127.0.0.1", port}}};

auto factory0 =
std::make_unique<SocketPartyCommunicationAgentFactory>(0, partyInfo);
std::make_unique<SocketPartyCommunicationAgentFactory>(0, partyInfo0);
auto factory1 =
std::make_unique<SocketPartyCommunicationAgentFactory>(1, partyInfo);
std::make_unique<SocketPartyCommunicationAgentFactory>(1, partyInfo1);

int size = 1048576; // 1024 ^ 2
auto thread0 = std::thread(testAgentFactory, 0, size, std::move(factory0));
Expand Down
14 changes: 9 additions & 5 deletions fbpcf/engine/util/test/benchmarks/BenchmarkHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ getSocketAgents() {
auto retries = 5;
while (retries--) {
try {
auto port = intDistro(e);
std::map<
int,
communication::SocketPartyCommunicationAgentFactory::PartyInfo>
partyInfo = {
{0, {"127.0.0.1", intDistro(e)}},
{1, {"127.0.0.1", intDistro(e)}}};
partyInfo0 = {{1, {"127.0.0.1", port}}};
std::map<
int,
communication::SocketPartyCommunicationAgentFactory::PartyInfo>
partyInfo1 = {{0, {"127.0.0.1", port}}};

auto factory0 =
std::make_unique<communication::SocketPartyCommunicationAgentFactory>(
0, partyInfo);
0, partyInfo0);
auto factory1 =
std::make_unique<communication::SocketPartyCommunicationAgentFactory>(
1, partyInfo);
1, partyInfo1);

auto task =
[](std::unique_ptr<communication::IPartyCommunicationAgentFactory>
Expand Down
47 changes: 47 additions & 0 deletions fbpcf/frontend/test/IntE2ETest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <fbpcf/test/TestHelper.h>
#include <gtest/gtest.h>
#include "fbpcf/engine/communication/SocketPartyCommunicationAgentFactory.h"
#include "fbpcf/engine/communication/test/AgentFactoryCreationHelper.h"
#include "fbpcf/frontend/Int.h"

namespace fbpcf::frontend {

template <int PARTY, int schedulerId>
static int runGame() {
Integer<Secret<Signed<63>>, schedulerId> int1(PARTY == 0 ? -45 : 10, 0);
Integer<Secret<Signed<63>>, schedulerId> int2(PARTY == 1 ? 15 : -90, 1);

auto sum = int1 + int2;

return sum.openToParty(PARTY + 1 % 2).getValue();
}

class IntE2ETest : public ::testing::Test {
protected:
void SetUp() override {
auto factories = fbpcf::engine::communication::getSocketAgentFactory(2);
fbpcf::setupRealBackend<5, 10>(*factories[0], *factories[1]);
}

void TearDown() override {}
};

TEST_F(IntE2ETest, TestCorrectness) {
auto futureAlice = std::async(runGame<0, 5>);
auto futureBob = std::async(runGame<1, 10>);

int ans1 = futureAlice.get();
int ans2 = futureBob.get();

EXPECT_EQ(ans1, 30);
EXPECT_EQ(ans2, 30);
}

} // namespace fbpcf::frontend