diff options
| author | Sander Vrijders <sander.vrijders@ugent.be> | 2017-09-25 14:26:26 +0200 | 
|---|---|---|
| committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-09-25 14:26:26 +0200 | 
| commit | e245a809296dad1ea22956f015751cc172a44ad2 (patch) | |
| tree | 38171f07be9f2a18e15212eef5fc6f3fd5516041 /src/ipcpd/normal/pol/tests | |
| parent | baa9da56af12d14d63d504101c7efeb20da71a78 (diff) | |
| download | ouroboros-e245a809296dad1ea22956f015751cc172a44ad2.tar.gz ouroboros-e245a809296dad1ea22956f015751cc172a44ad2.zip | |
ipcpd: normal: Return list as routing table
This returns a list as routing table instead of a pointer to a pointer
to a pointer, which simplifies the looping through the routing table
and makes it more extensible for future additions.
Diffstat (limited to 'src/ipcpd/normal/pol/tests')
| -rw-r--r-- | src/ipcpd/normal/pol/tests/graph_test.c | 130 | 
1 files changed, 83 insertions, 47 deletions
| diff --git a/src/ipcpd/normal/pol/tests/graph_test.c b/src/ipcpd/normal/pol/tests/graph_test.c index 87574187..0baba6fc 100644 --- a/src/ipcpd/normal/pol/tests/graph_test.c +++ b/src/ipcpd/normal/pol/tests/graph_test.c @@ -30,80 +30,108 @@  #include "graph.c" -struct graph *          graph; -struct routing_table ** table; -ssize_t                 n_table; -qosspec_t               qs; +struct graph *   graph; +struct list_head table; +qosspec_t        qs;  int graph_test_entries(int entries)  { -        n_table = graph_routing_table(graph, 1, &table); +        struct list_head * p; +        int                i = 0; -        if (n_table != entries) { +        if (graph_routing_table(graph, 1, &table)) { +                printf("Failed to get routing table.\n"); +                return -1; +        } + +        list_for_each(p, &table) { +                i++; +        } + +        if (i != entries) {                  printf("Wrong number of entries.\n"); -                freepp(struct routing_table, table, n_table); +                graph_free_routing_table(graph, &table);                  return -1;          } -        freepp(struct routing_table, table, n_table); +        graph_free_routing_table(graph, &table);          return 0;  }  int graph_test_double_link(void)  { -        n_table = graph_routing_table(graph, 1, &table); -        if (n_table < 0 || table == NULL) { +        struct list_head * p; +        int                i = 0; + +        if (graph_routing_table(graph, 1, &table)) {                  printf("Failed to get routing table.\n");                  return -1;          } -        if (n_table != 2) { -                printf("Wrong number of entries.\n"); -                freepp(struct routing_table, table, n_table); -                return -1; +        list_for_each(p, &table) { +                i++;          } -        if ((table[0]->dst != 2 && table[0]->nhop != 2) || -            (table[0]->dst != 3 && table[0]->nhop != 2)) { -                printf("Wrong routing entry.\n"); -                freepp(struct routing_table, table, n_table); +        if (i != 2) { +                printf("Wrong number of entries.\n"); +                graph_free_routing_table(graph, &table);                  return -1;          } -        if ((table[1]->dst != 2 && table[1]->nhop != 2) || -            (table[0]->dst != 3 && table[0]->nhop != 2)) { -                printf("Wrong routing entry.\n"); -                freepp(struct routing_table, table, n_table); -                return -1; +        list_for_each(p, &table) { +                struct routing_table * t = +                        list_entry(p, struct routing_table, next); +                struct nhop *          n = +                        list_first_entry(&t->nhops, struct nhop, next); + +                if ((t->dst != 2 && n->nhop != 2) || +                    (t->dst != 3 && n->nhop != 2)) { +                        printf("Wrong routing entry.\n"); +                        graph_free_routing_table(graph, &table); +                        return -1; +                }          } -        freepp(struct routing_table, table, n_table); +        graph_free_routing_table(graph, &table);          return 0;  }  int graph_test_single_link(void)  { -        n_table = graph_routing_table(graph, 1, &table); -        if (n_table < 0 || table == NULL) { +        struct list_head * p; +        int                i = 0; + +        if (graph_routing_table(graph, 1, &table)) {                  printf("Failed to get routing table.\n");                  return -1;          } -        if (n_table != 1) { +        list_for_each(p, &table) { +                i++; +        } + +        if (i != 1) {                  printf("Wrong number of entries.\n"); -                freepp(struct routing_table, table, n_table); +                graph_free_routing_table(graph, &table);                  return -1;          } -        if (table[0]->dst != 2 && table[0]->nhop != 2) { -                printf("Wrong routing entry.\n"); -                freepp(struct routing_table, table, n_table); -                return -1; +        list_for_each(p, &table) { +                struct routing_table * t = +                        list_entry(p, struct routing_table, next); +                struct nhop *          n = +                        list_first_entry(&t->nhops, struct nhop, next); + +                if (t->dst != 2 && n->nhop != 2) { +                        printf("Wrong routing entry.\n"); +                        graph_free_routing_table(graph, &table); +                        return -1; +                }          } -        freepp(struct routing_table, table, n_table); +        graph_free_routing_table(graph, &table);          return 0;  } @@ -111,9 +139,9 @@ int graph_test_single_link(void)  int graph_test(int     argc,                 char ** argv)  { -        int i; -        int nhop; -        int dst; +        int                nhop; +        int                dst; +        struct list_head * p;          (void) argc;          (void) argv; @@ -192,50 +220,58 @@ int graph_test(int     argc,                  return -1;          } -        n_table = graph_routing_table(graph, 1, &table); +        if (graph_routing_table(graph, 1, &table)) { +                printf("Failed to get routing table.\n"); +                return -1; +        } + +        list_for_each(p, &table) { +                struct routing_table * t = +                        list_entry(p, struct routing_table, next); +                struct nhop *          n = +                        list_first_entry(&t->nhops, struct nhop, next); -        for (i = 0; i < 6; i++) { -                nhop = table[i]->nhop; -                dst = table[i]->dst; +                dst = t->dst; +                nhop = n->nhop;                  if (dst == 3 && nhop != 3) {                          printf("Wrong entry."); -                        freepp(struct routing_table, table, n_table); +                        graph_free_routing_table(graph, &table);                          return -1;                  }                  if (dst == 2 && nhop != 2) {                          printf("Wrong entry."); -                        freepp(struct routing_table, table, n_table); +                        graph_free_routing_table(graph, &table);                          return -1;                  }                  if (dst == 6 && nhop != 2) {                          printf("Wrong entry."); -                        freepp(struct routing_table, table, n_table); +                        graph_free_routing_table(graph, &table);                          return -1;                  }                  if (dst == 4 && nhop != 3) {                          printf("Wrong entry."); -                        freepp(struct routing_table, table, n_table); +                        graph_free_routing_table(graph, &table);                          return -1;                  }                  if (dst == 5 && nhop != 3) {                          printf("Wrong entry."); -                        freepp(struct routing_table, table, n_table); +                        graph_free_routing_table(graph, &table);                          return -1;                  }                  if (dst == 7 && nhop != 3) {                          printf("Wrong entry."); -                        freepp(struct routing_table, table, n_table); +                        graph_free_routing_table(graph, &table);                          return -1;                  }          } -        freepp(struct routing_table, table, n_table); +        graph_free_routing_table(graph, &table);          return 0;  } | 
