Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
plug a "leak"
[simgrid.git] / teshsuite / simdag / basic-link-test / basic-link-test.c
1 /* Copyright (c) 2008-2010, 2012-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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(basic_link_test, sd, "SimDag test basic_link_test");
11
12 static int cmp_link(const void*a, const void*b) {
13   return strcmp(sg_link_name(*(SD_link_t*)a)  , sg_link_name(*(SD_link_t*)b));
14 }
15
16 int main(int argc, char **argv)
17 {
18   const char *user_data = "some user_data";
19
20   /* initialization of SD */
21   SD_init(&argc, argv);
22
23   /* creation of the environment */
24   SD_create_environment(argv[1]);
25   SD_link_t *links = sg_link_list();
26   int count = sg_link_count();
27   XBT_INFO("Link count: %d", count);
28   qsort((void *)links, count, sizeof(SD_link_t), cmp_link);
29    
30   for (int i=0; i < count; i++){
31     XBT_INFO("%s: latency = %.5f, bandwidth = %f", sg_link_name(links[i]),
32              sg_link_latency(links[i]), sg_link_bandwidth(links[i]));
33     sg_link_data_set(links[i], (void*) user_data);
34     xbt_assert(!strcmp(user_data, (const char*)sg_link_data(links[i])),"User data was corrupted.");
35   }
36   xbt_free(links);
37   SD_exit();
38   return 0;
39 }