From 2a7322743e3af84a806192546031d86f483aecba Mon Sep 17 00:00:00 2001 From: Fabio Streun Date: Fri, 17 Jan 2025 10:59:18 +0000 Subject: [PATCH 1/2] config: fix peer test --- src/test/config_parser_test.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/test/config_parser_test.c b/src/test/config_parser_test.c index 194345c8..07033c62 100644 --- a/src/test/config_parser_test.c +++ b/src/test/config_parser_test.c @@ -134,9 +134,9 @@ init_test1_config(struct lf_config *config) }; struct lf_config_peer *peer2; - peer1 = malloc(sizeof *peer2); + peer2 = malloc(sizeof *peer2); lf_parse_isd_as("0-1", &ia); - *peer1 = (struct lf_config_peer){ + *peer2 = (struct lf_config_peer){ .isd_as = rte_cpu_to_be_64(ia), .drkey_protocol = rte_cpu_to_be_16(0), .ratelimit_option = false, @@ -145,7 +145,8 @@ init_test1_config(struct lf_config *config) config->nb_peers = 3; config->peers = peer0; peer0->next = peer1; - peer1->next = NULL; + peer1->next = peer2; + peer2->next = NULL; return 0; } @@ -439,22 +440,14 @@ check_config(struct lf_config *config, struct lf_config *config_exp) printf("Error: nb_peers = %ld, expected %ld\n", config->nb_peers, config_exp->nb_peers); } else { - peer = config->peers; peer_exp = config_exp->peers; - for (peer_counter = 0; peer_counter <= config->nb_peers; - ++peer_counter) { - if (peer == NULL) { - printf("Error: Found %d peers but nb_peers is %ld", - peer_counter, config->nb_peers); - error_count++; - break; - } + peer_counter = 0; + while (peer != NULL){ + peer_counter++; if (peer_exp == NULL) { - printf("Fatal: Expected structure is faulty: Found %d peers " - "but nb_peers is %ld", - peer_counter, config->nb_peers); error_count++; + printf("Error: Found more peers than expected peers were provided"); break; } res = check_peer(peer, peer_exp); @@ -462,6 +455,14 @@ check_config(struct lf_config *config, struct lf_config *config_exp) error_count += res; printf("Error: Peer number %d\n", peer_counter); } + peer = peer->next; + peer_exp = peer_exp->next; + } + if (peer_exp != NULL) { + printf("Error: Found less peers than expected"); + } + if (peer_counter != config->nb_peers) { + printf("Error: nb_peers = %ld, list length = %d", config->nb_peers, peer_counter); } } From f326d8dbd37079691d683b55d420dfdaad0c4a0b Mon Sep 17 00:00:00 2001 From: Fabio Streun Date: Fri, 17 Jan 2025 11:28:23 +0000 Subject: [PATCH 2/2] format --- src/test/config_parser_test.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/config_parser_test.c b/src/test/config_parser_test.c index 07033c62..10fb9ba3 100644 --- a/src/test/config_parser_test.c +++ b/src/test/config_parser_test.c @@ -443,11 +443,11 @@ check_config(struct lf_config *config, struct lf_config *config_exp) peer = config->peers; peer_exp = config_exp->peers; peer_counter = 0; - while (peer != NULL){ + while (peer != NULL) { peer_counter++; if (peer_exp == NULL) { error_count++; - printf("Error: Found more peers than expected peers were provided"); + printf("Error: Found more peers than expected peers"); break; } res = check_peer(peer, peer_exp); @@ -462,7 +462,8 @@ check_config(struct lf_config *config, struct lf_config *config_exp) printf("Error: Found less peers than expected"); } if (peer_counter != config->nb_peers) { - printf("Error: nb_peers = %ld, list length = %d", config->nb_peers, peer_counter); + printf("Error: nb_peers = %ld, list length = %d", config->nb_peers, + peer_counter); } }