xref: /aosp_15_r20/system/update_engine/testrunner.cc (revision 5a9231315b4521097b8dc3750bc806fcafe0c72f)
1*5a923131SAndroid Build Coastguard Worker //
2*5a923131SAndroid Build Coastguard Worker // Copyright (C) 2012 The Android Open Source Project
3*5a923131SAndroid Build Coastguard Worker //
4*5a923131SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
5*5a923131SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
6*5a923131SAndroid Build Coastguard Worker // You may obtain a copy of the License at
7*5a923131SAndroid Build Coastguard Worker //
8*5a923131SAndroid Build Coastguard Worker //      http://www.apache.org/licenses/LICENSE-2.0
9*5a923131SAndroid Build Coastguard Worker //
10*5a923131SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
11*5a923131SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
12*5a923131SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*5a923131SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
14*5a923131SAndroid Build Coastguard Worker // limitations under the License.
15*5a923131SAndroid Build Coastguard Worker //
16*5a923131SAndroid Build Coastguard Worker 
17*5a923131SAndroid Build Coastguard Worker // based on pam_google_testrunner.cc
18*5a923131SAndroid Build Coastguard Worker 
19*5a923131SAndroid Build Coastguard Worker #include <xz.h>
20*5a923131SAndroid Build Coastguard Worker 
21*5a923131SAndroid Build Coastguard Worker #include <base/at_exit.h>
22*5a923131SAndroid Build Coastguard Worker #include <base/command_line.h>
23*5a923131SAndroid Build Coastguard Worker #include <brillo/test_helpers.h>
24*5a923131SAndroid Build Coastguard Worker #include <gtest/gtest.h>
25*5a923131SAndroid Build Coastguard Worker 
26*5a923131SAndroid Build Coastguard Worker #include "update_engine/common/terminator.h"
27*5a923131SAndroid Build Coastguard Worker #include "update_engine/payload_generator/xz.h"
28*5a923131SAndroid Build Coastguard Worker 
main(int argc,char ** argv)29*5a923131SAndroid Build Coastguard Worker int main(int argc, char** argv) {
30*5a923131SAndroid Build Coastguard Worker   LOG(INFO) << "started";
31*5a923131SAndroid Build Coastguard Worker   base::AtExitManager exit_manager;
32*5a923131SAndroid Build Coastguard Worker   // xz-embedded requires to initialize its CRC-32 table once on startup.
33*5a923131SAndroid Build Coastguard Worker   xz_crc32_init();
34*5a923131SAndroid Build Coastguard Worker   // The LZMA SDK-based Xz compressor used in the payload generation requires
35*5a923131SAndroid Build Coastguard Worker   // this one-time initialization.
36*5a923131SAndroid Build Coastguard Worker   chromeos_update_engine::XzCompressInit();
37*5a923131SAndroid Build Coastguard Worker   // TODO(garnold) temporarily cause the unittest binary to exit with status
38*5a923131SAndroid Build Coastguard Worker   // code 2 upon catching a SIGTERM. This will help diagnose why the unittest
39*5a923131SAndroid Build Coastguard Worker   // binary is perceived as failing by the buildbot.  We should revert it to use
40*5a923131SAndroid Build Coastguard Worker   // the default exit status of 1.  Corresponding reverts are necessary in
41*5a923131SAndroid Build Coastguard Worker   // terminator_unittest.cc.
42*5a923131SAndroid Build Coastguard Worker   chromeos_update_engine::Terminator::Init(2);
43*5a923131SAndroid Build Coastguard Worker   LOG(INFO) << "parsing command line arguments";
44*5a923131SAndroid Build Coastguard Worker   base::CommandLine::Init(argc, argv);
45*5a923131SAndroid Build Coastguard Worker   LOG(INFO) << "initializing gtest";
46*5a923131SAndroid Build Coastguard Worker   SetUpTests(&argc, argv, true);
47*5a923131SAndroid Build Coastguard Worker   // Logging to string is not thread safe.
48*5a923131SAndroid Build Coastguard Worker   brillo::LogToString(false);
49*5a923131SAndroid Build Coastguard Worker   LOG(INFO) << "running unit tests";
50*5a923131SAndroid Build Coastguard Worker   int test_result = RUN_ALL_TESTS();
51*5a923131SAndroid Build Coastguard Worker   LOG(INFO) << "unittest return value: " << test_result;
52*5a923131SAndroid Build Coastguard Worker   return test_result;
53*5a923131SAndroid Build Coastguard Worker }
54