Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to activate coverity for simgrid
[simgrid.git] / teshsuite / surf / trace_usage / trace_usage.c
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/trace_mgr.h"
10 #include "surf/surf.h"
11
12 #include "xbt/log.h"
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test,
19                              "Messages specific for surf example");
20
21 void test(void);
22 void test(void)
23 {
24   tmgr_history_t history = tmgr_history_new();
25   tmgr_trace_t trace_A = tmgr_trace_new_from_file("trace_A.txt");
26   tmgr_trace_t trace_B = tmgr_trace_new_from_file("trace_B.txt");
27   double next_event_date = -1.0;
28   double value = -1.0;
29   char *resource = NULL;
30   char *host_A = strdup("Host A");
31   char *host_B = strdup("Host B");
32
33   tmgr_history_add_trace(history, trace_A, 1.0, 2, host_A);
34   tmgr_history_add_trace(history, trace_B, 0.0, 0, host_B);
35
36   while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
37     XBT_DEBUG("%g" " : \n", next_event_date);
38     while (tmgr_history_get_next_event_leq(history, next_event_date,
39                                            &value, (void **) &resource)) {
40       XBT_DEBUG("\t %s : " "%g" "\n", resource, value);
41     }
42     if (next_event_date > 1000)
43       break;
44   }
45
46   tmgr_history_free(history);
47   free(host_B);
48   free(host_A);
49 }
50
51 int main(int argc, char **argv)
52 {
53   surf_init(&argc, argv);
54   test();
55   surf_exit();
56   return 0;
57 }