capsules_core::test

Module double_grant_entry

Source
Expand description

Test that tries to enter a grant twice.

This must fail or Tock allows multiple mutable references to the same memory which is undefined behavior.

To use, setup this capsule and connect the syscall Driver implementation to userspace. Then call the commands to test various double grant entries.

§Usage

Here is my example usage for hail:

diff --git a/boards/hail/src/main.rs b/boards/hail/src/main.rs
index 110d45fa7..e8f4728c2 100644
--- a/boards/hail/src/main.rs
+++ b/boards/hail/src/main.rs
@@ -73,6 +73,7 @@ struct Hail {
     ipc: kernel::ipc::IPC<NUM_PROCS>,
     crc: &'static capsules::crc::Crc<'static, sam4l::crccu::Crccu<'static>>,
     dac: &'static capsules::dac::Dac<'static>,
+    dge: &'static capsules::test::double_grant_entry::TestGrantDoubleEntry,
 }

 /// Mapping of integer syscalls to objects that implement syscalls.
@@ -102,6 +103,8 @@ impl Platform for Hail {

             capsules::dac::DRIVER_NUM => f(Some(self.dac)),

+            capsules::test::double_grant_entry::DRIVER_NUM => f(Some(self.dge)),
+
             kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
             _ => f(None),
         }
@@ -396,6 +399,14 @@ pub unsafe fn reset_handler() {
         capsules::dac::Dac::new(&peripherals.dac)
     );

+    // Test double grant entry
+    let dge = static_init!(
+        capsules::test::double_grant_entry::TestGrantDoubleEntry,
+        capsules::test::double_grant_entry::TestGrantDoubleEntry::new(
+            board_kernel.create_grant(&memory_allocation_capability)
+        )
+    );
+
     // // DEBUG Restart All Apps
     // //
     // // Uncomment to enable a button press to restart all apps.
@@ -440,6 +451,7 @@ pub unsafe fn reset_handler() {
         ipc: kernel::ipc::IPC::new(board_kernel, &memory_allocation_capability),
         crc,
         dac,
+        dge,
     };

     // Setup the UART bus for nRF51 serialization..
    ```

Structs§

Constants§