| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2012 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 16 |  | 
|  | 17 | // based on pam_google_testrunner.cc | 
|  | 18 |  | 
| Sen Jiang | a78ee10 | 2016-04-01 14:15:08 -0700 | [diff] [blame] | 19 | #include <string> | 
|  | 20 |  | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 21 | #include <xz.h> | 
|  | 22 |  | 
| Darin Petkov | 9c0baf8 | 2010-10-07 13:44:48 -0700 | [diff] [blame] | 23 | #include <base/at_exit.h> | 
|  | 24 | #include <base/command_line.h> | 
| Sen Jiang | a78ee10 | 2016-04-01 14:15:08 -0700 | [diff] [blame] | 25 | #include <base/environment.h> | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 26 | #include <brillo/test_helpers.h> | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 27 | #include <gtest/gtest.h> | 
| Darin Petkov | 9c0baf8 | 2010-10-07 13:44:48 -0700 | [diff] [blame] | 28 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 29 | #include "update_engine/common/terminator.h" | 
| Sen Jiang | a78ee10 | 2016-04-01 14:15:08 -0700 | [diff] [blame] | 30 | #include "update_engine/common/test_utils.h" | 
| Alex Deymo | 246bf21 | 2016-03-22 19:27:33 -0700 | [diff] [blame] | 31 | #include "update_engine/payload_generator/xz.h" | 
| adlr@google.com | c98a7ed | 2009-12-04 18:54:03 +0000 | [diff] [blame] | 32 |  | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 33 | int main(int argc, char **argv) { | 
| Gilad Arnold | fc35929 | 2012-04-30 22:04:24 -0700 | [diff] [blame] | 34 | LOG(INFO) << "started"; | 
| Darin Petkov | 5c0a8af | 2010-08-24 13:39:13 -0700 | [diff] [blame] | 35 | base::AtExitManager exit_manager; | 
| Alex Deymo | 2e71f90 | 2015-09-30 01:25:48 -0700 | [diff] [blame] | 36 | // xz-embedded requires to initialize its CRC-32 table once on startup. | 
|  | 37 | xz_crc32_init(); | 
| Alex Deymo | 246bf21 | 2016-03-22 19:27:33 -0700 | [diff] [blame] | 38 | // The LZMA SDK-based Xz compressor used in the payload generation requires | 
|  | 39 | // this one-time initialization. | 
|  | 40 | chromeos_update_engine::XzCompressInit(); | 
| Gilad Arnold | 0b4a6ff | 2012-04-30 13:13:03 -0700 | [diff] [blame] | 41 | // TODO(garnold) temporarily cause the unittest binary to exit with status | 
|  | 42 | // code 2 upon catching a SIGTERM. This will help diagnose why the unittest | 
|  | 43 | // binary is perceived as failing by the buildbot.  We should revert it to use | 
|  | 44 | // the default exit status of 1.  Corresponding reverts are necessary in | 
|  | 45 | // terminator_unittest.cc. | 
|  | 46 | chromeos_update_engine::Terminator::Init(2); | 
| Sen Jiang | a78ee10 | 2016-04-01 14:15:08 -0700 | [diff] [blame] | 47 | // In Android bsdiff is located in update_engine_unittests, add it to PATH. | 
|  | 48 | #ifdef __ANDROID__ | 
|  | 49 | std::unique_ptr<base::Environment> env(base::Environment::Create()); | 
|  | 50 | std::string path_env; | 
|  | 51 | CHECK(env->GetVar("PATH", &path_env)); | 
|  | 52 | path_env += | 
|  | 53 | ":" + chromeos_update_engine::test_utils::GetBuildArtifactsPath().value(); | 
|  | 54 | CHECK(env->SetVar("PATH", path_env)); | 
|  | 55 | #endif | 
| Gilad Arnold | fc35929 | 2012-04-30 22:04:24 -0700 | [diff] [blame] | 56 | LOG(INFO) << "parsing command line arguments"; | 
| Alex Vakulenko | b96ecda | 2015-04-02 14:31:10 -0700 | [diff] [blame] | 57 | base::CommandLine::Init(argc, argv); | 
| Gilad Arnold | fc35929 | 2012-04-30 22:04:24 -0700 | [diff] [blame] | 58 | LOG(INFO) << "initializing gtest"; | 
| Alex Deymo | 0bb2341 | 2015-06-19 00:04:46 -0700 | [diff] [blame] | 59 | SetUpTests(&argc, argv, true); | 
| Gilad Arnold | fc35929 | 2012-04-30 22:04:24 -0700 | [diff] [blame] | 60 | LOG(INFO) << "running unit tests"; | 
| Gilad Arnold | faac2a5 | 2012-04-26 14:44:17 -0700 | [diff] [blame] | 61 | int test_result = RUN_ALL_TESTS(); | 
|  | 62 | LOG(INFO) << "unittest return value: " << test_result; | 
|  | 63 | return test_result; | 
| rspangler@google.com | 49fdf18 | 2009-10-10 00:57:34 +0000 | [diff] [blame] | 64 | } |