From 0fd124e82ef724c47001585688113f844d4c0f75 Mon Sep 17 00:00:00 2001 From: tb <> Date: Sun, 4 May 2025 11:04:02 +0000 Subject: Improve the pqueue test This simplifies the test in portable and makes the whole thing a bit less ugly overall. From Kenjiro Nakayama with minor tweaks by me --- src/regress/lib/libssl/pqueue/pq_test.c | 95 +++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 39 deletions(-) (limited to 'src/regress/lib/libssl/pqueue/pq_test.c') diff --git a/src/regress/lib/libssl/pqueue/pq_test.c b/src/regress/lib/libssl/pqueue/pq_test.c index a078ba5366..822fdea961 100644 --- a/src/regress/lib/libssl/pqueue/pq_test.c +++ b/src/regress/lib/libssl/pqueue/pq_test.c @@ -59,60 +59,77 @@ #include #include #include + #include "pqueue.h" -/* remember to change expected.txt if you change these values */ -unsigned char prio1[8] = "supercal"; -unsigned char prio2[8] = "ifragili"; -unsigned char prio3[8] = "sticexpi"; +static const unsigned char *pq_expected[3] = { + "ifragili", + "sticexpi", + "supercal" +}; -static void -pqueue_print(pqueue pq) +static int +test_pqueue(void) { - pitem *iter, *item; - - iter = pqueue_iterator(pq); - for (item = pqueue_next(&iter); item != NULL; - item = pqueue_next(&iter)) { - printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n", - item->priority[0], item->priority[1], - item->priority[2], item->priority[3], - item->priority[4], item->priority[5], - item->priority[6], item->priority[7]); - } -} + const unsigned char *prio1 = pq_expected[2]; + const unsigned char *prio2 = pq_expected[0]; + const unsigned char *prio3 = pq_expected[1]; + pqueue pq = NULL; + pitem *item = NULL; + pitem *iter = NULL; + int i = 0; + int failed = 1; -int -main(void) -{ - pitem *item; - pqueue pq; + if ((pq = pqueue_new()) == NULL) + goto failure; - pq = pqueue_new(); + if (!pqueue_insert(pq, pitem_new(prio3, NULL))) + goto failure; + if (!pqueue_insert(pq, pitem_new(prio1, NULL))) + goto failure; + if (!pqueue_insert(pq, pitem_new(prio2, NULL))) + goto failure; - item = pitem_new(prio3, NULL); - pqueue_insert(pq, item); + if (pqueue_size(pq) != 3) + goto failure; - item = pitem_new(prio1, NULL); - pqueue_insert(pq, item); + if ((item = pqueue_find(pq, prio1)) == NULL) + goto failure; + if ((item = pqueue_find(pq, prio2)) == NULL) + goto failure; + if ((item = pqueue_find(pq, prio3)) == NULL) + goto failure; - item = pitem_new(prio2, NULL); - pqueue_insert(pq, item); + if ((item = pqueue_peek(pq)) == NULL) + goto failure; - item = pqueue_find(pq, prio1); - fprintf(stderr, "found %p\n", item->priority); + if (memcmp(item->priority, pq_expected[0], 8)) + goto failure; - item = pqueue_find(pq, prio2); - fprintf(stderr, "found %p\n", item->priority); + iter = pqueue_iterator(pq); + for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) { + if (memcmp(item->priority, pq_expected[i], 8) != 0) + goto failure; + i++; + } - item = pqueue_find(pq, prio3); - fprintf(stderr, "found %p\n", item ? item->priority: 0); + failed = (i != 3); - pqueue_print(pq); + failure: for (item = pqueue_pop(pq); item != NULL; item = pqueue_pop(pq)) pitem_free(item); - pqueue_free(pq); - return 0; + + return failed; +} + +int +main(void) +{ + int failed = 0; + + failed |= test_pqueue(); + + return failed; } -- cgit v1.2.3-55-g6feb