// Takes a Wasm with two mutable float globals and checks whether we can set and
// get their values.
Takes a Wasm with two mutable float globals and checks whether we can set and
get their values.
Takes a Wasm with two mutable float globals and checks whether we can set and get their values .
fn can_set_and_get_float_globals() {
        let log = logger();
        let wasm = &wat2wasm(
            r#"
                    (module
                        (import "ic0" "msg_reply" (func $msg_reply))
                        (func $test
                            (call $msg_reply)
                        )
                        (global (export "g1") (mut f64) (f64.const 0.0))
                        (global (export "g2") (mut f32) (f32.const 42.42))
                        (func (export "canister_update test"))
                    )"#,
        )
        .unwrap();
        let embedder = WasmtimeEmbedder::new(ic_config::embedders::Config::default(), log);
        let mut inst = embedder.new_instance(
            &embedder.compile(PersistenceType::Sigsegv, wasm).unwrap(),
            &[],
            NumWasmPages::from(0),
            None,
            None,
        );
        let cycles_account_manager = Arc::new(CyclesAccountManagerBuilder::new().build());
        let system_state = SystemStateBuilder::default().build();
        let system_state_accessor = ic_system_api::SystemStateAccessorDirect::new(
            system_state,
            Arc::clone(&cycles_account_manager),
        );
        // Initial read, the globals should have a value of 0.0 and 42.42 respectively.
        let res = inst
            .run(
                &mut ic_system_api::SystemApiImpl::new(
                    ic_system_api::ApiType::init(mock_time(), vec![], user_test_id(24).get()),
                    system_state_accessor,
                    NumBytes::from(4 << 30),
                    NumBytes::from(0),
                    MAX_SUBNET_AVAILABLE_MEMORY.clone(),
                    ComputeAllocation::default(),
                ),
                FuncRef::Method(WasmMethod::Update("test".to_string())),
            )
            .unwrap();
        assert_eq!(
            res.exported_globals[..],
            [Global::F64(0.0), Global::F32(42.42)]
        );
        // Change the value of globals and verify we can get them back.
        let mut inst = embedder.new_instance(
            &embedder.compile(PersistenceType::Sigsegv, wasm).unwrap(),
            &[Global::F64(5.3), Global::F32(12.37)],
            NumWasmPages::from(0),
            None,
            None,
        );
        let system_state = SystemStateBuilder::default().build();
        let system_state_accessor =
            ic_system_api::SystemStateAccessorDirect::new(system_state, cycles_account_manager);
        let res = inst
            .run(
                &mut ic_system_api::SystemApiImpl::new(
                    ic_system_api::ApiType::init(mock_time(), vec![], user_test_id(24).get()),
                    system_state_accessor,
                    NumBytes::from(4 << 30),
                    NumBytes::from(0),
                    MAX_SUBNET_AVAILABLE_MEMORY.clone(),
                    ComputeAllocation::default(),
                ),
                FuncRef::Method(WasmMethod::Update("test".to_string())),
            )
            .unwrap();
        assert_eq!(
            res.exported_globals[..],
            [Global::F64(5.3), Global::F32(12.37)]
        );
    }
fn can_set_and_get_float_globals ( ) { let log = logger ( ) ; let wasm = & wat2wasm ( r#"
                    (module
                        (import "ic0" "msg_reply" (func $msg_reply))
                        (func $test
                            (call $msg_reply)
                        )
                        (global (export "g1") (mut f64) (f64.const 0.0))
                        (global (export "g2") (mut f32) (f32.const 42.42))
                        (func (export "canister_update test"))
                    )"# , ) . unwrap ( ) ; let embedder = WasmtimeEmbedder :: new ( ic_config :: embedders :: Config :: default ( ) , log ) ; let mut inst = embedder . new_instance ( & embedder . compile ( PersistenceType :: Sigsegv , wasm ) . unwrap ( ) , & [ ] , NumWasmPages :: from ( 0 ) , None , None , ) ; let cycles_account_manager = Arc :: new ( CyclesAccountManagerBuilder :: new ( ) . build ( ) ) ; let system_state = SystemStateBuilder :: default ( ) . build ( ) ; let system_state_accessor = ic_system_api :: SystemStateAccessorDirect :: new ( system_state , Arc :: clone ( & cycles_account_manager ) , ) ; // Initial read, the globals should have a value of 0.0 and 42.42 respectively. let res = inst . run ( & mut ic_system_api :: SystemApiImpl :: new ( ic_system_api :: ApiType :: init ( mock_time ( ) , vec ! [ ] , user_test_id ( 24 ) . get ( ) ) , system_state_accessor , NumBytes :: from ( 4 << 30 ) , NumBytes :: from ( 0 ) , MAX_SUBNET_AVAILABLE_MEMORY . clone ( ) , ComputeAllocation :: default ( ) , ) , FuncRef :: Method ( WasmMethod :: Update ( " " . to_string ( ) ) ) , ) . unwrap ( ) ; assert_eq ! ( res exported_globals [ ] [ Global F64 ( 0.0 ) Global F32 ( 42.42 ) ] ) ; // Change the value of globals and verify we can get them back. let mut inst = embedder . new_instance ( & embedder . compile ( PersistenceType :: Sigsegv , wasm ) . unwrap ( ) , & [ Global :: F64 ( 5.3 ) , Global :: F32 ( 12.37 ) ] , NumWasmPages :: from ( 0 ) , None , None , ) ; let system_state = SystemStateBuilder :: default ( ) . build ( ) ; let system_state_accessor = ic_system_api :: SystemStateAccessorDirect :: new ( system_state , cycles_account_manager ) ; let res = inst . run ( & mut ic_system_api :: SystemApiImpl :: new ( ic_system_api :: ApiType :: init ( mock_time ( ) , vec ! [ ] , user_test_id ( 24 ) . get ( ) ) , system_state_accessor , NumBytes :: from ( 4 << 30 ) , NumBytes :: from ( 0 ) , MAX_SUBNET_AVAILABLE_MEMORY . clone ( ) , ComputeAllocation :: default ( ) , ) , FuncRef :: Method ( WasmMethod :: Update ( " " . to_string ( ) ) ) , ) . unwrap ( ) ; assert_eq ! ( res exported_globals [ ] [ Global F64 ( 5.3 ) Global F32 ( 12.37 ) ] ) ; }
Takes a Wasm with two mutable float globals and checks whether we can set and
get their values.
Takes a Wasm with two mutable float globals and checks whether we can set and get their values .