Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
klee_tutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ruben Asplund
klee_tutorial
Commits
7c0265b9
Commit
7c0265b9
authored
4 years ago
by
Ruben Asplund
Browse files
Options
Downloads
Patches
Plain Diff
cyccnt.rs DONE
parent
3c984479
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cargo_klee_examples/examples/cyccnt.rs
+15
-8
15 additions, 8 deletions
cargo_klee_examples/examples/cyccnt.rs
with
15 additions
and
8 deletions
cargo_klee_examples/examples/cyccnt.rs
+
15
−
8
View file @
7c0265b9
...
@@ -9,8 +9,8 @@ extern crate panic_klee;
...
@@ -9,8 +9,8 @@ extern crate panic_klee;
#[no_mangle]
#[no_mangle]
fn
main
()
{
fn
main
()
{
let
mut
core
=
cortex_m
::
Peripherals
::
take
()
.unwrap
();
let
mut
core
=
cortex_m
::
Peripherals
::
take
()
.unwrap
();
//
core.DCB.enable_trace();
core
.DCB
.enable_trace
();
//
core.DWT.enable_cycle_counter();
core
.DWT
.enable_cycle_counter
();
let
start
:
u32
=
core
.DWT.cyccnt
.read
();
let
start
:
u32
=
core
.DWT.cyccnt
.read
();
...
@@ -208,9 +208,10 @@ fn main() {
...
@@ -208,9 +208,10 @@ fn main() {
// Why does these values cause an error debug/dev build but not in a release build?
// Why does these values cause an error debug/dev build but not in a release build?
//
//
// [This line is causing the problem: let _time = end - start;
// [This line is causing the problem: let _time = end - start;
// When taking substraction of values two values there is a high risk that it will overflow,
// When taking substraction between two values with unsigned variable,
// therefore the error occurs in debug/dev build.
// there is a possibility that the value becomes negative. The u32 cant represent negative
// In release build the substractions occurs and no overflow is found then errors will not occurs.
// values therefore error occurs in debug/dev build.
// In release build the substractions occurs and no negative value is found then errors will not occur.
// It seems like the release build is not detecting potential problems, only problems that occurs.]
// It seems like the release build is not detecting potential problems, only problems that occurs.]
//
//
// C) Fix the problem!
// C) Fix the problem!
...
@@ -223,8 +224,8 @@ fn main() {
...
@@ -223,8 +224,8 @@ fn main() {
// There are numerous ways to solve the problem.
// There are numerous ways to solve the problem.
// Argue for your solution in your own words.
// Argue for your solution in your own words.
//
//
// [
The substraction can overflow, to
remove the error and make sure the substraction
is almost always correct,
// [
I added wrapper_sub to the caculation. It will
remove the error and make sure the substraction
wrap around instead
//
we need to use wrapper_sub.
]
//
of giving an error when the differance is negative.
]
//
//
// D) Learning outcomes and major takeaways.
// D) Learning outcomes and major takeaways.
//
//
...
@@ -243,7 +244,13 @@ fn main() {
...
@@ -243,7 +244,13 @@ fn main() {
//
//
// How long time would lines 16/17 take to run to trigger the error?
// How long time would lines 16/17 take to run to trigger the error?
//
//
// [your answer here]
// [
// They are hard do find becasue the error appears when the timer has wrapped around.
// The error is triggered when end is smaller than start.
// The CYCCNT is a 32 bit unsigned integer, it will wrap around when the value has reached 2^32.
// 2^32/8MHz = 537 s
// It would take at least 537s.
// ]
//
//
// Of course this is a contrived example, and may not occur in practice.
// Of course this is a contrived example, and may not occur in practice.
// But, it represents a class of problems/errors/bugs that is
// But, it represents a class of problems/errors/bugs that is
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment