Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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 25 of file run_all_unittests.cc.

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

References fml::TimeDelta::FromSeconds(), and flutter::testing::GetArgsForProcess().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 43 of file run_all_unittests.cc.

43 {
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}
#define FML_LOG(severity)
Definition logging.h:101
char ** argv
Definition library.h:9
DebuggerStatus GetDebuggerStatus()
void SetArgsForProcess(int argc, char **argv)
Definition test_args.cc:15
void InstallCrashHandler()
Definition backtrace.cc:126
std::optional< fml::TimeDelta > GetTestTimeout()

References argv, FML_LOG, flutter::testing::GetDebuggerStatus(), GetTestTimeout(), impeller::testing::ImpellerUnittestSetup(), fml::InstallCrashHandler(), flutter::testing::kAttached, and flutter::testing::SetArgsForProcess().