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

Adapt test worker to profile flag #2450

Merged
merged 5 commits into from
Nov 24, 2023
Merged
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 @@ -36,7 +36,7 @@ impl TestHost {
where
F: FnOnce(&mut Config),
{
let (prepare_worker_path, execute_worker_path) = testing::build_workers_and_get_paths(true);
let (prepare_worker_path, execute_worker_path) = testing::build_workers_and_get_paths();

let cache_dir = tempfile::tempdir().unwrap();
let mut config = Config::new(
Expand Down
21 changes: 21 additions & 0 deletions polkadot/node/core/pvf/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

fn main() {
if let Ok(profile) = std::env::var("PROFILE") {
println!(r#"cargo:rustc-cfg=build_type="{}""#, profile);
bkchr marked this conversation as resolved.
Show resolved Hide resolved
}
}
11 changes: 6 additions & 5 deletions polkadot/node/core/pvf/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,22 @@ pub fn validate_candidate(
///
/// NOTE: This should only be called in dev code (tests, benchmarks) as it relies on the relative
/// paths of the built workers.
pub fn build_workers_and_get_paths(is_bench: bool) -> (PathBuf, PathBuf) {
pub fn build_workers_and_get_paths() -> (PathBuf, PathBuf) {
// Only needs to be called once for the current process.
static WORKER_PATHS: OnceLock<Mutex<(PathBuf, PathBuf)>> = OnceLock::new();

fn build_workers(is_bench: bool) {
fn build_workers() {
let mut build_args = vec![
"build",
"--package=polkadot",
"--bin=polkadot-prepare-worker",
"--bin=polkadot-execute-worker",
];
if is_bench {
// Benches require --release. Regular tests are debug (no flag needed).

if cfg!(build_type = "release") {
build_args.push("--release");
}

let mut cargo = std::process::Command::new("cargo");
let cmd = cargo
// wasm runtime not needed
Expand Down Expand Up @@ -117,7 +118,7 @@ pub fn build_workers_and_get_paths(is_bench: bool) -> (PathBuf, PathBuf) {
}
}

build_workers(is_bench);
build_workers();

Mutex::new((prepare_worker_path, execute_worker_path))
});
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/core/pvf/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TestHost {
where
F: FnOnce(&mut Config),
{
let (prepare_worker_path, execute_worker_path) = build_workers_and_get_paths(false);
let (prepare_worker_path, execute_worker_path) = build_workers_and_get_paths();

let cache_dir = tempfile::tempdir().unwrap();
let mut config = Config::new(
Expand Down
6 changes: 3 additions & 3 deletions polkadot/node/core/pvf/tests/it/worker_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{env, time::Duration};
// Test spawning a program that immediately exits with a failure code.
#[tokio::test]
async fn spawn_immediate_exit() {
let (prepare_worker_path, _) = build_workers_and_get_paths(false);
let (prepare_worker_path, _) = build_workers_and_get_paths();

// There's no explicit `exit` subcommand in the worker; it will panic on an unknown
// subcommand anyway
Expand All @@ -41,7 +41,7 @@ async fn spawn_immediate_exit() {

#[tokio::test]
async fn spawn_timeout() {
let (_, execute_worker_path) = build_workers_and_get_paths(false);
let (_, execute_worker_path) = build_workers_and_get_paths();

let result = spawn_with_program_path(
"integration-test",
Expand All @@ -57,7 +57,7 @@ async fn spawn_timeout() {

#[tokio::test]
async fn should_connect() {
let (prepare_worker_path, _) = build_workers_and_get_paths(false);
let (prepare_worker_path, _) = build_workers_and_get_paths();

let _ = spawn_with_program_path(
"integration-test",
Expand Down