Logo AND Algorithmique Numérique Distribuée

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