You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: flash.rs
    path of file: ./repos/tock/boards/opentitan/src/tests
    
    the code of the file until where you have to start completion: // Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

//! Test the opentitan flash implementation

mod key_value {
    use crate::tests::run_kernel_op;
    use crate::{SIPHASH, TICKV};
    use capsules_core::virtualizers::virtual_flash::FlashUser;
    use capsules_extra::test::kv_system::KVSystemTest;
    use capsules_extra::tickv::KVSystem;
    use capsules_extra::tickv::{TicKVKeyType, TicKVSystem};
    use kernel::debug;
    use kernel::hil::hasher::Hasher;
    use kernel::static_init;
    use kernel::utilities::leasable_buffer::SubSliceMut;

    #[test_case]
    fn tickv_append_key() {
        debug!("start TicKV append key test...")
    
    fn flash_ctrl_erase_page() {
        let perf = unsafe { PERIPHERALS.unwrap() };
        let flash_ctl = &perf.flash_ctrl;

        let cb = unsafe { static_init_test!() };
        cb.reset();
        flash_ctl.set_client(cb);

        debug!("[FLASH_CTRL] Test page erase....");

        #[cfg(feature = "hardware_tests")]
        {
            let page_num: usize = 500;
            run_kernel_op(100);
            // Lets do a page erase
            assert!(flash_ctl.erase_page(page_num).is_ok());
            run_kernel_op(100);

            // Do Page Write
            let write_page = cb.write_in_page.take().unwrap();
            assert!(flash_ctl.write_page(page_num, write_page).is_ok());
            cb.write_pending.set(true);
            run_kernel_op(100);
            // OP Complete, buffer recovered.
            assert!(!cb.write_pending.get());
            cb.reset();

            // Erase again
            assert!(flash_ctl.erase_page(page_num).is_ok());
            run_kernel_op(100);

            // Read Page
            let read_page = cb.read_in_page.take().unwrap();
            assert!(flash_ctl.read_page(page_num, read_page).is_ok());
            cb.read_pending.set(true);
            run_kernel_op(100);
            assert!(!cb.read_pending.get());
            cb.reset();

            // Check that the erased paged is all `0xFF` bytes
            let read_out = cb.read_out_buf.take().unwrap();
            assert!(
                read_out.iter().all(|&a| a == 0xFF),
                "[ERR] Read data indicates erase failure on page {}",
                page_num
            );

            cb.read_out_buf.replace(read_out);
        }
        run_kernel_op(100);
        debug!("    [ok]");
        run_kernel_op(100);
    }