Skip to content

Commit

Permalink
add hybrid_test assert against in the clear results
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktaubeneck committed Dec 6, 2024
1 parent 44500bb commit fd76f4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
4 changes: 1 addition & 3 deletions ipa-core/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ pub fn spawn_shards(
command.args(["--shard-server-socket-fd", &shard.as_raw_fd().to_string()]);

// something went wrong if command is terminated at this point.
// let mut child = command.silent().spawn().unwrap();
// TODO: make this silent again
let mut child = command.spawn().unwrap();
let mut child = command.silent().spawn().unwrap();
match child.try_wait() {
Ok(Some(status)) => {
panic!("Helper binary terminated early with status = {status}")
Expand Down
29 changes: 16 additions & 13 deletions ipa-core/tests/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#[allow(dead_code)]
mod common;

use std::process::{Command, Stdio};
use std::{
fs::File,
process::{Command, Stdio},
};

use common::{
spawn_shards, tempdir::TempDir, test_sharded_setup, CommandExt, TerminateOnDropExt,
Expand All @@ -11,6 +14,7 @@ use common::{
use ipa_core::{cli::playbook::HybridQueryResult, helpers::query::HybridQueryParams};
use rand::thread_rng;
use rand_core::RngCore;
use serde_json::from_reader;

pub const IN_THE_CLEAR_BIN: &str = env!("CARGO_BIN_EXE_in_the_clear");

Expand Down Expand Up @@ -59,12 +63,6 @@ fn test_hybrid() {
.stdin(Stdio::piped());
command.status().unwrap_status();

println!(
"In the clear results: {}",
&std::fs::read_to_string(&in_the_clear_output_file)
.expect("IPA in the clear results file exists")
);

let config_path = dir.path().join("config");
let sockets = test_sharded_setup::<SHARDS>(&config_path);
let _helpers = spawn_shards(&config_path, &sockets, true);
Expand All @@ -90,6 +88,7 @@ fn test_hybrid() {
.args(["--shard-count", SHARDS.to_string().as_str()])
.args(["--wait", "2"])
.arg("malicious-hybrid")
.silent()
.args(["--count", INPUT_SIZE.to_string().as_str()])
.args(["--enc-input-file1".as_ref(), enc1.as_os_str()])
.args(["--enc-input-file2".as_ref(), enc2.as_os_str()])
Expand All @@ -112,11 +111,6 @@ fn test_hybrid() {
test_mpc.wait().unwrap_status();

// basic output checks - output should have the exact size as number of breakdowns
println!(
"{}",
&std::fs::read_to_string(&output_file).expect("IPA results file should exist")
);

let output = serde_json::from_str::<HybridQueryResult>(
&std::fs::read_to_string(&output_file).expect("IPA results file should exist"),
)
Expand All @@ -129,5 +123,14 @@ fn test_hybrid() {
);
assert_eq!(INPUT_SIZE, usize::from(output.input_size));

// TODO compare in the clear results with MPC results
let expected_result: Vec<u32> = from_reader(
File::open(in_the_clear_output_file)
.expect("file should exist as it's created above in the test"),
)
.expect("should match hard coded format from in_the_clear");
assert!(output
.breakdowns
.iter()
.zip(expected_result.iter())
.all(|(a, b)| a == b));
}

0 comments on commit fd76f4e

Please sign in to comment.