Skip to content

Commit

Permalink
test(run-895): add tests to check whether the DTS slicing for dirty m…
Browse files Browse the repository at this point in the history
…emory copy is disabled for system subnets.
  • Loading branch information
alexandru-uta committed Jan 31, 2024
1 parent 16d3179 commit 3beed43
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions rs/execution_environment/src/hypervisor/tests.rs
@@ -1,6 +1,7 @@
use assert_matches::assert_matches;
use candid::{Decode, Encode};
use ic_base_types::{NumSeconds, PrincipalId};
use ic_config::subnet_config::SchedulerConfig;
use ic_cycles_account_manager::ResourceSaturation;
use ic_embedders::wasm_utils::instrumentation::instruction_to_cost_new;
use ic_error_types::{ErrorCode, RejectCode};
Expand Down Expand Up @@ -6684,3 +6685,68 @@ fn yield_abort_does_not_modify_state() {
// This time the dirty pages should be equal to `pages_to_touch`.
assert_eq!(dirty_pages, pages_to_touch);
}

#[test]
fn yield_for_dirty_page_copy_does_not_trigger_on_system_subnets() {
let pages_to_touch = 100;
let wat = generate_wat_to_touch_pages(pages_to_touch);

const CYCLES: Cycles = Cycles::new(20_000_000_000_000);

let mut test = ExecutionTestBuilder::new()
.with_deterministic_time_slicing()
.with_subnet_type(SubnetType::System)
.with_slice_instruction_limit(
SchedulerConfig::system_subnet()
.max_instructions_per_slice
.get(),
)
.with_instruction_limit(
SchedulerConfig::system_subnet()
.max_instructions_per_message
.get(),
)
.with_manual_execution()
.with_max_dirty_pages_optimization_embedder_config(pages_to_touch - 1)
.build();

let wasm = wat::parse_str(wat).unwrap();
let canister_id = test.canister_from_cycles_and_binary(CYCLES, wasm).unwrap();

let _result = test.ingress_raw(canister_id, "test", vec![]);

// The test touches `pages_to_touch`, but the embedder is configured to yield when `pages_to_touch - 1` pages are dirty.
// This should not happen for system subnets.
test.execute_slice(canister_id);
assert_eq!(
test.canister_state(canister_id).next_execution(),
NextExecution::None
);
}

#[test]
fn yield_for_dirty_page_copy_does_not_trigger_on_system_subnets_without_dts() {
let pages_to_touch = 100;
let wat = generate_wat_to_touch_pages(pages_to_touch);

const CYCLES: Cycles = Cycles::new(20_000_000_000_000);

let mut test = ExecutionTestBuilder::new()
.with_subnet_type(SubnetType::System)
.with_manual_execution()
.with_max_dirty_pages_optimization_embedder_config(pages_to_touch - 1)
.build();

let wasm = wat::parse_str(wat).unwrap();
let canister_id = test.canister_from_cycles_and_binary(CYCLES, wasm).unwrap();

let _result = test.ingress_raw(canister_id, "test", vec![]);

// The test touches `pages_to_touch`, but the embedder is configured to yield when `pages_to_touch - 1` pages are dirty.
// This should not happen for system subnets.
test.execute_slice(canister_id);
assert_eq!(
test.canister_state(canister_id).next_execution(),
NextExecution::None
);
}

0 comments on commit 3beed43

Please sign in to comment.