Flutter Engine
 
Loading...
Searching...
No Matches
testing.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 "testing.h"
6
7#include <utility>
8
9#include "flutter/fml/file.h"
10#include "flutter/fml/paths.h"
11
12namespace flutter::testing {
13
14std::string GetCurrentTestName() {
15 return ::testing::UnitTest::GetInstance()->current_test_info()->name();
16}
17
19 return fml::paths::JoinPaths({GetFixturesPath(), "kernel_blob.bin"});
20}
21
23 auto fixtures_directory =
24 OpenDirectory(GetFixturesPath(), // path
25 false, // create
26 fml::FilePermission::kRead // permission
27 );
28
29 if (!fixtures_directory.is_valid()) {
30 FML_LOG(ERROR) << "Could not open fixtures directory.";
31 return {};
32 }
33 return fixtures_directory;
34}
35
36fml::UniqueFD OpenFixture(const std::string& fixture_name) {
37 if (fixture_name.size() == 0) {
38 FML_LOG(ERROR) << "Invalid fixture name.";
39 return {};
40 }
41
42 auto fixtures_directory = OpenFixturesDirectory();
43
44 auto fixture_fd = fml::OpenFile(fixtures_directory, // base directory
45 fixture_name.c_str(), // path
46 false, // create
47 fml::FilePermission::kRead // permission
48 );
49 if (!fixture_fd.is_valid()) {
50 FML_LOG(ERROR) << "Could not open fixture for path: " << GetFixturesPath()
51 << "/" << fixture_name << ".";
52 return {};
53 }
54
55 return fixture_fd;
56}
57
58std::unique_ptr<fml::Mapping> OpenFixtureAsMapping(
59 const std::string& fixture_name) {
61}
62
63sk_sp<SkData> OpenFixtureAsSkData(const std::string& fixture_name) {
64 auto mapping = flutter::testing::OpenFixtureAsMapping(fixture_name);
65 if (!mapping) {
66 return nullptr;
67 }
68 auto data = SkData::MakeWithProc(
69 mapping->GetMapping(), mapping->GetSize(),
70 [](const void* ptr, void* context) {
71 delete reinterpret_cast<fml::Mapping*>(context);
72 },
73 mapping.get());
74 mapping.release();
75 return data;
76}
77
78bool MemsetPatternSetOrCheck(uint8_t* buffer, size_t size, MemsetPatternOp op) {
79 if (buffer == nullptr) {
80 return false;
81 }
82
83 auto pattern = reinterpret_cast<const uint8_t*>("dErP");
84 constexpr auto pattern_length = 4;
85
86 uint8_t* start = buffer;
87 uint8_t* p = buffer;
88
89 while ((start + size) - p >= pattern_length) {
90 switch (op) {
92 memmove(p, pattern, pattern_length);
93 break;
95 if (memcmp(pattern, p, pattern_length) != 0) {
96 return false;
97 }
98 break;
99 };
100 p += pattern_length;
101 }
102
103 if ((start + size) - p != 0) {
104 switch (op) {
106 memmove(p, pattern, (start + size) - p);
107 break;
109 if (memcmp(pattern, p, (start + size) - p) != 0) {
110 return false;
111 }
112 break;
113 }
114 }
115
116 return true;
117}
118
119bool MemsetPatternSetOrCheck(std::vector<uint8_t>& buffer, MemsetPatternOp op) {
120 return MemsetPatternSetOrCheck(buffer.data(), buffer.size(), op);
121}
122
123} // namespace flutter::testing
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20
#define FML_LOG(severity)
Definition logging.h:101
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition testing.cc:14
std::string GetDefaultKernelFilePath()
Returns the default path to kernel_blob.bin. This file is within the directory returned by GetFixture...
Definition testing.cc:18
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
bool MemsetPatternSetOrCheck(uint8_t *buffer, size_t size, MemsetPatternOp op)
Depending on the operation, either scribbles a known pattern into the buffer or checks if that patter...
Definition testing.cc:78
sk_sp< SkData > OpenFixtureAsSkData(const std::string &fixture_name)
Opens a fixture of the given file name and returns a Skia SkData holding its contents.
Definition testing.cc:63
fml::UniqueFD OpenFixture(const std::string &fixture_name)
Opens a fixture of the given file name.
Definition testing.cc:36
fml::UniqueFD OpenFixturesDirectory()
Opens the fixtures directory for the unit-test harness.
Definition testing.cc:22
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
Definition testing.cc:58
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
Definition file_posix.cc:66
const size_t start