Flutter Engine
The Flutter Engine
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
9#include "flutter/fml/backtrace.h"
10#include "flutter/fml/build_config.h"
11#include "flutter/fml/command_line.h"
12#include "flutter/testing/debugger_detection.h"
13#include "flutter/testing/test_args.h"
14#include "flutter/testing/test_timeout_listener.h"
15#include "gtest/gtest.h"
16
17#ifdef FML_OS_IOS
18#include <asl.h>
19#endif // FML_OS_IOS
20
21std::optional<fml::TimeDelta> GetTestTimeout() {
22 const auto& command_line = flutter::testing::GetArgsForProcess();
23
24 std::string timeout_seconds;
25 if (!command_line.GetOptionValue("timeout", &timeout_seconds)) {
26 // No timeout specified. Default to 300s.
27 return fml::TimeDelta::FromSeconds(300u);
28 }
29
30 const auto seconds = std::stoi(timeout_seconds);
31
32 if (seconds < 1) {
33 return std::nullopt;
34 }
35
36 return fml::TimeDelta::FromSeconds(seconds);
37}
38
39int main(int argc, char** argv) {
41
43
44#ifdef FML_OS_IOS
45 asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO,
46 ASL_LOG_DESCRIPTOR_WRITE);
47 asl_log_descriptor(NULL, NULL, ASL_LEVEL_ERR, STDERR_FILENO,
48 ASL_LOG_DESCRIPTOR_WRITE);
49#endif // FML_OS_IOS
50
51 ::testing::InitGoogleTest(&argc, argv);
52 GTEST_FLAG_SET(death_test_style, "threadsafe");
53
54 // Check if the user has specified a timeout.
55 const auto timeout = GetTestTimeout();
56 if (!timeout.has_value()) {
57 FML_LOG(INFO) << "Timeouts disabled via a command line flag.";
58 return RUN_ALL_TESTS();
59 }
60
61 // Check if the user is debugging the process.
64 FML_LOG(INFO) << "Debugger is attached. Suspending test timeouts.";
65 return RUN_ALL_TESTS();
66 }
67
68 auto timeout_listener =
70 auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
71 listeners.Append(timeout_listener);
72 auto result = RUN_ALL_TESTS();
73 delete listeners.Release(timeout_listener);
74 return result;
75}
static constexpr TimeDelta FromSeconds(int64_t seconds)
Definition: time_delta.h:49
GAsyncResult * result
#define FML_LOG(severity)
Definition: logging.h:82
char ** argv
Definition: library.h:9
bool stoi(std::string_view s, SKSL_INT *value)
Definition: SkSLString.cpp:66
const fml::CommandLine & GetArgsForProcess()
Definition: test_args.cc:12
DebuggerStatus GetDebuggerStatus()
void SetArgsForProcess(int argc, char **argv)
Definition: test_args.cc:16
void InstallCrashHandler()
Definition: backtrace.cc:126
def timeout(deadline, cmd)
int main(int argc, char **argv)
std::optional< fml::TimeDelta > GetTestTimeout()