Skip to content

Commit

Permalink
[UT] Add unit tests to check :use_backtrace_gdb_reporter option
Browse files Browse the repository at this point in the history
Add to assets test_example_file_sigsegv.c sigsegv test file
  • Loading branch information
luze-mobica committed Jan 23, 2023
1 parent 7fa217d commit 94cfcc9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
sudo apt-get update -qq
sudo apt-get install --assume-yes --quiet gcc-multilib
sudo apt-get install -qq gcc-avr binutils-avr avr-libc
sudo apt-get install -qq gcc-avr binutils-avr avr-libc gdb
# Install GCovr
- name: Install GCovr
Expand Down
16 changes: 16 additions & 0 deletions assets/test_example_file_sigsegv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <signal.h>
#include "unity.h"
#include "example_file.h"


void setUp(void) {}
void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
TEST_ASSERT_EQUAL(2, add_numbers(1,1));
}

void test_add_numbers_will_fail(void) {
raise(SIGSEGV);
TEST_ASSERT_EQUAL(2, add_numbers(2,2));
}
51 changes: 51 additions & 0 deletions spec/spec_system_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,55 @@ def handles_destroying_a_module_that_does_not_exist_using_the_module_plugin_path
end
end

def test_run_of_projects_fail_because_of_sigsegv_without_report
@c.with_context do
Dir.chdir @proj_name do
FileUtils.cp test_asset_path("example_file.h"), 'src/'
FileUtils.cp test_asset_path("example_file.c"), 'src/'
FileUtils.cp test_asset_path("test_example_file_sigsegv.c"), 'test/'

output = `bundle exec ruby -S ceedling test:all 2>&1`
expect($?.exitstatus).to match(1) # Test should fail as sigsegv is called
expect(output).to match(/Segmentation fault \(core dumped\)/)
expect(output).to match(/No tests executed./)
expect(!File.exists?('./build/test/results/test_add.fail'))
end
end
end

def test_run_of_projects_fail_because_of_sigsegv_with_report
@c.with_context do
Dir.chdir @proj_name do
FileUtils.cp test_asset_path("example_file.h"), 'src/'
FileUtils.cp test_asset_path("example_file.c"), 'src/'
FileUtils.cp test_asset_path("test_example_file_sigsegv.c"), 'test/'

add_line = false
updated_prj_yml = []
File.read('project.yml').split("\n").each do |line|
if line =~ /\:project\:/
add_line = true
updated_prj_yml.append(line)
else
if add_line
updated_prj_yml.append(' :use_backtrace_gdb_reporter: TRUE')
add_line = false
end
updated_prj_yml.append(line)
end
end

File.write('project.yml', updated_prj_yml.join("\n"), mode: 'w')

output = `bundle exec ruby -S ceedling test:all 2>&1`
expect($?.exitstatus).to match(1) # Test should fail as sigsegv is called
expect(output).to match(/Program received signal SIGSEGV, Segmentation fault./)
expect(output).to match(/Unit test failures./)
expect(File.exists?('./build/test/results/test_example_file_sigsegv.fail'))
output_rd = File.read('./build/test/results/test_example_file_sigsegv.fail')
expect(output_rd =~ /test_add_numbers_will_fail \(\) at test\/test_example_file_sigsegv.c\:14/ )
end
end
end

end
3 changes: 3 additions & 0 deletions spec/system/deployment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
it { handles_creating_the_same_module_twice_using_the_module_plugin }
it { handles_destroying_a_module_that_does_not_exist_using_the_module_plugin }
it { handles_destroying_a_module_that_does_not_exist_using_the_module_plugin_path_extension }

it { test_run_of_projects_fail_because_of_sigsegv_without_report }
it { test_run_of_projects_fail_because_of_sigsegv_with_report }
end

describe "deployed in a project's `vendor` directory with gitignore." do
Expand Down

0 comments on commit 94cfcc9

Please sign in to comment.