diff options
| author | tb <> | 2025-05-04 11:04:02 +0000 |
|---|---|---|
| committer | tb <> | 2025-05-04 11:04:02 +0000 |
| commit | cd61689a37c714168ad3ac43623273d70f2bce16 (patch) | |
| tree | cc536517c6709e51b0a3942c6d8ce199b8f4aed1 /src | |
| parent | 160eaa0c6e4db50ab2f62adbc974105628cb8adc (diff) | |
| download | openbsd-cd61689a37c714168ad3ac43623273d70f2bce16.tar.gz openbsd-cd61689a37c714168ad3ac43623273d70f2bce16.tar.bz2 openbsd-cd61689a37c714168ad3ac43623273d70f2bce16.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libssl/pqueue/Makefile | 7 | ||||
| -rw-r--r-- | src/regress/lib/libssl/pqueue/expected.txt | 3 | ||||
| -rw-r--r-- | src/regress/lib/libssl/pqueue/pq_test.c | 95 |
3 files changed, 57 insertions, 48 deletions
diff --git a/src/regress/lib/libssl/pqueue/Makefile b/src/regress/lib/libssl/pqueue/Makefile index 48c2cb7e61..05fe9a268d 100644 --- a/src/regress/lib/libssl/pqueue/Makefile +++ b/src/regress/lib/libssl/pqueue/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2016/11/04 19:45:12 jsing Exp $ | 1 | # $OpenBSD: Makefile,v 1.2 2025/05/04 11:04:02 tb Exp $ |
| 2 | 2 | ||
| 3 | PROG= pq_test | 3 | PROG= pq_test |
| 4 | SRC= ${.CURDIR}/../../../../lib/libssl | 4 | SRC= ${.CURDIR}/../../../../lib/libssl |
| @@ -9,9 +9,4 @@ DPADD= ${LIBSSL} ${LIBCRYPTO} | |||
| 9 | WARNINGS= Yes | 9 | WARNINGS= Yes |
| 10 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror | 10 | CFLAGS+= -DLIBRESSL_INTERNAL -Werror |
| 11 | 11 | ||
| 12 | REGRESS_TARGETS= regress-pq_test | ||
| 13 | |||
| 14 | regress-pq_test: ${PROG} | ||
| 15 | ${.OBJDIR}/pq_test | cmp -s ${.CURDIR}/expected.txt /dev/stdin | ||
| 16 | |||
| 17 | .include <bsd.regress.mk> | 12 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libssl/pqueue/expected.txt b/src/regress/lib/libssl/pqueue/expected.txt deleted file mode 100644 index c59d6cd838..0000000000 --- a/src/regress/lib/libssl/pqueue/expected.txt +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | item 6966726167696c69 | ||
| 2 | item 7374696365787069 | ||
| 3 | item 737570657263616c | ||
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 @@ | |||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
| 61 | #include <string.h> | 61 | #include <string.h> |
| 62 | |||
| 62 | #include "pqueue.h" | 63 | #include "pqueue.h" |
| 63 | 64 | ||
| 64 | /* remember to change expected.txt if you change these values */ | 65 | static const unsigned char *pq_expected[3] = { |
| 65 | unsigned char prio1[8] = "supercal"; | 66 | "ifragili", |
| 66 | unsigned char prio2[8] = "ifragili"; | 67 | "sticexpi", |
| 67 | unsigned char prio3[8] = "sticexpi"; | 68 | "supercal" |
| 69 | }; | ||
| 68 | 70 | ||
| 69 | static void | 71 | static int |
| 70 | pqueue_print(pqueue pq) | 72 | test_pqueue(void) |
| 71 | { | 73 | { |
| 72 | pitem *iter, *item; | 74 | const unsigned char *prio1 = pq_expected[2]; |
| 73 | 75 | const unsigned char *prio2 = pq_expected[0]; | |
| 74 | iter = pqueue_iterator(pq); | 76 | const unsigned char *prio3 = pq_expected[1]; |
| 75 | for (item = pqueue_next(&iter); item != NULL; | 77 | pqueue pq = NULL; |
| 76 | item = pqueue_next(&iter)) { | 78 | pitem *item = NULL; |
| 77 | printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n", | 79 | pitem *iter = NULL; |
| 78 | item->priority[0], item->priority[1], | 80 | int i = 0; |
| 79 | item->priority[2], item->priority[3], | 81 | int failed = 1; |
| 80 | item->priority[4], item->priority[5], | ||
| 81 | item->priority[6], item->priority[7]); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | 82 | ||
| 85 | int | 83 | if ((pq = pqueue_new()) == NULL) |
| 86 | main(void) | 84 | goto failure; |
| 87 | { | ||
| 88 | pitem *item; | ||
| 89 | pqueue pq; | ||
| 90 | 85 | ||
| 91 | pq = pqueue_new(); | 86 | if (!pqueue_insert(pq, pitem_new(prio3, NULL))) |
| 87 | goto failure; | ||
| 88 | if (!pqueue_insert(pq, pitem_new(prio1, NULL))) | ||
| 89 | goto failure; | ||
| 90 | if (!pqueue_insert(pq, pitem_new(prio2, NULL))) | ||
| 91 | goto failure; | ||
| 92 | 92 | ||
| 93 | item = pitem_new(prio3, NULL); | 93 | if (pqueue_size(pq) != 3) |
| 94 | pqueue_insert(pq, item); | 94 | goto failure; |
| 95 | 95 | ||
| 96 | item = pitem_new(prio1, NULL); | 96 | if ((item = pqueue_find(pq, prio1)) == NULL) |
| 97 | pqueue_insert(pq, item); | 97 | goto failure; |
| 98 | if ((item = pqueue_find(pq, prio2)) == NULL) | ||
| 99 | goto failure; | ||
| 100 | if ((item = pqueue_find(pq, prio3)) == NULL) | ||
| 101 | goto failure; | ||
| 98 | 102 | ||
| 99 | item = pitem_new(prio2, NULL); | 103 | if ((item = pqueue_peek(pq)) == NULL) |
| 100 | pqueue_insert(pq, item); | 104 | goto failure; |
| 101 | 105 | ||
| 102 | item = pqueue_find(pq, prio1); | 106 | if (memcmp(item->priority, pq_expected[0], 8)) |
| 103 | fprintf(stderr, "found %p\n", item->priority); | 107 | goto failure; |
| 104 | 108 | ||
| 105 | item = pqueue_find(pq, prio2); | 109 | iter = pqueue_iterator(pq); |
| 106 | fprintf(stderr, "found %p\n", item->priority); | 110 | for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) { |
| 111 | if (memcmp(item->priority, pq_expected[i], 8) != 0) | ||
| 112 | goto failure; | ||
| 113 | i++; | ||
| 114 | } | ||
| 107 | 115 | ||
| 108 | item = pqueue_find(pq, prio3); | 116 | failed = (i != 3); |
| 109 | fprintf(stderr, "found %p\n", item ? item->priority: 0); | ||
| 110 | 117 | ||
| 111 | pqueue_print(pq); | 118 | failure: |
| 112 | 119 | ||
| 113 | for (item = pqueue_pop(pq); item != NULL; item = pqueue_pop(pq)) | 120 | for (item = pqueue_pop(pq); item != NULL; item = pqueue_pop(pq)) |
| 114 | pitem_free(item); | 121 | pitem_free(item); |
| 115 | |||
| 116 | pqueue_free(pq); | 122 | pqueue_free(pq); |
| 117 | return 0; | 123 | |
| 124 | return failed; | ||
| 125 | } | ||
| 126 | |||
| 127 | int | ||
| 128 | main(void) | ||
| 129 | { | ||
| 130 | int failed = 0; | ||
| 131 | |||
| 132 | failed |= test_pqueue(); | ||
| 133 | |||
| 134 | return failed; | ||
| 118 | } | 135 | } |
