Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions
thread_unittests.cc File Reference
#include "flutter/fml/build_config.h"
#include "flutter/fml/thread.h"
#include <algorithm>
#include <memory>
#include "gtest/gtest.h"

Go to the source code of this file.

Macros

#define FLUTTER_PTHREAD_SUPPORTED   0
 

Functions

 TEST (Thread, CanStartAndEnd)
 
 TEST (Thread, CanStartAndEndWithExplicitJoin)
 
 TEST (Thread, HasARunningMessageLoop)
 
 TEST (Thread, HasExpectedStackSize)
 

Macro Definition Documentation

◆ FLUTTER_PTHREAD_SUPPORTED

#define FLUTTER_PTHREAD_SUPPORTED   0

Definition at line 11 of file thread_unittests.cc.

Function Documentation

◆ TEST() [1/4]

TEST ( Thread  ,
CanStartAndEnd   
)

Definition at line 27 of file thread_unittests.cc.

27 {
28 fml::Thread thread;
29 ASSERT_TRUE(thread.GetTaskRunner());
30}
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition thread.cc:164

◆ TEST() [2/4]

TEST ( Thread  ,
CanStartAndEndWithExplicitJoin   
)

Definition at line 32 of file thread_unittests.cc.

32 {
33 fml::Thread thread;
34 ASSERT_TRUE(thread.GetTaskRunner());
35 thread.Join();
36}
void Join()
Definition thread.cc:168

◆ TEST() [3/4]

TEST ( Thread  ,
HasARunningMessageLoop   
)

Definition at line 38 of file thread_unittests.cc.

38 {
39 fml::Thread thread;
40 bool done = false;
41 thread.GetTaskRunner()->PostTask([&done]() { done = true; });
42 thread.Join();
43 ASSERT_TRUE(done);
44}
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
Definition DM.cpp:263
virtual void PostTask(const fml::closure &task) override

◆ TEST() [4/4]

TEST ( Thread  ,
HasExpectedStackSize   
)

Definition at line 46 of file thread_unittests.cc.

46 {
47 size_t stack_size = 0;
48 fml::Thread thread;
49
50 thread.GetTaskRunner()->PostTask([&stack_size]() {
51#if defined(FML_OS_WIN)
52 ULONG_PTR low_limit;
53 ULONG_PTR high_limit;
54 GetCurrentThreadStackLimits(&low_limit, &high_limit);
55 stack_size = high_limit - low_limit;
56#elif defined(FML_OS_MACOSX)
57 stack_size = pthread_get_stacksize_np(pthread_self());
58#else
59 pthread_attr_t attr;
60 pthread_getattr_np(pthread_self(), &attr);
61 pthread_attr_getstacksize(&attr, &stack_size);
62 pthread_attr_destroy(&attr);
63#endif
64 });
65 thread.Join();
66
67 // Actual stack size will be aligned to page size, this assumes no supported
68 // platform has a page size larger than 16k. On Linux reducing the default
69 // stack size (8MB) does not seem to have any effect.
70 const size_t kPageSize = 16384;
71 ASSERT_TRUE(stack_size / kPageSize >=
73}
static size_t GetDefaultStackSize()
Definition thread.cc:177
__w64 unsigned long ULONG_PTR