Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
run_all_unittests.cc File Reference
#include <iostream>
#include <optional>
#include <string>
#include "flutter/fml/backtrace.h"
#include "flutter/fml/build_config.h"
#include "flutter/fml/command_line.h"
#include "flutter/testing/debugger_detection.h"
#include "flutter/testing/test_args.h"
#include "flutter/testing/test_timeout_listener.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

std::optional< fml::TimeDeltaGetTestTimeout ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ GetTestTimeout()

std::optional< fml::TimeDelta > GetTestTimeout ( )

Definition at line 21 of file run_all_unittests.cc.

21 {
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}
static constexpr TimeDelta FromSeconds(int64_t seconds)
Definition time_delta.h:49
const fml::CommandLine & GetArgsForProcess()
Definition test_args.cc:12

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 39 of file run_all_unittests.cc.

39 {
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}
GAsyncResult * result
#define FML_LOG(severity)
Definition logging.h:82
DebuggerStatus GetDebuggerStatus()
void SetArgsForProcess(int argc, char **argv)
Definition test_args.cc:16
void InstallCrashHandler()
Definition backtrace.cc:126
timeout(deadline, cmd)
std::optional< fml::TimeDelta > GetTestTimeout()