Skip to content

Commit

Permalink
Updated temp_sensor project to better capture a variety of test run o…
Browse files Browse the repository at this point in the history
…ptions.

Add tests for more run options.
  • Loading branch information
mvandervoord committed Apr 25, 2024
1 parent b9986f3 commit 58841a8
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 11 deletions.
15 changes: 5 additions & 10 deletions examples/temp_sensor/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,11 @@
:use_test_definition: FALSE

# Configure additional command line flags provided to tools used in each build step
# :flags:
# :release:
# :compile: # Add '-Wall' and '--02' to compilation of all files in release target
# - -Wall
# - --O2
# :test:
# :compile:
# '(_|-)special': # Add '-pedantic' to compilation of all files in all test executables with '_special' or '-special' in their names
# - -pedantic
# '*': # Add '-foo' to compilation of all files in all test executables
:flags:
:test:
:compile:
'TemperatureCalculator':
- '-DSUPPLY_VOLTAGE=3.0'

# Configuration Options specific to CMock. See CMock docs for details
:cmock:
Expand Down
6 changes: 5 additions & 1 deletion examples/temp_sensor/src/TemperatureCalculator.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
#define logl log
#endif

#ifndef SUPPLY_VOLTAGE
#define SUPPLY_VOLTAGE 5.0
#endif

float TemperatureCalculator_Calculate(uint16 millivolts)
{
const double supply_voltage = 3.0;
const double supply_voltage = SUPPLY_VOLTAGE;
const double series_resistance = 5000;
const double coefficient_A = 316589.698;
const double coefficient_B = -0.1382009;
Expand Down
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions spec/gcov/gcov_deployment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,60 @@
end
end
end

it "should be able to test a single module (it should INHERIT file-specific flags)" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling gcov:TemperatureCalculator 2>&1`
expect(@output).to match(/TESTED:\s+2/)
expect(@output).to match(/PASSED:\s+2/)

expect(@output).to match(/TemperatureCalculator\.c \| Lines executed:/i)
end
end
end

it "should be able to test multiple files matching a pattern" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling gcov:pattern[Temp] 2>&1`
expect(@output).to match(/TESTED:\s+6/)
expect(@output).to match(/PASSED:\s+6/)

expect(@output).to match(/TemperatureCalculator\.c \| Lines executed:/i)
expect(@output).to match(/TemperatureFilter\.c \| Lines executed:/i)
end
end
end

it "should be able to test all files matching in a path" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling gcov:path[adc] 2>&1`
expect(@output).to match(/TESTED:\s+15/)
expect(@output).to match(/PASSED:\s+15/)

expect(@output).to match(/AdcConductor\.c \| Lines executed:/i)
expect(@output).to match(/AdcHardware\.c \| Lines executed:/i)
expect(@output).to match(/AdcModel\.c \| Lines executed:/i)
end
end
end

it "should be able to test specific test cases in a file" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling gcov:path[adc] --test-case="RunShouldNot" 2>&1`
expect(@output).to match(/TESTED:\s+2/)
expect(@output).to match(/PASSED:\s+2/)

expect(@output).to match(/AdcConductor\.c \| Lines executed:/i)
expect(@output).to match(/AdcHardware\.c \| Lines executed:/i)
expect(@output).to match(/AdcModel\.c \| Lines executed:/i)
end
end
end

end
end
end
Expand Down
53 changes: 53 additions & 0 deletions spec/system/deployment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,59 @@
end
end
end

it "should be able to test a single module (it includes file-specific flags)" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling test:TemperatureCalculator 2>&1`
expect(@output).to match(/TESTED:\s+2/)
expect(@output).to match(/PASSED:\s+2/)

expect(@output).to match(/TemperatureCalculator\.out/i)
end
end
end

it "should be able to test multiple files matching a pattern" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling test:pattern[Temp] 2>&1`
expect(@output).to match(/TESTED:\s+6/)
expect(@output).to match(/PASSED:\s+6/)

expect(@output).to match(/TemperatureCalculator\.out/i)
expect(@output).to match(/TemperatureFilter\.out/i)
end
end
end

it "should be able to test all files matching in a path" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling test:path[adc] 2>&1`
expect(@output).to match(/TESTED:\s+15/)
expect(@output).to match(/PASSED:\s+15/)

expect(@output).to match(/AdcModel\.out/i)
expect(@output).to match(/AdcHardware\.out/i)
expect(@output).to match(/AdcConductor\.out/i)
end
end
end

it "should be able to test specific test cases in a file" do
@c.with_context do
Dir.chdir "temp_sensor" do
@output = `bundle exec ruby -S ceedling test:path[adc] --test-case="RunShouldNot" 2>&1`
expect(@output).to match(/TESTED:\s+2/)
expect(@output).to match(/PASSED:\s+2/)

expect(@output).to match(/AdcModel\.out/i)
expect(@output).to match(/AdcHardware\.out/i)
expect(@output).to match(/AdcConductor\.out/i)
end
end
end
end

# # blinky depends on avr-gcc. If you happen to have this installed, go
Expand Down

0 comments on commit 58841a8

Please sign in to comment.