Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
run_all_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <iostream>
6#include <optional>
7#include <string>
8
15#include "gtest/gtest.h"
16
17#ifdef IMPELLER_UNITTEST_SUITE
19#endif // IMPELLER_UNITTEST_SUITE
20
21#ifdef FML_OS_IOS
22#include <asl.h>
23#endif // FML_OS_IOS
24
25std::optional<fml::TimeDelta> GetTestTimeout() {
26 const auto& command_line = flutter::testing::GetArgsForProcess();
27
28 std::string timeout_seconds;
29 if (!command_line.GetOptionValue("timeout", &timeout_seconds)) {
30 // No timeout specified. Default to 300s.
31 return fml::TimeDelta::FromSeconds(300u);
32 }
33
34 const auto seconds = std::stoi(timeout_seconds);
35
36 if (seconds < 1) {
37 return std::nullopt;
38 }
39
40 return fml::TimeDelta::FromSeconds(seconds);
41}
42
43int main(int argc, char** argv) {
45
47
48#ifdef FML_OS_IOS
49 asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO,
50 ASL_LOG_DESCRIPTOR_WRITE);
51 asl_log_descriptor(NULL, NULL, ASL_LEVEL_ERR, STDERR_FILENO,
52 ASL_LOG_DESCRIPTOR_WRITE);
53#endif // FML_OS_IOS
54
55 ::testing::InitGoogleTest(&argc, argv);
56 GTEST_FLAG_SET(death_test_style, "threadsafe");
57
58 // Check if the user has specified a timeout.
59 const auto timeout = GetTestTimeout();
60 if (!timeout.has_value()) {
61 FML_LOG(INFO) << "Timeouts disabled via a command line flag.";
62 return RUN_ALL_TESTS();
63 }
64
65 // Check if the user is debugging the process.
68 FML_LOG(INFO) << "Debugger is attached. Suspending test timeouts.";
69 return RUN_ALL_TESTS();
70 }
71
72#ifdef IMPELLER_UNITTEST_SUITE
74#endif // IMPELLER_UNITTEST_SUITE
75
76 auto timeout_listener =
77 new flutter::testing::TestTimeoutListener(timeout.value());
78 auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
79 listeners.Append(timeout_listener);
80 auto result = RUN_ALL_TESTS();
81 delete listeners.Release(timeout_listener);
82 return result;
83}
static constexpr TimeDelta FromSeconds(int64_t seconds)
Definition time_delta.h:49
#define FML_LOG(severity)
Definition logging.h:101
char ** argv
Definition library.h:9
const fml::CommandLine & GetArgsForProcess()
Definition test_args.cc:11
DebuggerStatus GetDebuggerStatus()
void SetArgsForProcess(int argc, char **argv)
Definition test_args.cc:15
void InstallCrashHandler()
Definition backtrace.cc:126
int main(int argc, char **argv)
std::optional< fml::TimeDelta > GetTestTimeout()