Flutter Engine
The Flutter Engine
run_ffi_unit_tests.cc
Go to the documentation of this file.
1// Copyright (c) 2020, 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// A slimmed down version of bin/run_vm_tests.cc that only runs C++ non-DartVM
6// unit tests.
7//
8// By slimming it down to non-VM, we can run with the defines for all target
9// architectures and operating systems.
10
12
13#include "platform/assert.h"
14#include "platform/syslog.h"
15
16namespace dart {
17namespace compiler {
18namespace ffi {
19
20static constexpr const char* kNone = "No Test";
21static constexpr const char* kList = "List all Tests";
22static constexpr const char* kAll = "Run all Tests";
23static const char* run_filter = kNone;
24
25static constexpr const char* kCommandAll = "--all";
26static constexpr const char* kCommandList = "--list";
27static constexpr const char* kCommandUpdate = "--update";
28
29static int run_matches = 0;
30
31TestCaseBase* TestCaseBase::first_ = nullptr;
32TestCaseBase* TestCaseBase::tail_ = nullptr;
34
36 : next_(nullptr), name_(name), expectation_(expectation) {
37 ASSERT(strlen(expectation) > 0);
38 if (first_ == nullptr) {
39 first_ = this;
40 } else {
41 tail_->next_ = this;
42 }
43 tail_ = this;
44}
45
47 TestCaseBase* test = first_;
48 while (test != nullptr) {
49 test->RunTest();
50 test = test->next_;
51 }
52}
53
55 if (run_filter == kList) {
56 Syslog::Print("%s %s\n", this->name(), this->expectation());
57 run_matches++;
58 } else if (run_filter == kAll) {
59 this->Run();
60 run_matches++;
61 } else if (strcmp(run_filter, this->name()) == 0) {
62 this->Run();
63 run_matches++;
64 }
65}
66
68 Syslog::Print("Running test: %s\n", name());
69 (*run_)();
70 Syslog::Print("Done: %s\n", name());
71}
72
73static int Main(int argc, const char** argv) {
74 if (argc == 2 && strcmp(argv[1], kCommandList) == 0) {
76 // List all tests and benchmarks and exit.
78 fflush(stdout);
79 return 0;
80 }
81 if (argc > 1 && strcmp(argv[1], kCommandUpdate) == 0) {
83 }
84 if (strcmp(argv[argc - 1], kCommandAll) == 0) {
85 // Run all tests.
87 } else if (argc > 1) {
88 // Run only test with specific name.
89 run_filter = argv[argc - 1];
90 }
91
93
94 // Print a warning message if no tests or benchmarks were matched.
95 if (run_matches == 0) {
96 Syslog::PrintErr("No tests matched: %s\n", run_filter);
97 return 1;
98 }
99 if (Expect::failed()) {
101 "Some tests failed. Run the following command to update "
102 "expectations.\ntools/test.py --vm-options=--update ffi_unit");
103 return 255;
104 }
105
106 return 0;
107}
108
109} // namespace ffi
110} // namespace compiler
111} // namespace dart
112
113int main(int argc, const char** argv) {
114 return dart::compiler::ffi::Main(argc, argv);
115}
void static bool failed()
Definition: assert.h:94
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
const char * name() const
Definition: unit_test.h:54
TestCaseBase(const char *name, const char *expectation)
const char * expectation() const
Definition: unit_test.h:55
#define ASSERT(E)
char ** argv
Definition: library.h:9
static int Main(int argc, const char **argv)
static constexpr const char * kAll
static constexpr const char * kCommandList
static constexpr const char * kCommandAll
static constexpr const char * kCommandUpdate
static const char * run_filter
static constexpr const char * kList
static constexpr const char * kNone
Definition: dart_vm.cc:33
const char *const name
int main(int argc, const char **argv)