Generated on for Gecode by doxygen 1.17.0
test.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
6 *
7 * Copyright:
8 * Christian Schulte, 2004
9 * Mikael Zayenz Lagerkvist, 2005
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.dev
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include "test/test.hh"
37
38#ifdef GECODE_HAS_MTRACE
39#include <mcheck.h>
40#endif
41
42#include <iostream>
43#include <iomanip>
44
45#include <cstdlib>
46#include <cstring>
47#include <ctime>
48#include <utility>
49#include <vector>
50
51namespace Test {
52
53 // Log stream
54 std::ostringstream olog;
55
58 const char* name;
60 };
61
63 static const TestTagDescription test_tag_descriptions[] = {
64 {"check", TestTag::check},
65 {"standard", TestTag::standard},
66 {"sweep", TestTag::sweep}
67 };
68
71 TestTags tags;
72 for (const TestTagDescription& description : test_tag_descriptions)
73 tags.add(description.tag);
74 return tags;
75 }
76
78 static TestTags
79 tag_set(const char* name) {
80 for (const TestTagDescription& description : test_tag_descriptions)
81 if (!strcmp(name, description.name))
82 return TestTags(description.tag);
83 if (!strcmp(name, "all"))
84 return TestTags::all();
85 return TestTags();
86 }
87
89 static void
90 print_tags(std::ostream& os) {
91 for (const TestTagDescription& description : test_tag_descriptions)
92 os << description.name << std::endl;
93 }
94
96 static std::string
97 tag_choices(void) {
98 std::string choices;
99 for (const TestTagDescription& description : test_tag_descriptions) {
100 if (!choices.empty())
101 choices += "|";
102 choices += description.name;
103 }
104 return choices + "|all";
105 }
106
108 static std::string
109 tags_to_string(TestTags tags) {
110 std::string s;
111 for (const TestTagDescription& description : test_tag_descriptions) {
112 if (tags.overlaps(TestTags(description.tag))) {
113 if (!s.empty())
114 s += ",";
115 s += description.name;
116 }
117 }
118 return s;
119 }
120
121 /*
122 * Base class for tests
123 *
124 */
125 Base::Base(std::string s)
126 : Base(s, TestTags::standard()) {}
127
128 Base::Base(std::string s, TestTags t)
129 : _name(std::move(s)), _tags(t), _next(_tests), _rand(Gecode::Support::RandomGenerator()) {
130 _tests = this; _n_tests++;
131 }
132
133 Base* Base::_tests = nullptr;
134 unsigned int Base::_n_tests = 0;
135
138 public:
139 forceinline bool
141 return x->name() > y->name();
142 }
143 };
144
145 void
147 Base** b = Gecode::heap.alloc<Base*>(_n_tests);
148 unsigned int i=0;
149 for (Base* t = _tests; t != nullptr; t = t->next())
150 b[i++] = t;
151 SortByName sbn;
152 Gecode::Support::quicksort(b, _n_tests,sbn);
153 i=0;
154 _tests = nullptr;
155 for ( ; i < _n_tests; i++) {
156 b[i]->next(_tests); _tests = b[i];
157 }
158 Gecode::heap.free(b,_n_tests);
159 }
160
161 Base::~Base() = default;
162
164 const int Options::defiter;
165 const unsigned int Options::deffixprob;
166
167 void report_error(const std::string& name, unsigned int seed, const Options& options, std::ostream& ostream) {
168 ostream << "Options: -replay " << seed;
169 if (options.fixprob != Test::Options::deffixprob)
170 ostream << " -fixprob " << options.fixprob;
171 ostream << " -test " << name << std::endl;
172 if (options.log)
173 ostream << olog.str();
174 }
175
176 void
177 Options::parse(int argc, char* argv[]) {
178 int i = 1;
179 while (i < argc) {
180 if (!strcmp(argv[i],"-help") || !strcmp(argv[i],"--help")) {
181 std::cerr << "Options for testing:" << std::endl
182 << "\t-threads (unsigned int) default: " << threads << std::endl
183 << "\t\tnumber of threads to use. If 0, as many threads as there are cores are used.\n"
184 << "\t\tThreaded execution and logging can not be used at the same time."
185 << std::endl
186 << "\t-seed (unsigned int or \"time\") default: "
187 << seed << std::endl
188 << "\t\tseed for random number generator (unsigned int),"
189 << std::endl
190 << "\t\tor \"time\" for a random seed based on "
191 << "current time" << std::endl
192 << "\t-replay (unsigned int)\n"
193 << "\t\treplay the exact -test name once, on one thread\n"
194 << "\t-fixprob (unsigned int) default: "
195 << fixprob << std::endl
196 << "\t\t1/fixprob is the probability of computing a fixpoint"
197 << std::endl
198 << "\t-iter (unsigned int) default: " <<iter<< std::endl
199 << "\t\tthe number of iterations" << std::endl
200 << "\t-test (string) default: (none)" << std::endl
201 << "\t\tsimple pattern for the tests to run" << std::endl
202 << "\t\tprefixing with \"-\" negates the pattern" << std::endl
203 << "\t\tprefixing with \"^\" requires a match at the beginning" << std::endl
204 << "\t\tmultiple pattern-options may be given"
205 << std::endl
206 << "\t-tag (" << tag_choices() << ") default: (none)" << std::endl
207 << "\t\ttag for the tests to run" << std::endl
208 << "\t\tmultiple tag-options may be given"
209 << std::endl
210 << "\t-start (string) default: (none)" << std::endl
211 << "\t\tsimple pattern for the first test to run" << std::endl
212 << "\t-log"
213 << std::endl
214 << "\t\tlog execution of tests"
215 << std::endl
216 << "\t\tthe optional argument determines the style of the log"
217 << std::endl
218 << "\t\twith text as the default style"
219 << std::endl
220 << "\t-stop (boolean) default: "
221 << (stop ? "true" : "false") << std::endl
222 << "\t\tstop on first error or continue" << std::endl
223 << "\t-list" << std::endl
224 << "\t\toutput list of all test cases and exit" << std::endl
225 << "\t-list-tags" << std::endl
226 << "\t\toutput list of known test tags and exit" << std::endl
227 << "\t-list-with-tags" << std::endl
228 << "\t\toutput list of all test cases with tags and exit" << std::endl
229 ;
230 exit(EXIT_SUCCESS);
231 } else if (!strcmp(argv[i],"-threads")) {
232 if (++i == argc) goto missing;
233 unsigned int argument = static_cast<unsigned int>(atoi(argv[i]));
234 if (argument == 0) {
236 } else {
237 threads = argument;
238 }
239 } else if (!strcmp(argv[i],"-seed") || !strcmp(argv[i],"-replay")) {
240 replay = !strcmp(argv[i],"-replay");
241 if (++i == argc) goto missing;
242 if (!strcmp(argv[i],"time")) {
243 seed = static_cast<unsigned int>(time(nullptr));
244 } else {
245 seed = static_cast<unsigned int>(atoi(argv[i]));
246 }
247 } else if (!strcmp(argv[i],"-iter")) {
248 if (++i == argc) goto missing;
249 iter = static_cast<unsigned int>(atoi(argv[i]));
250 } else if (!strcmp(argv[i],"-fixprob")) {
251 if (++i == argc) goto missing;
252 fixprob = static_cast<unsigned int>(atoi(argv[i]));
253 } else if (!strcmp(argv[i],"-test")) {
254 if (++i == argc) goto missing;
255 if (argv[i][0] == '^')
256 testpat.emplace_back(MT_FIRST, argv[i] + 1);
257 else if (argv[i][0] == '-')
258 testpat.emplace_back(MT_NOT, argv[i] + 1);
259 else
260 testpat.emplace_back(MT_ANY, argv[i]);
261 } else if (!strcmp(argv[i],"-tag")) {
262 if (++i == argc) goto missing;
263 TestTags tag = tag_set(argv[i]);
264 if (tag.empty()) {
265 std::cerr << "Erroneous argument (-tag)" << std::endl
266 << " unknown tag: " << argv[i] << std::endl;
267 exit(EXIT_FAILURE);
268 }
269 testtags.add(tag);
270 } else if (!strcmp(argv[i],"-start")) {
271 if (++i == argc) goto missing;
272 start_from = argv[i];
273 } else if (!strcmp(argv[i],"-log")) {
274 log = true;
275 } else if (!strcmp(argv[i],"-stop")) {
276 if (++i == argc) goto missing;
277 if(argv[i][0] == 't') {
278 stop = true;
279 } else if (argv[i][0] == 'f') {
280 stop = false;
281 }
282 } else if (!strcmp(argv[i],"-list")) {
283 list = true;
284 } else if (!strcmp(argv[i],"-list-tags")) {
285 list_tags = true;
286 } else if (!strcmp(argv[i],"-list-with-tags")) {
287 list_with_tags = true;
288 }
289 i++;
290 }
291
292 if (replay) {
293 if (testpat.size() != 1 || testpat[0].first != MT_ANY ||
294 start_from != nullptr) {
295 std::cerr << "-replay requires one exact -test name." << std::endl;
296 exit(EXIT_FAILURE);
297 }
298 threads = 1;
299 iter = 1;
300 }
301
302 if (threads > 1 && log) {
303 std::cerr << "Logging and multi threading can not be used jointly." << std::endl;
304 exit(EXIT_FAILURE);
305 }
306
307 return;
308 missing:
309 std::cerr << "Erroneous argument (" << argv[i-1] << ")" << std::endl
310 << " missing parameter" << std::endl;
311 exit(EXIT_FAILURE);
312 }
313
314 bool Options::is_test_name_matching(const std::string& test_name) const {
315 if (replay)
316 return testpat.size() == 1 && test_name == testpat[0].second;
317 if (!testpat.empty()) {
318 bool positive_patterns = false;
319 bool match_found = false;
320 for (const auto& type_pattern: testpat) {
321 const auto& type = type_pattern.first;
322 const auto& pattern = type_pattern.second;
323 if (type == MT_NOT) { // Negative pattern
324 if (test_name.find(pattern) != std::string::npos) {
325 // Test matches a negative pattern, should not run
326 return false;
327 }
328 } else {
329 // Positive pattern
330 positive_patterns = true;
331 if (!match_found) {
332 // No match found yet, test with current pattern
333 if (((type == MT_ANY) && (test_name.find(pattern) != std::string::npos)) ||
334 ((type == MT_FIRST) && (test_name.find(pattern) == 0)))
335 match_found = true;
336 }
337 }
338 }
339
340 if (positive_patterns && match_found) {
341 // Some positive pattern matched the test name
342 return true;
343 } else if (positive_patterns && !match_found) {
344 // No positive pattern matched the test name
345 return false;
346 } else {
347 // No positive patterns, but no negative pattern ruled the test name out
348 return true;
349 }
350 } else {
351 // With no test-patterns, all tests should run.
352 return true;
353 }
354 }
355
357 return testtags.empty() || tags.overlaps(testtags);
358 }
359
361 bool run_test(Base* test, unsigned int test_seed, const Options& options, std::ostream& ostream) {
362 unsigned int seed = options.replay ? options.seed : test_seed;
363 try {
364 ostream << test->name() << " ";
365 ostream.flush();
366 test->_rand.seed(seed);
367 for (unsigned int i = options.iter; i--;) {
368 // Normalize evolved states so the reported seed restores this iteration.
369 test->_rand.seed(test->_rand.seed());
370 seed = test->_rand.seed();
371 if (test->run()) {
372 ostream << '+';
373 ostream.flush();
374 } else {
375 ostream << "-" << std::endl;
376 report_error(test->name(), seed, options, ostream);
377 return false;
378 }
379 }
380 ostream << std::endl;
381 return true;
382 } catch (Gecode::Exception& e) {
383 ostream << "Exception in \"Gecode::" << e.what()
384 << "." << std::endl
385 << "Stopping..." << std::endl;
386 report_error(test->name(), seed, options, ostream);
387 return false;
388 }
389 }
390
392 void print_test_summary(size_t selected, size_t passed, size_t failed) {
393 const size_t ran = passed + failed;
394 std::cout << "\nTest summary: " << selected << " selected, "
395 << ran << " ran, " << passed << " passed, "
396 << failed << " failed, " << selected - ran << " not run."
397 << std::endl;
398 }
399
401 int run_tests(const std::vector<Base*>& tests, const Options& options) {
402 Gecode::Support::RandomGenerator seed_sequence(options.seed);
403 size_t passed = 0;
404 size_t failed = 0;
405 for (auto test : tests) {
406 unsigned int test_seed = seed_sequence.next();
407 if (run_test(test, test_seed, options, std::cout)) {
408 ++passed;
409 } else {
410 ++failed;
411 if (options.stop)
412 break;
413 }
414 }
415 print_test_summary(tests.size(), passed, failed);
416 return failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
417 }
418
419 class TestExecutor;
420
426 const std::vector<Base*>& tests;
428 const Options& options;
430 Gecode::Support::Mutex output_mutex;
432 std::atomic<size_t> next_tests;
434 std::atomic<size_t> passed;
435 std::atomic<size_t> failed;
437 std::atomic<int> running_threads;
439 std::atomic<bool> execution_done_wait_started;
441 Gecode::Support::Event execution_done_event;
442
443 friend class TestExecutor;
444
446 static size_t choose_batch_size(size_t test_count, int thread_count) {
447 const int batches_per_thread = 5;
448 std::vector<size_t> batch_sizes = {25, 10, 5, 2};
449 for (auto batch_size : batch_sizes) {
450 if (test_count > batch_size * thread_count * batches_per_thread) {
451 return batch_size;
452 }
453 }
454 return 1;
455 }
456
457 public:
458 TestExecutionControl(const std::vector<Base*>& tests0, const Options& options0, int thread_count)
459 : tests(tests0), options(options0), output_mutex(),
460 next_tests(0), passed(0), failed(0), running_threads(thread_count),
461 execution_done_wait_started(false), execution_done_event() {}
462
465 assert(running_threads.load() == 0);
466 print_test_summary(tests.size(), passed.load(), failed.load());
467 return failed.load() == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
468 }
469
475#ifndef NDEBUG
476 bool some_waiting =
477#endif
478 execution_done_wait_started.exchange(true);
479 assert(some_waiting == false && "Only one thread is allowed to await the result");
480 execution_done_event.wait();
481 }
482 private:
484 void record_result(bool success) {
485 if (success)
486 ++passed;
487 else
488 ++failed;
489 }
490
492 void thread_done() {
493 if (running_threads.fetch_sub(1) == 1) {
494 execution_done_event.signal();
495 }
496 }
497
500 std::pair<size_t, size_t> next_batch() {
501 const size_t current_start = next_tests.load();
502 const size_t batch_size = choose_batch_size(tests.size() - current_start, running_threads);
503 const size_t next_start = next_tests.fetch_add(batch_size);
504 return std::make_pair(next_start, batch_size);
505 }
506
508 bool continue_testing() {
509 // Note: implementation should be cheap to call form multiple threads often
510 return !options.stop || failed.load() == 0;
511 }
512
514 void write_output(std::string output) {
515 Gecode::Support::Lock lock(output_mutex);
516 std::cout << output;
517 std::cout.flush();
518 }
519 };
520
528 const int initial_seed;
529 public:
530
531 TestExecutor(TestExecutionControl& tec, const int initialSeed)
532 : tec(tec), initial_seed(initialSeed) {}
533
534 void run(void) override {
535 // Set up a local source of randomness seeds based on the initial seed supplied.
536 Gecode::Support::RandomGenerator seed_sequence(initial_seed);
537
538 // Loop runs tests continuously in batches from the test execution control
539 while (true) {
540 // Get next batch
541 const std::pair<size_t, size_t>& start_and_size = tec.next_batch();
542 const size_t batch_start = start_and_size.first;
543 const size_t batch_size = start_and_size.second;
544 if (batch_start >= tec.tests.size()) {
545 // No more tests to run
546 break;
547 }
548 // Run each test in the batch, handling output and failures
549 for (size_t i = batch_start; i < batch_start + batch_size && i < tec.tests.size(); ++i) {
550 if (!tec.continue_testing()) {
551 break;
552 }
553 auto test = tec.tests[i];
554 unsigned int test_seed = seed_sequence.next();
555 std::ostringstream test_output;
556 tec.record_result(run_test(test, test_seed, tec.options, test_output));
557 tec.write_output(test_output.str());
558 }
559 if (!tec.continue_testing()) {
560 break;
561 }
562 }
563
564 // Signal that this thread is done. Last one signals the waiting main thread.
565 tec.thread_done();
566 }
567 };
568
570 int run_tests_parallel(const std::vector<Base*>& tests, const Options& options) {
571 using namespace Gecode::Support;
572 RandomGenerator seed_sequence(options.seed);
573
574 TestExecutionControl tec(tests, options, options.threads);
575
576 for (unsigned int i = 0; i < options.threads; ++i) {
577 Thread::run(new TestExecutor(tec, seed_sequence.next()));
578 }
580
581 return tec.report_result();
582 }
583
584 std::vector<Base*> select_tests(const Options& options) {
585 std::vector<Base*> tests;
586 bool started = options.start_from == nullptr;
587 for (Base* t = Base::tests(); t != nullptr; t = t->next()) {
588 if (!started) {
589 if (t->name().find(options.start_from) != std::string::npos) {
590 started = true;
591 } else {
592 continue;
593 }
594 }
595 if (options.is_test_name_matching(t->name()) &&
596 options.is_test_tags_matching(t->tags())) {
597 tests.emplace_back(t);
598 }
599 }
600 return tests;
601 }
602
603 int run_registered_tests(int argc, char* argv[]) {
604 opt = Options();
605 opt.parse(argc, argv);
606
607 if (opt.list_tags) {
608 print_tags(std::cout);
609 return EXIT_SUCCESS;
610 }
611
612 Base::sort();
613
614 if (opt.list || opt.list_with_tags) {
615 for (Base* t = Base::tests(); t != nullptr; t = t->next()) {
616 std::cout << t->name();
617 if (opt.list_with_tags)
618 std::cout << " [" << tags_to_string(t->tags()) << "]";
619 std::cout << std::endl;
620 }
621 return EXIT_SUCCESS;
622 }
623
624 const std::vector<Base*> tests = select_tests(opt);
625 if (opt.replay && tests.size() != 1) {
626 std::cerr << "-replay requires exactly one registered test." << std::endl;
627 return EXIT_FAILURE;
628 }
630 timer.start();
631 const int result = opt.threads > 1 ?
633 std::ostringstream elapsed;
634 elapsed << std::fixed << std::setprecision(3) << timer.stop() / 1000.0;
635 std::cout << "Elapsed time: " << elapsed.str() << " s." << std::endl;
636 return result;
637 }
638}
639
640std::ostream&
641operator<<(std::ostream& os, const Test::ind& i) {
642 for (int j=i.l; j--; )
643 os << " ";
644 return os;
645}
646
647// STATISTICS: test-core
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1606
Exception: Base-class for exceptions
Definition exception.hpp:42
virtual const char * what(void) const noexcept
Return information.
Definition exception.cpp:55
An event for synchronization.
Definition thread.hpp:138
void signal(void)
Signal the event.
Definition thread.hpp:133
unsigned int next(void)
Generate next number in series.
Definition random.hpp:92
void seed(unsigned int s)
Set the current seed to s.
Definition random.hpp:100
A mutex for mutual exclausion among several threads.
Definition thread.hpp:78
An interface for objects that can be run by a thread.
Definition thread.hpp:181
static void run(Runnable *r)
Construct a new thread and run r.
Definition thread.hpp:177
static unsigned int npu(void)
Return number of processing units (1 if information not available).
Definition thread.hpp:164
double stop(void)
Get time since start of timer.
Definition timer.hpp:63
void start(void)
Start timer.
Definition timer.hpp:58
Base class for all tests to be run
Definition test.hh:186
Gecode::Support::RandomGenerator _rand
Random number generator.
Definition test.hh:238
Base(std::string s)
Create and register a standard test with name s.
Definition test.cpp:125
static Base * tests(void)
Return all tests.
Definition test.hpp:99
virtual ~Base(void)
Destructor.
virtual bool run(void)=0
Run test.
const std::string & name(void) const
Return name of test.
Definition test.hpp:91
static void sort(void)
Sort tests alphabetically.
Definition test.cpp:146
Commandline options.
Definition test.hh:133
bool list_tags
Whether to list known tags.
Definition test.hh:162
std::vector< std::pair< MatchType, const char * > > testpat
Patterns to test against.
Definition test.hh:154
bool is_test_name_matching(const std::string &test_name) const
Test whether a test name should be executed.
Definition test.cpp:314
void parse(int argc, char *argv[])
Parse commandline arguments.
Definition test.cpp:177
bool log
Whether to log the tests.
Definition test.hh:152
unsigned int seed
The random seed to be used.
Definition test.hh:138
const char * start_from
Name of first test to start with.
Definition test.hh:158
bool is_test_tags_matching(TestTags tags) const
True iff test tags should be executed according to the requested tags. With no tag request,...
Definition test.cpp:356
static const unsigned int deffixprob
Default fixpoint probability.
Definition test.hh:148
bool replay
Replay one named test from its reported random state.
Definition test.hh:140
bool list
Whether to list all tests.
Definition test.hh:160
unsigned int iter
Number of iterations for each test.
Definition test.hh:142
bool stop
Whether to stop on an error.
Definition test.hh:150
unsigned int threads
Number of threads to use.
Definition test.hh:136
unsigned int fixprob
The probability for computing a fixpoint.
Definition test.hh:146
static const int defiter
Default number of iterations.
Definition test.hh:144
TestTags testtags
Tags to test against.
Definition test.hh:156
bool list_with_tags
Whether to include tags when listing tests.
Definition test.hh:164
Sort tests by name.
Definition test.cpp:137
bool operator()(Base *x, Base *y)
Definition test.cpp:140
friend class TestExecutor
Definition test.cpp:443
int report_result()
Report the results after all threads have finished and return the exit status.
Definition test.cpp:464
TestExecutionControl(const std::vector< Base * > &tests0, const Options &options0, int thread_count)
Definition test.cpp:458
void await_test_runners_completed()
Definition test.cpp:474
TestExecutor(TestExecutionControl &tec, const int initialSeed)
Definition test.cpp:531
void run(void) override
The function that is executed when the thread starts.
Definition test.cpp:534
Set of test tags.
Definition test.hh:105
static TestTags all(void)
Return set with all known tags.
Definition test.cpp:70
void add(TestTags t)
Add tags t.
Definition test.hpp:71
bool overlaps(TestTags t) const
Whether this set contains any tag from t.
Definition test.hpp:67
bool empty(void) const
Whether no tags are set.
Definition test.hpp:63
TestTags(void)
Initialize with no tags.
Definition test.hpp:41
Simple class for describing indentation.
Definition test.hh:82
Heap heap
The single global heap.
Definition heap.cpp:44
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
Support algorithms and datastructures
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Definition sort.hpp:130
Gecode toplevel namespace
Case output("Data::Output", [](void) { Data d=read("n: int f: float w: word m[2][2]: int repeat n { k: int x[k]: int }", "2 20 a 1 2 3 4 1 5 2 6 7");std::ostringstream z;d.dzn(z);CHECK(z.str().find("f = 20.0;") !=std::string::npos);CHECK(z.str().find("m = [| 1, 2\n | 3, 4 |];") !=std::string::npos);CHECK(z.str().find("% x: array[int] of tuple(array[int] of int)\n" "x = [([5],), ([6, 7],)];") !=std::string::npos);CHECK(z.str().find("w = \"a\";") !=std::string::npos);std::ostringstream zq;read("var: int w: word", "3 a\033b").dzn(zq);CHECK(zq.str().find("'var' = 3;") !=std::string::npos);CHECK(zq.str().find("w = \"a\\x1bb\";") !=std::string::npos);Data e=read("e[2][0]: int repeat 2 { k: int repeat k { list y: int until 0 } }", "1 7 0 2 8 9 0 0");std::ostringstream ze;e.dzn(ze);CHECK(ze.str().find("e = array2d(1..2, 1..0, []);") !=std::string::npos);CHECK(ze.str().find("y = [([([7],)],), ([([8, 9],), ([],)],)];") !=std::string::npos);std::ostringstream z7;read("a[1][1][1][1][1][1][1]: int", "5").dzn(z7);CHECK(z7.str().find("a = [([([([([([([5],)],)],)],)],)],)];") !=std::string::npos);return true;})
General test support.
Definition afc.cpp:41
void print_test_summary(size_t selected, size_t passed, size_t failed)
Report test cases; iterations of a test count as one case.
Definition test.cpp:392
std::ostringstream olog
Stream used for logging.
Definition test.cpp:54
std::vector< Base * > select_tests(const Options &options)
Definition test.cpp:584
@ MT_FIRST
Definition test.hh:94
@ MT_ANY
Definition test.hh:92
@ MT_NOT
Definition test.hh:93
int run_tests(const std::vector< Base * > &tests, const Options &options)
Run all the tests with the supplied options.
Definition test.cpp:401
int run_registered_tests(int argc, char *argv[])
Definition test.cpp:603
bool run_test(Base *test, unsigned int test_seed, const Options &options, std::ostream &ostream)
Run a single test, returning true iff the test succeeded.
Definition test.cpp:361
TestTag
Tags for test selection.
Definition test.hh:98
@ check
Basic integrity tests.
Definition test.hh:99
@ standard
Standard test suite.
Definition test.hh:100
@ sweep
Really heavy sweep tests.
Definition test.hh:101
Options opt
The options.
Definition test.cpp:163
void report_error(const std::string &name, unsigned int seed, const Options &options, std::ostream &ostream)
Definition test.cpp:167
int run_tests_parallel(const std::vector< Base * > &tests, const Options &options)
Run all the tests with the supplied options in parallel.
Definition test.cpp:570
A command-line name and its corresponding test tag.
Definition test.cpp:57
const char * name
Definition test.cpp:58
#define forceinline
Definition config.hpp:144
std::ostream & operator<<(std::ostream &os, const Test::ind &i)
Definition test.cpp:641