OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #include "src/shared/flags.h" | 5 #include "src/shared/flags.h" |
6 #include "src/shared/test_case.h" | 6 #include "src/shared/test_case.h" |
7 #include "src/shared/platform.h" | 7 #include "src/shared/platform.h" |
8 | 8 |
9 #include "include/fletch_api.h" | 9 #include "include/dartino_api.h" |
10 | 10 |
11 namespace fletch { | 11 namespace dartino { |
12 | 12 |
13 // This multiprogram runner uses only the FletchStartMain() API function. | 13 // This multiprogram runner uses only the DartinoStartMain() API function. |
14 class Runner { | 14 class Runner { |
15 public: | 15 public: |
16 Runner(int count, FletchProgram* programs, int* exitcodes) | 16 Runner(int count, DartinoProgram* programs, int* exitcodes) |
17 : monitor_(Platform::CreateMonitor()), | 17 : monitor_(Platform::CreateMonitor()), |
18 programs_(programs), | 18 programs_(programs), |
19 exitcodes_(exitcodes), | 19 exitcodes_(exitcodes), |
20 count_(count), | 20 count_(count), |
21 started_(0), | 21 started_(0), |
22 awaited_(0), | 22 awaited_(0), |
23 finished_(0) {} | 23 finished_(0) {} |
24 ~Runner() { delete monitor_; } | 24 ~Runner() { delete monitor_; } |
25 | 25 |
26 // Starts all programs and then waits for all of them. | 26 // Starts all programs and then waits for all of them. |
(...skipping 24 matching lines...) Expand all Loading... |
51 int remaining = count_ - max_parallel; | 51 int remaining = count_ - max_parallel; |
52 for (int i = 0; i < remaining; i++) { | 52 for (int i = 0; i < remaining; i++) { |
53 Wait(1); | 53 Wait(1); |
54 Start(1); | 54 Start(1); |
55 } | 55 } |
56 Wait(max_parallel); | 56 Wait(max_parallel); |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 Monitor* monitor_; | 60 Monitor* monitor_; |
61 FletchProgram* programs_; | 61 DartinoProgram* programs_; |
62 int* exitcodes_; | 62 int* exitcodes_; |
63 int count_; | 63 int count_; |
64 int started_; | 64 int started_; |
65 int awaited_; | 65 int awaited_; |
66 int finished_; | 66 int finished_; |
67 | 67 |
68 static void CaptureExitCode(FletchProgram* program, | 68 static void CaptureExitCode(DartinoProgram* program, |
69 int exitcode, | 69 int exitcode, |
70 void* data) { | 70 void* data) { |
71 Runner* runner = reinterpret_cast<Runner*>(data); | 71 Runner* runner = reinterpret_cast<Runner*>(data); |
72 ScopedMonitorLock locker(runner->monitor_); | 72 ScopedMonitorLock locker(runner->monitor_); |
73 for (int i = 0; i < runner->count_; i++) { | 73 for (int i = 0; i < runner->count_; i++) { |
74 if (runner->programs_[i] == program) { | 74 if (runner->programs_[i] == program) { |
75 runner->exitcodes_[i] = exitcode; | 75 runner->exitcodes_[i] = exitcode; |
76 runner->finished_++; | 76 runner->finished_++; |
77 runner->monitor_->NotifyAll(); | 77 runner->monitor_->NotifyAll(); |
78 | 78 |
79 FletchDeleteProgram(program); | 79 DartinoDeleteProgram(program); |
80 | 80 |
81 return; | 81 return; |
82 } | 82 } |
83 } | 83 } |
84 UNREACHABLE(); | 84 UNREACHABLE(); |
85 } | 85 } |
86 | 86 |
87 void Start(int count) { | 87 void Start(int count) { |
88 ScopedMonitorLock locker(monitor_); | 88 ScopedMonitorLock locker(monitor_); |
89 for (int i = started_; i < started_ + count; i++) { | 89 for (int i = started_; i < started_ + count; i++) { |
90 FletchStartMain(programs_[i], &Runner::CaptureExitCode, this); | 90 DartinoStartMain(programs_[i], &Runner::CaptureExitCode, this); |
91 } | 91 } |
92 started_ += count; | 92 started_ += count; |
93 } | 93 } |
94 | 94 |
95 void Wait(int count) { | 95 void Wait(int count) { |
96 ScopedMonitorLock locker(monitor_); | 96 ScopedMonitorLock locker(monitor_); |
97 int finished = awaited_ + count; | 97 int finished = awaited_ + count; |
98 while (finished_ < finished) { | 98 while (finished_ < finished) { |
99 monitor_->Wait(); | 99 monitor_->Wait(); |
100 } | 100 } |
101 awaited_ += count; | 101 awaited_ += count; |
102 } | 102 } |
103 }; | 103 }; |
104 | 104 |
105 static void PrintAndDie(char **argv) { | 105 static void PrintAndDie(char **argv) { |
106 FATAL1("Usage: %0 " | 106 FATAL1("Usage: %0 " |
107 "<parallel|sequence|batch=NUM|overlapped=NUM> " | 107 "<parallel|sequence|batch=NUM|overlapped=NUM> " |
108 "[[<snapshot> <expected-exitcode>] ...]", | 108 "[[<snapshot> <expected-exitcode>] ...]", |
109 argv[0]); | 109 argv[0]); |
110 } | 110 } |
111 | 111 |
112 static int Main(int argc, char** argv) { | 112 static int Main(int argc, char** argv) { |
113 Flags::ExtractFromCommandLine(&argc, argv); | 113 Flags::ExtractFromCommandLine(&argc, argv); |
114 | 114 |
115 FletchSetup(); | 115 DartinoSetup(); |
116 | 116 |
117 if (argc <= 1 || (argc % 2) != 0) PrintAndDie(argv); | 117 if (argc <= 1 || (argc % 2) != 0) PrintAndDie(argv); |
118 | 118 |
119 bool parallel = strcmp(argv[1], "parallel") == 0; | 119 bool parallel = strcmp(argv[1], "parallel") == 0; |
120 bool sequence = strcmp(argv[1], "sequence") == 0; | 120 bool sequence = strcmp(argv[1], "sequence") == 0; |
121 bool batch = strncmp(argv[1], "batch=", strlen("batch=")) == 0; | 121 bool batch = strncmp(argv[1], "batch=", strlen("batch=")) == 0; |
122 bool overlapped = strncmp(argv[1], "overlapped=", strlen("overlapped=")) == 0; | 122 bool overlapped = strncmp(argv[1], "overlapped=", strlen("overlapped=")) == 0; |
123 if (!parallel && !sequence && !batch && !overlapped) PrintAndDie(argv); | 123 if (!parallel && !sequence && !batch && !overlapped) PrintAndDie(argv); |
124 | 124 |
125 int program_count = (argc - 2) / 2; | 125 int program_count = (argc - 2) / 2; |
126 FletchProgram* programs = new FletchProgram[program_count]; | 126 DartinoProgram* programs = new DartinoProgram[program_count]; |
127 int* expected_exit_codes = new int[program_count]; | 127 int* expected_exit_codes = new int[program_count]; |
128 for (int i = 0; i < program_count; i++) { | 128 for (int i = 0; i < program_count; i++) { |
129 List<uint8> bytes = Platform::LoadFile(argv[2 + 2 * i]); | 129 List<uint8> bytes = Platform::LoadFile(argv[2 + 2 * i]); |
130 if (bytes.is_empty()) FATAL("Invalid snapshot"); | 130 if (bytes.is_empty()) FATAL("Invalid snapshot"); |
131 programs[i] = FletchLoadSnapshot(bytes.data(), bytes.length()); | 131 programs[i] = DartinoLoadSnapshot(bytes.data(), bytes.length()); |
132 expected_exit_codes[i] = atoi(argv[2 + 2 * i + 1]); | 132 expected_exit_codes[i] = atoi(argv[2 + 2 * i + 1]); |
133 bytes.Delete(); | 133 bytes.Delete(); |
134 } | 134 } |
135 | 135 |
136 int* actual_exitcodes = new int[program_count]; | 136 int* actual_exitcodes = new int[program_count]; |
137 Runner runner(program_count, programs, actual_exitcodes); | 137 Runner runner(program_count, programs, actual_exitcodes); |
138 if (parallel) { | 138 if (parallel) { |
139 runner.RunInParallel(); | 139 runner.RunInParallel(); |
140 } else if (sequence) { | 140 } else if (sequence) { |
141 runner.RunInSequence(); | 141 runner.RunInSequence(); |
(...skipping 13 matching lines...) Expand all Loading... |
155 fprintf(stderr, "%s: Expected exitcode: %d, Actual exitcode: %d\n", | 155 fprintf(stderr, "%s: Expected exitcode: %d, Actual exitcode: %d\n", |
156 argv[2 + 2 * i], expected_exit_codes[i], actual_exitcodes[i]); | 156 argv[2 + 2 * i], expected_exit_codes[i], actual_exitcodes[i]); |
157 result++; | 157 result++; |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 delete[] actual_exitcodes; | 161 delete[] actual_exitcodes; |
162 delete[] expected_exit_codes; | 162 delete[] expected_exit_codes; |
163 delete[] programs; | 163 delete[] programs; |
164 | 164 |
165 FletchTearDown(); | 165 DartinoTearDown(); |
166 | 166 |
167 return result; | 167 return result; |
168 } | 168 } |
169 | 169 |
170 } // namespace fletch | 170 } // namespace dartino |
171 | 171 |
172 int main(int argc, char** argv) { return fletch::Main(argc, argv); } | 172 int main(int argc, char** argv) { return dartino::Main(argc, argv); } |
OLD | NEW |