From 16c704fa0950498cb65bea32a167e93ce00d566e Mon Sep 17 00:00:00 2001 From: Alex Dale Date: Thu, 11 Mar 2021 19:32:34 -0800 Subject: [PATCH] Android tests call exit() when complete. [ Merge of http://go/wvgerrit/119804 ] The coverage framework used by Android requires the process to call exit() for coverage information to be dumped after the tests. Android unit tests have been adapted to use the a new main module. The core test_main.cpp used by integration tests has been updated to call exit(). Bug: 138941105 Test: Linux and Android unittests Change-Id: Ifffc7b8290c50dffe527738a36547c1d2fb90bd3 --- libwvdrmengine/cdm/core/test/test_main.cpp | 7 +++++-- libwvdrmengine/cdm/test/cdm_test_main.cpp | 17 +++++++++++++++++ libwvdrmengine/cdm/test/unit-test.mk | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 libwvdrmengine/cdm/test/cdm_test_main.cpp diff --git a/libwvdrmengine/cdm/core/test/test_main.cpp b/libwvdrmengine/cdm/core/test/test_main.cpp index edf9e306..ae305021 100644 --- a/libwvdrmengine/cdm/core/test/test_main.cpp +++ b/libwvdrmengine/cdm/core/test/test_main.cpp @@ -5,7 +5,7 @@ // Use in place of the gtest_main in order to initialize the WvCdmTestBase using // command line parameters. -#include +#include #include "log.h" #include "test_base.h" @@ -13,5 +13,8 @@ int main(int argc, char** argv) { if (!wvcdm::WvCdmTestBase::Initialize(argc, argv)) return 1; ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + const int status = RUN_ALL_TESTS(); + LOGD("CDM test complete with status %d", status); + exit(status); // Explicit call to exit() is required for code coverage. + return status; } diff --git a/libwvdrmengine/cdm/test/cdm_test_main.cpp b/libwvdrmengine/cdm/test/cdm_test_main.cpp new file mode 100644 index 00000000..8bbf6221 --- /dev/null +++ b/libwvdrmengine/cdm/test/cdm_test_main.cpp @@ -0,0 +1,17 @@ +// Copyright 2021 Google LLC. All Rights Reserved. This file and proprietary +// source code may only be used and distributed under the Widevine License +// Agreement. +#include + +#include "gtest/gtest.h" + +#include "log.h" + +int main(int argc, char** argv) { + LOGI("Running Android CDM tests"); + testing::InitGoogleTest(&argc, argv); + const int status = RUN_ALL_TESTS(); + LOGD("CDM test complete with status %d", status); + exit(status); // Explicit call to exit() is required for code coverage. + return status; +} diff --git a/libwvdrmengine/cdm/test/unit-test.mk b/libwvdrmengine/cdm/test/unit-test.mk index 4daa4b88..f4919842 100644 --- a/libwvdrmengine/cdm/test/unit-test.mk +++ b/libwvdrmengine/cdm/test/unit-test.mk @@ -20,6 +20,7 @@ LOCAL_SRC_FILES := \ ../core/test/url_request.cpp \ ../../oemcrypto/test/oec_device_features.cpp \ ../util/test/test_sleep.cpp \ + ./cdm_test_main.cpp \ LOCAL_C_INCLUDES := \ vendor/widevine/libwvdrmengine/android/cdm/test \ @@ -44,7 +45,6 @@ LOCAL_STATIC_LIBRARIES := \ libjsmn \ libgmock \ libgtest \ - libgtest_main \ libwvlevel3 \ LOCAL_SHARED_LIBRARIES := \