From 820d529b5a62d576b7282a78afb04e5a98bbca1c Mon Sep 17 00:00:00 2001 From: Per <Per Lindgren> Date: Thu, 1 Mar 2018 18:00:45 +0100 Subject: [PATCH] simple files --- examples/simple.rs | 86 +++++++++++++++++++++++++++++++++++++ examples/simple2.rs | 88 ++++++++++++++++++++++++++++++++++++++ examples/simple3.rs | 88 ++++++++++++++++++++++++++++++++++++++ examples/simple4.rs | 100 ++++++++++++++++++++++++++++++++++++++++++++ examples/simple5.rs | 96 ++++++++++++++++++++++++++++++++++++++++++ examples/simple6.rs | 98 +++++++++++++++++++++++++++++++++++++++++++ examples/simple7.rs | 100 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 656 insertions(+) create mode 100644 examples/simple.rs create mode 100644 examples/simple2.rs create mode 100644 examples/simple3.rs create mode 100644 examples/simple4.rs create mode 100644 examples/simple5.rs create mode 100644 examples/simple6.rs create mode 100644 examples/simple7.rs diff --git a/examples/simple.rs b/examples/simple.rs new file mode 100644 index 0000000..187239d --- /dev/null +++ b/examples/simple.rs @@ -0,0 +1,86 @@ +//! Minimal example with zero tasks +//#![deny(unsafe_code)] +// IMPORTANT always include this feature gate +#![feature(proc_macro)] +#![feature(used)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +// IMPORTANT always do this rename +extern crate stm32f413; + +//#[macro_use] +extern crate klee; +//use klee::{k_abort, k_assert, k_assume}; + +// import the procedural macro +use rtfm::{app, Threshold}; + +app! { + // this is the path to the device crate + device: stm32f413, + + resources: { + static X:u32 = 1; + static Y:u32 = 1; + }, + + tasks: { + EXTI1: { + path: exti1, + priority: 1, + resources: [X, Y], + }, + }, +} + +#[inline(never)] +fn exti1(_t: &mut Threshold, mut r: EXTI1::Resources) { + if *r.X > 10 { + *r.Y = 5; + } else { + *r.Y = 8; + } +} + +// The `init` function +// +// This function runs as an atomic section before any tasks +// are allowed to start +#[inline(never)] +#[allow(dead_code)] +fn init(_: init::Peripherals, _: init::Resources) {} + +// The idle loop. +// +// This runs after `init` and has a priority of 0. All tasks can preempt this +// function. This function can never return so it must contain some sort of +// endless loop. +#[inline(never)] +fn idle() -> ! { + loop {} +} + +// Assignments +// +// Rust strives at being a safe language. +// - Memory safety, +// - static checking where possible +// - run-time checking causing `panic!` on violation +// +// - No undefined behavior in "safe" Rust +// - panic! in case undef behavior (e.g., div 0) +// +// Compiling and analysing the code using KLEE +// +// What problem(s) did KLEE identify +// ** your answer here ** +// +// Now try to solve this by contracts +// You should not change the code, just enable the contacts +// The `_` should be filled with concrete values +// +// Can you find a type invariant that satisfies BOTH pre- and post-conditions +// at the same time. +// +// If not, why is that not possible? diff --git a/examples/simple2.rs b/examples/simple2.rs new file mode 100644 index 0000000..d4adb82 --- /dev/null +++ b/examples/simple2.rs @@ -0,0 +1,88 @@ +//! Minimal example with zero tasks +//#![deny(unsafe_code)] +// IMPORTANT always include this feature gate +#![feature(proc_macro)] +#![feature(used)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +// IMPORTANT always do this rename +extern crate stm32f413; + +#[macro_use] +extern crate klee; +use klee::{k_abort, k_assert, k_assume}; + +// import the procedural macro +use rtfm::{app, Threshold}; + +app! { + // this is the path to the device crate + device: stm32f413, + + resources: { + static X:u32 = 1; + static Y:u32 = 1; + }, + + tasks: { + EXTI1: { + path: exti1, + priority: 1, + resources: [X, Y], + }, + }, +} + +#[inline(never)] +fn exti1(_t: &mut Threshold, mut r: EXTI1::Resources) { + if *r.X > 10 { + *r.Y = 5; + } else { + if *r.X < 5 { + *r.Y = 8; + } + } +} + +// The `init` function +// +// This function runs as an atomic section before any tasks +// are allowed to start +#[inline(never)] +#[allow(dead_code)] +fn init(_: init::Peripherals, _: init::Resources) {} + +// The idle loop. +// +// This runs after `init` and has a priority of 0. All tasks can preempt this +// function. This function can never return so it must contain some sort of +// endless loop. +#[inline(never)] +fn idle() -> ! { + loop {} +} + +// Assignments +// +// Rust strives at being a safe language. +// - Memory safety, +// - static checking where possible +// - run-time checking causing `panic!` on violation +// +// - No undefined behavior in "safe" Rust +// - panic! in case undef behavior (e.g., div 0) +// +// Compiling and analysing the code using KLEE +// +// What problem(s) did KLEE identify +// ** your answer here ** +// +// Now try to solve this by contracts +// You should not change the code, just enable the contacts +// The `_` should be filled with concrete values +// +// Can you find a type invariant that satisfies BOTH pre- and post-conditions +// at the same time. +// +// If not, why is that not possible? diff --git a/examples/simple3.rs b/examples/simple3.rs new file mode 100644 index 0000000..deb8a3d --- /dev/null +++ b/examples/simple3.rs @@ -0,0 +1,88 @@ +//! Minimal example with zero tasks +//#![deny(unsafe_code)] +// IMPORTANT always include this feature gate +#![feature(proc_macro)] +#![feature(used)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +// IMPORTANT always do this rename +extern crate stm32f413; + +#[macro_use] +extern crate klee; +use klee::{k_abort, k_assert, k_assume}; + +// import the procedural macro +use rtfm::{app, Threshold}; + +app! { + // this is the path to the device crate + device: stm32f413, + + resources: { + static X:u32 = 1; + static Y:u32 = 1; + }, + + tasks: { + EXTI1: { + path: exti1, + priority: 1, + resources: [X, Y], + }, + }, +} + +#[inline(never)] +fn exti1(_t: &mut Threshold, mut r: EXTI1::Resources) { + if *r.X < 5 { + let old = *r.Y; + for _ in 0..*r.X { + *r.Y += 1; + } + k_assert!(*r.Y == *r.X + old); + } +} + +// The `init` function +// +// This function runs as an atomic section before any tasks +// are allowed to start +#[inline(never)] +#[allow(dead_code)] +fn init(_: init::Peripherals, _: init::Resources) {} + +// The idle loop. +// +// This runs after `init` and has a priority of 0. All tasks can preempt this +// function. This function can never return so it must contain some sort of +// endless loop. +#[inline(never)] +fn idle() -> ! { + loop {} +} + +// Assignments +// +// Rust strives at being a safe language. +// - Memory safety, +// - static checking where possible +// - run-time checking causing `panic!` on violation +// +// - No undefined behavior in "safe" Rust +// - panic! in case undef behavior (e.g., div 0) +// +// Compiling and analysing the code using KLEE +// +// What problem(s) did KLEE identify +// ** your answer here ** +// +// Now try to solve this by contracts +// You should not change the code, just enable the contacts +// The `_` should be filled with concrete values +// +// Can you find a type invariant that satisfies BOTH pre- and post-conditions +// at the same time. +// +// If not, why is that not possible? diff --git a/examples/simple4.rs b/examples/simple4.rs new file mode 100644 index 0000000..22e1b8f --- /dev/null +++ b/examples/simple4.rs @@ -0,0 +1,100 @@ +//! Minimal example with zero tasks +//#![deny(unsafe_code)] +// IMPORTANT always include this feature gate +#![feature(proc_macro)] +#![feature(used)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +// IMPORTANT always do this rename +extern crate stm32f413; + +#[macro_use] +extern crate klee; +use klee::{k_abort, k_assert, k_assume}; + +// import the procedural macro +use rtfm::{app, Resource, Threshold}; + +app! { + // this is the path to the device crate + device: stm32f413, + + resources: { + static X:u32 = 1; + static Y:u32 = 1; + }, + + tasks: { + EXTI1: { + path: exti1, + priority: 1, + resources: [X, Y], + }, + EXTI2: { + path: exti2, + priority: 2, + resources: [X, Y], + }, + }, +} + +#[inline(never)] +#[allow(non_snake_case)] +fn exti1(t: &mut Threshold, EXTI1::Resources { X, mut Y }: EXTI1::Resources) { + X.claim(t, |x, t1| { + Y.claim_mut(t1, |y, _| { + let old = *y; + if *x < 5 { + for _ in 0..*x { + *y += 1; + } + //assert!(*y == *x + old); + } + }); + }); +} + +fn exti2(_: &mut Threshold, _: EXTI2::Resources) {} + +// The `init` function +// +// This function runs as an atomic section before any tasks +// are allowed to start +#[inline(never)] +#[allow(dead_code)] +fn init(_: init::Peripherals, _: init::Resources) {} + +// The idle loop. +// +// This runs after `init` and has a priority of 0. All tasks can preempt this +// function. This function can never return so it must contain some sort of +// endless loop. +#[inline(never)] +fn idle() -> ! { + loop {} +} + +// Assignments +// +// Rust strives at being a safe language. +// - Memory safety, +// - static checking where possible +// - run-time checking causing `panic!` on violation +// +// - No undefined behavior in "safe" Rust +// - panic! in case undef behavior (e.g., div 0) +// +// Compiling and analysing the code using KLEE +// +// What problem(s) did KLEE identify +// ** your answer here ** +// +// Now try to solve this by contracts +// You should not change the code, just enable the contacts +// The `_` should be filled with concrete values +// +// Can you find a type invariant that satisfies BOTH pre- and post-conditions +// at the same time. +// +// If not, why is that not possible? diff --git a/examples/simple5.rs b/examples/simple5.rs new file mode 100644 index 0000000..0e5f60e --- /dev/null +++ b/examples/simple5.rs @@ -0,0 +1,96 @@ +//! Minimal example with zero tasks +//#![deny(unsafe_code)] +// IMPORTANT always include this feature gate +#![feature(proc_macro)] +#![feature(used)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +// IMPORTANT always do this rename +extern crate stm32f413; + +#[macro_use] +extern crate klee; +use klee::{k_abort, k_assert, k_assume}; + +// import the procedural macro +use rtfm::{app, Resource, Threshold}; + +app! { + // this is the path to the device crate + device: stm32f413, + + resources: { + static X:u32 = 1; + static Y:u32 = 1; + }, + + tasks: { + EXTI1: { + path: exti1, + priority: 1, + resources: [X, Y], + }, + EXTI2: { + path: exti2, + priority: 2, + resources: [Y], + }, + }, +} + +#[inline(never)] +#[allow(non_snake_case)] +fn exti1(t: &mut Threshold, EXTI1::Resources { X, mut Y }: EXTI1::Resources) { + Y.claim_mut(t, |y, _| { + if *X < 5 { + for _ in 0..*X { + *y += 1; + } + } + }); +} + +fn exti2(_: &mut Threshold, _: EXTI2::Resources) {} + +// The `init` function +// +// This function runs as an atomic section before any tasks +// are allowed to start +#[inline(never)] +#[allow(dead_code)] +fn init(_: init::Peripherals, _: init::Resources) {} + +// The idle loop. +// +// This runs after `init` and has a priority of 0. All tasks can preempt this +// function. This function can never return so it must contain some sort of +// endless loop. +#[inline(never)] +fn idle() -> ! { + loop {} +} + +// Assignments +// +// Rust strives at being a safe language. +// - Memory safety, +// - static checking where possible +// - run-time checking causing `panic!` on violation +// +// - No undefined behavior in "safe" Rust +// - panic! in case undef behavior (e.g., div 0) +// +// Compiling and analysing the code using KLEE +// +// What problem(s) did KLEE identify +// ** your answer here ** +// +// Now try to solve this by contracts +// You should not change the code, just enable the contacts +// The `_` should be filled with concrete values +// +// Can you find a type invariant that satisfies BOTH pre- and post-conditions +// at the same time. +// +// If not, why is that not possible? diff --git a/examples/simple6.rs b/examples/simple6.rs new file mode 100644 index 0000000..ec18fe9 --- /dev/null +++ b/examples/simple6.rs @@ -0,0 +1,98 @@ +//! Minimal example with zero tasks +//#![deny(unsafe_code)] +// IMPORTANT always include this feature gate +#![feature(proc_macro)] +#![feature(used)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +// IMPORTANT always do this rename +extern crate stm32f413; + +#[macro_use] +extern crate klee; +use klee::{k_abort, k_assert, k_assume, k_read}; + +// import the procedural macro +use rtfm::{app, Resource, Threshold}; + +app! { + // this is the path to the device crate + device: stm32f413, + + resources: { + static X:u32 = 1; + static Y:u32 = 1; + }, + + tasks: { + EXTI1: { + path: exti1, + priority: 1, + resources: [X, Y], + }, + EXTI2: { + path: exti2, + priority: 2, + resources: [X], + }, + }, +} + +#[inline(never)] +#[allow(non_snake_case)] +fn exti1(t: &mut Threshold, EXTI1::Resources { X, mut Y }: EXTI1::Resources) { + X.claim(t, |x, _| { + if *x > 10 { + *Y = 5; + } else { + if *x < 5 { + *Y = 8; + } + } + }); +} + +fn exti2(_: &mut Threshold, _: EXTI2::Resources) {} + +// The `init` function +// +// This function runs as an atomic section before any tasks +// are allowed to start +#[inline(never)] +#[allow(dead_code)] +fn init(_: init::Peripherals, _: init::Resources) {} + +// The idle loop. +// +// This runs after `init` and has a priority of 0. All tasks can preempt this +// function. This function can never return so it must contain some sort of +// endless loop. +#[inline(never)] +fn idle() -> ! { + loop {} +} + +// Assignments +// +// Rust strives at being a safe language. +// - Memory safety, +// - static checking where possible +// - run-time checking causing `panic!` on violation +// +// - No undefined behavior in "safe" Rust +// - panic! in case undef behavior (e.g., div 0) +// +// Compiling and analysing the code using KLEE +// +// What problem(s) did KLEE identify +// ** your answer here ** +// +// Now try to solve this by contracts +// You should not change the code, just enable the contacts +// The `_` should be filled with concrete values +// +// Can you find a type invariant that satisfies BOTH pre- and post-conditions +// at the same time. +// +// If not, why is that not possible? diff --git a/examples/simple7.rs b/examples/simple7.rs new file mode 100644 index 0000000..bb91ed9 --- /dev/null +++ b/examples/simple7.rs @@ -0,0 +1,100 @@ +//! Minimal example with zero tasks +//#![deny(unsafe_code)] +// IMPORTANT always include this feature gate +#![feature(proc_macro)] +#![feature(used)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +// IMPORTANT always do this rename +extern crate stm32f413; + +#[macro_use] +extern crate klee; +use klee::{k_abort, k_assert, k_assume, k_read}; + +// import the procedural macro +use rtfm::{app, Resource, Threshold}; + +app! { + // this is the path to the device crate + device: stm32f413, + + resources: { + static X:u32 = 1; + static Y:u32 = 1; + }, + + tasks: { + EXTI1: { + path: exti1, + priority: 1, + resources: [X, Y], + }, + EXTI2: { + path: exti2, + priority: 2, + resources: [X, Y], + }, + }, +} + +#[inline(never)] +#[allow(non_snake_case)] +fn exti1(t: &mut Threshold, EXTI1::Resources { X, mut Y }: EXTI1::Resources) { + X.claim(t, |x, t| { + Y.claim_mut(t, |y, _| { + if *x > 10 { + *y = 5; + } else { + if *x < 5 { + *y = 8; + } + } + }); + }); +} + +fn exti2(_: &mut Threshold, _: EXTI2::Resources) {} + +// The `init` function +// +// This function runs as an atomic section before any tasks +// are allowed to start +#[inline(never)] +#[allow(dead_code)] +fn init(_: init::Peripherals, _: init::Resources) {} + +// The idle loop. +// +// This runs after `init` and has a priority of 0. All tasks can preempt this +// function. This function can never return so it must contain some sort of +// endless loop. +#[inline(never)] +fn idle() -> ! { + loop {} +} + +// Assignments +// +// Rust strives at being a safe language. +// - Memory safety, +// - static checking where possible +// - run-time checking causing `panic!` on violation +// +// - No undefined behavior in "safe" Rust +// - panic! in case undef behavior (e.g., div 0) +// +// Compiling and analysing the code using KLEE +// +// What problem(s) did KLEE identify +// ** your answer here ** +// +// Now try to solve this by contracts +// You should not change the code, just enable the contacts +// The `_` should be filled with concrete values +// +// Can you find a type invariant that satisfies BOTH pre- and post-conditions +// at the same time. +// +// If not, why is that not possible? -- GitLab