diff --git a/external-crates/move/crates/bytecode-interpreter-testsuite/tests/concrete_check_testsuite.rs b/external-crates/move/crates/bytecode-interpreter-testsuite/tests/concrete_check_testsuite.rs index e1283e5cb8056..329ac07732c7f 100644 --- a/external-crates/move/crates/bytecode-interpreter-testsuite/tests/concrete_check_testsuite.rs +++ b/external-crates/move/crates/bytecode-interpreter-testsuite/tests/concrete_check_testsuite.rs @@ -7,7 +7,7 @@ use std::{env, path::Path}; use move_command_line_common::{env::read_bool_env_var, testing::EXP_EXT}; use move_prover_test_utils::baseline_test::verify_or_update_baseline; use move_stdlib::move_stdlib_files; -use move_unit_test::{UnitTestingConfig, DEFAULT_EXECUTION_BOUND_SOLANA}; +use move_unit_test::UnitTestingConfig; fn test_runner(path: &Path) -> datatest_stable::Result<()> { env::set_var("NO_COLOR", "1"); @@ -29,7 +29,7 @@ fn test_runner(path: &Path) -> datatest_stable::Result<()> { let test_plan = config.build_test_plan().unwrap(); let mut buffer = vec![]; - config.run_and_report_unit_tests(test_plan, None, None, &mut buffer, DEFAULT_EXECUTION_BOUND_SOLANA)?; + config.run_and_report_unit_tests(test_plan, None, None, &mut buffer)?; let output = String::from_utf8(buffer)?; let baseline_path = path.with_extension(EXP_EXT); diff --git a/external-crates/move/crates/move-cli/src/base/test.rs b/external-crates/move/crates/move-cli/src/base/test.rs index bddbaafac14c0..8112dcb0510d0 100644 --- a/external-crates/move/crates/move-cli/src/base/test.rs +++ b/external-crates/move/crates/move-cli/src/base/test.rs @@ -14,7 +14,7 @@ use move_compiler::{ }; use move_coverage::coverage_map::{output_map_to_file, CoverageMap}; use move_package::{compilation::build_plan::BuildPlan, BuildConfig}; -use move_unit_test::{UnitTestingConfig, DEFAULT_EXECUTION_BOUND_SOLANA_STDLIB_TEST}; +use move_unit_test::UnitTestingConfig; use move_vm_test_utils::gas_schedule::CostTable; use std::{ collections::HashMap, @@ -241,7 +241,7 @@ pub fn run_move_unit_tests( // Run the tests. If any of the tests fail, then we don't produce a coverage report, so cleanup // the trace files. if !unit_test_config - .run_and_report_unit_tests(test_plan, Some(natives), cost_table, writer, DEFAULT_EXECUTION_BOUND_SOLANA_STDLIB_TEST) + .run_and_report_unit_tests(test_plan, Some(natives), cost_table, writer) .unwrap() .1 { diff --git a/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/args.exp b/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/args.exp index c79fc4e1f5e8b..2737d5bc1846e 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/args.exp +++ b/external-crates/move/crates/move-cli/tests/build_tests/canonicalize_module/args.exp @@ -1,10 +1,10 @@ Command `disassemble --Xdebug --package Test --name c`: // Move bytecode v6 module 2.c { -use 0000000000000000000000000000000000000000000000000000000000000002::b; -use 0000000000000000000000000000000000000000000000000000000000000003::d; -use 0000000000000000000000000000000000000000000000000000000000000001::a; -use 0000000000000000000000000000000000000000000000000000000000000004::e; +use 0x0000000000000000000000000000000000000000000000000000000000000002::b; +use 0x0000000000000000000000000000000000000000000000000000000000000003::d; +use 0x0000000000000000000000000000000000000000000000000000000000000001::a; +use 0x0000000000000000000000000000000000000000000000000000000000000004::e; struct B { @@ -208,10 +208,10 @@ CompiledModule { ), ], address_identifiers: [ - 0000000000000000000000000000000000000000000000000000000000000002, - 0000000000000000000000000000000000000000000000000000000000000001, - 0000000000000000000000000000000000000000000000000000000000000003, - 0000000000000000000000000000000000000000000000000000000000000004, + 0x0000000000000000000000000000000000000000000000000000000000000002, + 0x0000000000000000000000000000000000000000000000000000000000000001, + 0x0000000000000000000000000000000000000000000000000000000000000003, + 0x0000000000000000000000000000000000000000000000000000000000000004, ], constant_pool: [], metadata: [], diff --git a/external-crates/move/crates/move-cli/tests/build_tests/help/args.exp b/external-crates/move/crates/move-cli/tests/build_tests/help/args.exp index 435689be105c2..768a4896edf20 100644 --- a/external-crates/move/crates/move-cli/tests/build_tests/help/args.exp +++ b/external-crates/move/crates/move-cli/tests/build_tests/help/args.exp @@ -31,6 +31,8 @@ Options: Installation directory for compiled artifacts. Defaults to current directory --force Force recompilation of all packages + --arch + --fetch-deps-only Only fetch dependency repos to MOVE_HOME --skip-fetch-latest-git-deps diff --git a/external-crates/move/crates/move-compiler/src/unit_test/mod.rs b/external-crates/move/crates/move-compiler/src/unit_test/mod.rs index 93e521b4e03e9..ef2668a3ec655 100644 --- a/external-crates/move/crates/move-compiler/src/unit_test/mod.rs +++ b/external-crates/move/crates/move-compiler/src/unit_test/mod.rs @@ -34,7 +34,7 @@ pub struct TestCase { pub test_name: TestName, pub arguments: Vec, pub expected_failure: Option, - pub gas_budget: Option, + pub gas_budget: Option, } #[derive(Debug, Clone)] @@ -47,13 +47,6 @@ pub enum ExpectedFailure { ExpectedWithError(ExpectedMoveError), } -#[derive(Debug, Clone)] -pub struct GasBudgetParams { - pub compute_budget:u64, - pub heap_size:u64, - pub max_call_depth:u64, -} - #[derive(Debug, Clone, Ord, PartialOrd, PartialEq, Eq)] pub struct ExpectedMoveError( pub StatusCode, @@ -66,6 +59,23 @@ pub struct ExpectedMoveErrorDisplay<'a> { is_past_tense: bool, } +#[derive(Debug, Clone)] +pub struct SolanaGasBudgetParams { + pub compute_budget: u64, + pub heap_size: usize, + pub max_call_depth: usize, +} + +impl SolanaGasBudgetParams { + pub fn new() -> Self { + SolanaGasBudgetParams { + compute_budget: i64::MAX as u64, + heap_size: 10000000, + max_call_depth: 8192, + } + } +} + impl ModuleTestPlan { pub fn new( addr: &NumericalAddress, diff --git a/external-crates/move/crates/move-compiler/src/unit_test/plan_builder.rs b/external-crates/move/crates/move-compiler/src/unit_test/plan_builder.rs index 0ea12594d6743..7c8076de56be5 100644 --- a/external-crates/move/crates/move-compiler/src/unit_test/plan_builder.rs +++ b/external-crates/move/crates/move-compiler/src/unit_test/plan_builder.rs @@ -14,7 +14,7 @@ use crate::{ known_attributes::TestingAttribute, unique_map::UniqueMap, CompilationEnv, Identifier, NumericalAddress, }, - unit_test::{ExpectedFailure, ExpectedMoveError, ModuleTestPlan, TestCase}, + unit_test::{ExpectedFailure, ExpectedMoveError, ModuleTestPlan, TestCase, SolanaGasBudgetParams}, }; use move_core_types::{ account_address::AccountAddress as MoveAddress, language_storage::ModuleId, @@ -24,8 +24,6 @@ use move_ir_types::location::Loc; use move_symbol_pool::Symbol; use std::collections::BTreeMap; -use super::GasBudgetParams; - struct Context<'env> { env: &'env mut CompilationEnv, constants: UniqueMap)>>, @@ -184,7 +182,7 @@ fn build_test_info<'func>( None => None, Some(abort_attribute) => parse_failure_attribute(context, abort_attribute), }; - let gas_budget: Option = parse_gas_budget_attribute(context, gas_budget_attr); + let gas_budget = parse_gas_budget_attribute(context, gas_budget_attr); Some(TestCase { test_name: fn_name.to_string(), @@ -491,12 +489,8 @@ fn parse_failure_attribute( } } -fn parse_gas_budget_attribute(context: &mut Context, gas_budget_attr: Option<&E::Attribute>) -> Option { - let mut assigned_gas_budget = GasBudgetParams { - compute_budget:1, - heap_size: 1, - max_call_depth: 1, - }; +fn parse_gas_budget_attribute(context: &mut Context, gas_budget_attr: Option<&E::Attribute>) -> Option { + let mut assigned_gas_budget = SolanaGasBudgetParams::new(); if gas_budget_attr.is_none(){ return Some(assigned_gas_budget); } @@ -546,21 +540,22 @@ fn parse_gas_budget_attribute(context: &mut Context, gas_budget_attr: Option<&E: } while !gas_budget_kind_vec.is_empty() { let (gas_budget_kind, (attr_loc, attr)) = gas_budget_kind_vec.pop().unwrap(); - match gas_budget_kind.as_str() { + let gb = gas_budget_kind.as_str(); + match gb { TestingAttribute::GAS_BUDGET_COMPUTE_UNIT_LIMIT => { - let u = get_assigned_attribute_as_u64(context, TestingAttribute::GAS_BUDGET_COMPUTE_UNIT_LIMIT, attr_loc, attr)?; + let u = get_assigned_attribute_as_u64(context, gb, attr_loc, attr)?; // TODO: Do some sanity check that u shouldn't be larger than a max value. assigned_gas_budget.compute_budget = u; } TestingAttribute::GAS_BUDGET_HEAP_SIZE => { - let u = get_assigned_attribute_as_u64(context, TestingAttribute::GAS_BUDGET_HEAP_SIZE, attr_loc, attr)?; + let u = get_assigned_attribute_as_u64(context, gb, attr_loc, attr)?; // TODO: Do some sanity check that u shouldn't be larger than a max value. - assigned_gas_budget.heap_size = u; + assigned_gas_budget.heap_size = u as usize; } TestingAttribute::GAS_BUDGET_MAX_CALL_DEPTH => { - let u = get_assigned_attribute_as_u64(context, TestingAttribute::GAS_BUDGET_MAX_CALL_DEPTH, attr_loc, attr)?; + let u = get_assigned_attribute_as_u64(context, gb, attr_loc, attr)?; // TODO: Do some sanity check that u shouldn't be larger than a max value. - assigned_gas_budget.max_call_depth = u; + assigned_gas_budget.max_call_depth = u as usize; } _ => return None, }; diff --git a/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move b/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move index 5e1c4297fa1e6..29a5ceb7b2311 100644 --- a/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move +++ b/external-crates/move/crates/move-stdlib/tests/bit_vector_tests.move @@ -53,7 +53,7 @@ module std::bit_vector_tests { } #[test] - #[gas_budget(compute_unit_limit=10000000, heap_size=1000, max_call_depth=10)] + #[gas_budget(compute_unit_limit=10000000, heap_size=40000, max_call_depth=10)] fun test_set_bit_and_index_basic() { test_bitvector_set_unset_of_size(8) } diff --git a/external-crates/move/crates/move-unit-test/src/cargo_runner.rs b/external-crates/move/crates/move-unit-test/src/cargo_runner.rs index 8dee75077f7fc..0784e5ebad505 100644 --- a/external-crates/move/crates/move-unit-test/src/cargo_runner.rs +++ b/external-crates/move/crates/move-unit-test/src/cargo_runner.rs @@ -6,7 +6,7 @@ use move_command_line_common::files::find_filenames; use move_vm_runtime::native_functions::NativeFunctionTable; use move_vm_test_utils::gas_schedule::CostTable; -use crate::{UnitTestingConfig, DEFAULT_EXECUTION_BOUND}; +use crate::UnitTestingConfig; pub fn run_tests_with_config_and_filter( mut config: UnitTestingConfig, @@ -40,7 +40,6 @@ pub fn run_tests_with_config_and_filter( native_function_table, cost_table, std::io::stdout(), - DEFAULT_EXECUTION_BOUND ) .expect("Failed to execute tests"); diff --git a/external-crates/move/crates/move-unit-test/src/lib.rs b/external-crates/move/crates/move-unit-test/src/lib.rs index dcfa992387c0f..b7c73ee535507 100644 --- a/external-crates/move/crates/move-unit-test/src/lib.rs +++ b/external-crates/move/crates/move-unit-test/src/lib.rs @@ -198,7 +198,6 @@ impl UnitTestingConfig { native_function_table: Option, cost_table: Option, writer: W, - gas_limit: u64, ) -> Result<(W, bool)> { let shared_writer = Mutex::new(writer); @@ -217,14 +216,14 @@ impl UnitTestingConfig { } writeln!(shared_writer.lock().unwrap(), "Running Move unit tests")?; - let (num_threads, cgas_limit) = if cfg!(feature = "solana-backend") { - (1, gas_limit) // enforce single threaded execution for Solana, as llvm-sys is not re-entrant. + let num_threads = if cfg!(feature = "solana-backend") { + 1 // enforce single threaded execution for Solana, as llvm-sys is not re-entrant. } else { - (self.num_threads, self.gas_limit.unwrap()) + self.num_threads }; let mut test_runner = TestRunner::new( - cgas_limit, + self.gas_limit.unwrap_or(DEFAULT_EXECUTION_BOUND), num_threads, self.check_stackless_vm, self.verbose, diff --git a/external-crates/move/crates/move-unit-test/src/main.rs b/external-crates/move/crates/move-unit-test/src/main.rs index 15327d00fe083..f3521bcc2ceb5 100644 --- a/external-crates/move/crates/move-unit-test/src/main.rs +++ b/external-crates/move/crates/move-unit-test/src/main.rs @@ -3,14 +3,14 @@ // SPDX-License-Identifier: Apache-2.0 use clap::*; -use move_unit_test::{UnitTestingConfig, DEFAULT_EXECUTION_BOUND}; +use move_unit_test::UnitTestingConfig; pub fn main() { let args = UnitTestingConfig::parse(); let test_plan = args.build_test_plan(); if let Some(test_plan) = test_plan { - args.run_and_report_unit_tests(test_plan, None, None, std::io::stdout(), DEFAULT_EXECUTION_BOUND) + args.run_and_report_unit_tests(test_plan, None, None, std::io::stdout()) .unwrap(); } } diff --git a/external-crates/move/crates/move-unit-test/src/test_runner.rs b/external-crates/move/crates/move-unit-test/src/test_runner.rs index 20b8c5446cfe2..ff3dbf0f679fe 100644 --- a/external-crates/move/crates/move-unit-test/src/test_runner.rs +++ b/external-crates/move/crates/move-unit-test/src/test_runner.rs @@ -529,10 +529,10 @@ impl SharedTestingConfig { } let gen_options = move_to_solana::options::Options::default(); - // TODO: Get the compute budget from the test file. anza-xyz/sui/issues/20 - let compute_budget = move_to_solana::runner::compute_budget(self.execution_bound); for (function_name, test_info) in &test_plan.tests { + let compute_budget = move_to_solana::runner::compute_budget(&test_info.gas_budget); + let shared_object = match move_to_solana::run_for_unit_test( &gen_options, &model, diff --git a/external-crates/move/crates/move-unit-test/tests/move_unit_test_testsuite.rs b/external-crates/move/crates/move-unit-test/tests/move_unit_test_testsuite.rs index eac9ce02ee57b..43a25645b8f4a 100644 --- a/external-crates/move/crates/move-unit-test/tests/move_unit_test_testsuite.rs +++ b/external-crates/move/crates/move-unit-test/tests/move_unit_test_testsuite.rs @@ -5,7 +5,7 @@ use move_command_line_common::testing::{ add_update_baseline_fix, format_diff, read_env_update_baseline, EXP_EXT, }; -use move_unit_test::{self, UnitTestingConfig, DEFAULT_EXECUTION_BOUND, DEFAULT_EXECUTION_BOUND_SOLANA}; +use move_unit_test::{self, UnitTestingConfig}; use regex::RegexBuilder; use std::{ fs, @@ -34,12 +34,12 @@ fn run_test_with_modifiers( if !cfg!(feature = "solana-backend") { results.push(( - unit_test_config.run_and_report_unit_tests(test_plan.unwrap(), None, None, buffer, DEFAULT_EXECUTION_BOUND)?, + unit_test_config.run_and_report_unit_tests(test_plan.unwrap(), None, None, buffer)?, path.with_extension(EXP_EXT), )); } else { results.push(( - unit_test_config.run_and_report_unit_tests(test_plan.unwrap(), None, None, buffer, DEFAULT_EXECUTION_BOUND_SOLANA)?, + unit_test_config.run_and_report_unit_tests(test_plan.unwrap(), None, None, buffer)?, path.with_extension(format!("{}.{}", "solana", EXP_EXT)), )); } diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/other_expected_failures.move b/external-crates/move/crates/move-unit-test/tests/test_sources/other_expected_failures.move index c0a81b502a4f8..02da72d50c818 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/other_expected_failures.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/other_expected_failures.move @@ -25,6 +25,7 @@ module 0x42::m { #[test] #[expected_failure(out_of_gas, location=Self)] + #[gas_budget(compute_unit_limit=10000000, heap_size=40000, max_call_depth=10)] fun t4() { loop {} } diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/out_of_gas.move b/external-crates/move/crates/move-unit-test/tests/test_sources/out_of_gas.move index 78e171ae3673e..6544f6553b6f1 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/out_of_gas.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/out_of_gas.move @@ -5,13 +5,14 @@ module 0x42::m { fun t0() {} #[test] -#[expected_failure(arithmetic_error, location=Self)] +#[expected_failure(out_of_gas, location=Self)] +#[gas_budget(compute_unit_limit=10000000, heap_size=40000, max_call_depth=10)] fun t1() { loop {} } #[test] -#[expected_failure(out_of_gas, location=Self)] +#[expected_failure(arithmetic_error, location=Self)] fun t2() { 0 - 1; } diff --git a/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move b/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move index 1c045830269af..69ba2cb2f852c 100644 --- a/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move +++ b/external-crates/move/crates/move-unit-test/tests/test_sources/timeout.move @@ -1,12 +1,14 @@ address 0x1 { module M { #[test] + #[gas_budget(compute_unit_limit=10000000, heap_size=40000, max_call_depth=10)] fun timeout_fail() { while (true) {} } #[test] #[expected_failure] + #[gas_budget(compute_unit_limit=10000000, heap_size=40000, max_call_depth=10)] fun timeout_fail_with_expected_failure() { while (true) {} } diff --git a/external-crates/move/solana/move-to-solana/src/runner.rs b/external-crates/move/solana/move-to-solana/src/runner.rs index b810a55397ba8..498f821795cc6 100644 --- a/external-crates/move/solana/move-to-solana/src/runner.rs +++ b/external-crates/move/solana/move-to-solana/src/runner.rs @@ -35,6 +35,8 @@ use std::{ time::{Duration, Instant}, }; +use move_compiler::unit_test::SolanaGasBudgetParams; + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct AccountInfo { pub key: String, @@ -67,11 +69,15 @@ pub struct ExecuteResult { pub log: String, } -pub fn compute_budget(execution_bound: u64) -> ComputeBudget { +pub fn compute_budget(gas_budget_params: &Option) -> ComputeBudget { + let gb = match gas_budget_params { + Some(gb) => gb.clone(), + None => SolanaGasBudgetParams::new(), + }; ComputeBudget { - compute_unit_limit: execution_bound, - heap_size: Some(10000000), - max_call_depth: 8192, + compute_unit_limit: gb.compute_budget, + heap_size: Some(gb.heap_size), + max_call_depth: gb.max_call_depth, ..ComputeBudget::default() } }