Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <poll.h> |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <map> |
Christopher Ferris | ee59d49 | 2018-09-17 15:52:20 -0700 | [diff] [blame] | 24 | #include <memory> |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 25 | #include <stack> |
| 26 | #include <string> |
| 27 | #include <tuple> |
| 28 | #include <unordered_map> |
| 29 | #include <vector> |
| 30 | |
| 31 | #include "Color.h" |
| 32 | #include "Options.h" |
| 33 | #include "Test.h" |
| 34 | |
| 35 | namespace android { |
| 36 | namespace gtest_extras { |
| 37 | |
| 38 | class Isolate { |
| 39 | public: |
Christopher Ferris | 2b6124f | 2019-09-19 23:06:41 -0700 | [diff] [blame] | 40 | Isolate(const Options& options, const std::vector<char*>& child_args) |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 41 | : options_(options), child_args_(child_args) {} |
| 42 | |
| 43 | void EnumerateTests(); |
| 44 | |
| 45 | int Run(); |
| 46 | |
| 47 | private: |
Christopher Ferris | ef98217 | 2018-09-27 15:19:07 -0700 | [diff] [blame] | 48 | struct ResultsType { |
| 49 | const char* color; |
| 50 | const char* prefix; |
| 51 | const char* list_desc; |
| 52 | const char* title; |
| 53 | bool (*match_func)(const Test&); |
| 54 | void (*print_func)(const Options&, const Test&); |
| 55 | }; |
| 56 | |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 57 | size_t CheckTestsFinished(); |
| 58 | |
| 59 | void CheckTestsTimeout(); |
| 60 | |
| 61 | int ChildProcessFn(const std::tuple<std::string, std::string>& test); |
| 62 | |
| 63 | void HandleSignals(); |
| 64 | |
| 65 | void LaunchTests(); |
| 66 | |
| 67 | void ReadTestsOutput(); |
| 68 | |
| 69 | void RunAllTests(); |
| 70 | |
| 71 | void PrintFooter(uint64_t elapsed_time_ns); |
| 72 | |
Christopher Ferris | ef98217 | 2018-09-27 15:19:07 -0700 | [diff] [blame] | 73 | void PrintResults(size_t total, const ResultsType& results, std::string* footer); |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 74 | |
| 75 | void WriteXmlResults(uint64_t elapsed_time_ns, time_t start_time); |
| 76 | |
| 77 | static std::string GetTestName(const std::tuple<std::string, std::string>& test) { |
| 78 | return std::get<0>(test) + std::get<1>(test); |
| 79 | } |
| 80 | |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 81 | const Options& options_; |
Christopher Ferris | 2b6124f | 2019-09-19 23:06:41 -0700 | [diff] [blame] | 82 | const std::vector<char*>& child_args_; |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 83 | |
Christopher Ferris | c2f85d6 | 2019-03-10 13:40:40 -0700 | [diff] [blame] | 84 | size_t total_suites_ = 0; |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 85 | size_t total_tests_ = 0; |
| 86 | size_t total_disable_tests_ = 0; |
| 87 | size_t total_pass_tests_; |
| 88 | size_t total_xpass_tests_; |
| 89 | size_t total_fail_tests_; |
| 90 | size_t total_xfail_tests_; |
| 91 | size_t total_timeout_tests_; |
| 92 | size_t total_slow_tests_; |
Christopher Ferris | 849d24e | 2019-03-09 16:47:04 -0800 | [diff] [blame] | 93 | size_t total_skipped_tests_; |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 94 | size_t cur_test_index_ = 0; |
| 95 | |
| 96 | uint64_t slow_threshold_ns_; |
| 97 | uint64_t deadline_threshold_ns_; |
| 98 | std::vector<std::tuple<std::string, std::string>> tests_; |
| 99 | |
| 100 | std::vector<Test*> running_; |
| 101 | std::vector<pollfd> running_pollfds_; |
Christopher Ferris | ee59d49 | 2018-09-17 15:52:20 -0700 | [diff] [blame] | 102 | std::vector<size_t> running_indices_; |
| 103 | std::unordered_map<pid_t, std::unique_ptr<Test>> running_by_pid_; |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 104 | std::map<size_t, Test*> running_by_test_index_; |
| 105 | |
Christopher Ferris | ee59d49 | 2018-09-17 15:52:20 -0700 | [diff] [blame] | 106 | std::map<size_t, std::unique_ptr<Test>> finished_; |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 107 | |
| 108 | static constexpr useconds_t MIN_USECONDS_WAIT = 1000; |
Christopher Ferris | ef98217 | 2018-09-27 15:19:07 -0700 | [diff] [blame] | 109 | |
| 110 | static ResultsType SlowResults; |
| 111 | static ResultsType XpassFailResults; |
| 112 | static ResultsType FailResults; |
| 113 | static ResultsType TimeoutResults; |
Christopher Ferris | 849d24e | 2019-03-09 16:47:04 -0800 | [diff] [blame] | 114 | static ResultsType SkippedResults; |
Christopher Ferris | 1a99356 | 2018-08-21 12:43:50 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace gtest_extras |
| 118 | } // namespace android |