Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smells -= a lot
[simgrid.git] / teshsuite / simdag / basic-parsing-test / basic-parsing-test.c
1 /* Copyright (c) 2008-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include "simgrid/simdag.h"
9
10 int main(int argc, char **argv)
11 {
12   SD_init(&argc, argv);
13
14   /* creation of the environment */
15   SD_create_environment(argv[1]);
16   fprintf(stderr, "Workstation number: %zu, link number: %d\n", sg_host_count(), sg_link_count());
17
18   sg_host_t *hosts = sg_host_list();
19   if (argc >= 3) {
20     if (!strcmp(argv[2], "ONE_LINK")) {
21       sg_host_t h1 = hosts[0];
22       sg_host_t h2 = hosts[1];
23       const char *name1 = sg_host_get_name(h1);
24       const char *name2 = sg_host_get_name(h2);
25
26       fprintf(stderr, "Route between %s and %s\n", name1, name2);
27       xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL);
28       sg_host_route(h1, h2, route);
29       fprintf(stderr, "Route size %lu\n", xbt_dynar_length(route));
30       unsigned int i;
31       SD_link_t link;
32       xbt_dynar_foreach(route, i, link)
33         fprintf(stderr, "  Link %s: latency = %f, bandwidth = %f\n", sg_link_name(link),
34                sg_link_latency(link), sg_link_bandwidth(link));
35       fprintf(stderr, "Route latency = %f, route bandwidth = %f\n",
36              sg_host_route_latency(h1, h2), sg_host_route_bandwidth(h1, h2));
37       xbt_dynar_free_container(&route);
38     }
39     if (!strcmp(argv[2], "FULL_LINK")) {
40       int list_size = sg_host_count();
41       for (int i = 0; i < list_size; i++) {
42         sg_host_t h1 = hosts[i];
43         const char *name1 = sg_host_get_name(h1);
44         for (int j = 0; j < list_size; j++) {
45           sg_host_t h2 = hosts[j];
46           const char *name2 = sg_host_get_name(h2);
47           fprintf(stderr, "Route between %s and %s\n", name1, name2);
48           xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL);
49           sg_host_route(h1, h2, route);
50           fprintf(stderr, "  Route size %lu\n", xbt_dynar_length(route));
51           unsigned int k;
52           SD_link_t link;
53           xbt_dynar_foreach(route, k, link)
54             fprintf(stderr, "  Link %s: latency = %f, bandwidth = %f\n",
55                 sg_link_name(link), sg_link_latency(link), sg_link_bandwidth(link));
56           fprintf(stderr, "  Route latency = %f, route bandwidth = %f\n",
57                  sg_host_route_latency(h1, h2), sg_host_route_bandwidth(h1, h2));
58           xbt_dynar_free_container(&route);
59         }
60       }
61     }
62     if (!strcmp(argv[2], "PROP"))
63       fprintf(stderr,"SG_TEST_mem: %s\n", sg_host_get_property_value(sg_host_by_name("host1"), "SG_TEST_mem"));
64   }
65   xbt_free(hosts);
66
67   SD_exit();
68   return 0;
69 }