Flutter Engine
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_timeout_listener.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

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

Function Documentation

◆ GetTestTimeoutFromArgs()

std::optional<fml::TimeDelta> GetTestTimeoutFromArgs ( int  argc,
char **  argv 
)

Definition at line 20 of file run_all_unittests.cc.

References fml::CommandLineFromArgcArgv(), and fml::TimeDelta::FromSeconds().

Referenced by main().

20  {
21  const auto command_line = fml::CommandLineFromArgcArgv(argc, argv);
22 
23  std::string timeout_seconds;
24  if (!command_line.GetOptionValue("timeout", &timeout_seconds)) {
25  // No timeout specified. Default to 30s.
26  return fml::TimeDelta::FromSeconds(30u);
27  }
28 
29  const auto seconds = std::stoi(timeout_seconds);
30 
31  if (seconds < 1) {
32  return std::nullopt;
33  }
34 
35  return fml::TimeDelta::FromSeconds(seconds);
36 }
static constexpr TimeDelta FromSeconds(int64_t seconds)
Definition: time_delta.h:49
CommandLine CommandLineFromArgcArgv(int argc, const char *const *argv)
Definition: command_line.h:222

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 38 of file run_all_unittests.cc.

References FML_LOG, flutter::testing::GetDebuggerStatus(), GetTestTimeoutFromArgs(), fml::InstallCrashHandler(), and flutter::testing::kAttached.

38  {
40 #ifdef OS_IOS
41  asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO,
42  ASL_LOG_DESCRIPTOR_WRITE);
43  asl_log_descriptor(NULL, NULL, ASL_LEVEL_ERR, STDERR_FILENO,
44  ASL_LOG_DESCRIPTOR_WRITE);
45 #endif // OS_IOS
46 
47  ::testing::InitGoogleTest(&argc, argv);
48 
49  // Check if the user has specified a timeout.
50  const auto timeout = GetTestTimeoutFromArgs(argc, argv);
51  if (!timeout.has_value()) {
52  FML_LOG(INFO) << "Timeouts disabled via a command line flag.";
53  return RUN_ALL_TESTS();
54  }
55 
56  // Check if the user is debugging the process.
59  FML_LOG(INFO) << "Debugger is attached. Suspending test timeouts.";
60  return RUN_ALL_TESTS();
61  }
62 
63  auto timeout_listener =
64  new flutter::testing::TestTimeoutListener(timeout.value());
65  auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
66  listeners.Append(timeout_listener);
67  auto result = RUN_ALL_TESTS();
68  delete listeners.Release(timeout_listener);
69  return result;
70 }
std::optional< fml::TimeDelta > GetTestTimeoutFromArgs(int argc, char **argv)
void InstallCrashHandler()
Definition: backtrace.cc:133
#define FML_LOG(severity)
Definition: logging.h:65
DebuggerStatus GetDebuggerStatus()