Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'coverity_scan' of github.com:mquinson/simgrid
[simgrid.git] / examples / simdag / dot / dot_test2.c
1 /* simple test trying to load a DOT file.                                   */
2
3 /* Copyright (c) 2010-2016. 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 <stdlib.h>
10 #include <stdio.h>
11 #include "simgrid/simdag.h"
12 #include "xbt/log.h"
13 #include "xbt/ex.h"
14 #include <string.h>
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Logging specific to this SimDag example");
17
18 int main(int argc, char **argv)
19 {
20   xbt_dynar_t dot;
21   unsigned int cursor;
22   SD_task_t task, *dot_as_array=NULL;
23
24   /* SD initialization */
25   SD_init(&argc, argv);
26
27   /* Check our arguments */
28   xbt_assert(argc > 1, "Usage: %s dot_file", argv[0]);
29
30   /* load the DOT file */
31   dot = SD_dotload(argv[1]);
32
33   /* Display all the tasks */
34   XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
35   xbt_dynar_foreach(dot, cursor, task) {
36       SD_task_dump(task);
37     }
38
39   XBT_INFO("--------------------- Transform the dynar into an array ---------------------------");
40   cursor=0;
41   dot_as_array = (SD_task_t*) xbt_dynar_to_array(dot);
42   XBT_INFO("----------------------------- dump tasks again ------------------------------------");
43   while ((task=dot_as_array[cursor++])){
44     SD_task_dump(task);
45   }
46
47   cursor=0;
48   while ((task=dot_as_array[cursor++])){
49     SD_task_destroy(task);
50   }
51
52   free(dot_as_array);
53
54   /* exit */
55   SD_exit();
56   return 0;
57 }