Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / catch_simgrid.hpp
1 /* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef ACTIVITY_LIFECYCLE_HPP
7 #define ACTIVITY_LIFECYCLE_HPP
8
9 #include "src/3rd-party/catch.hpp"
10
11 #include <simgrid/s4u.hpp>
12 #include <xbt/log.h>
13
14 #include <vector>
15
16 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(s4u_test);
17
18 extern std::vector<simgrid::s4u::Host*> all_hosts;
19
20 /* Helper function easing the testing of actor's ending condition */
21 extern void assert_exit(bool exp_success, double duration);
22
23 /* Helper function in charge of doing some sanity checks after each test */
24 extern void assert_cleanup();
25
26 /* We need an extra actor here, so that it can sleep until the end of each test */
27 #define BEGIN_SECTION(descr)                                                                                           \
28   SECTION(descr)                                                                                                       \
29   { simgrid::s4u::Actor::create(descr, all_hosts[0], []()
30 #define END_SECTION                                                                                                    \
31   })
32
33 #define RUN_SECTION(descr, ...) SECTION(descr) simgrid::s4u::Actor::create(descr, all_hosts[0], __VA_ARGS__)
34
35 // Normally, we should be able use Catch2's REQUIRE_THROWS_AS(...), but it generates errors with Address Sanitizer.
36 // They're certainly false positive. Nevermind and use this simpler replacement.
37 #define REQUIRE_NETWORK_FAILURE(...)                                                                                   \
38   do {                                                                                                                 \
39     try {                                                                                                              \
40       __VA_ARGS__;                                                                                                     \
41       FAIL("Expected exception NetworkFailureException not caught");                                                   \
42     } catch (simgrid::NetworkFailureException const&) {                                                                \
43       XBT_VERB("got expected NetworkFailureException");                                                                \
44     }                                                                                                                  \
45   } while (0)
46
47 #endif // ACTIVITY_LIFECYCLE_HPP