@@ -194,4 +194,147 @@ def can_create_html_report
194194 end
195195 end
196196 end
197+
198+ def can_create_gcov_html_report_from_crashing_test_runner_with_enabled_debug_and_cmd_args_set_to_true_for_test_cases_not_causing_crash
199+ @c . with_context do
200+ Dir . chdir @proj_name do
201+ FileUtils . cp test_asset_path ( "example_file.h" ) , 'src/'
202+ FileUtils . cp test_asset_path ( "example_file.c" ) , 'src/'
203+ FileUtils . cp test_asset_path ( "test_example_file_sigsegv.c" ) , 'test/'
204+ FileUtils . cp test_asset_path ( "project_with_guts_gcov.yml" ) , 'project.yml'
205+
206+ add_line = false
207+ updated_prj_yml = [ ]
208+ File . read ( 'project.yml' ) . split ( "\n " ) . each do |line |
209+ if line =~ /\: project\: /
210+ add_line = true
211+ updated_prj_yml . append ( line )
212+ else
213+ if add_line
214+ updated_prj_yml . append ( ' :use_backtrace_gdb_reporter: TRUE' )
215+ add_line = false
216+ end
217+ updated_prj_yml . append ( line )
218+ end
219+ end
220+ enable_unity_extra_args = "\n :test_runner:\n " \
221+ " :cmdline_args: true\n "
222+
223+ updated_prj_yml . insert ( updated_prj_yml . length ( ) -1 , enable_unity_extra_args )
224+
225+ File . write ( 'project.yml' , updated_prj_yml . join ( "\n " ) , mode : 'w' )
226+
227+ output = `bundle exec ruby -S ceedling gcov:all 2>&1`
228+ expect ( $?. exitstatus ) . to match ( 1 ) # Test should fail as sigsegv is called
229+ gcov_html_report = `bundle exec ruby -S ceedling utils:gcov 2>&1`
230+ expect ( $?. exitstatus ) . to match ( 0 )
231+ expect ( output ) . to match ( /Program received signal SIGSEGV, Segmentation fault./ )
232+ expect ( output ) . to match ( /Unit test failures./ )
233+ expect ( File . exist? ( './build/gcov/results/test_example_file_sigsegv.fail' ) )
234+ output_rd = File . read ( './build/gcov/results/test_example_file_sigsegv.fail' )
235+ expect ( output_rd =~ /test_add_numbers_will_fail \( \) at test\/ test_example_file_sigsegv.c\: 14/ )
236+ expect ( output ) . to match ( /TESTED:\s +2/ )
237+ expect ( output ) . to match ( /PASSED:\s +1/ )
238+ expect ( output ) . to match ( /FAILED:\s +1/ )
239+ expect ( output ) . to match ( /IGNORED:\s +0/ )
240+ expect ( output ) . to match ( /example_file.c Lines executed:50.00% of 4/ )
241+
242+ expect ( gcov_html_report ) . to match ( /Creating gcov results report\( s\) in 'build\/ artifacts\/ gcov'\. \. \. Done/ )
243+ expect ( File . exist? ( 'build/artifacts/gcov/GcovCoverageResults.html' ) ) . to eq true
244+ end
245+ end
246+ end
247+
248+ def can_create_gcov_html_report_from_crashing_test_runner_with_enabled_debug_and_cmd_args_set_to_true_with_zero_coverage
249+ @c . with_context do
250+ Dir . chdir @proj_name do
251+ FileUtils . cp test_asset_path ( "example_file.h" ) , 'src/'
252+ FileUtils . cp test_asset_path ( "example_file.c" ) , 'src/'
253+ FileUtils . cp test_asset_path ( "test_example_file_sigsegv.c" ) , 'test/'
254+ FileUtils . cp test_asset_path ( "project_with_guts_gcov.yml" ) , 'project.yml'
255+
256+ add_line = false
257+ updated_prj_yml = [ ]
258+ File . read ( 'project.yml' ) . split ( "\n " ) . each do |line |
259+ if line =~ /\: project\: /
260+ add_line = true
261+ updated_prj_yml . append ( line )
262+ else
263+ if add_line
264+ updated_prj_yml . append ( ' :use_backtrace_gdb_reporter: TRUE' )
265+ add_line = false
266+ end
267+ updated_prj_yml . append ( line )
268+ end
269+ end
270+ enable_unity_extra_args = "\n :test_runner:\n " \
271+ " :cmdline_args: true\n "
272+
273+ updated_prj_yml . insert ( updated_prj_yml . length ( ) -1 , enable_unity_extra_args )
274+
275+ File . write ( 'project.yml' , updated_prj_yml . join ( "\n " ) , mode : 'w' )
276+
277+ output = `bundle exec ruby -S ceedling gcov:all --exclude_test_case=test_add_numbers_adds_numbers 2>&1`
278+ expect ( $?. exitstatus ) . to match ( 1 ) # Test should fail as sigsegv is called
279+ gcov_html_report = `bundle exec ruby -S ceedling utils:gcov 2>&1`
280+ expect ( $?. exitstatus ) . to match ( 0 )
281+ expect ( output ) . to match ( /Program received signal SIGSEGV, Segmentation fault./ )
282+ expect ( output ) . to match ( /Unit test failures./ )
283+ expect ( File . exist? ( './build/gcov/results/test_example_file_sigsegv.fail' ) )
284+ output_rd = File . read ( './build/gcov/results/test_example_file_sigsegv.fail' )
285+ expect ( output_rd =~ /test_add_numbers_will_fail \( \) at test\/ test_example_file_sigsegv.c\: 14/ )
286+ expect ( output ) . to match ( /TESTED:\s +1/ )
287+ expect ( output ) . to match ( /PASSED:\s +0/ )
288+ expect ( output ) . to match ( /FAILED:\s +1/ )
289+ expect ( output ) . to match ( /IGNORED:\s +0/ )
290+ expect ( output ) . to match ( /example_file.c Lines executed:0.00% of 4/ )
291+
292+ expect ( gcov_html_report ) . to match ( /Creating gcov results report\( s\) in 'build\/ artifacts\/ gcov'\. \. \. Done/ )
293+ expect ( File . exist? ( 'build/artifacts/gcov/GcovCoverageResults.html' ) ) . to eq true
294+ end
295+ end
296+ end
297+
298+ def can_create_gcov_html_report_from_test_runner_with_enabled_debug_and_cmd_args_set_to_true_with_100_coverage_when_excluding_crashing_test_case
299+ @c . with_context do
300+ Dir . chdir @proj_name do
301+ FileUtils . cp test_asset_path ( "example_file.h" ) , 'src/'
302+ FileUtils . cp test_asset_path ( "example_file.c" ) , 'src/'
303+ FileUtils . cp test_asset_path ( "test_example_file_sigsegv.c" ) , 'test/'
304+ FileUtils . cp test_asset_path ( "project_with_guts_gcov.yml" ) , 'project.yml'
305+
306+ add_line = false
307+ updated_prj_yml = File . read ( 'project.yml' ) . split ( "\n " )
308+ enable_unity_extra_args = "\n :test_runner:\n " \
309+ " :cmdline_args: true\n "
310+
311+ updated_prj_yml . insert ( updated_prj_yml . length ( ) -1 , enable_unity_extra_args )
312+
313+ File . write ( 'project.yml' , updated_prj_yml . join ( "\n " ) , mode : 'w' )
314+
315+ add_test_case = "\n void test_difference_between_two_numbers(void)\n " \
316+ "{\n " \
317+ " TEST_ASSERT_EQUAL(0, difference_between_numbers(1,1));\n " \
318+ "}\n "
319+
320+ updated_test_file = File . read ( 'test/test_example_file_sigsegv.c' ) . split ( "\n " )
321+ updated_test_file . insert ( updated_test_file . length ( ) , add_test_case )
322+ File . write ( 'test/test_example_file_sigsegv.c' , updated_test_file . join ( "\n " ) , mode : 'w' )
323+
324+ output = `bundle exec ruby -S ceedling gcov:all --exclude_test_case=test_add_numbers_will_fail 2>&1`
325+ expect ( $?. exitstatus ) . to match ( 0 )
326+ gcov_html_report = `bundle exec ruby -S ceedling utils:gcov 2>&1`
327+ expect ( $?. exitstatus ) . to match ( 0 )
328+ expect ( File . exist? ( './build/gcov/results/test_example_file_sigsegv.pass' ) )
329+ expect ( output ) . to match ( /TESTED:\s +2/ )
330+ expect ( output ) . to match ( /PASSED:\s +2/ )
331+ expect ( output ) . to match ( /FAILED:\s +0/ )
332+ expect ( output ) . to match ( /IGNORED:\s +0/ )
333+ expect ( output ) . to match ( /example_file.c Lines executed:100.00% of 4/ )
334+
335+ expect ( gcov_html_report ) . to match ( /Creating gcov results report\( s\) in 'build\/ artifacts\/ gcov'\. \. \. Done/ )
336+ expect ( File . exist? ( 'build/artifacts/gcov/GcovCoverageResults.html' ) ) . to eq true
337+ end
338+ end
339+ end
197340end
0 commit comments