ci: Collect and report test results (#1244)

All gtest-based tests should now use add_gtest. Results from these tests
will be surfaced more prominently in GitHub Actions. Before this, it was
hard to find test failures in the log.
This commit is contained in:
Joey Parrish 2023-07-17 16:11:41 -07:00 committed by GitHub
parent 60fb057f1a
commit 868a8c5d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 61 additions and 23 deletions

View File

@ -152,6 +152,12 @@ jobs:
- name: Test
run: ctest -C "${{ matrix.build_type }}" -V --test-dir build/
- name: Publish Test Report
uses: mikepenz/action-junit-report@150e2f992e4fad1379da2056d1d1c279f520e058
if: ${{ always() }}
with:
report_paths: 'junit-reports/TEST-*.xml'
# TODO(joeyparrish): Prepare artifacts when build system is complete again
# - name: Prepare artifacts (static release only)
# run: |

3
.gitignore vendored
View File

@ -14,5 +14,6 @@
.repo
.settings
build/
/packager/docs/
junit-reports/
packager/docs/
.vscode/

View File

@ -43,6 +43,9 @@ else()
add_compile_options(-Wno-unknown-warning-option)
endif()
# Include our module for gtest-based testing.
include("gtest.cmake")
# Include our module for building protos.
include("protobuf.cmake")

View File

@ -50,4 +50,4 @@ target_link_libraries(file_unittest
gtest_main
nlohmann_json
test_web_server)
add_test(NAME file_unittest COMMAND file_unittest)
add_gtest(file_unittest)

40
packager/gtest.cmake Normal file
View File

@ -0,0 +1,40 @@
# Copyright 2023 Google LLC. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
# Define a custom function to create gtest-based tests. This will standardize
# all gtests to output junit XML files that can be used to flag specific test
# failures on a PR.
function(add_gtest NAME)
cmake_parse_arguments(PARSE_ARGV
# How many arguments to skip (1 for the library name)
1
# Prefix for automatic variables created by the parser
ADD_GTEST
# Boolean flags
""
# One-value arguments
"WORKING_DIRECTORY"
# Multi-value arguments
"")
# Optional working directory for the test executable.
if(${ADD_GTEST_WORKING_DIRECTORY})
set(ADD_GTEST_WORKING_DIRECTORY_SETTING
WORKING_DIRECTORY ${ADD_GTEST_WORKING_DIRECTORY})
else()
set(ADD_GTEST_WORKING_DIRECTORY_SETTING)
endif()
# Where we output test results in junit format.
set(ADD_GTEST_REPORT_PATH
${PROJECT_SOURCE_DIR}/junit-reports/TEST-${NAME}.xml)
# Output gtest results in junit format in a consistent place.
add_test(NAME ${NAME}
COMMAND ${NAME} --gtest_output=xml:${ADD_GTEST_REPORT_PATH}
${ADD_GTEST_WORKING_DIRECTORY_SETTINGS})
endfunction()

View File

@ -17,4 +17,4 @@ target_link_libraries(kv_pairs_unittest
gmock
gtest
gtest_main)
add_test(NAME kv_pairs_unittest COMMAND kv_pairs_unittest)
add_gtest(kv_pairs_unittest)

View File

@ -105,4 +105,4 @@ target_link_libraries(media_base_unittest
gtest_main
test_data_util
test_web_server)
add_test(NAME media_base_unittest COMMAND media_base_unittest)
add_gtest(media_base_unittest)

View File

@ -10,7 +10,6 @@ add_library(chunking STATIC
sync_point_queue.cc
text_chunker.cc
)
target_link_libraries(chunking
media_base
)
@ -20,7 +19,6 @@ add_executable(chunking_unittest
cue_alignment_handler_unittest.cc
text_chunker_unittest.cc
)
target_link_libraries(chunking_unittest
gmock
gtest
@ -28,5 +26,4 @@ target_link_libraries(chunking_unittest
media_handler_test_base
chunking
)
add_test(NAME chunking_unittest COMMAND chunking_unittest)
add_gtest(chunking_unittest)

View File

@ -66,4 +66,4 @@ target_link_libraries(codecs_unittest
gtest_main
test_data_util)
add_test(NAME codecs_unittest COMMAND codecs_unittest)
add_gtest(codecs_unittest)

View File

@ -28,5 +28,4 @@ target_link_libraries(media_crypto_unittest
gmock
gtest
gtest_main)
add_test(NAME media_crypto_unittest COMMAND media_crypto_unittest)
add_gtest(media_crypto_unittest)

View File

@ -13,7 +13,6 @@ add_library(media_event STATIC
muxer_listener_internal.cc
vod_media_info_dump_muxer_listener.cc
)
target_link_libraries(media_event
file
mpd_media_info_proto
@ -24,7 +23,6 @@ target_link_libraries(media_event
add_library(mock_muxer_listener STATIC
mock_muxer_listener.cc
)
target_link_libraries(mock_muxer_listener
gmock
media_event
@ -39,7 +37,6 @@ add_executable(media_event_unittest
muxer_listener_test_helper.cc
vod_media_info_dump_muxer_listener_unittest.cc
)
target_link_libraries(media_event_unittest
file
file_test_util
@ -50,5 +47,4 @@ target_link_libraries(media_event_unittest
media_event
mock_muxer_listener
)
add_test(NAME media_event_unittest COMMAND media_event_unittest)
add_gtest(media_event_unittest)

View File

@ -26,7 +26,6 @@ add_library(formats_webm STATIC
webm_video_client.cc
webm_webvtt_parser.cc
)
target_link_libraries(formats_webm
webm
file
@ -48,7 +47,6 @@ add_executable(webm_unittest
webm_tracks_parser_unittest.cc
webm_webvtt_parser_unittest.cc
)
target_link_libraries(webm_unittest
formats_webm
gmock
@ -56,5 +54,4 @@ target_link_libraries(webm_unittest
gtest_main
test_data_util
)
add_test(NAME webm_unittest COMMAND webm_unittest)
add_gtest(webm_unittest)

View File

@ -21,5 +21,4 @@ target_link_libraries(media_trick_play_unittest
gmock
gtest
gtest_main)
add_test(NAME media_trick_play_unittest COMMAND media_trick_play_unittest)
add_gtest(media_trick_play_unittest)

View File

@ -22,4 +22,4 @@ target_link_libraries(status_unittest
gmock
gtest
gtest_main)
add_test(NAME status_unittest COMMAND status_unittest)
add_gtest(status_unittest)