Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sanitize the surf API
[simgrid.git] / teshsuite / surf / trace_usage / trace_usage.cpp
1 /* A few tests for the trace library                                       */
2
3 /* Copyright (c) 2004-2006, 2009-2015. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "surf/surf.h"
10
11 #include "xbt/log.h"
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include "src/surf/network_cm02.hpp"
17 #include "src/surf/trace_mgr.hpp"
18
19 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
20                              "Messages specific for surf example");
21
22 class DummyTestResource
23     : public simgrid::surf::Resource {
24 public:
25   DummyTestResource(const char *name) : Resource(nullptr,name) {}
26   bool isUsed() override {return false;}
27   void updateState(tmgr_trace_iterator_t it, double value) override {}
28 };
29
30 static void test(void)
31 {
32   simgrid::trace_mgr::future_evt_set *fes = new simgrid::trace_mgr::future_evt_set();
33   tmgr_trace_t trace_A = tmgr_trace_new_from_file("trace_A.txt");
34   tmgr_trace_t trace_B = tmgr_trace_new_from_file("trace_B.txt");
35   double next_event_date = -1.0;
36   double value = -1.0;
37   simgrid::surf::Resource *resource = NULL;
38   simgrid::surf::Resource *hostA = new DummyTestResource("Host A");
39   simgrid::surf::Resource *hostB = new DummyTestResource("Host B");
40
41   fes->add_trace(trace_A, 1.0, hostA);
42   fes->add_trace(trace_B, 0.0, hostB);
43
44   while ((next_event_date = fes->next_date()) != -1.0) {
45     XBT_DEBUG("%g" " : \n", next_event_date);
46     while (fes->pop_leq(next_event_date, &value, &resource)) {
47       XBT_DEBUG("\t %s : " "%g" "\n", resource->getName(), value);
48     }
49     if (next_event_date > 1000)
50       break;
51   }
52
53   delete fes;
54   delete hostA;
55   delete hostB;
56 }
57
58 int main(int argc, char **argv)
59 {
60   surf_init(&argc, argv);
61   test();
62   surf_exit();
63   return 0;
64 }