blob: 5919c663bbed37cbd1e0101fccd2d7a7422a3aca [file] [log] [blame]
Christopher Ferris1a993562018-08-21 12:43:50 -07001/*
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 Ferrisee59d492018-09-17 15:52:20 -070024#include <memory>
Christopher Ferris1a993562018-08-21 12:43:50 -070025#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
35namespace android {
36namespace gtest_extras {
37
38class Isolate {
39 public:
Christopher Ferris2b6124f2019-09-19 23:06:41 -070040 Isolate(const Options& options, const std::vector<char*>& child_args)
Christopher Ferris1a993562018-08-21 12:43:50 -070041 : options_(options), child_args_(child_args) {}
42
43 void EnumerateTests();
44
45 int Run();
46
47 private:
Christopher Ferrisef982172018-09-27 15:19:07 -070048 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 Ferris1a993562018-08-21 12:43:50 -070057 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 Ferrisef982172018-09-27 15:19:07 -070073 void PrintResults(size_t total, const ResultsType& results, std::string* footer);
Christopher Ferris1a993562018-08-21 12:43:50 -070074
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 Ferris1a993562018-08-21 12:43:50 -070081 const Options& options_;
Christopher Ferris2b6124f2019-09-19 23:06:41 -070082 const std::vector<char*>& child_args_;
Christopher Ferris1a993562018-08-21 12:43:50 -070083
Christopher Ferrisc2f85d62019-03-10 13:40:40 -070084 size_t total_suites_ = 0;
Christopher Ferris1a993562018-08-21 12:43:50 -070085 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 Ferris849d24e2019-03-09 16:47:04 -080093 size_t total_skipped_tests_;
Christopher Ferris1a993562018-08-21 12:43:50 -070094 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 Ferrisee59d492018-09-17 15:52:20 -0700102 std::vector<size_t> running_indices_;
103 std::unordered_map<pid_t, std::unique_ptr<Test>> running_by_pid_;
Christopher Ferris1a993562018-08-21 12:43:50 -0700104 std::map<size_t, Test*> running_by_test_index_;
105
Christopher Ferrisee59d492018-09-17 15:52:20 -0700106 std::map<size_t, std::unique_ptr<Test>> finished_;
Christopher Ferris1a993562018-08-21 12:43:50 -0700107
108 static constexpr useconds_t MIN_USECONDS_WAIT = 1000;
Christopher Ferrisef982172018-09-27 15:19:07 -0700109
110 static ResultsType SlowResults;
111 static ResultsType XpassFailResults;
112 static ResultsType FailResults;
113 static ResultsType TimeoutResults;
Christopher Ferris849d24e2019-03-09 16:47:04 -0800114 static ResultsType SkippedResults;
Christopher Ferris1a993562018-08-21 12:43:50 -0700115};
116
117} // namespace gtest_extras
118} // namespace android