Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SURF: Embeed every fields of common_public directly into s_surf_model_t
[simgrid.git] / testsuite / surf / trace_usage.c
1 /*      $Id$     */
2
3 /* A few tests for the trace library                                       */
4
5 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9 #ifdef __BORLANDC__
10 #pragma hdrstop
11 #endif
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include "surf/trace_mgr.h"
17 #include "surf/surf.h"
18
19 #include "xbt/log.h"
20 XBT_LOG_NEW_DEFAULT_CATEGORY(surf_test, "Messages specific for surf example");
21
22 void test(void);
23 void test(void)
24 {
25   tmgr_history_t history = tmgr_history_new();
26   tmgr_trace_t trace_A = tmgr_trace_new("trace_A.txt");
27   tmgr_trace_t trace_B = tmgr_trace_new("trace_B.txt");
28   double next_event_date = -1.0;
29   double value = -1.0;
30   char *resource = NULL;
31   char *host_A = strdup("Host A");
32   char *host_B = strdup("Host B");
33
34   tmgr_history_add_trace(history, trace_A, 1.0, 2, host_A);
35   tmgr_history_add_trace(history, trace_B, 0.0, 0, host_B);
36
37   while ((next_event_date = tmgr_history_next_date(history)) != -1.0) {
38     DEBUG1("%g" " : \n", next_event_date);
39     while (tmgr_history_get_next_event_leq(history, next_event_date,
40                                            &value, (void **) &resource)) {
41       DEBUG2("\t %s : " "%g" "\n", resource, value);
42     }
43     if (next_event_date > 1000)
44       break;
45   }
46
47   tmgr_history_free(history);
48   free(host_B);
49   free(host_A);
50 }
51
52 #ifdef __BORLANDC__
53 #pragma argsused
54 #endif
55
56
57 int main(int argc, char **argv)
58 {
59   surf_init(&argc, argv);
60   test();
61   surf_exit();
62   return 0;
63 }