summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/pol/tests/graph_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd/normal/pol/tests/graph_test.c')
-rw-r--r--src/ipcpd/normal/pol/tests/graph_test.c153
1 files changed, 106 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..42cf3f06 100644
--- a/src/ipcpd/normal/pol/tests/graph_test.c
+++ b/src/ipcpd/normal/pol/tests/graph_test.c
@@ -30,80 +30,105 @@
#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) {
+ list_for_each(p, &table)
+ i++;
+
+ if (i != 2) {
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) ||
- (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 ((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;
+ 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 +136,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;
@@ -140,6 +165,12 @@ int graph_test(int argc,
return -1;
}
+ if (graph_update_edge(graph, 2, 1, qs)) {
+ printf("Failed to add edge.\n");
+ graph_destroy(graph);
+ return -1;
+ }
+
if (graph_test_single_link()) {
graph_destroy(graph);
return -1;
@@ -151,6 +182,13 @@ int graph_test(int argc,
return -1;
}
+ if (graph_update_edge(graph, 3, 2, qs)) {
+ printf("Failed to add edge.\n");
+ graph_destroy(graph);
+ return -1;
+ }
+
+
if (graph_test_double_link()) {
graph_destroy(graph);
return -1;
@@ -162,13 +200,21 @@ int graph_test(int argc,
return -1;
}
+ if (graph_del_edge(graph, 3, 2)) {
+ printf("Failed to delete edge.\n");
+ graph_destroy(graph);
+ return -1;
+ }
+
if (graph_test_single_link()) {
graph_destroy(graph);
return -1;
}
graph_update_edge(graph, 2, 3, qs);
+ graph_update_edge(graph, 3, 2, qs);
graph_update_edge(graph, 1, 3, qs);
+ graph_update_edge(graph, 3, 1, qs);
if (graph_test_entries(2)) {
graph_destroy(graph);
@@ -176,7 +222,9 @@ int graph_test(int argc,
}
graph_update_edge(graph, 3, 4, qs);
+ graph_update_edge(graph, 4, 3, qs);
graph_update_edge(graph, 4, 5, qs);
+ graph_update_edge(graph, 5, 4, qs);
if (graph_test_entries(4)) {
graph_destroy(graph);
@@ -184,58 +232,69 @@ int graph_test(int argc,
}
graph_update_edge(graph, 2, 6, qs);
+ graph_update_edge(graph, 6, 2, qs);
graph_update_edge(graph, 6, 7, qs);
+ graph_update_edge(graph, 7, 6, qs);
graph_update_edge(graph, 3, 7, qs);
+ graph_update_edge(graph, 7, 3, qs);
if (graph_test_entries(6)) {
graph_destroy(graph);
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;
}