Flutter Engine
The Flutter Engine
unit_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/unit_test.h"
6
7#include <stdio.h>
8
9#include "bin/builtin.h"
10#include "bin/dartutils.h"
11#include "bin/isolate_data.h"
12
13#include "platform/globals.h"
14#include "platform/uri.h"
15
19#include "vm/dart_api_impl.h"
20#include "vm/isolate_reload.h"
21#include "vm/kernel_isolate.h"
22#include "vm/parser.h"
23#include "vm/symbols.h"
24#include "vm/thread.h"
25#include "vm/virtual_memory.h"
26
29
30extern "C" {
31extern const uint8_t kPlatformStrongDill[];
32extern intptr_t kPlatformStrongDillSize;
33}
34
35namespace dart {
36
38DECLARE_FLAG(bool, force_evacuation);
39
42
43const uint8_t* TesterState::vm_snapshot_data = nullptr;
47const char** TesterState::argv = nullptr;
48int TesterState::argc = 0;
49
50void KernelBufferList::AddBufferToList(const uint8_t* kernel_buffer) {
51 next_ = new KernelBufferList(kernel_buffer_, next_);
52 kernel_buffer_ = kernel_buffer;
53}
54
55TestCaseBase* TestCaseBase::first_ = nullptr;
56TestCaseBase* TestCaseBase::tail_ = nullptr;
58
60 : raw_test_(false),
61 next_(nullptr),
62 name_(name),
63 expectation_(strlen(expectation) > 0 ? expectation : "Pass") {
64 if (first_ == nullptr) {
65 first_ = this;
66 } else {
67 tail_->next_ = this;
68 }
69 tail_ = this;
70}
71
73 TestCaseBase* test = first_;
74 while (test != nullptr) {
75 if (test->raw_test_) {
76 test->RunTest();
78 }
79 test = test->next_;
80 }
81}
82
84 TestCaseBase* test = first_;
85 while (test != nullptr) {
86 if (!test->raw_test_) {
87 test->RunTest();
89 }
90 test = test->next_;
91 }
92}
93
95 if (current_kernel_buffers_ != nullptr) {
98 }
99}
100
101void TestCaseBase::AddToKernelBuffers(const uint8_t* kernel_buffer) {
102 ASSERT(kernel_buffer != nullptr);
103 if (current_kernel_buffers_ == nullptr) {
104 current_kernel_buffers_ = new KernelBufferList(kernel_buffer);
105 } else {
107 }
108}
109
110Dart_Isolate TestCase::CreateIsolate(const uint8_t* data_buffer,
111 intptr_t len,
112 const uint8_t* instr_buffer,
113 const char* name,
114 void* group_data,
115 void* isolate_data) {
116 char* err;
117 Dart_IsolateFlags api_flags;
118 Isolate::FlagsInitialize(&api_flags);
119 api_flags.null_safety = true;
120 Dart_Isolate isolate = nullptr;
121 if (len == 0) {
122 isolate = Dart_CreateIsolateGroup(
123 /*script_uri=*/name, /*name=*/name, data_buffer, instr_buffer,
124 &api_flags, group_data, isolate_data, &err);
125 } else {
126 isolate = Dart_CreateIsolateGroupFromKernel(/*script_uri=*/name,
127 /*name=*/name, data_buffer, len,
128 &api_flags, group_data,
129 isolate_data, &err);
130 }
131 if (isolate == nullptr) {
132 OS::PrintErr("Creation of isolate failed '%s'\n", err);
133 free(err);
134 }
135
136 EXPECT(isolate != nullptr);
137 return isolate;
138}
139
141 void* group_data,
142 void* isolate_data) {
143 return CreateIsolate(bin::core_isolate_snapshot_data,
144 0 /* Snapshots have length encoded within them. */,
146 group_data, isolate_data);
147}
148
151
156 /*is_service_isolate=*/false,
157 /*trace_loading=*/false);
159
161}
162
164 Dart_Isolate parent,
165 void* group_data,
166 void* isolate_data) {
167 char* error;
169 reinterpret_cast<Isolate*>(parent)->group(), name, &error);
170 if (error != nullptr) {
171 OS::PrintErr("CreateTestIsolateInGroup failed: %s\n", error);
172 free(error);
173 }
174 EXPECT(result != nullptr);
175 return Api::CastIsolate(result);
176}
177
179 const char* url;
180 const char* source;
181};
182
184
185const char* TestCase::url() {
187}
188
189void TestCase::AddTestLib(const char* url, const char* source) {
190 if (test_libs_ == nullptr) {
192 }
193 // If the test lib is already added, replace the source.
194 for (intptr_t i = 0; i < test_libs_->length(); i++) {
195 if (strcmp(url, (*test_libs_)[i].url) == 0) {
196 (*test_libs_)[i].source = source;
197 return;
198 }
199 }
200 TestLibEntry entry;
201 entry.url = url;
202 entry.source = source;
203 test_libs_->Add(entry);
204}
205
206const char* TestCase::GetTestLib(const char* url) {
207 if (test_libs_ == nullptr) {
208 return nullptr;
209 }
210 for (intptr_t i = 0; i < test_libs_->length(); i++) {
211 if (strcmp(url, (*test_libs_)[i].url) == 0) {
212 return (*test_libs_)[i].source;
213 }
214 }
215 return nullptr;
216}
217
218#ifndef PRODUCT
219static const char* kIsolateReloadTestLibSource = R"(
220@pragma("vm:external-name", "Test_Reload")
221external void reloadTest();
222@pragma("vm:external-name", "Test_CollectNewSpace")
223external void collectNewSpace();
224@pragma("vm:external-name", "Test_CollectOldSpace")
225external void collectOldSpace();
226)";
227
228static const char* IsolateReloadTestLibUri() {
229 return "test:isolate_reload_helper";
230}
231
232#define RELOAD_NATIVE_LIST(V) \
233 V(Test_Reload, 0) \
234 V(Test_CollectNewSpace, 0) \
235 V(Test_CollectOldSpace, 0)
236
238
239static struct NativeEntries {
240 const char* name_;
242 int argument_count_;
244
247 int argument_count,
248 bool* auto_setup_scope) {
249 const char* function_name = nullptr;
252 ASSERT(function_name != nullptr);
253 ASSERT(auto_setup_scope != nullptr);
254 *auto_setup_scope = true;
255 int num_entries = sizeof(ReloadEntries) / sizeof(struct NativeEntries);
256 for (int i = 0; i < num_entries; i++) {
257 struct NativeEntries* entry = &(ReloadEntries[i]);
258 if ((strcmp(function_name, entry->name_) == 0) &&
259 (entry->argument_count_ == argument_count)) {
260 return reinterpret_cast<Dart_NativeFunction>(entry->function_);
261 }
262 }
263 return nullptr;
264}
265
267 Dart_Handle result = TestCase::TriggerReload(/* kernel_buffer= */ nullptr,
268 /* kernel_buffer_size= */ 0);
269 if (Dart_IsError(result)) {
271 }
272}
273
276 GCTestHelper::CollectNewSpace();
277}
278
281 GCTestHelper::CollectOldSpace();
282}
283
284#endif // !PRODUCT
285
286static void LoadIsolateReloadTestLibIfNeeded(const char* script) {
287#ifndef PRODUCT
288 if (strstr(script, IsolateReloadTestLibUri()) != nullptr) {
293 }
294#endif // ifndef PRODUCT
295}
296
298 const char* source,
299 const uint8_t** kernel_buffer,
300 intptr_t* kernel_buffer_size,
301 bool incrementally,
302 bool allow_compile_errors,
303 const char* multiroot_filepaths,
304 const char* multiroot_scheme) {
305 // clang-format off
306 Dart_SourceFile sourcefiles[] = {
307 {
308 url, source,
309 },
310 {
311 "file:///.packages", ""
312 }};
313 // clang-format on
315 url, sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
316 kernel_buffer, kernel_buffer_size, incrementally, allow_compile_errors,
317 multiroot_filepaths, multiroot_scheme);
318}
319
321 int sourcefiles_count,
322 Dart_SourceFile sourcefiles[],
323 const uint8_t** kernel_buffer,
324 intptr_t* kernel_buffer_size,
325 bool incrementally,
326 bool allow_compile_errors,
327 const char* multiroot_filepaths,
328 const char* multiroot_scheme) {
329 Zone* zone = Thread::Current()->zone();
332 sourcefiles, incrementally, /*for_snapshot=*/false,
333 /*embed_sources=*/true, nullptr, multiroot_filepaths, multiroot_scheme);
337 FATAL(
338 "An error occurred in the CFE while accepting the most recent"
339 " compilation results.");
340 }
341 }
342 return ValidateCompilationResult(zone, result, kernel_buffer,
343 kernel_buffer_size, allow_compile_errors);
344}
345
346char* TestCase::ValidateCompilationResult(
347 Zone* zone,
348 Dart_KernelCompilationResult compilation_result,
349 const uint8_t** kernel_buffer,
350 intptr_t* kernel_buffer_size,
351 bool allow_compile_errors) {
352 if (!allow_compile_errors &&
353 (compilation_result.status != Dart_KernelCompilationStatus_Ok)) {
354 char* result =
355 OS::SCreate(zone, "Compilation failed %s", compilation_result.error);
356 free(compilation_result.error);
357 if (compilation_result.kernel != nullptr) {
358 free(const_cast<uint8_t*>(compilation_result.kernel));
359 }
360 *kernel_buffer = nullptr;
361 *kernel_buffer_size = 0;
362 return result;
363 }
364 *kernel_buffer = compilation_result.kernel;
365 *kernel_buffer_size = compilation_result.kernel_size;
366 if (compilation_result.error != nullptr) {
367 free(compilation_result.error);
368 }
369 if (kernel_buffer == nullptr) {
370 return OS::SCreate(zone, "front end generated a nullptr kernel file");
371 }
372 return nullptr;
373}
374
376 Dart_Handle library,
377 Dart_Handle url) {
378 if (tag == Dart_kCanonicalizeUrl) {
379 Dart_Handle library_url = Dart_LibraryUrl(library);
380 if (Dart_IsError(library_url)) {
381 return library_url;
382 }
383
384 const char* library_url_cstr;
385 Dart_Handle result = Dart_StringToCString(library_url, &library_url_cstr);
386 if (Dart_IsError(result)) {
387 return result;
388 }
389 const char* url_cstr;
390 result = Dart_StringToCString(url, &url_cstr);
391 if (Dart_IsError(result)) {
392 return result;
393 }
394 CStringUniquePtr resolved_uri = ResolveUri(url_cstr, library_url_cstr);
395 if (!resolved_uri) {
396 return DartUtils::NewError("%s: Unable to canonicalize uri '%s'.",
397 __FUNCTION__, url_cstr);
398 }
399 result = Dart_NewStringFromCString(resolved_uri.get());
400 return result;
401 }
402 UNREACHABLE();
403 return Dart_Null();
404}
405
406static intptr_t BuildSourceFilesArray(
407 Dart_SourceFile** sourcefiles,
408 const char* script,
409 const char* script_url = RESOLVED_USER_TEST_URI) {
410 ASSERT(sourcefiles != nullptr);
411 ASSERT(script != nullptr);
412
413 intptr_t num_test_libs = 0;
414 if (test_libs_ != nullptr) {
415 num_test_libs = test_libs_->length();
416 }
417
418 *sourcefiles = new Dart_SourceFile[num_test_libs + 1];
419 (*sourcefiles)[0].uri = script_url;
420 (*sourcefiles)[0].source = script;
421 for (intptr_t i = 0; i < num_test_libs; ++i) {
422 (*sourcefiles)[i + 1].uri = test_libs_->At(i).url;
423 (*sourcefiles)[i + 1].source = test_libs_->At(i).source;
424 }
425 return num_test_libs + 1;
426}
427
429 const char* script,
431 const char* lib_url,
432 bool finalize_classes) {
433 return LoadTestScript(script, resolver, lib_url, finalize_classes, true);
434}
435
438 const char* lib_url,
439 bool finalize_classes,
440 bool allow_compile_errors) {
442 Dart_SourceFile* sourcefiles = nullptr;
443 intptr_t num_sources = BuildSourceFilesArray(&sourcefiles, script, lib_url);
445 LoadTestScriptWithDFE(num_sources, sourcefiles, resolver,
446 finalize_classes, true, allow_compile_errors);
447 delete[] sourcefiles;
448 return result;
449}
450
451static void MallocFinalizer(void* isolate_callback_data, void* peer) {
452 free(peer);
453}
454
456 const char* script,
457 Dart_NativeEntryResolver resolver) {
459 const char* prefixed_lib_uri =
460 OS::SCreate(Thread::Current()->zone(), "file:///%s", lib_uri);
461 Dart_SourceFile sourcefiles[] = {{prefixed_lib_uri, script}};
462 const uint8_t* kernel_buffer = nullptr;
463 intptr_t kernel_buffer_size = 0;
464 int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile);
466 sourcefiles[0].uri, sourcefiles_count, sourcefiles, &kernel_buffer,
467 &kernel_buffer_size, true);
468 if ((kernel_buffer == nullptr) && (error != nullptr)) {
469 return Dart_NewApiError(error);
470 }
471
473 Dart_TypedData_kUint8, const_cast<uint8_t*>(kernel_buffer),
474 kernel_buffer_size, const_cast<uint8_t*>(kernel_buffer),
475 kernel_buffer_size, MallocFinalizer);
476 EXPECT_VALID(td);
479
480 // TODO(32618): Kernel doesn't correctly represent the root library.
481 lib = Dart_LookupLibrary(Dart_NewStringFromCString(sourcefiles[0].uri));
485
486 Dart_SetNativeResolver(lib, resolver, nullptr);
487 return lib;
488}
489
491 Dart_SourceFile sourcefiles[],
493 bool finalize,
494 bool incrementally,
495 bool allow_compile_errors,
496 const char* entry_script_uri,
497 const char* multiroot_filepaths,
498 const char* multiroot_scheme) {
499 // First script is the main script.
502 const uint8_t* kernel_buffer = nullptr;
503 intptr_t kernel_buffer_size = 0;
505 entry_script_uri != nullptr ? entry_script_uri : sourcefiles[0].uri,
506 sourcefiles_count, sourcefiles, &kernel_buffer, &kernel_buffer_size,
507 incrementally, allow_compile_errors, multiroot_filepaths,
508 multiroot_scheme);
509 if ((kernel_buffer == nullptr) && error != nullptr) {
510 return Dart_NewApiError(error);
511 }
512
514 Dart_TypedData_kUint8, const_cast<uint8_t*>(kernel_buffer),
515 kernel_buffer_size, const_cast<uint8_t*>(kernel_buffer),
516 kernel_buffer_size, MallocFinalizer);
517 EXPECT_VALID(td);
520
521 // BOGUS: Kernel doesn't correctly represent the root library.
523 entry_script_uri != nullptr ? entry_script_uri : sourcefiles[0].uri));
527
528 result = Dart_SetNativeResolver(lib, resolver, nullptr);
530 if (finalize) {
533 }
534 return lib;
535}
536
537#ifndef PRODUCT
538
540 // For our vm/cc/IsolateReload_* tests we flip the GC flag on, which will
541 // cause the isolate reload to do GCs before/after morphing, etc.
542 FLAG_gc_during_reload = true;
543 FLAG_force_evacuation = true;
544
545 Dart_SourceFile* sourcefiles = nullptr;
546 intptr_t num_files = BuildSourceFilesArray(&sourcefiles, script);
547 Dart_KernelCompilationResult compilation_result =
548 KernelIsolate::UpdateInMemorySources(num_files, sourcefiles);
549 delete[] sourcefiles;
550 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
551 Dart_Handle result = Dart_NewApiError(compilation_result.error);
552 free(compilation_result.error);
553 return result;
554 }
555 return Api::Success();
556}
557
559 std::function<bool(IsolateGroup*, JSONStream*)> do_reload) {
560 Thread* thread = Thread::Current();
561 IsolateGroup* isolate_group = thread->isolate_group();
563 bool success = false;
564 {
565 TransitionNativeToVM transition(thread);
566 success = do_reload(isolate_group, &js);
567 OS::PrintErr("RELOAD REPORT:\n%s\n", js.ToCString());
568 }
569
571 if (success) {
573 }
574
575 if (Dart_IsError(result)) {
576 // Keep load error.
577 } else if (isolate_group->reload_context()->reload_aborted()) {
578 TransitionNativeToVM transition(thread);
579 result = Api::NewHandle(thread, isolate_group->program_reload_context()
581 ->error());
582 } else {
584 }
585
586 TransitionNativeToVM transition(thread);
587 if (isolate_group->program_reload_context() != nullptr) {
588 isolate_group->DeleteReloadContext();
589 }
590
591 return result;
592}
593
594Dart_Handle TestCase::TriggerReload(const char* root_script_url) {
595 return TriggerReload([&](IsolateGroup* isolate_group, JSONStream* js) {
596 return isolate_group->ReloadSources(js,
597 /*force_reload=*/false, root_script_url,
598 /*packages_url=*/nullptr,
599 /*dont_delete_reload_context=*/true);
600 });
601}
602
603Dart_Handle TestCase::TriggerReload(const uint8_t* kernel_buffer,
604 intptr_t kernel_buffer_size) {
605 return TriggerReload([&](IsolateGroup* isolate_group, JSONStream* js) {
606 return isolate_group->ReloadKernel(js,
607 /*force_reload=*/false, kernel_buffer,
608 kernel_buffer_size,
609 /*dont_delete_reload_context=*/true);
610 });
611}
612
614 Dart_SourceFile* sourcefiles = nullptr;
615 intptr_t num_files = BuildSourceFilesArray(&sourcefiles, script);
616 Dart_KernelCompilationResult compilation_result =
617 KernelIsolate::UpdateInMemorySources(num_files, sourcefiles);
618 delete[] sourcefiles;
619 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
620 Dart_Handle result = Dart_NewApiError(compilation_result.error);
621 free(compilation_result.error);
622 if (compilation_result.kernel != nullptr) {
623 free(const_cast<uint8_t*>(compilation_result.kernel));
624 }
625 return result;
626 }
627
628 return TriggerReload(/*kernel_buffer=*/nullptr, /*kernel_buffer_size=*/0);
629}
630
631Dart_Handle TestCase::ReloadTestKernel(const uint8_t* kernel_buffer,
632 intptr_t kernel_buffer_size) {
633 return TriggerReload(kernel_buffer, kernel_buffer_size);
634}
635
636#endif // !PRODUCT
637
639 Dart_NativeEntryResolver resolver) {
640 return LoadTestScript(script, resolver, CORELIB_TEST_URI);
641}
642
648 return lib;
649}
650
652 Dart_Handle library,
653 Dart_Handle url) {
654 if (tag == Dart_kCanonicalizeUrl) {
655 return url;
656 }
657 return Api::Success();
658}
659
661 const String& expr,
662 const Array& param_names,
663 const Array& param_values) {
664 Thread* thread = Thread::Current();
665
666 Object& val = Object::Handle();
668 UNREACHABLE();
669 } else {
670 Dart_KernelCompilationResult compilation_result =
672 /* platform_kernel= */ nullptr, /* platform_kernel_size= */ 0,
673 expr.ToCString(), param_names, Array::empty_array(),
674 Array::empty_array(), Array::empty_array(), Array::empty_array(),
676 /* klass= */ nullptr,
677 /* method= */ nullptr,
678 /* token_pos= */ TokenPosition::kNoSource,
679 /* script_uri= */ String::Handle(lib.url()).ToCString(),
680 /* is_static= */ true);
681 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
682 return Api::NewError("%s", compilation_result.error);
683 }
684
685 const ExternalTypedData& kernel_buffer =
687 const_cast<uint8_t*>(compilation_result.kernel),
688 compilation_result.kernel_size));
689
690 val = lib.EvaluateCompiledExpression(kernel_buffer, Array::empty_array(),
691 param_values,
692 TypeArguments::null_type_arguments());
693 }
694 return Api::NewHandle(thread, val.ptr());
695}
696
697#if !defined(PRODUCT) && (defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64))
698static bool IsHex(int c) {
699 return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f');
700}
701#endif
702
704 auto thread = Thread::Current();
705 const String& function_name = String::ZoneHandle(Symbols::New(thread, name_));
706
707 // We make a dummy script so that exception objects can be composed for
708 // assembler instructions that do runtime calls.
709 const char* kDummyScript = "assembler_test_dummy_function() {}";
713 const Class& cls = Class::ZoneHandle(
717 signature, function_name, UntaggedFunction::kRegularFunction, true, false,
718 false, false, false, cls, TokenPosition::kMinSource));
719 SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
720 code_ = Code::FinalizeCodeAndNotify(function, nullptr, assembler_,
722 code_.set_owner(function);
723 code_.set_exception_handlers(Object::empty_exception_handlers());
724#ifndef PRODUCT
725 // Disassemble relative since code addresses are not stable from run to run.
726 SetFlagScope<bool> sfs(&FLAG_disassemble_relative, true);
727 uword start = code_.PayloadStart();
728 if (FLAG_disassemble) {
729 OS::PrintErr("Code for test '%s' {\n", name_);
731 OS::PrintErr("}\n");
732 }
733 Disassembler::Disassemble(start, start + assembler_->CodeSize(), disassembly_,
734 DISASSEMBLY_SIZE);
735#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
736 // Blank out absolute addressing constants on ia32, since they are not stable
737 // from run to run.
738 // Blank out thread-relative offsets on x64 since they change when new fields
739 // are added to thread object.
740 bool in_hex_constant = false;
741 for (char* p = disassembly_; *p != '\0'; p++) {
742 if (in_hex_constant) {
743 if (IsHex(*p)) {
744 *p = '.';
745 } else {
746 in_hex_constant = false;
747 }
748 } else {
749#if defined(TARGET_ARCH_IA32)
750 if (*p == '[' && *(p + 1) == '0' && *(p + 2) == 'x' && IsHex(*(p + 3)) &&
751 IsHex(*(p + 4))) {
752 p += 2;
753 in_hex_constant = true;
754 }
755#endif // defined(TARGET_ARCH_IA32)
756#if defined(TARGET_ARCH_X64)
757 if (*p == '[' && *(p + 1) == 't' && *(p + 2) == 'h' && *(p + 3) == 'r' &&
758 *(p + 4) == '+' && *(p + 5) == '0' && *(p + 6) == 'x' &&
759 IsHex(*(p + 7)) && IsHex(*(p + 8))) {
760 p += 6;
761 in_hex_constant = true;
762 }
763#endif // defined(TARGET_ARCH_X64)
764 }
765 }
766#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
767#endif // !PRODUCT
768}
769
771 const char* name,
772 const std::function<void(compiler::Assembler* assembler)>& generator) {
773 compiler::ObjectPoolBuilder object_pool_builder;
774 compiler::Assembler assembler(&object_pool_builder, /*far_branch_level=*/0);
776 assembler.Ret();
777 test.Assemble();
778 return test.code();
779}
780
782 Thread* thread = Thread::Current();
783 ASSERT(thread != nullptr);
785 const Object& result =
787 return result.IsCode();
788}
789
790void ElideJSONSubstring(const char* prefix,
791 const char* in,
792 char* out,
793 const char* postfix) {
794 const char* pos = strstr(in, prefix);
795 while (pos != nullptr) {
796 // Copy up to pos into the output buffer.
797 while (in < pos) {
798 *out++ = *in++;
799 }
800
801 // Skip to the closing postfix.
802 in += strlen(prefix);
803 in += strcspn(in, postfix);
804 pos = strstr(in, prefix);
805 }
806 // Copy the remainder of in to out.
807 while (*in != '\0') {
808 *out++ = *in++;
809 }
810 *out = '\0';
811}
812
814 ElideJSONSubstring(",\"tokenPos\":", buffer, buffer, ",");
815 ElideJSONSubstring(",\"endTokenPos\":", buffer, buffer, "}");
816}
817
818} // namespace dart
#define test(name)
SkPoint pos
static bool ok(int result)
#define EXPECT(type, expectedAlignment, expectedSize)
#define UNREACHABLE()
Definition: assert.h:248
#define RELEASE_ASSERT(cond)
Definition: assert.h:327
#define FUNCTION_NAME(name)
Definition: builtin.h:19
static Dart_Handle Success()
static Dart_Handle NewHandle(Thread *thread, ObjectPtr raw)
static Dart_Isolate CastIsolate(Isolate *isolate)
static Dart_Handle NewError(const char *format,...) PRINTF_ATTRIBUTE(1
compiler::Assembler * assembler() const
Definition: unit_test.h:515
static const Code & Generate(const char *name, const std::function< void(compiler::Assembler *assembler)> &generator)
Definition: unit_test.cc:770
static bool AllClassesFinalized()
static ClassPtr New(IsolateGroup *isolate_group, bool register_class=true)
Definition: object.cc:3053
void set_exception_handlers(const ExceptionHandlers &handlers) const
Definition: object.h:7119
static CodePtr FinalizeCodeAndNotify(const Function &function, FlowGraphCompiler *compiler, compiler::Assembler *assembler, PoolAttachment pool_attachment, bool optimized=false, CodeStatistics *stats=nullptr)
Definition: object.cc:17983
uword PayloadStart() const
Definition: object.h:6850
void set_owner(const Object &owner) const
Definition: object.cc:17636
static bool TestCompileFunction(const Function &function)
Definition: unit_test.cc:781
static ObjectPtr CompileFunction(Thread *thread, const Function &function)
Definition: compiler.cc:824
static void Disassemble(uword start, uword end, DisassemblyFormatter *formatter, const Code &code, const CodeComments *comments=nullptr)
static ExternalTypedDataPtr NewFinalizeWithFree(uint8_t *data, intptr_t len)
Definition: object.cc:25649
static FunctionTypePtr New(intptr_t num_parent_type_arguments=0, Nullability nullability=Nullability::kNonNullable, Heap::Space space=Heap::kOld)
Definition: object.cc:11631
static FunctionPtr New(const FunctionType &signature, const String &name, UntaggedFunction::Kind kind, bool is_static, bool is_const, bool is_abstract, bool is_external, bool is_native, const Object &owner, TokenPosition token_pos, Heap::Space space=Heap::kOld)
Definition: object.cc:10243
bool ReloadKernel(JSONStream *js, bool force_reload, const uint8_t *kernel_buffer=nullptr, intptr_t kernel_buffer_size=0, bool dont_delete_reload_context=false)
Definition: isolate.cc:2102
void DeleteReloadContext()
Definition: isolate.cc:2131
SafepointRwLock * program_lock()
Definition: isolate.h:537
IsolateGroupReloadContext * reload_context()
Definition: isolate.h:656
bool ReloadSources(JSONStream *js, bool force_reload, const char *root_script_url=nullptr, const char *packages_url=nullptr, bool dont_delete_reload_context=false)
Definition: isolate.cc:2073
ProgramReloadContext * program_reload_context()
Definition: isolate.h:659
static void FlagsInitialize(Dart_IsolateFlags *api_flags)
Definition: isolate.cc:1648
KernelBufferList(const uint8_t *kernel_buffer)
Definition: unit_test.h:265
void AddBufferToList(const uint8_t *kernel_buffer)
Definition: unit_test.cc:50
static Dart_KernelCompilationResult UpdateInMemorySources(int source_files_count, Dart_SourceFile source_files[])
static Dart_KernelCompilationResult CompileToKernel(const char *script_uri, const uint8_t *platform_kernel, intptr_t platform_kernel_size, int source_files_count=0, Dart_SourceFile source_files[]=nullptr, bool incremental_compile=true, bool for_snapshot=false, bool embed_sources=true, const char *package_config=nullptr, const char *multiroot_filepaths=nullptr, const char *multiroot_scheme=nullptr, Dart_KernelCompilationVerbosityLevel verbosity=Dart_KernelCompilationVerbosityLevel_All)
static bool IsRunning()
static Dart_KernelCompilationResult CompileExpressionToKernel(const uint8_t *platform_kernel, intptr_t platform_kernel_size, const char *expression, const Array &definitions, const Array &definition_types, const Array &type_definitions, const Array &type_bounds, const Array &type_defaults, const char *library_url, const char *klass, const char *method, TokenPosition token_pos, char const *script_uri, bool is_static)
static Dart_KernelCompilationResult AcceptCompilation()
static LibraryPtr CoreLibrary()
Definition: object.cc:14787
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
ObjectPtr ptr() const
Definition: object.h:332
virtual const char * ToCString() const
Definition: object.h:366
static Object & Handle()
Definition: object.h:407
static Object & ZoneHandle()
Definition: object.h:419
IsolateGroupReloadContext * group_reload_context()
static ScriptPtr New(const String &url, const String &source)
Definition: object.cc:13451
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static const char * ToCString(Thread *thread, StringPtr ptr)
Definition: object.cc:24126
static StringPtr New(Thread *thread, const char *cstr)
Definition: symbols.h:723
static void CleanupState()
Definition: unit_test.cc:94
static void AddToKernelBuffers(const uint8_t *kernel_buffer)
Definition: unit_test.cc:101
static void RunAllRaw()
Definition: unit_test.cc:72
const char * name() const
Definition: unit_test.h:290
static void RunAll()
Definition: unit_test.cc:83
static KernelBufferList * current_kernel_buffers_
Definition: unit_test.h:302
TestCaseBase(const char *name, const char *expectation)
Definition: unit_test.cc:59
static Dart_Handle TriggerReload(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition: unit_test.cc:603
static Dart_Handle LoadTestScriptWithDFE(int sourcefiles_count, Dart_SourceFile sourcefiles[], Dart_NativeEntryResolver resolver=nullptr, bool finalize=true, bool incrementally=true, bool allow_compile_errors=false, const char *entry_script_uri=nullptr, const char *multiroot_filepaths=nullptr, const char *multiroot_scheme=nullptr)
Definition: unit_test.cc:490
static Dart_Handle lib()
Definition: unit_test.cc:643
static void AddTestLib(const char *url, const char *source)
Definition: unit_test.cc:189
static Dart_Handle LoadTestScript(const char *script, Dart_NativeEntryResolver resolver, const char *lib_uri=RESOLVED_USER_TEST_URI, bool finalize=true, bool allow_compile_errors=false)
Definition: unit_test.cc:436
static Dart_Handle ReloadTestScript(const char *script)
Definition: unit_test.cc:613
static char * CompileTestScriptWithDFE(const char *url, const char *source, const uint8_t **kernel_buffer, intptr_t *kernel_buffer_size, bool incrementally=true, bool allow_compile_errors=false, const char *multiroot_filepaths=nullptr, const char *multiroot_scheme=nullptr)
Definition: unit_test.cc:297
static Dart_Isolate CreateTestIsolateInGroup(const char *name, Dart_Isolate parent, void *group_data=nullptr, void *isolate_data=nullptr)
Definition: unit_test.cc:163
static Dart_Handle SetReloadTestScript(const char *script)
Definition: unit_test.cc:539
static const char * url()
Definition: unit_test.cc:185
static Dart_Handle LoadTestScriptWithErrors(const char *script, Dart_NativeEntryResolver resolver=nullptr, const char *lib_uri=RESOLVED_USER_TEST_URI, bool finalize=true)
Definition: unit_test.cc:428
static Dart_Handle LoadTestLibrary(const char *lib_uri, const char *script, Dart_NativeEntryResolver resolver=nullptr)
Definition: unit_test.cc:455
static Dart_Handle ReloadTestKernel(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition: unit_test.cc:631
static Dart_Handle library_handler(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
Definition: unit_test.cc:651
static Dart_Handle EvaluateExpression(const Library &lib, const String &expr, const Array &param_names, const Array &param_values)
Definition: unit_test.cc:660
static Dart_Isolate CreateTestIsolate(const char *name=nullptr, void *isolate_group_data=nullptr, void *isolate_data=nullptr)
Definition: unit_test.cc:140
static const char * GetTestLib(const char *url)
Definition: unit_test.cc:206
static Dart_Handle LoadCoreTestScript(const char *script, Dart_NativeEntryResolver resolver)
Definition: unit_test.cc:638
static Dart_IsolateShutdownCallback shutdown_callback
Definition: unit_test.h:257
static Dart_IsolateGroupCreateCallback create_callback
Definition: unit_test.h:256
static const char ** argv
Definition: unit_test.h:259
static Dart_IsolateGroupCleanupCallback group_cleanup_callback
Definition: unit_test.h:258
static int argc
Definition: unit_test.h:260
static const uint8_t * vm_snapshot_data
Definition: unit_test.h:255
Zone * zone() const
Definition: thread_state.h:37
static Thread * Current()
Definition: thread.h:362
IsolateGroup * isolate_group() const
Definition: thread.h:541
static const TokenPosition kMinSource
static bool SetOriginalWorkingDirectory()
Definition: dartutils.cc:821
static Dart_Handle PrepareForScriptLoading(bool is_service_isolate, bool trace_loading)
Definition: dartutils.cc:570
void Ret(Condition cond=AL)
Dart_Isolate(* Dart_IsolateGroupCreateCallback)(const char *script_uri, const char *main, const char *package_root, const char *package_config, Dart_IsolateFlags *flags, void *isolate_data, char **error)
Definition: dart_api.h:654
@ Dart_KernelCompilationStatus_Ok
Definition: dart_api.h:3785
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
struct _Dart_Isolate * Dart_Isolate
Definition: dart_api.h:88
Dart_NativeFunction(* Dart_NativeEntryResolver)(Dart_Handle name, int num_of_arguments, bool *auto_setup_scope)
Definition: dart_api.h:3234
struct _Dart_NativeArguments * Dart_NativeArguments
Definition: dart_api.h:3019
@ Dart_TypedData_kUint8
Definition: dart_api.h:2615
void(* Dart_IsolateGroupCleanupCallback)(void *isolate_group_data)
Definition: dart_api.h:745
Dart_LibraryTag
Definition: dart_api.h:3419
@ Dart_kCanonicalizeUrl
Definition: dart_api.h:3420
void(* Dart_IsolateShutdownCallback)(void *isolate_group_data, void *isolate_data)
Definition: dart_api.h:711
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition: dart_api.h:3207
#define ASSERT(E)
SkBitmap source
Definition: examples.cpp:28
#define FATAL(error)
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
Dart_NativeFunction function
Definition: fuchsia.cc:51
#define REGISTER_FUNCTION(name, count)
Definition: fuchsia.cc:41
int argument_count
Definition: fuchsia.cc:52
#define DECLARE_FUNCTION(name, count)
Definition: fuchsia.cc:42
const uint8_t * core_isolate_snapshot_data
Definition: main_impl.cc:54
const uint8_t * core_isolate_snapshot_instructions
Definition: main_impl.cc:55
Definition: dart_vm.cc:33
DART_EXPORT bool Dart_IsLibrary(Dart_Handle object)
void ElideJSONSubstring(const char *prefix, const char *in, char *out, const char *postfix)
Definition: unit_test.cc:790
DART_EXPORT void Dart_EnterScope()
const uint8_t * platform_strong_dill
Definition: unit_test.cc:40
const char *const name
DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures)
static intptr_t BuildSourceFilesArray(Dart_SourceFile **sourcefiles, const char *script, const char *script_url=RESOLVED_USER_TEST_URI)
Definition: unit_test.cc:406
DART_EXPORT Dart_Handle Dart_RootLibrary()
void FUNCTION_NAME() Test_CollectNewSpace(Dart_NativeArguments native_args)
Definition: unit_test.cc:274
DART_EXPORT Dart_Handle Dart_NewExternalTypedDataWithFinalizer(Dart_TypedData_Type type, void *data, intptr_t length, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
Definition: unit_test.cc:375
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
void FUNCTION_NAME() Test_Reload(Dart_NativeArguments native_args)
Definition: unit_test.cc:266
static MallocGrowableArray< TestLibEntry > * test_libs_
Definition: unit_test.cc:183
static const char * IsolateReloadTestLibUri()
Definition: unit_test.cc:228
static struct dart::NativeEntries ReloadEntries[]
const intptr_t platform_strong_dill_size
Definition: unit_test.cc:41
uintptr_t uword
Definition: globals.h:501
static void LoadIsolateReloadTestLibIfNeeded(const char *script)
Definition: unit_test.cc:286
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
static Dart_NativeFunction IsolateReloadTestNativeResolver(Dart_Handle name, int argument_count, bool *auto_setup_scope)
Definition: unit_test.cc:245
CStringUniquePtr ResolveUri(const char *ref_uri, const char *base_uri)
Definition: uri.cc:432
DART_EXPORT Dart_Handle Dart_SetNativeResolver(Dart_Handle library, Dart_NativeEntryResolver resolver, Dart_NativeEntrySymbol symbol)
DART_EXPORT Dart_Isolate Dart_CreateIsolateGroup(const char *script_uri, const char *name, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions, Dart_IsolateFlags *flags, void *isolate_group_data, void *isolate_data, char **error)
Dart_Handle NewString(const char *str)
DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle kernel_buffer)
DART_EXPORT Dart_Isolate Dart_CreateIsolateGroupFromKernel(const char *script_uri, const char *name, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size, Dart_IsolateFlags *flags, void *isolate_group_data, void *isolate_data, char **error)
void SetupCoreLibrariesForUnitTest()
Definition: unit_test.cc:149
static const char * kIsolateReloadTestLibSource
Definition: unit_test.cc:219
DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler)
DART_EXPORT void Dart_ExitScope()
DART_EXPORT Dart_Handle Dart_NewApiError(const char *error)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library)
DART_EXPORT Dart_Handle Dart_Null()
gc_during_reload
Isolate * CreateWithinExistingIsolateGroup(IsolateGroup *group, const char *name, char **error)
const char *const function_name
DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library)
static void MallocFinalizer(void *isolate_callback_data, void *peer)
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, const char **cstr)
void StripTokenPositions(char *buffer)
Definition: unit_test.cc:813
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
RELOAD_NATIVE_LIST(DECLARE_FUNCTION)
DECLARE_FLAG(bool, show_invisible_frames)
void FUNCTION_NAME() Test_CollectOldSpace(Dart_NativeArguments native_args)
Definition: unit_test.cc:279
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
Dart_KernelCompilationStatus status
Definition: dart_api.h:3792
const char * uri
Definition: dart_api.h:3850
const char *const name_
const char * url
Definition: unit_test.cc:179
const char * source
Definition: unit_test.cc:180
const uint8_t kPlatformStrongDill[]
intptr_t kPlatformStrongDillSize
#define RESOLVED_USER_TEST_URI
Definition: unit_test.h:317
#define CORELIB_TEST_URI
Definition: unit_test.h:318
#define EXPECT_VALID(handle)
Definition: unit_test.h:643