Download raw body.
[PATCH] libressl: Rewrite pq_test to perform internal checks
Convert pq_test.c to perform internal checks of priority order
rather than comparing output against expected.txt.
This simplifies the test logic and removes the need for external files.
Delete expected.txt and update the Makefile accordingly.
---
src/regress/lib/libssl/pqueue/Makefile | 5 --
src/regress/lib/libssl/pqueue/expected.txt | 3 -
src/regress/lib/libssl/pqueue/pq_test.c | 90 +++++++++++++---------
3 files changed, 55 insertions(+), 43 deletions(-)
delete mode 100644 src/regress/lib/libssl/pqueue/expected.txt
diff --git a/src/regress/lib/libssl/pqueue/Makefile b/src/regress/lib/libssl/pqueue/Makefile
index 48c2cb7..ce1b05d 100644
--- a/src/regress/lib/libssl/pqueue/Makefile
+++ b/src/regress/lib/libssl/pqueue/Makefile
@@ -9,9 +9,4 @@ DPADD= ${LIBSSL} ${LIBCRYPTO}
WARNINGS= Yes
CFLAGS+= -DLIBRESSL_INTERNAL -Werror
-REGRESS_TARGETS= regress-pq_test
-
-regress-pq_test: ${PROG}
- ${.OBJDIR}/pq_test | cmp -s ${.CURDIR}/expected.txt /dev/stdin
-
.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 c59d6cd..0000000
--- a/src/regress/lib/libssl/pqueue/expected.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-item 6966726167696c69
-item 7374696365787069
-item 737570657263616c
diff --git a/src/regress/lib/libssl/pqueue/pq_test.c b/src/regress/lib/libssl/pqueue/pq_test.c
index a078ba5..9839dcd 100644
--- a/src/regress/lib/libssl/pqueue/pq_test.c
+++ b/src/regress/lib/libssl/pqueue/pq_test.c
@@ -61,58 +61,78 @@
#include <string.h>
#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 void
-pqueue_print(pqueue pq)
-{
- 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]);
- }
-}
+static const char *pq_expected[3] = {
+ "ifragili",
+ "sticexpi",
+ "supercal"
+};
-int
-main(void)
+static int
+test_pqueue(void)
{
- pitem *item;
- pqueue pq;
+ pqueue pq = NULL;
+ pitem *item = NULL;
+ pitem *iter = NULL;
+ char buf[256];
+ int i = 0;
+ int failed = 1;
pq = pqueue_new();
+ if (pq == NULL)
+ return failed;
+
+ 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);
+ item = pqueue_peek(pq);
+ if (item == NULL || memcmp(item->priority, pq_expected[0], 8))
+ goto failure;
- item = pqueue_find(pq, prio1);
- 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, prio2);
- fprintf(stderr, "found %p\n", item->priority);
+ if (i != 3)
+ goto failure;
- item = pqueue_find(pq, prio3);
- fprintf(stderr, "found %p\n", item ? item->priority: 0);
+ failed = 0;
- 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;
}
--
2.39.5 (Apple Git-154)
[PATCH] libressl: Rewrite pq_test to perform internal checks