-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#97 Added unit test framework and a few tests
- Loading branch information
1 parent
d177bde
commit 66aff47
Showing
14 changed files
with
563 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ version.c | |
/cf2.* | ||
/cf1.* | ||
*.gch | ||
|
||
/generated-test/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[submodule "vendor/libdw1000"] | ||
path = vendor/libdw1000 | ||
url = https://github.com/bitcraze/libdw1000 | ||
[submodule "vendor/unity"] | ||
path = vendor/unity | ||
url = https://github.com/throwtheswitch/unity.git | ||
[submodule "vendor/cmock"] | ||
path = vendor/cmock | ||
url = https://github.com/throwtheswitch/cmock.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Rakefile used for running unit tests | ||
|
||
HERE = File.expand_path(File.dirname(__FILE__)) + '/' | ||
|
||
require 'rake' | ||
require 'rake/clean' | ||
require 'rake/testtask' | ||
require './tools/test/rakefile_helper' | ||
|
||
include RakefileHelpers | ||
|
||
# Load default configuration, for now | ||
DEFAULT_CONFIG_FILE = './tools/test/gcc.yml' | ||
configure_toolchain(DEFAULT_CONFIG_FILE) | ||
|
||
task :unit do | ||
run_tests(get_unit_test_files) | ||
end | ||
|
||
desc "Generate test summary" | ||
task :summary do | ||
report_summary | ||
end | ||
|
||
desc "Build and test Unity" | ||
task :all => [:clean, :unit, :summary] | ||
task :default => [:clobber, :all] | ||
task :ci => [:default] | ||
task :cruise => [:default] | ||
|
||
desc "Load configuration" | ||
task :config, :config_file do |t, args| | ||
configure_toolchain(args[:config_file]) | ||
end |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#include "unity.h" | ||
#include "num.h" | ||
|
||
|
||
void testThatLimitUint16NotLimitInRange() { | ||
// Fixture | ||
int32_t value = 4711; | ||
uint16_t expected = 4711; | ||
|
||
// Test | ||
uint16_t actual = limitUint16(value); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_UINT16(expected, actual); | ||
} | ||
|
||
|
||
void testThatLimitUint16LimitZero() { | ||
// Fixture | ||
int32_t value = -100; | ||
uint16_t expected = 0; | ||
|
||
// Test | ||
uint16_t actual = limitUint16(value); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_UINT16(expected, actual); | ||
} | ||
|
||
|
||
void testThatLimitUint16LimitMax() { | ||
// Fixture | ||
int32_t value = UINT16_MAX + 100; | ||
uint16_t expected = UINT16_MAX; | ||
|
||
// Test | ||
uint16_t actual = limitUint16(value); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_UINT16(expected, actual); | ||
} | ||
|
||
|
||
void testThatConstrainDoesNotLimitInRange() { | ||
// Fixture | ||
float value = 3.45; | ||
float expected = value; | ||
|
||
// Test | ||
float actual = constrain(value, 0.0, 100.0); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_FLOAT(expected, actual); | ||
} | ||
|
||
|
||
void testThatConstrainLimitsMin() { | ||
// Fixture | ||
float value = -10.0; | ||
float min = 3.45; | ||
float expected = min; | ||
|
||
// Test | ||
float actual = constrain(value, min, 100.0); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_FLOAT(expected, actual); | ||
} | ||
|
||
|
||
void testThatConstrainLimitsMax() { | ||
// Fixture | ||
float value = 10.0; | ||
float max = 3.45; | ||
float expected = max; | ||
|
||
// Test | ||
float actual = constrain(value, -100.0, max); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_FLOAT(expected, actual); | ||
} | ||
|
||
|
||
void testThatDeadbandInDeadbandPositive() { | ||
// Fixture | ||
float value = 0.5; | ||
float threshold = 1.0; | ||
float expected = 0.0; | ||
|
||
// Test | ||
float actual = deadband(value, threshold); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_FLOAT(expected, actual); | ||
} | ||
|
||
|
||
void testThatDeadbandInDeadbandNegative() { | ||
// Fixture | ||
float value = -0.5; | ||
float threshold = 1.0; | ||
float expected = 0.0; | ||
|
||
// Test | ||
float actual = deadband(value, threshold); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_FLOAT(expected, actual); | ||
} | ||
|
||
|
||
void testThatDeadbandOutsideDeadbandPositive() { | ||
// Fixture | ||
float value = 2.5; | ||
float threshold = 1.0; | ||
float expected = 1.5; | ||
|
||
// Test | ||
float actual = deadband(value, threshold); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_FLOAT(expected, actual); | ||
} | ||
|
||
|
||
void testThatDeadbandOutsideDeadbandNegative() { | ||
// Fixture | ||
float value = -2.5; | ||
float threshold = 1.0; | ||
float expected = -1.5; | ||
|
||
// Test | ||
float actual = deadband(value, threshold); | ||
|
||
// Assert | ||
TEST_ASSERT_EQUAL_FLOAT(expected, actual); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
scriptDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
|
||
make --directory=${scriptDir}/../.. "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
scriptDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
|
||
rake -f ${scriptDir}/../../Rakefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
compiler: | ||
path: gcc | ||
source_path: &source_path 'src/' | ||
unit_tests_path: &unit_tests_path 'test/**/' | ||
mocks_path: &mocks_path 'generated-test/mocks/' | ||
build_path: &build_path 'generated-test/build/' | ||
options: | ||
- '-c' | ||
- '-Wall' | ||
- '-Wextra' | ||
- '-Wunused-parameter' | ||
- '-Wno-address' | ||
- '-std=c11' | ||
- '-pedantic' | ||
- '-O0' | ||
includes: | ||
prefix: '-I' | ||
items: | ||
- *source_path | ||
- *unit_tests_path | ||
- *mocks_path | ||
- 'vendor/unity/src/' | ||
- 'vendor/cmock/src/' | ||
- 'src/utils/interface/' | ||
- 'src/utils/src/' | ||
defines: | ||
prefix: '-D' | ||
items: | ||
- CMOCK | ||
- 'UNITY_SUPPORT_64' | ||
- 'HSI48_VALUE="((uint32_t)48000000)"' | ||
- 'STM32F072xB' | ||
object_files: | ||
prefix: '-o' | ||
extension: '.o' | ||
destination: *build_path | ||
|
||
linker: | ||
path: gcc | ||
options: | ||
- -lm | ||
includes: | ||
prefix: '-I' | ||
object_files: | ||
path: *build_path | ||
extension: '.o' | ||
bin_files: | ||
prefix: '-o' | ||
extension: '.exe' | ||
destination: *build_path | ||
|
||
unsupported: | ||
- out_of_memory | ||
- unity_64bit_support | ||
- callingconv | ||
|
||
colour: true | ||
|
||
:cmock: | ||
:plugins: | ||
- :ignore_arg | ||
- :array | ||
- :callback | ||
:mock_path: *mocks_path | ||
:mock_prefix: mock_ |
Oops, something went wrong.