Skip to content

Commit

Permalink
Update sample project to include a couple integration tests.
Browse files Browse the repository at this point in the history
Update sample project to include test-specific defines.
Add manual stress test.
Bump vendor versions.
  • Loading branch information
mvandervoord committed Oct 4, 2024
1 parent e06f844 commit 847fcff
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 6 deletions.
51 changes: 51 additions & 0 deletions examples/temp_sensor/mixin/add_gcov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# =========================================================================
# Ceedling - Test-Centered Build System for C
# ThrowTheSwitch.org
# Copyright (c) 2010-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
# SPDX-License-Identifier: MIT
# =========================================================================

---

# Enable gcov plugin
:plugins:
:enabled:
- gcov

# Add -gcov to the plugins list to make sure of the gcov plugin
# You will need to have gcov and gcovr both installed to make it work.
# For more information on these options, see docs in plugins/gcov
:gcov:
:utilities:
- gcovr # Use gcovr to create the specified reports (default).
#- ReportGenerator # Use ReportGenerator to create the specified reports.
:reports: # Specify one or more reports to generate.
# Make an HTML summary report.
# - HtmlBasic
- HtmlDetailed
# - Text
# - Cobertura
# - SonarQube
# - JSON
# - HtmlInline
# - HtmlInlineAzure
# - HtmlInlineAzureDark
# - HtmlChart
# - MHtml
# - Badges
# - CsvSummary
# - Latex
# - LatexSummary
# - PngChart
# - TeamCitySummary
# - lcov
# - Xml
# - XmlSummary
:gcovr:
# :html_artifact_filename: TestCoverageReport.html
# :html_title: Test Coverage Report
:html_medium_threshold: 75
:html_high_threshold: 90
# :html_absolute_paths: TRUE
# :html_encoding: UTF-8
...
8 changes: 7 additions & 1 deletion examples/temp_sensor/mixin/add_unity_helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
# Enable the unity helper's define to enable our custom assertion
:defines:
:test:
- TEST_CUSTOM_EXAMPLE_STRUCT_T
'*':
- TEST # Simple list option to add symbol 'TEST' to compilation of all files in all test executables
- TEST_CUSTOM_EXAMPLE_STRUCT_T
'TestUsartIntegrated.c':
- TEST
- TEST_CUSTOM_EXAMPLE_STRUCT_T
- TEST_USART_INTEGRATED_STRING=\"It's Awesome Time!\n\"
:release: []

# Add the unity helper configuration to cmock
Expand Down
8 changes: 6 additions & 2 deletions examples/temp_sensor/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
:enabled:
#- beep # beeps when finished, so you don't waste time waiting for ceedling
- module_generator # handy for quickly creating source, header, and test templates
- gcov # test coverage using gcov. Requires gcc, gcov, and a coverage analyzer like gcovr
#- gcov # test coverage using gcov. Requires gcc, gcov, and a coverage analyzer like gcovr
#- bullseye # test coverage using bullseye. Requires bullseye for your platform
#- command_hooks # write custom actions to be called at different points during the build process
#- compile_commands_json_db # generate a compile_commands.json file
Expand Down Expand Up @@ -120,7 +120,11 @@
# - Specifiying symbols used during test preprocessing
:defines:
:test:
- TEST # Simple list option to add symbol 'TEST' to compilation of all files in all test executables
'*':
- TEST # Simple list option to add symbol 'TEST' to compilation of all files in all test executables
'TestUsartIntegrated.c':
- TEST
- TEST_USART_INTEGRATED_STRING=\"It's Awesome Time!\n\"
:release: []

# Enable to inject name of a test as a unique compilation symbol into its respective executable build.
Expand Down
53 changes: 53 additions & 0 deletions examples/temp_sensor/test/TestTimerIntegrated.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* =========================================================================
Ceedling - Test-Centered Build System for C
ThrowTheSwitch.org
Copyright (c) 2010-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */

#include "unity.h"
#include "Types.h"
#include "TimerConductor.h"
#include "TimerHardware.h"
#include "TimerModel.h"
#include "MockTimerConfigurator.h"
#include "MockTimerInterruptHandler.h"
#include "MockTaskScheduler.h"

/* NOTE: we probably wouldn't actually perform this test on our own projects
but it's a good example of testing the same module(s) from multiple test
files, and therefore we like having it in this example.
*/

void setUp(void)
{
}

void tearDown(void)
{
}

void testInitShouldCallHardwareInit(void)
{
Timer_EnablePeripheralClocks_Expect();
Timer_Reset_Expect();
Timer_ConfigureMode_Expect();
Timer_ConfigurePeriod_Expect();
Timer_EnableOutputPin_Expect();
Timer_Enable_Expect();
Timer_ConfigureInterruptHandler_Expect();
Timer_Start_Expect();

TimerConductor_Init();
}

void testRunShouldGetSystemTimeAndPassOnToModelForEventScheduling(void)
{
Timer_GetSystemTime_ExpectAndReturn(1230);
TaskScheduler_Update_Expect(1230);
TimerConductor_Run();

Timer_GetSystemTime_ExpectAndReturn(837460);
TaskScheduler_Update_Expect(837460);
TimerConductor_Run();
}
63 changes: 63 additions & 0 deletions examples/temp_sensor/test/TestUsartIntegrated.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* =========================================================================
Ceedling - Test-Centered Build System for C
ThrowTheSwitch.org
Copyright (c) 2010-24 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */

#include "unity.h"
#include "Types.h"
#include "UsartConductor.h"
#include "UsartModel.h"
#include "UsartHardware.h"
#include "ModelConfig.h"
#include "MockTaskScheduler.h"
#include "MockUsartConfigurator.h"
#include "MockUsartPutChar.h"
#include "MockTemperatureFilter.h"
#include "MockUsartBaudRateRegisterCalculator.h"
#include <math.h>

/* NOTE: we probably wouldn't actually perform this test on our own projects
but it's a good example of testing the same module(s) from multiple test
files, and therefore we like having it in this example.
*/

#ifndef TEST_USART_INTEGRATED_STRING
#define TEST_USART_INTEGRATED_STRING "THIS WILL FAIL"
#endif

void setUp(void)
{
}

void tearDown(void)
{
}

void testShouldInitializeHardwareWhenInitCalled(void)
{
size_t i;
const char* test_str = TEST_USART_INTEGRATED_STRING;

UsartModel_CalculateBaudRateRegisterSetting_ExpectAndReturn(MASTER_CLOCK, USART0_BAUDRATE, 4);
Usart_ConfigureUsartIO_Expect();
Usart_EnablePeripheralClock_Expect();
Usart_Reset_Expect();
Usart_ConfigureMode_Expect();
Usart_SetBaudRateRegister_Expect(4);
Usart_Enable_Expect();
for (i=0; i < strlen(test_str); i++)
{
Usart_PutChar_Expect(test_str[i]);
}

UsartConductor_Init();
}

void testRunShouldNotDoAnythingIfSchedulerSaysItIsNotTimeYet(void)
{
TaskScheduler_DoUsart_ExpectAndReturn(FALSE);

UsartConductor_Run();
}
24 changes: 24 additions & 0 deletions spec/manual/stress_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
iterations = (ARGV[0] || 25).to_i
puts "Stress Testing Each Scenario #{iterations} times..."

require 'open3'

defaults = { :dir => File.expand_path(File.dirname(__FILE__)) + '/../../examples/temp_sensor' }

tasks = {
'ceedling clobber test:all' => defaults,
'ceedling -v=4 clobber test:all' => defaults,
'ceedling test:all' => defaults,
'ceedling --verbosity=obnoxious --mixin=add_unity_helper --mixin=add_gcov clobber test:all' => defaults,
}

tasks.each_pair do |k,v|
Dir.chdir(v[:dir]) do
iterations.times do |i|
puts "=============== RUNNING ITERATION #{i+1}:\n#{k.to_s}\n===============\n\n"
stdout, stderr, status = Open3.capture3(k)
puts stdout,stderr,status
raise "\n\nCrashed on #{k} Iteration #{i+1}" unless status.success?
end
end
end
2 changes: 1 addition & 1 deletion vendor/c_exception
Submodule c_exception updated 1 files
+23 −16 project.yml
2 changes: 1 addition & 1 deletion vendor/cmock
Submodule cmock updated 63 files
+13 −8 .github/workflows/main.yml
+0 −7 Gemfile
+1 −1 LICENSE.txt
+26 −10 README.md
+34 −0 cmock.gemspec
+1 −1 config/production_environment.rb
+1 −1 config/test_environment.rb
+166 −0 docs/CMockChangeLog.md
+13 −0 docs/CMockKnownIssues.md
+274 −0 docs/CMock_ArgumentValidation.md
+14 −5 docs/CMock_Summary.md
+138 −0 docs/CODE_OF_CONDUCT.md
+238 −0 docs/CONTRIBUTING.md
+1 −1 examples/make_example/Makefile
+1 −1 examples/make_example/test/test_foo.c
+0 −44 examples/temp_sensor/gcc.yml
+0 −92 examples/temp_sensor/iar_v4.yml
+0 −81 examples/temp_sensor/iar_v5.yml
+1 −1 examples/temp_sensor/rakefile.rb
+26 −21 examples/temp_sensor/rakefile_helper.rb
+13 −12 examples/temp_sensor/src/AT91SAM7X256.h
+8 −5 examples/temp_sensor/src/TemperatureFilter.c
+1 −1 examples/temp_sensor/src/TimerInterruptConfigurator.c
+90 −0 examples/temp_sensor/targets/gcc.yml
+136 −0 examples/temp_sensor/targets/iar_v4.yml
+125 −0 examples/temp_sensor/targets/iar_v5.yml
+2 −2 examples/temp_sensor/test/TestTimerInterruptConfigurator.c
+21 −6 lib/cmock.rb
+13 −6 lib/cmock_config.rb
+4 −4 lib/cmock_file_writer.rb
+10 −12 lib/cmock_generator.rb
+9 −5 lib/cmock_generator_plugin_array.rb
+1 −2 lib/cmock_generator_plugin_callback.rb
+1 −2 lib/cmock_generator_plugin_cexception.rb
+8 −4 lib/cmock_generator_plugin_expect.rb
+5 −4 lib/cmock_generator_plugin_expect_any_args.rb
+4 −3 lib/cmock_generator_plugin_ignore.rb
+4 −3 lib/cmock_generator_plugin_ignore_stateless.rb
+2 −2 lib/cmock_generator_plugin_return_thru_ptr.rb
+5 −5 lib/cmock_generator_utils.rb
+28 −27 lib/cmock_header_parser.rb
+2 −2 lib/cmock_plugin_manager.rb
+4 −3 lib/cmock_unityhelper_parser.rb
+22 −0 lib/cmock_version.rb
+6 −6 scripts/create_makefile.rb
+2 −2 src/cmock.h
+1 −0 test/.ruby-version
+6 −3 test/rakefile
+19 −6 test/rakefile_helper.rb
+1 −1 test/system/test_compilation/osek.h
+1 −1 test/system/test_interactions/skeleton_update.yml
+142 −0 test/system/test_interactions/wrong_expect_and_return.yml
+8 −10 test/unit/cmock_generator_main_test.rb
+6 −3 test/unit/cmock_generator_plugin_array_test.rb
+6 −3 test/unit/cmock_generator_plugin_expect_a_test.rb
+5 −2 test/unit/cmock_generator_plugin_expect_any_args_test.rb
+6 −3 test/unit/cmock_generator_plugin_expect_b_test.rb
+7 −3 test/unit/cmock_generator_plugin_ignore_stateless_test.rb
+7 −3 test/unit/cmock_generator_plugin_ignore_test.rb
+10 −10 test/unit/cmock_generator_plugin_return_thru_ptr_test.rb
+5 −5 test/unit/cmock_header_parser_test.rb
+1 −1 vendor/c_exception
+1 −1 vendor/unity

0 comments on commit 847fcff

Please sign in to comment.