Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
unit_test.h File Reference
#include <functional>
#include "include/dart_native_api.h"
#include "platform/globals.h"
#include "vm/dart.h"
#include "vm/dart_api_state.h"
#include "vm/dart_entry.h"
#include "vm/globals.h"
#include "vm/isolate.h"
#include "vm/longjump.h"
#include "vm/object.h"
#include "vm/object_store.h"
#include "vm/simulator.h"
#include "vm/zone.h"

Go to the source code of this file.

Classes

class  dart::TesterState
 
class  dart::KernelBufferList
 
class  dart::TestCaseBase
 
class  dart::TestCase
 
class  dart::RawTestCase
 
class  dart::TestIsolateScope
 
struct  dart::is_void< T >
 
struct  dart::is_void< void >
 
struct  dart::is_double< T >
 
struct  dart::is_double< double >
 
class  dart::AssemblerTest
 
class  dart::CompilerTest
 
class  dart::SetFlagScope< T >
 
class  dart::DisableBackgroundCompilationScope
 

Namespaces

namespace  dart
 
namespace  dart::compiler
 
namespace  dart::bin
 

Macros

#define VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define VM_UNIT_TEST_CASE(name)   VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define UNIT_TEST_CASE(name)   UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define ISOLATE_UNIT_TEST_CASE(name)    ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define TEST_CASE_WITH_EXPECTATION(name, expectation)
 
#define TEST_CASE(name)   TEST_CASE_WITH_EXPECTATION(name, "Pass")
 
#define ASSEMBLER_TEST_GENERATE(name, assembler)    void AssemblerTestGenerate##name(compiler::Assembler* assembler)
 
#define ASSEMBLER_TEST_EXTERN(name)    extern void AssemblerTestGenerate##name(compiler::Assembler* assembler);
 
#define ASSEMBLER_TEST_RUN_WITH_EXPECTATION(name, test, expectation)
 
#define ASSEMBLER_TEST_RUN(name, test)    ASSEMBLER_TEST_RUN_WITH_EXPECTATION(name, test, "Pass")
 
#define ZONE_STR(FMT, ...)    OS::SCreate(Thread::Current()->zone(), FMT, __VA_ARGS__)
 
#define USER_TEST_URI   "test-lib"
 
#define RESOLVED_USER_TEST_URI   "file:///test-lib"
 
#define CORELIB_TEST_URI   "dart:test-lib"
 
#define EXPECT_VALID(handle)
 
#define EXPECT_ERROR(handle, substring)
 
#define EXPECT_TRUE(handle)
 
#define EXPECT_NULL(handle)
 
#define EXPECT_NON_NULL(handle)
 

Functions

Dart_Handle NewString (const char *str)
 
void dart::SetupCoreLibrariesForUnitTest ()
 
void dart::ElideJSONSubstring (const char *prefix, const char *in, char *out, const char *postfix)
 
void dart::StripTokenPositions (char *buffer)
 

Macro Definition Documentation

◆ ASSEMBLER_TEST_EXTERN

#define ASSEMBLER_TEST_EXTERN (   name)     extern void AssemblerTestGenerate##name(compiler::Assembler* assembler);

Definition at line 94 of file unit_test.h.

101 { \
102 volatile intptr_t far_branch_level = 0; \
103 while (true) { \
104 LongJumpScope jump(thread); \
105 if (setjmp(*jump.Set()) == 0) { \
106 compiler::ObjectPoolBuilder object_pool_builder; \
107 compiler::Assembler assembler(&object_pool_builder, far_branch_level); \
108 AssemblerTest test("" #name, &assembler, thread->zone()); \
109 AssemblerTestGenerate##name(test.assembler()); \
110 test.Assemble(); \
111 AssemblerTestRun##name(&test); \
112 return; \
113 } else { \
114 const Error& error = Error::Handle(thread->StealStickyError()); \
115 if (error.ptr() == Object::branch_offset_error().ptr()) { \
116 RELEASE_ASSERT(far_branch_level < 2); \
117 far_branch_level++; \
118 } else { \
119 FATAL("Unexpected error: %s\n", error.ToErrorCString()); \
120 } \
121 } \
122 } \
123 } \
124 static void AssemblerTestRun##name(AssemblerTest* test)
125
126#define ASSEMBLER_TEST_RUN(name, test) \
127 ASSEMBLER_TEST_RUN_WITH_EXPECTATION(name, test, "Pass")
128
129#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
130// We don't have simulators for these architectures, but define the macros so
131// they can be used in architecture-independent tests.
132#define EXECUTE_TEST_CODE_INT32(name, entry) reinterpret_cast<name>(entry)()
133#define EXECUTE_TEST_CODE_INT64(name, entry) reinterpret_cast<name>(entry)()
134#define EXECUTE_TEST_CODE_INT64_LL(name, entry, long_arg0, long_arg1) \
135 reinterpret_cast<name>(entry)(long_arg0, long_arg1)
136#define EXECUTE_TEST_CODE_FLOAT(name, entry) reinterpret_cast<name>(entry)()
137#define EXECUTE_TEST_CODE_DOUBLE(name, entry) reinterpret_cast<name>(entry)()
138#define EXECUTE_TEST_CODE_INT32_F(name, entry, float_arg) \
139 reinterpret_cast<name>(entry)(float_arg)
140#define EXECUTE_TEST_CODE_INT32_D(name, entry, double_arg) \
141 reinterpret_cast<name>(entry)(double_arg)
142#define EXECUTE_TEST_CODE_INTPTR_INTPTR(name, entry, pointer_arg) \
143 reinterpret_cast<name>(entry)(pointer_arg)
144#define EXECUTE_TEST_CODE_INT32_INTPTR(name, entry, pointer_arg) \
145 reinterpret_cast<name>(entry)(pointer_arg)
146#define EXECUTE_TEST_CODE_UWORD_UWORD_UINT32(name, entry, arg0, arg1) \
147 reinterpret_cast<name>(entry)(arg0, arg1)
148#elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_ARM64) || \
149 defined(TARGET_ARCH_RISCV32) || defined(TARGET_ARCH_RISCV64)
150#if defined(HOST_ARCH_ARM) || defined(HOST_ARCH_ARM64) || \
151 defined(HOST_ARCH_RISCV32) || defined(HOST_ARCH_RISCV64)
152// Running on actual ARM hardware, execute code natively.
153#define EXECUTE_TEST_CODE_INT32(name, entry) reinterpret_cast<name>(entry)()
154#define EXECUTE_TEST_CODE_INT64(name, entry) reinterpret_cast<name>(entry)()
155#define EXECUTE_TEST_CODE_INT64_LL(name, entry, long_arg0, long_arg1) \
156 reinterpret_cast<name>(entry)(long_arg0, long_arg1)
157#define EXECUTE_TEST_CODE_FLOAT(name, entry) reinterpret_cast<name>(entry)()
158#define EXECUTE_TEST_CODE_DOUBLE(name, entry) reinterpret_cast<name>(entry)()
159#define EXECUTE_TEST_CODE_INT32_F(name, entry, float_arg) \
160 reinterpret_cast<name>(entry)(float_arg)
161#define EXECUTE_TEST_CODE_INT32_D(name, entry, double_arg) \
162 reinterpret_cast<name>(entry)(double_arg)
163#define EXECUTE_TEST_CODE_INTPTR_INTPTR(name, entry, pointer_arg) \
164 reinterpret_cast<name>(entry)(pointer_arg)
165#define EXECUTE_TEST_CODE_INT32_INTPTR(name, entry, pointer_arg) \
166 reinterpret_cast<name>(entry)(pointer_arg)
167#define EXECUTE_TEST_CODE_UWORD_UWORD_UINT32(name, entry, arg0, arg1) \
168 reinterpret_cast<name>(entry)(arg0, arg1)
169#else
170// Not running on ARM hardware, call simulator to execute code.
171#if defined(ARCH_IS_64_BIT)
172#define EXECUTE_TEST_CODE_INT64(name, entry) \
173 static_cast<int64_t>( \
174 Simulator::Current()->Call(bit_cast<int64_t, uword>(entry), 0, 0, 0, 0))
175#define EXECUTE_TEST_CODE_DOUBLE(name, entry) \
176 bit_cast<double, int64_t>(Simulator::Current()->Call( \
177 bit_cast<int64_t, uword>(entry), 0, 0, 0, 0, true))
178#define EXECUTE_TEST_CODE_INTPTR_INTPTR(name, entry, pointer_arg) \
179 static_cast<intptr_t>(Simulator::Current()->Call( \
180 bit_cast<int64_t, uword>(entry), \
181 bit_cast<int64_t, intptr_t>(pointer_arg), 0, 0, 0))
182#define EXECUTE_TEST_CODE_INT32_INTPTR(name, entry, pointer_arg) \
183 static_cast<int32_t>(Simulator::Current()->Call( \
184 bit_cast<int64_t, uword>(entry), \
185 bit_cast<int64_t, intptr_t>(pointer_arg), 0, 0, 0))
186#else
187#define EXECUTE_TEST_CODE_INT32(name, entry) \
188 static_cast<int32_t>( \
189 Simulator::Current()->Call(bit_cast<int32_t, uword>(entry), 0, 0, 0, 0))
190#define EXECUTE_TEST_CODE_DOUBLE(name, entry) \
191 bit_cast<double, int64_t>(Simulator::Current()->Call( \
192 bit_cast<int32_t, uword>(entry), 0, 0, 0, 0, true))
193#define EXECUTE_TEST_CODE_INTPTR_INTPTR(name, entry, pointer_arg) \
194 static_cast<intptr_t>(Simulator::Current()->Call( \
195 bit_cast<int32_t, uword>(entry), \
196 bit_cast<int32_t, intptr_t>(pointer_arg), 0, 0, 0))
197#define EXECUTE_TEST_CODE_INT32_INTPTR(name, entry, pointer_arg) \
198 static_cast<int32_t>(Simulator::Current()->Call( \
199 bit_cast<int32_t, uword>(entry), \
200 bit_cast<int32_t, intptr_t>(pointer_arg), 0, 0, 0))
201#endif // defined(ARCH_IS_64_BIT)
202#define EXECUTE_TEST_CODE_INT64_LL(name, entry, long_arg0, long_arg1) \
203 static_cast<int64_t>(Simulator::Current()->Call( \
204 bit_cast<int32_t, uword>(entry), Utils::Low32Bits(long_arg0), \
205 Utils::High32Bits(long_arg0), Utils::Low32Bits(long_arg1), \
206 Utils::High32Bits(long_arg1)))
207#define EXECUTE_TEST_CODE_FLOAT(name, entry) \
208 bit_cast<float, int32_t>(Simulator::Current()->Call( \
209 bit_cast<int32_t, uword>(entry), 0, 0, 0, 0, true))
210#define EXECUTE_TEST_CODE_INT32_F(name, entry, float_arg) \
211 static_cast<int32_t>(Simulator::Current()->Call( \
212 bit_cast<int32_t, uword>(entry), bit_cast<int32_t, float>(float_arg), 0, \
213 0, 0, false, true))
214#define EXECUTE_TEST_CODE_INT32_D(name, entry, double_arg) \
215 static_cast<int32_t>(Simulator::Current()->Call( \
216 bit_cast<int32_t, uword>(entry), \
217 Utils::Low32Bits(bit_cast<int64_t, double>(double_arg)), \
218 Utils::High32Bits(bit_cast<int64_t, double>(double_arg)), 0, 0, false, \
219 true))
220#define EXECUTE_TEST_CODE_UWORD_UWORD_UINT32(name, entry, arg0, arg1) \
221 static_cast<uint32_t>(Simulator::Current()->Call(entry, arg0, arg1, 0, 0))
222#endif // defined(HOST_ARCH_ARM)
223#endif // defined(TARGET_ARCH_{ARM, ARM64})
224
225#define ZONE_STR(FMT, ...) \
226 OS::SCreate(Thread::Current()->zone(), FMT, __VA_ARGS__)
227
228inline Dart_Handle NewString(const char* str) {
229 return Dart_NewStringFromCString(str);
230}
231
232namespace dart {
233
234// Forward declarations.
235namespace compiler {
236class Assembler;
237}
238class CodeGenerator;
239class VirtualMemory;
240
241namespace bin {
242// Snapshot pieces if we link in a snapshot, otherwise initialized to nullptr.
243extern const uint8_t* vm_snapshot_data;
244extern const uint8_t* vm_snapshot_instructions;
245extern const uint8_t* core_isolate_snapshot_data;
246extern const uint8_t* core_isolate_snapshot_instructions;
247} // namespace bin
248
249extern const uint8_t* platform_strong_dill;
250extern const intptr_t platform_strong_dill_size;
251
252class TesterState : public AllStatic {
253 public:
254 static const uint8_t* vm_snapshot_data;
258 static const char** argv;
259 static int argc;
260};
261
262class KernelBufferList {
263 public:
264 explicit KernelBufferList(const uint8_t* kernel_buffer)
265 : kernel_buffer_(kernel_buffer), next_(nullptr) {}
266
267 KernelBufferList(const uint8_t* kernel_buffer, KernelBufferList* next)
268 : kernel_buffer_(kernel_buffer), next_(next) {}
269
271 free(const_cast<uint8_t*>(kernel_buffer_));
272 if (next_ != nullptr) {
273 delete next_;
274 }
275 }
276
277 void AddBufferToList(const uint8_t* kernel_buffer);
278
279 private:
280 const uint8_t* kernel_buffer_;
281 KernelBufferList* next_;
282};
283
284class TestCaseBase {
285 public:
286 explicit TestCaseBase(const char* name, const char* expectation);
287 virtual ~TestCaseBase() {}
288
289 const char* name() const { return name_; }
290 const char* expectation() const { return expectation_; }
291
292 virtual void Run() = 0;
293 void RunTest();
294
295 static void RunAll();
296 static void RunAllRaw();
297 static void CleanupState();
298 static void AddToKernelBuffers(const uint8_t* kernel_buffer);
299
300 protected:
301 static KernelBufferList* current_kernel_buffers_;
302 bool raw_test_;
303
304 private:
305 static TestCaseBase* first_;
306 static TestCaseBase* tail_;
307
308 TestCaseBase* next_;
309 const char* name_;
310 const char* expectation_;
311
312 DISALLOW_COPY_AND_ASSIGN(TestCaseBase);
313};
314
315#define USER_TEST_URI "test-lib"
316#define RESOLVED_USER_TEST_URI "file:///test-lib"
317#define CORELIB_TEST_URI "dart:test-lib"
318
319class TestCase : TestCaseBase {
320 public:
321 typedef void(RunEntry)();
322
323 TestCase(RunEntry* run, const char* name, const char* expectation)
324 : TestCaseBase(name, expectation), run_(run) {}
325
326 static char* CompileTestScriptWithDFE(
327 const char* url,
328 const char* source,
329 const uint8_t** kernel_buffer,
330 intptr_t* kernel_buffer_size,
331 bool incrementally = true,
332 bool allow_compile_errors = false,
333 const char* multiroot_filepaths = nullptr,
334 const char* multiroot_scheme = nullptr);
335 static char* CompileTestScriptWithDFE(
336 const char* url,
337 int sourcefiles_count,
338 Dart_SourceFile sourcefiles[],
339 const uint8_t** kernel_buffer,
340 intptr_t* kernel_buffer_size,
341 bool incrementally = true,
342 bool allow_compile_errors = false,
343 const char* multiroot_filepaths = nullptr,
344 const char* multiroot_scheme = nullptr);
346 const char* script,
348 const char* lib_uri = RESOLVED_USER_TEST_URI,
349 bool finalize = true,
350 bool allow_compile_errors = false);
352 const char* script,
353 Dart_NativeEntryResolver resolver = nullptr,
354 const char* lib_uri = RESOLVED_USER_TEST_URI,
355 bool finalize = true);
357 const char* lib_uri,
358 const char* script,
359 Dart_NativeEntryResolver resolver = nullptr);
361 int sourcefiles_count,
362 Dart_SourceFile sourcefiles[],
363 Dart_NativeEntryResolver resolver = nullptr,
364 bool finalize = true,
365 bool incrementally = true,
366 bool allow_compile_errors = false,
367 const char* entry_script_uri = nullptr,
368 const char* multiroot_filepaths = nullptr,
369 const char* multiroot_scheme = nullptr);
370 static Dart_Handle LoadCoreTestScript(const char* script,
371 Dart_NativeEntryResolver resolver);
372
373 static Dart_Handle EvaluateExpression(const Library& lib,
374 const String& expr,
375 const Array& param_names,
376 const Array& param_values);
377
378 static Dart_Handle lib();
379 static const char* url();
381 uint8_t* buffer,
382 const char* name = nullptr) {
383 return CreateIsolate(buffer, 0, nullptr, name);
384 }
385 static Dart_Isolate CreateTestIsolate(const char* name = nullptr,
386 void* isolate_group_data = nullptr,
387 void* isolate_data = nullptr);
388 static Dart_Isolate CreateTestIsolateInGroup(const char* name,
389 Dart_Isolate parent,
390 void* group_data = nullptr,
391 void* isolate_data = nullptr);
392
394 Dart_Handle library,
396
397 virtual void Run();
398
399 // Sets |script| to be the source used at next reload.
400 static Dart_Handle SetReloadTestScript(const char* script);
401
402 // Initiates the reload.
403 static Dart_Handle TriggerReload(const uint8_t* kernel_buffer,
404 intptr_t kernel_buffer_size);
405 static Dart_Handle TriggerReload(const char* root_script_url);
406
407 // Helper function which reloads the current isolate using |script|.
408 static Dart_Handle ReloadTestScript(const char* script);
409
410 // Helper function which reloads the current isolate using |script|.
411 static Dart_Handle ReloadTestKernel(const uint8_t* kernel_buffer,
412 intptr_t kernel_buffer_size);
413
414 static void AddTestLib(const char* url, const char* source);
415 static const char* GetTestLib(const char* url);
416
417 // Return true if non-nullable experiment is enabled.
418 static bool IsNNBD();
419
420 static const char* NullableTag() { return IsNNBD() ? "?" : ""; }
421 static const char* NullAssertTag() { return IsNNBD() ? "!" : ""; }
422 static const char* LateTag() { return IsNNBD() ? "late" : ""; }
423
424 private:
426 std::function<bool(IsolateGroup*, JSONStream*)> do_reload);
427
428 // |data_buffer| can either be snapshot data, or kernel binary data.
429 // If |data_buffer| is snapshot data, then |len| should be zero as snapshot
430 // size is encoded within them. If |len| is non-zero, then |data_buffer|
431 // will be treated as a kernel binary (but CreateIsolate will not
432 // take ownership of the buffer) and |instr_buffer| will be ignored.
433 static Dart_Isolate CreateIsolate(const uint8_t* data_buffer,
434 intptr_t len,
435 const uint8_t* instr_buffer,
436 const char* name,
437 void* group_data = nullptr,
438 void* isolate_data = nullptr);
439
440 static char* ValidateCompilationResult(Zone* zone,
442 const uint8_t** kernel_buffer,
443 intptr_t* kernel_buffer_size,
444 bool allow_compile_errors);
445
446 RunEntry* const run_;
447};
448
449class RawTestCase : TestCaseBase {
450 public:
451 typedef void(RunEntry)();
452
453 RawTestCase(RunEntry* run, const char* name, const char* expectation)
454 : TestCaseBase(name, expectation), run_(run) {
455 raw_test_ = true;
456 }
457 virtual void Run();
458
459 private:
460 RunEntry* const run_;
461};
462
463class TestIsolateScope {
464 public:
465 TestIsolateScope(void* isolate_group_data = nullptr,
466 void* isolate_data = nullptr) {
467 isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate(
468 /*name=*/nullptr, isolate_group_data, isolate_data));
469 Dart_EnterScope(); // Create a Dart API scope for unit tests.
470 }
472 Dart_ExitScope(); // Exit the Dart API scope created for unit tests.
473 ASSERT(isolate_ == Isolate::Current());
475 isolate_ = nullptr;
476 }
477 Isolate* isolate() const { return isolate_; }
478
479 private:
480 Isolate* isolate_;
481
482 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope);
483};
484
485// Ensures core libraries are initialized, thereby allowing vm/cc tests to
486// e.g. run functions using microtasks.
488
489template <typename T>
490struct is_void {
491 static constexpr bool value = false;
492};
493
494template <>
495struct is_void<void> {
496 static constexpr bool value = true;
497};
498
499template <typename T>
500struct is_double {
501 static constexpr bool value = false;
502};
503
504template <>
505struct is_double<double> {
506 static constexpr bool value = true;
507};
508
509class AssemblerTest {
510 public:
511 AssemblerTest(const char* name, compiler::Assembler* assembler, Zone* zone)
512 : name_(name),
513 assembler_(assembler),
514 code_(Code::ZoneHandle(zone)),
515 disassembly_(zone->Alloc<char>(DISASSEMBLY_SIZE)) {
516 ASSERT(name != nullptr);
517 ASSERT(assembler != nullptr);
518 }
519 ~AssemblerTest() {}
520
521 compiler::Assembler* assembler() const { return assembler_; }
522
523 const Code& code() const { return code_; }
524
525 uword payload_start() const { return code_.PayloadStart(); }
526 uword payload_size() const { return assembler_->CodeSize(); }
527 uword entry() const { return code_.EntryPoint(); }
528
529// Invoke/InvokeWithCodeAndThread is used to call assembler test functions
530// using the ABI calling convention.
531// ResultType is the return type of the assembler test function.
532// ArgNType is the type of the Nth argument.
533#if defined(USING_SIMULATOR)
534
535 // Since Simulator::Call always return a int64_t, bit_cast does not work
536 // on 32-bit platforms when returning an int32_t. Use static cast on the
537 // call site in 32-bit to get rid of the upper bits if needed.
538 template <typename ResultType>
540 const bool fp_return = is_double<ResultType>::value;
541 const bool fp_args = false;
542 Thread* thread = Thread::Current();
543 ASSERT(thread != nullptr);
544 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call(
545 bit_cast<intptr_t, uword>(entry()), static_cast<intptr_t>(code_.ptr()),
546 reinterpret_cast<intptr_t>(thread), 0, 0, fp_return, fp_args));
547 }
548 template <typename ResultType, typename Arg1Type>
549 ResultType InvokeWithCodeAndThread(Arg1Type arg1) {
550 const bool fp_return = is_double<ResultType>::value;
551 const bool fp_args = is_double<Arg1Type>::value;
552 // TODO(fschneider): Support double arguments for simulator calls.
553 COMPILE_ASSERT(!fp_args);
554 Thread* thread = Thread::Current();
555 ASSERT(thread != nullptr);
556 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call(
557 bit_cast<intptr_t, uword>(entry()), static_cast<intptr_t>(code_.ptr()),
558 reinterpret_cast<intptr_t>(thread), reinterpret_cast<intptr_t>(arg1), 0,
559 fp_return, fp_args));
560 }
561
562 template <typename ResultType, typename Arg1Type>
563 ResultType Invoke(Arg1Type arg1) {
565 const bool fp_args = false;
566 const bool fp_return = false;
567 return Simulator::Current()->Call(bit_cast<intptr_t, uword>(entry()),
568 static_cast<intptr_t>(arg1), 0, 0, 0,
569 fp_return, fp_args);
570 }
571
572 template <typename ResultType,
573 typename Arg1Type,
574 typename Arg2Type,
575 typename Arg3Type>
576 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) {
577 // TODO(fschneider): Support double arguments for simulator calls.
582 const bool fp_args = false;
583 const bool fp_return = false;
585 bit_cast<intptr_t, uword>(entry()), static_cast<intptr_t>(arg1),
586 static_cast<intptr_t>(arg2), reinterpret_cast<intptr_t>(arg3), 0,
587 fp_return, fp_args);
588 }
589#else
590 template <typename ResultType>
592 Thread* thread = Thread::Current();
593 ASSERT(thread != nullptr);
594 typedef ResultType (*FunctionType)(CodePtr, Thread*);
595 return reinterpret_cast<FunctionType>(entry())(code_.ptr(), thread);
596 }
597
598 template <typename ResultType, typename Arg1Type>
599 ResultType InvokeWithCodeAndThread(Arg1Type arg1) {
600 Thread* thread = Thread::Current();
601 ASSERT(thread != nullptr);
602 typedef ResultType (*FunctionType)(CodePtr, Thread*, Arg1Type);
603 return reinterpret_cast<FunctionType>(entry())(code_.ptr(), thread, arg1);
604 }
605
606 template <typename ResultType, typename Arg1Type>
607 ResultType Invoke(Arg1Type arg1) {
608 typedef ResultType (*FunctionType)(Arg1Type);
609 return reinterpret_cast<FunctionType>(entry())(arg1);
610 }
611
612 template <typename ResultType,
613 typename Arg1Type,
614 typename Arg2Type,
615 typename Arg3Type>
616 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) {
617 typedef ResultType (*FunctionType)(Arg1Type, Arg2Type, Arg3Type);
618 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3);
619 }
620#endif // defined(USING_SIMULATOR)
621
622 // Assemble test and set code_.
623 void Assemble();
624
625 // Disassembly of the code with relative branch/jump targets.
626 char* RelativeDisassembly() { return disassembly_; }
627
628 static const Code& Generate(
629 const char* name,
630 const std::function<void(compiler::Assembler* assembler)>& generator);
631
632 private:
633 const char* name_;
634 compiler::Assembler* assembler_;
635 Code& code_;
636 static constexpr intptr_t DISASSEMBLY_SIZE = 10240;
637 char* disassembly_;
638
639 DISALLOW_COPY_AND_ASSIGN(AssemblerTest);
640};
641
642class CompilerTest : public AllStatic {
643 public:
644 // Test the Compiler::CompileFunction functionality by checking the return
645 // value to see if no parse errors were reported.
646 static bool TestCompileFunction(const Function& function);
647};
648
649#define EXPECT_VALID(handle) \
650 do { \
651 Dart_Handle tmp_handle = (handle); \
652 if (!Api::IsValid(tmp_handle)) { \
653 dart::Expect(__FILE__, __LINE__) \
654 .Fail( \
655 "expected '%s' to be a valid handle but '%s' has already been " \
656 "freed\n", \
657 #handle, #handle); \
658 } \
659 if (Dart_IsError(tmp_handle)) { \
660 dart::Expect(__FILE__, __LINE__) \
661 .Fail( \
662 "expected '%s' to be a valid handle but found an error " \
663 "handle:\n" \
664 " '%s'\n", \
665 #handle, Dart_GetError(tmp_handle)); \
666 } \
667 } while (0)
668
669#define EXPECT_ERROR(handle, substring) \
670 do { \
671 Dart_Handle tmp_handle = (handle); \
672 if (Dart_IsError(tmp_handle)) { \
673 dart::Expect(__FILE__, __LINE__) \
674 .IsSubstring((substring), Dart_GetError(tmp_handle)); \
675 } else { \
676 dart::Expect(__FILE__, __LINE__) \
677 .Fail( \
678 "expected '%s' to be an error handle but found a valid " \
679 "handle.\n", \
680 #handle); \
681 } \
682 } while (0)
683
684#define EXPECT_TRUE(handle) \
685 do { \
686 Dart_Handle tmp_handle = (handle); \
687 if (Dart_IsBoolean(tmp_handle)) { \
688 bool value; \
689 Dart_BooleanValue(tmp_handle, &value); \
690 if (!value) { \
691 dart::Expect(__FILE__, __LINE__) \
692 .Fail("expected True, but was '%s'\n", #handle); \
693 } \
694 } else { \
695 dart::Expect(__FILE__, __LINE__) \
696 .Fail("expected True, but was '%s'\n", #handle); \
697 } \
698 } while (0)
699
700#define EXPECT_NULL(handle) \
701 do { \
702 Dart_Handle tmp_handle = (handle); \
703 if (!Dart_IsNull(tmp_handle)) { \
704 dart::Expect(__FILE__, __LINE__) \
705 .Fail("expected '%s' to be a null handle.\n", #handle); \
706 } \
707 } while (0)
708
709#define EXPECT_NON_NULL(handle) \
710 do { \
711 Dart_Handle tmp_handle = (handle); \
712 if (Dart_IsNull(tmp_handle)) { \
713 dart::Expect(__FILE__, __LINE__) \
714 .Fail("expected '%s' to be a non-null handle.\n", #handle); \
715 } \
716 } while (0)
717
718// Elide a substring which starts with some prefix and ends with some postfix.
719//
720// Prefix is inclusive, postfix is exclusive.
721//
722// This is used to remove non-deterministic or fragile substrings from
723// JSON output.
724//
725// For example:
726//
727// prefix = "classes"
728// in = "\"id\":\"classes/46\""
729//
730// Yields:
731//
732// out = "\"id\":\"\""
733//
734// WARNING: This function is not safe to use if `in` is bigger than `out`!
735void ElideJSONSubstring(const char* prefix,
736 const char* in,
737 char* out,
738 const char* postfix = "\"");
739
740// Elide a substrings such as ",\"tokenPos\":4372,\"endTokenPos\":4430".
741//
742// Substring to be followed by "}".
743//
744// Modifies buffer in place.
745void StripTokenPositions(char* buffer);
746
747template <typename T>
748class SetFlagScope : public ValueObject {
749 public:
750 SetFlagScope(T* flag, T value) : flag_(flag), original_value_(*flag) {
751 *flag_ = value;
752 }
753
754 ~SetFlagScope() { *flag_ = original_value_; }
755
756 private:
757 T* flag_;
758 T original_value_;
759};
760
761class DisableBackgroundCompilationScope : public ValueObject {
762 public:
764 : FLAG_background_compilation_(FLAG_background_compilation) {
765 FLAG_background_compilation = false;
766 }
767
769 FLAG_background_compilation = FLAG_background_compilation_;
770 }
771
772 private:
773 const bool FLAG_background_compilation_;
774};
775
776} // namespace dart
777
778#endif // RUNTIME_VM_UNIT_TEST_H_
#define test(name)
static float next(float f)
#define COMPILE_ASSERT(expr)
Definition assert.h:339
uword payload_size() const
Definition unit_test.h:527
uword entry() const
Definition unit_test.h:528
ResultType InvokeWithCodeAndThread()
Definition unit_test.h:592
compiler::Assembler * assembler() const
Definition unit_test.h:522
char * RelativeDisassembly()
Definition unit_test.h:627
uword payload_start() const
Definition unit_test.h:526
const Code & code() const
Definition unit_test.h:524
static const Code & Generate(const char *name, const std::function< void(compiler::Assembler *assembler)> &generator)
Definition unit_test.cc:756
AssemblerTest(const char *name, compiler::Assembler *assembler, Zone *zone)
Definition unit_test.h:512
ResultType Invoke(Arg1Type arg1)
Definition unit_test.h:608
uword EntryPoint() const
Definition object.h:6837
uword PayloadStart() const
Definition object.h:6823
static bool TestCompileFunction(const Function &function)
Definition unit_test.cc:767
static Isolate * Current()
Definition isolate.h:939
KernelBufferList(const uint8_t *kernel_buffer)
Definition unit_test.h:265
void AddBufferToList(const uint8_t *kernel_buffer)
Definition unit_test.cc:49
ObjectPtr ptr() const
Definition object.h:332
RawTestCase(RunEntry *run, const char *name, const char *expectation)
Definition unit_test.h:454
void() RunEntry()
Definition unit_test.h:452
virtual void Run()
SetFlagScope(T *flag, T value)
Definition unit_test.h:751
static Simulator * Current()
int64_t Call(int32_t entry, int32_t parameter0, int32_t parameter1, int32_t parameter2, int32_t parameter3, bool fp_return=false, bool fp_args=false)
virtual void Run()=0
static void CleanupState()
Definition unit_test.cc:93
const char * expectation() const
Definition unit_test.h:291
static void AddToKernelBuffers(const uint8_t *kernel_buffer)
Definition unit_test.cc:100
static void RunAllRaw()
Definition unit_test.cc:71
const char * name() const
Definition unit_test.h:290
static void RunAll()
Definition unit_test.cc:82
virtual ~TestCaseBase()
Definition unit_test.h:288
static KernelBufferList * current_kernel_buffers_
Definition unit_test.h:302
TestCaseBase(const char *name, const char *expectation)
Definition unit_test.cc:58
static Dart_Handle TriggerReload(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition unit_test.cc:589
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:476
static Dart_Handle lib()
Definition unit_test.cc:629
static void AddTestLib(const char *url, const char *source)
Definition unit_test.cc:188
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:422
static const char * NullAssertTag()
Definition unit_test.h:422
static Dart_Handle ReloadTestScript(const char *script)
Definition unit_test.cc:599
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:300
static const char * LateTag()
Definition unit_test.h:423
static Dart_Isolate CreateTestIsolateInGroup(const char *name, Dart_Isolate parent, void *group_data=nullptr, void *isolate_data=nullptr)
Definition unit_test.cc:162
static Dart_Handle SetReloadTestScript(const char *script)
Definition unit_test.cc:525
static const char * url()
Definition unit_test.cc:184
void() RunEntry()
Definition unit_test.h:322
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:414
virtual void Run()
static Dart_Handle LoadTestLibrary(const char *lib_uri, const char *script, Dart_NativeEntryResolver resolver=nullptr)
Definition unit_test.cc:441
static bool IsNNBD()
Definition unit_test.cc:217
static Dart_Handle ReloadTestKernel(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition unit_test.cc:617
static const char * NullableTag()
Definition unit_test.h:421
static Dart_Handle library_handler(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
Definition unit_test.cc:637
static Dart_Handle EvaluateExpression(const Library &lib, const String &expr, const Array &param_names, const Array &param_values)
Definition unit_test.cc:646
static Dart_Isolate CreateTestIsolate(const char *name=nullptr, void *isolate_group_data=nullptr, void *isolate_data=nullptr)
Definition unit_test.cc:139
static const char * GetTestLib(const char *url)
Definition unit_test.cc:205
static Dart_Handle LoadCoreTestScript(const char *script, Dart_NativeEntryResolver resolver)
Definition unit_test.cc:624
static Dart_Isolate CreateTestIsolateFromSnapshot(uint8_t *buffer, const char *name=nullptr)
Definition unit_test.h:381
Isolate * isolate() const
Definition unit_test.h:478
TestIsolateScope(void *isolate_group_data=nullptr, void *isolate_data=nullptr)
Definition unit_test.h:466
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
static Thread * Current()
Definition thread.h:361
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:653
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:3225
void(* Dart_IsolateGroupCleanupCallback)(void *isolate_group_data)
Definition dart_api.h:744
Dart_LibraryTag
Definition dart_api.h:3339
void(* Dart_IsolateShutdownCallback)(void *isolate_group_data, void *isolate_data)
Definition dart_api.h:710
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
#define ASSERT(E)
SkBitmap source
Definition examples.cpp:28
FlutterSemanticsFlag flag
static const uint8_t buffer[]
const uint8_t uint32_t uint32_t GError ** error
uint8_t value
GAsyncResult * result
const char * name
Definition fuchsia.cc:50
const uint8_t * vm_snapshot_data
Definition main_impl.cc:56
const uint8_t * vm_snapshot_instructions
Definition main_impl.cc:57
const uint8_t * core_isolate_snapshot_data
Definition main_impl.cc:58
const uint8_t * core_isolate_snapshot_instructions
Definition main_impl.cc:59
void ElideJSONSubstring(const char *prefix, const char *in, char *out, const char *postfix)
Definition unit_test.cc:776
DART_EXPORT void Dart_EnterScope()
const uint8_t * platform_strong_dill
Definition unit_test.cc:39
const char *const name
const intptr_t platform_strong_dill_size
Definition unit_test.cc:40
uintptr_t uword
Definition globals.h:501
void SetupCoreLibrariesForUnitTest()
Definition unit_test.cc:148
DART_EXPORT void Dart_ExitScope()
static CompileType * ResultType(Definition *call)
DART_EXPORT void Dart_ShutdownIsolate()
void StripTokenPositions(char *buffer)
Definition unit_test.cc:799
Definition run.py:1
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581
#define T
static constexpr bool value
Definition unit_test.h:502
static constexpr bool value
Definition unit_test.h:492
Dart_Handle NewString(const char *str)
Definition unit_test.h:229
#define RESOLVED_USER_TEST_URI
Definition unit_test.h:317

◆ ASSEMBLER_TEST_GENERATE

#define ASSEMBLER_TEST_GENERATE (   name,
  assembler 
)     void AssemblerTestGenerate##name(compiler::Assembler* assembler)

Definition at line 89 of file unit_test.h.

◆ ASSEMBLER_TEST_RUN

#define ASSEMBLER_TEST_RUN (   name,
  test 
)     ASSEMBLER_TEST_RUN_WITH_EXPECTATION(name, test, "Pass")

Definition at line 127 of file unit_test.h.

◆ ASSEMBLER_TEST_RUN_WITH_EXPECTATION

#define ASSEMBLER_TEST_RUN_WITH_EXPECTATION (   name,
  test,
  expectation 
)
Value:
static void AssemblerTestRun##name(AssemblerTest* test); \
ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(Assembler_##name, expectation) { \
volatile intptr_t far_branch_level = 0; \
while (true) { \
LongJumpScope jump(thread); \
if (setjmp(*jump.Set()) == 0) { \
compiler::ObjectPoolBuilder object_pool_builder; \
compiler::Assembler assembler(&object_pool_builder, far_branch_level); \
AssemblerTest test("" #name, &assembler, thread->zone()); \
AssemblerTestGenerate##name(test.assembler()); \
test.Assemble(); \
AssemblerTestRun##name(&test); \
return; \
} else { \
const Error& error = Error::Handle(thread->StealStickyError()); \
if (error.ptr() == Object::branch_offset_error().ptr()) { \
RELEASE_ASSERT(far_branch_level < 2); \
far_branch_level++; \
} else { \
FATAL("Unexpected error: %s\n", error.ToErrorCString()); \
} \
} \
} \
} \
static void AssemblerTestRun##name(AssemblerTest* test)

Definition at line 100 of file unit_test.h.

102 { \
103 volatile intptr_t far_branch_level = 0; \
104 while (true) { \
105 LongJumpScope jump(thread); \
106 if (setjmp(*jump.Set()) == 0) { \
107 compiler::ObjectPoolBuilder object_pool_builder; \
108 compiler::Assembler assembler(&object_pool_builder, far_branch_level); \
109 AssemblerTest test("" #name, &assembler, thread->zone()); \
110 AssemblerTestGenerate##name(test.assembler()); \
111 test.Assemble(); \
112 AssemblerTestRun##name(&test); \
113 return; \
114 } else { \
115 const Error& error = Error::Handle(thread->StealStickyError()); \
116 if (error.ptr() == Object::branch_offset_error().ptr()) { \
117 RELEASE_ASSERT(far_branch_level < 2); \
118 far_branch_level++; \
119 } else { \
120 FATAL("Unexpected error: %s\n", error.ToErrorCString()); \
121 } \
122 } \
123 } \
124 } \
125 static void AssemblerTestRun##name(AssemblerTest* test)

◆ CORELIB_TEST_URI

#define CORELIB_TEST_URI   "dart:test-lib"

Definition at line 318 of file unit_test.h.

◆ EXPECT_ERROR

#define EXPECT_ERROR (   handle,
  substring 
)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (Dart_IsError(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.IsSubstring((substring), Dart_GetError(tmp_handle)); \
} else { \
dart::Expect(__FILE__, __LINE__) \
.Fail( \
"expected '%s' to be an error handle but found a valid " \
"handle.\n", \
#handle); \
} \
} while (0)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)

Definition at line 670 of file unit_test.h.

671 { \
672 Dart_Handle tmp_handle = (handle); \
673 if (Dart_IsError(tmp_handle)) { \
674 dart::Expect(__FILE__, __LINE__) \
675 .IsSubstring((substring), Dart_GetError(tmp_handle)); \
676 } else { \
677 dart::Expect(__FILE__, __LINE__) \
678 .Fail( \
679 "expected '%s' to be an error handle but found a valid " \
680 "handle.\n", \
681 #handle); \
682 } \
683 } while (0)

◆ EXPECT_NON_NULL

#define EXPECT_NON_NULL (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (Dart_IsNull(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected '%s' to be a non-null handle.\n", #handle); \
} \
} while (0)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)

Definition at line 710 of file unit_test.h.

711 { \
712 Dart_Handle tmp_handle = (handle); \
713 if (Dart_IsNull(tmp_handle)) { \
714 dart::Expect(__FILE__, __LINE__) \
715 .Fail("expected '%s' to be a non-null handle.\n", #handle); \
716 } \
717 } while (0)

◆ EXPECT_NULL

#define EXPECT_NULL (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (!Dart_IsNull(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected '%s' to be a null handle.\n", #handle); \
} \
} while (0)

Definition at line 701 of file unit_test.h.

702 { \
703 Dart_Handle tmp_handle = (handle); \
704 if (!Dart_IsNull(tmp_handle)) { \
705 dart::Expect(__FILE__, __LINE__) \
706 .Fail("expected '%s' to be a null handle.\n", #handle); \
707 } \
708 } while (0)

◆ EXPECT_TRUE

#define EXPECT_TRUE (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (Dart_IsBoolean(tmp_handle)) { \
bool value; \
Dart_BooleanValue(tmp_handle, &value); \
if (!value) { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected True, but was '%s'\n", #handle); \
} \
} else { \
dart::Expect(__FILE__, __LINE__) \
.Fail("expected True, but was '%s'\n", #handle); \
} \
} while (0)
DART_EXPORT bool Dart_IsBoolean(Dart_Handle object)

Definition at line 685 of file unit_test.h.

686 { \
687 Dart_Handle tmp_handle = (handle); \
688 if (Dart_IsBoolean(tmp_handle)) { \
689 bool value; \
690 Dart_BooleanValue(tmp_handle, &value); \
691 if (!value) { \
692 dart::Expect(__FILE__, __LINE__) \
693 .Fail("expected True, but was '%s'\n", #handle); \
694 } \
695 } else { \
696 dart::Expect(__FILE__, __LINE__) \
697 .Fail("expected True, but was '%s'\n", #handle); \
698 } \
699 } while (0)

◆ EXPECT_VALID

#define EXPECT_VALID (   handle)
Value:
do { \
Dart_Handle tmp_handle = (handle); \
if (!Api::IsValid(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail( \
"expected '%s' to be a valid handle but '%s' has already been " \
"freed\n", \
#handle, #handle); \
} \
if (Dart_IsError(tmp_handle)) { \
dart::Expect(__FILE__, __LINE__) \
.Fail( \
"expected '%s' to be a valid handle but found an error " \
"handle:\n" \
" '%s'\n", \
#handle, Dart_GetError(tmp_handle)); \
} \
} while (0)

Definition at line 650 of file unit_test.h.

651 { \
652 Dart_Handle tmp_handle = (handle); \
653 if (!Api::IsValid(tmp_handle)) { \
654 dart::Expect(__FILE__, __LINE__) \
655 .Fail( \
656 "expected '%s' to be a valid handle but '%s' has already been " \
657 "freed\n", \
658 #handle, #handle); \
659 } \
660 if (Dart_IsError(tmp_handle)) { \
661 dart::Expect(__FILE__, __LINE__) \
662 .Fail( \
663 "expected '%s' to be a valid handle but found an error " \
664 "handle:\n" \
665 " '%s'\n", \
666 #handle, Dart_GetError(tmp_handle)); \
667 } \
668 } while (0)

◆ ISOLATE_UNIT_TEST_CASE

#define ISOLATE_UNIT_TEST_CASE (   name)     ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 64 of file unit_test.h.

◆ ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION

#define ISOLATE_UNIT_TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
static void Dart_TestHelper##name(Thread* thread); \
VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation) { \
TestIsolateScope __test_isolate__; \
Thread* __thread__ = Thread::Current(); \
ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \
TransitionNativeToVM transition(__thread__); \
StackZone __zone__(__thread__); \
HandleScope __hs__(__thread__); \
Dart_TestHelper##name(__thread__); \
} \
static void Dart_TestHelper##name(Thread* thread)

Definition at line 51 of file unit_test.h.

53 { \
54 TestIsolateScope __test_isolate__; \
55 Thread* __thread__ = Thread::Current(); \
56 ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \
57 TransitionNativeToVM transition(__thread__); \
58 StackZone __zone__(__thread__); \
59 HandleScope __hs__(__thread__); \
60 Dart_TestHelper##name(__thread__); \
61 } \
62 static void Dart_TestHelper##name(Thread* thread)

◆ RESOLVED_USER_TEST_URI

#define RESOLVED_USER_TEST_URI   "file:///test-lib"

Definition at line 317 of file unit_test.h.

◆ TEST_CASE

#define TEST_CASE (   name)    TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 85 of file unit_test.h.

◆ TEST_CASE_WITH_EXPECTATION

#define TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
static void Dart_TestHelper##name(Thread* thread); \
VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, expectation) { \
TestIsolateScope __test_isolate__; \
Thread* __thread__ = Thread::Current(); \
ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \
TransitionNativeToVM transition1(__thread__); \
StackZone __zone__(__thread__); \
HandleScope __hs__(__thread__); \
TransitionVMToNative transition2(__thread__); \
Dart_TestHelper##name(__thread__); \
} \
static void Dart_TestHelper##name(Thread* thread)

Definition at line 71 of file unit_test.h.

73 { \
74 TestIsolateScope __test_isolate__; \
75 Thread* __thread__ = Thread::Current(); \
76 ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \
77 TransitionNativeToVM transition1(__thread__); \
78 StackZone __zone__(__thread__); \
79 HandleScope __hs__(__thread__); \
80 TransitionVMToNative transition2(__thread__); \
81 Dart_TestHelper##name(__thread__); \
82 } \
83 static void Dart_TestHelper##name(Thread* thread)

◆ UNIT_TEST_CASE

#define UNIT_TEST_CASE (   name)    UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 44 of file unit_test.h.

◆ UNIT_TEST_CASE_WITH_EXPECTATION

#define UNIT_TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
void Dart_Test##name(); \
static const dart::RawTestCase kRegister##name(Dart_Test##name, #name, \
expectation); \
void Dart_Test##name()

Definition at line 38 of file unit_test.h.

◆ USER_TEST_URI

#define USER_TEST_URI   "test-lib"

Definition at line 316 of file unit_test.h.

◆ VM_UNIT_TEST_CASE

#define VM_UNIT_TEST_CASE (   name)    VM_UNIT_TEST_CASE_WITH_EXPECTATION(name, "Pass")

Definition at line 33 of file unit_test.h.

◆ VM_UNIT_TEST_CASE_WITH_EXPECTATION

#define VM_UNIT_TEST_CASE_WITH_EXPECTATION (   name,
  expectation 
)
Value:
void Dart_Test##name(); \
static const dart::TestCase kRegister##name(Dart_Test##name, #name, \
expectation); \
void Dart_Test##name()

Definition at line 27 of file unit_test.h.

◆ ZONE_STR

#define ZONE_STR (   FMT,
  ... 
)     OS::SCreate(Thread::Current()->zone(), FMT, __VA_ARGS__)

Definition at line 226 of file unit_test.h.

Function Documentation

◆ NewString()

Dart_Handle NewString ( const char *  str)
inline

Definition at line 229 of file unit_test.h.

229 {
230 return Dart_NewStringFromCString(str);
231}