Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / teshsuite / simdag / basic-parsing-test / basic-parsing-test.c
1 /* Copyright (c) 2008-2021. 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 static void test_one_link(const sg_host_t* hosts)
11 {
12   const_sg_host_t h1 = hosts[0];
13   const_sg_host_t h2 = hosts[1];
14   const char* name1  = sg_host_get_name(h1);
15   const char* name2  = sg_host_get_name(h2);
16
17   fprintf(stderr, "Route between %s and %s\n", name1, name2);
18   xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL);
19   sg_host_get_route(h1, h2, route);
20   fprintf(stderr, "Route size %lu\n", xbt_dynar_length(route));
21   unsigned int i;
22   SD_link_t link;
23   xbt_dynar_foreach (route, i, link)
24     fprintf(stderr, "  Link %s: latency = %f, bandwidth = %f\n", sg_link_get_name(link), sg_link_get_latency(link),
25             sg_link_get_bandwidth(link));
26   fprintf(stderr, "Route latency = %f, route bandwidth = %f\n", sg_host_get_route_latency(h1, h2),
27           sg_host_get_route_bandwidth(h1, h2));
28   xbt_dynar_free_container(&route);
29 }
30
31 static void test_full_link(const sg_host_t* hosts)
32 {
33   size_t list_size = sg_host_count();
34   for (size_t i = 0; i < list_size; i++) {
35     const_sg_host_t h1 = hosts[i];
36     const char* name1  = sg_host_get_name(h1);
37     for (size_t j = 0; j < list_size; j++) {
38       const_sg_host_t h2 = hosts[j];
39       const char* name2  = sg_host_get_name(h2);
40       fprintf(stderr, "Route between %s and %s\n", name1, name2);
41       xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL);
42       sg_host_get_route(h1, h2, route);
43       fprintf(stderr, "  Route size %lu\n", xbt_dynar_length(route));
44       unsigned int k;
45       SD_link_t link;
46       xbt_dynar_foreach (route, k, link)
47         fprintf(stderr, "  Link %s: latency = %f, bandwidth = %f\n", sg_link_get_name(link), sg_link_get_latency(link),
48                 sg_link_get_bandwidth(link));
49       fprintf(stderr, "  Route latency = %f, route bandwidth = %f\n", sg_host_get_route_latency(h1, h2),
50               sg_host_get_route_bandwidth(h1, h2));
51       xbt_dynar_free_container(&route);
52     }
53   }
54 }
55
56 int main(int argc, char** argv)
57 {
58   SD_init(&argc, argv);
59
60   /* creation of the environment */
61   SD_create_environment(argv[1]);
62   fprintf(stderr, "Workstation number: %zu, link number: %d\n", sg_host_count(), sg_link_count());
63
64   sg_host_t* hosts = sg_host_list();
65   if (argc >= 3) {
66     if (!strcmp(argv[2], "ONE_LINK"))
67       test_one_link(hosts);
68     if (!strcmp(argv[2], "FULL_LINK"))
69       test_full_link(hosts);
70     if (!strcmp(argv[2], "PROP"))
71       fprintf(stderr,"SG_TEST_mem: %s\n", sg_host_get_property_value(sg_host_by_name("host1"), "SG_TEST_mem"));
72   }
73   xbt_free(hosts);
74
75   return 0;
76 }