Skip to content

Commit

Permalink
Include billionaire problem in sanity check (#200)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #200

## Why
We want to include a sanity check script for PCF 2 just like we have for PCF 1. It also is an example of how to use PCF 2.

## What
1. Add an executable into the CMakeLists
2. Modify the sanity check script to run both v1 and v2
3. Move the folder to the `example` directory

Reviewed By: wuman

Differential Revision: D36176047

fbshipit-source-id: ea853a9f5fbc6e2e41a894edc5e6ccd18f9cece9
  • Loading branch information
adshastri authored and facebook-github-bot committed May 6, 2022
1 parent bef560e commit fda0d07
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 61 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ jobs:
run: |
./build-docker.sh -u
- name: Sanity check fbpcf library (only tests v1 functionality)
- name: Sanity check fbpcf library (v1)
timeout-minutes: 3
run: |
./run-millionaire-sample.sh -u
./run-sanity_check.sh -u -v 1
working-directory: fbpcf/tests/github/

- name: Sanity check fbpcf library (v2)
timeout-minutes: 3
run: |
./run-sanity_check.sh -u -v 2
working-directory: fbpcf/tests/github/

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v1
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ jobs:
run: |
./build-docker.sh -u
- name: Sanity check fbpcf library
- name: Sanity check fbpcf library (v1)
timeout-minutes: 3
run: |
./run-millionaire-sample.sh -u
./run-sanity_check.sh -u -v 1
working-directory: fbpcf/tests/github/

- name: Sanity check fbpcf library (v2)
timeout-minutes: 3
run: |
./run-sanity_check.sh -u -v 2
working-directory: fbpcf/tests/github/

- name: Cleanup
run: |
Expand Down
10 changes: 10 additions & 0 deletions docker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,14 @@ target_link_libraries(
millionaire
fbpcf)

add_executable(
billionaire
"example/billionaire_problem/main.cpp"
"example/billionaire_problem/BillionaireProblemGame.h"
"example/billionaire_problem/BillionaireProblemGame_impl.h")
target_link_libraries(
billionaire
fbpcf)

install(TARGETS millionaire DESTINATION bin)
install(TARGETS billionaire DESTINATION bin)
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ class BillionaireProblemGame : public frontend::MpcGame<schedulerId> {

} // namespace fbpcf::billionaire_problem

#include "fbpcf/test/billionaire_problem/BillionaireProblemGame_impl.h"
#include "./BillionaireProblemGame_impl.h"
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#pragma once

#include "./BillionaireProblemGame.h"
#include "fbpcf/frontend/mpcGame.h"
#include "fbpcf/test/billionaire_problem/BillionaireProblemGame.h"

namespace fbpcf::billionaire_problem {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "folly/init/Init.h"
#include "folly/logging/xlog.h"

#include "./BillionaireProblemGame.h"
#include "fbpcf/engine/communication/SocketPartyCommunicationAgentFactory.h"
#include "fbpcf/test/billionaire_problem/BillionaireProblemGame.h"

DEFINE_int32(party, 0, "my party ID");
DEFINE_string(server_ip, "127.0.0.1", "server's ip address");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include "fbpcf/test/billionaire_problem/BillionaireProblemGame.h"
#include "../BillionaireProblemGame.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <functional>
Expand Down
80 changes: 80 additions & 0 deletions fbpcf/tests/github/run-sanity_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
# 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.

set -e

PROG_NAME=$0
usage() {
cat << EOF >&2
Usage: $PROG_NAME [-u] [-v VERSION]
-u: runs the sanity check sample game using the ubuntu docker image (default)
-v: specify 1 or 2 to determine whether to run PCF v1 or v2. Default is 2.
EOF
exit 1
}

IMAGE_PREFIX="ubuntu"
VERSION="1"
while getopts "u,v:" o; do
case $o in
(u) IMAGE_PREFIX="ubuntu";;
(v) VERSION=$OPTARG;;
(*) usage
esac
done
shift "$((OPTIND - 1))"

FBPCF_IMAGE=fbpcf/${IMAGE_PREFIX}:latest
if docker image inspect ${FBPCF_IMAGE} > /dev/null 2>&1; then
printf "Found %s docker image... \n" ${FBPCF_IMAGE}
else
printf "ERROR: Unable to find docker image %s. Please run build-docker.sh \n" ${FBPCF_IMAGE}
exit 1
fi

if [ "${VERSION}" == "1" ]; then
docker run --rm \
--network=host ${FBPCF_IMAGE} \
millionaire \
--role=1 \
--port=5000 \
2>&1 publisher & # Fork to background so "partner" can run below

if docker run --rm \
--network=host ${FBPCF_IMAGE} \
millionaire \
--role=2 \
--port=5000 \
--server_ip=127.0.0.1; then
printf "Millionaire ran successfully! "
else
printf "Something went wrong. You may want to check the logs above."
exit 1
fi
elif [ "${VERSION}" == "2" ]; then
docker run --rm \
--network=host ${FBPCF_IMAGE} \
billionaire \
--party=0 \
--port=5000 \
2>&1 publisher & # Fork to background so "partner" can run below

if docker run --rm \
--network=host ${FBPCF_IMAGE} \
billionaire \
--party=1 \
--port=5000 \
--server_ip=127.0.0.1; then
printf "Billionaire ran successfully! "
else
printf "Something went wrong. You may want to check the logs above."
exit 1
fi
else
printf "Invalid version provided. It must be either 1 or 2."
exit 1
fi
53 changes: 0 additions & 53 deletions run-millionaire-sample.sh

This file was deleted.

0 comments on commit fda0d07

Please sign in to comment.