Flutter Engine
The Flutter Engine
memory_region_test.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/memory_region.h"
6#include "platform/assert.h"
7#include "vm/unit_test.h"
8
9namespace dart {
10
11static void* NewRegion(uword size) {
12 void* pointer = new uint8_t[size];
13 return pointer;
14}
15
16static void DeleteRegion(const MemoryRegion& region) {
17 delete[] reinterpret_cast<uint8_t*>(region.pointer());
18}
19
20VM_UNIT_TEST_CASE(NullRegion) {
21 const uword kSize = 512;
22 MemoryRegion region(nullptr, kSize);
23 EXPECT(region.pointer() == nullptr);
24 EXPECT_EQ(kSize, region.size());
25}
26
28 const uword kSize = 1024;
29 MemoryRegion region(NewRegion(kSize), kSize);
30 EXPECT_EQ(kSize, region.size());
31 EXPECT(region.pointer() != nullptr);
32
33 region.Store<int32_t>(0, 42);
34 EXPECT_EQ(42, region.Load<int32_t>(0));
35
37}
38
40 const uword kSize = 1024;
41 const uword kSubOffset = 128;
42 const uword kSubSize = 512;
43 MemoryRegion region(NewRegion(kSize), kSize);
44 MemoryRegion sub_region;
45 sub_region.Subregion(region, kSubOffset, kSubSize);
46 EXPECT_EQ(kSubSize, sub_region.size());
47 EXPECT(sub_region.pointer() != nullptr);
48 EXPECT(sub_region.start() == region.start() + kSubOffset);
49
50 region.Store<int32_t>(0, 42);
51 sub_region.Store<int32_t>(0, 100);
52 EXPECT_EQ(42, region.Load<int32_t>(0));
53 EXPECT_EQ(100, region.Load<int32_t>(kSubOffset));
54
56}
57
58VM_UNIT_TEST_CASE(ExtendedRegion) {
59 const uword kSize = 1024;
60 const uword kSubSize = 512;
61 const uword kExtendSize = 512;
62 MemoryRegion region(NewRegion(kSize), kSize);
63 MemoryRegion sub_region;
64 sub_region.Subregion(region, 0, kSubSize);
65 MemoryRegion extended_region;
66 extended_region.Extend(sub_region, kExtendSize);
67 EXPECT_EQ(kSize, extended_region.size());
68 EXPECT(extended_region.pointer() == region.pointer());
69 EXPECT(extended_region.pointer() == sub_region.pointer());
70
71 extended_region.Store<int32_t>(0, 42);
72 EXPECT_EQ(42, extended_region.Load<int32_t>(0));
73
75}
76
77} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
void Subregion(const MemoryRegion &from, uword offset, uword size)
Definition: memory_region.h:63
void * pointer() const
Definition: memory_region.h:29
void Store(uword offset, T value) const
Definition: memory_region.h:42
uword start() const
Definition: memory_region.h:33
uword size() const
Definition: memory_region.h:30
T Load(uword offset) const
Definition: memory_region.h:37
void Extend(const MemoryRegion &region, uword extra)
Definition: memory_region.h:71
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
Definition: dart_vm.cc:33
uintptr_t uword
Definition: globals.h:501
static void * NewRegion(uword size)
static void DeleteRegion(const MemoryRegion &region)
VM_UNIT_TEST_CASE(DirectoryCurrentNoScope)
it will be possible to load the file into Perfetto s trace viewer 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
Definition: switches.h:259