Pārlūkot izejas kodu

Use a single test for `cargo-build-sbf` (#7379)

* Change tests

* Fix lints
Lucas Ste 3 mēneši atpakaļ
vecāks
revīzija
f26d0477e0

+ 0 - 1
.config/nextest.toml

@@ -31,7 +31,6 @@ threads-required = "num-cpus"
 
 
 [[profile.ci.overrides]]
 [[profile.ci.overrides]]
 filter = "package(solana-cargo-build-sbf)"
 filter = "package(solana-cargo-build-sbf)"
-threads-required = "num-cpus"
 
 
 [[profile.ci.overrides]]
 [[profile.ci.overrides]]
 filter = 'package(solana-local-cluster) & test(/^test_kill_partition_switch_threshold_progress$/)'
 filter = 'package(solana-local-cluster) & test(/^test_kill_partition_switch_threshold_progress$/)'

+ 0 - 1
Cargo.lock

@@ -7400,7 +7400,6 @@ dependencies = [
  "regex",
  "regex",
  "reqwest 0.12.22",
  "reqwest 0.12.22",
  "semver 1.0.26",
  "semver 1.0.26",
- "serial_test",
  "solana-file-download",
  "solana-file-download",
  "solana-keypair",
  "solana-keypair",
  "solana-logger 3.0.0",
  "solana-logger 3.0.0",

+ 0 - 1
platform-tools-sdk/cargo-build-sbf/Cargo.toml

@@ -33,4 +33,3 @@ tar = { workspace = true }
 [dev-dependencies]
 [dev-dependencies]
 assert_cmd = { workspace = true }
 assert_cmd = { workspace = true }
 predicates = { workspace = true }
 predicates = { workspace = true }
-serial_test = { workspace = true }

+ 34 - 31
platform-tools-sdk/cargo-build-sbf/tests/crates.rs

@@ -9,9 +9,6 @@ use {
     },
     },
 };
 };
 
 
-#[macro_use]
-extern crate serial_test;
-
 static SBF_TOOLS_INSTALL: AtomicBool = AtomicBool::new(true);
 static SBF_TOOLS_INSTALL: AtomicBool = AtomicBool::new(true);
 fn run_cargo_build(crate_name: &str, extra_args: &[&str], fail: bool) {
 fn run_cargo_build(crate_name: &str, extra_args: &[&str], fail: bool) {
     let cwd = env::current_dir().expect("Unable to get current working directory");
     let cwd = env::current_dir().expect("Unable to get current working directory");
@@ -54,15 +51,11 @@ fn clean_target(crate_name: &str) {
     fs::remove_dir_all(target).expect("Failed to remove target dir");
     fs::remove_dir_all(target).expect("Failed to remove target dir");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_build() {
 fn test_build() {
     run_cargo_build("noop", &[], false);
     run_cargo_build("noop", &[], false);
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_dump() {
 fn test_dump() {
     // This test requires rustfilt.
     // This test requires rustfilt.
     assert_cmd::Command::new("cargo")
     assert_cmd::Command::new("cargo")
@@ -82,8 +75,6 @@ fn test_dump() {
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_out_dir() {
 fn test_out_dir() {
     run_cargo_build("noop", &["--sbf-out-dir", "tmp_out"], false);
     run_cargo_build("noop", &["--sbf-out-dir", "tmp_out"], false);
     let cwd = env::current_dir().expect("Unable to get current working directory");
     let cwd = env::current_dir().expect("Unable to get current working directory");
@@ -93,8 +84,6 @@ fn test_out_dir() {
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_target_dir() {
 fn test_target_dir() {
     let target_dir = "./temp-target-dir";
     let target_dir = "./temp-target-dir";
     run_cargo_build("noop", &["--lto", "--", "--target-dir", target_dir], false);
     run_cargo_build("noop", &["--lto", "--", "--target-dir", target_dir], false);
@@ -109,8 +98,6 @@ fn test_target_dir() {
     fs::remove_dir_all(target_dir).expect("Failed to remove custom target dir");
     fs::remove_dir_all(target_dir).expect("Failed to remove custom target dir");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_target_and_out_dir() {
 fn test_target_and_out_dir() {
     let target_dir = "./temp-target-dir";
     let target_dir = "./temp-target-dir";
     run_cargo_build(
     run_cargo_build(
@@ -127,8 +114,6 @@ fn test_target_and_out_dir() {
     fs::remove_dir_all(target_dir).expect("Failed to remove custom target dir");
     fs::remove_dir_all(target_dir).expect("Failed to remove custom target dir");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_generate_child_script_on_failure() {
 fn test_generate_child_script_on_failure() {
     run_cargo_build("fail", &["--generate-child-script-on-failure"], true);
     run_cargo_build("fail", &["--generate-child-script-on-failure"], true);
     let cwd = env::current_dir().expect("Unable to get current working directory");
     let cwd = env::current_dir().expect("Unable to get current working directory");
@@ -170,8 +155,6 @@ fn build_noop_and_readelf(arch: &str) -> Assert {
     assert_cmd::Command::new(readelf).args(["-h", bin]).assert()
     assert_cmd::Command::new(readelf).args(["-h", bin]).assert()
 }
 }
 
 
-#[test]
-#[serial]
 fn test_sbpfv0() {
 fn test_sbpfv0() {
     let assert_v0 = build_noop_and_readelf("v0");
     let assert_v0 = build_noop_and_readelf("v0");
     assert_v0
     assert_v0
@@ -182,8 +165,6 @@ fn test_sbpfv0() {
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_sbpfv1() {
 fn test_sbpfv1() {
     let assert_v1 = build_noop_and_readelf("v1");
     let assert_v1 = build_noop_and_readelf("v1");
     assert_v1
     assert_v1
@@ -194,8 +175,6 @@ fn test_sbpfv1() {
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_sbpfv2() {
 fn test_sbpfv2() {
     let assert_v1 = build_noop_and_readelf("v2");
     let assert_v1 = build_noop_and_readelf("v2");
     assert_v1
     assert_v1
@@ -206,8 +185,6 @@ fn test_sbpfv2() {
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_sbpfv3() {
 fn test_sbpfv3() {
     let assert_v1 = build_noop_and_readelf("v3");
     let assert_v1 = build_noop_and_readelf("v3");
     assert_v1
     assert_v1
@@ -218,8 +195,6 @@ fn test_sbpfv3() {
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_sbpfv4() {
 fn test_sbpfv4() {
     let assert_v1 = build_noop_and_readelf("v4");
     let assert_v1 = build_noop_and_readelf("v4");
     assert_v1
     assert_v1
@@ -230,22 +205,16 @@ fn test_sbpfv4() {
     clean_target("noop");
     clean_target("noop");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_package_metadata_tools_version() {
 fn test_package_metadata_tools_version() {
     run_cargo_build("package-metadata", &[], false);
     run_cargo_build("package-metadata", &[], false);
     clean_target("package-metadata");
     clean_target("package-metadata");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_workspace_metadata_tools_version() {
 fn test_workspace_metadata_tools_version() {
     run_cargo_build("workspace-metadata", &[], false);
     run_cargo_build("workspace-metadata", &[], false);
     clean_target("workspace-metadata");
     clean_target("workspace-metadata");
 }
 }
 
 
-#[test]
-#[serial]
 fn test_corrupted_toolchain() {
 fn test_corrupted_toolchain() {
     run_cargo_build("noop", &[], false);
     run_cargo_build("noop", &[], false);
 
 
@@ -306,3 +275,37 @@ fn test_corrupted_toolchain() {
     // Revert to the original name, so other tests can run correctly.
     // Revert to the original name, so other tests can run correctly.
     fs::rename(wrong_rust_folder, right_rust_folder).expect("Failed to rename file");
     fs::rename(wrong_rust_folder, right_rust_folder).expect("Failed to rename file");
 }
 }
+
+#[test]
+fn cargo_build_sbf_all_tests() {
+    // The cargo-build-sbf tests must download and install the platform tools only once and run
+    // sequentially afterwards.
+    //
+    // The usage of an atomic boolean to prevent multiple tests downloading the tools and the
+    // #[serial] attribute only work when we execute `cargo test`.
+    //
+    // `cargo nextest` used in CI executes each test in a separate process, so the atomic boolean
+    // has no effect, nor does the #[serial] attribute. This causes all tests to download the tools,
+    // locks the toml files, and frequently corrupts the installation. Splitting the repository's
+    // tests in partitions further exacerbates the problem, since the cargo-build-sbf are not even
+    // run in the same machine.
+    //
+    // Creating an omnibus function to execute all tests at once is the simplest solution to that.
+    // It does not use process synchronization to handle the installation, and does not need
+    // any special configuration in nexttest to prevent these tests from being split in partitions.
+
+    test_build();
+    test_dump();
+    test_out_dir();
+    test_target_dir();
+    test_target_and_out_dir();
+    test_generate_child_script_on_failure();
+    test_sbpfv0();
+    test_sbpfv1();
+    test_sbpfv2();
+    test_sbpfv3();
+    test_sbpfv4();
+    test_package_metadata_tools_version();
+    test_workspace_metadata_tools_version();
+    test_corrupted_toolchain();
+}