testrunner.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. //
  16. // based on pam_google_testrunner.cc
  17. #include <xz.h>
  18. #include <base/at_exit.h>
  19. #include <base/command_line.h>
  20. #include <brillo/test_helpers.h>
  21. #include <gtest/gtest.h>
  22. #include "update_engine/common/terminator.h"
  23. #include "update_engine/payload_generator/xz.h"
  24. int main(int argc, char** argv) {
  25. LOG(INFO) << "started";
  26. base::AtExitManager exit_manager;
  27. // xz-embedded requires to initialize its CRC-32 table once on startup.
  28. xz_crc32_init();
  29. // The LZMA SDK-based Xz compressor used in the payload generation requires
  30. // this one-time initialization.
  31. chromeos_update_engine::XzCompressInit();
  32. // TODO(garnold) temporarily cause the unittest binary to exit with status
  33. // code 2 upon catching a SIGTERM. This will help diagnose why the unittest
  34. // binary is perceived as failing by the buildbot. We should revert it to use
  35. // the default exit status of 1. Corresponding reverts are necessary in
  36. // terminator_unittest.cc.
  37. chromeos_update_engine::Terminator::Init(2);
  38. LOG(INFO) << "parsing command line arguments";
  39. base::CommandLine::Init(argc, argv);
  40. LOG(INFO) << "initializing gtest";
  41. SetUpTests(&argc, argv, true);
  42. // Logging to string is not thread safe.
  43. brillo::LogToString(false);
  44. LOG(INFO) << "running unit tests";
  45. int test_result = RUN_ALL_TESTS();
  46. LOG(INFO) << "unittest return value: " << test_result;
  47. return test_result;
  48. }