File: catch_simgrid.cpp

package info (click to toggle)
simgrid 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,192 kB
  • sloc: cpp: 124,913; ansic: 66,744; python: 8,560; java: 6,773; fortran: 6,079; f90: 5,123; xml: 4,587; sh: 2,194; perl: 1,436; makefile: 111; lisp: 49; javascript: 7; sed: 6
file content (72 lines) | stat: -rw-r--r-- 2,564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright (c) 2010-2025. The SimGrid Team. All rights reserved.          */

/* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */

#define CATCH_CONFIG_RUNNER // we supply our own main()

#include "teshsuite/catch_simgrid.hpp"

#include <xbt/config.hpp>

XBT_LOG_NEW_CATEGORY(s4u_test, "Messages specific for this s4u example");

std::vector<simgrid::s4u::Host*> all_hosts;

/* Helper function easing the testing of actor's ending condition */
void assert_exit(bool exp_success, double duration)
{
  double expected_time = simgrid::s4u::Engine::get_clock() + duration;
  simgrid::s4u::this_actor::on_exit([exp_success, expected_time](bool got_failed) {
    XBT_VERB("Running checks on exit");
    INFO("Check exit status. Expected: " << exp_success);
    REQUIRE(exp_success == not got_failed);
    INFO("Check date at exit. Expected: " + std::to_string(expected_time));
    REQUIRE(simgrid::s4u::Engine::get_clock() == Approx(expected_time));
    XBT_VERB("Checks on exit successful");
  });
}

/* Helper function in charge of doing some sanity checks after each test */
void assert_cleanup()
{
  /* Check that no actor remain (but on host[0], where main_dispatcher lives */
  for (unsigned int i = 0; i < all_hosts.size(); i++) {
    std::vector<simgrid::s4u::ActorPtr> all_actors = all_hosts[i]->get_all_actors();
    unsigned int expected_count = (i == 0) ? 1 : 0; // host[0] contains main_dispatcher, all other are empty
    if (all_actors.size() != expected_count) {
      INFO("Host " << all_hosts[i]->get_cname() << " contains " << all_actors.size() << " actors but " << expected_count
                   << " are expected (i=" << i << "). Existing actors: ");
      for (auto act : all_actors)
        UNSCOPED_INFO(" - " << act->get_cname());
      FAIL("This is wrong");
    }
  }
  // TODO: Check that all LMM are empty
}

int main(int argc, char* argv[])
{
  simgrid::config::set_value("help-nostop", true);
  simgrid::s4u::Engine e(&argc, argv);

  std::string platf;
  if (argc > 1) {
    platf   = argv[1];
    argv[1] = argv[0];
    argv++;
    argc--;
  } else {
    XBT_WARN("No platform file provided. Using './testing_platform.xml'");
    platf = "./testing_platform.xml";
  }
  e.load_platform(platf);

  int status = 42;
  all_hosts  = e.get_all_hosts();
  all_hosts[0]->add_actor("main_dispatcher", [&argc, &argv, &status]() { status = Catch::Session().run(argc, argv); });

  e.run();
  XBT_INFO("Simulation done");
  return status;
}