summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Eckhardt <ulrich.eckhardt@base-42.de>2016-05-28 11:15:49 +0200
committerArun Raghavan <arun@arunraghavan.net>2016-07-22 15:18:27 +0530
commit37b0ce03338ddd17a31064b7ff16a517817d216a (patch)
treeb33d5ed5bfde492fdd715f1dbcf006f31dfb8281
parentac72e85f0a0aade2d1c62aaf356b7039c4387139 (diff)
memblockq-test: Utility function to validate queue invariants
In particular, the relations between base, minreq, tlength, length, missing, maxlength follow certain rules. On change, these invariants can be violated, which requires additional code to restore them. Setting one value can thus cause a cascade of changes. This utility function can assert those invariants after changing something.
-rw-r--r--src/tests/memblockq-test.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/tests/memblockq-test.c b/src/tests/memblockq-test.c
index 969e5121..b6d4f179 100644
--- a/src/tests/memblockq-test.c
+++ b/src/tests/memblockq-test.c
@@ -110,6 +110,68 @@ static void dump(pa_memblockq *bq, int n) {
fprintf(stderr, "<\n");
}
+/*
+ * utility function to validate invariants
+ *
+ * The different values like base, maxlength etc follow certain rules.
+ * This convenience function makes sure that changes don't violate
+ * these rules.
+ */
+static void check_queue_invariants(pa_memblockq *bq) {
+ size_t base = pa_memblockq_get_base(bq);
+ size_t maxlength = pa_memblockq_get_maxlength(bq);
+ size_t tlength = pa_memblockq_get_tlength(bq);
+ size_t minreq = pa_memblockq_get_minreq(bq);
+ size_t prebuf = pa_memblockq_get_prebuf(bq);
+ size_t length = pa_memblockq_get_length(bq);
+ size_t missing = pa_memblockq_missing(bq);
+
+ /* base > zero */
+ ck_assert_int_gt(base, 0);
+
+ /* maxlength multiple of base
+ * maxlength >= base */
+ ck_assert_int_eq(maxlength % base, 0);
+ ck_assert_int_ge(maxlength, base);
+
+ /* tlength multiple of base
+ * tlength >= base
+ * tlength <= maxlength */
+ ck_assert_int_eq(tlength % base, 0);
+ ck_assert_int_ge(tlength, base);
+ ck_assert_int_le(tlength, maxlength);
+
+ /* minreq multiple of base
+ * minreq >= base
+ * minreq <= tlength */
+ ck_assert_int_eq(minreq % base, 0);
+ ck_assert_int_ge(minreq, base);
+ ck_assert_int_le(minreq, tlength);
+
+ /* prebuf multiple of base
+ * prebuf >= 0
+ * prebuf <= tlength + base - minreq
+ * prebuf <= tlength (because minreq >= base) */
+ ck_assert_int_eq(prebuf % base, 0);
+ ck_assert_int_ge(prebuf, 0);
+ ck_assert_int_le(prebuf, tlength + base - minreq);
+ ck_assert_int_le(prebuf, tlength);
+
+ /* length >= 0
+ * length <= maxlength */
+ ck_assert_int_ge(length, 0);
+ ck_assert_int_le(length, maxlength);
+
+ /* missing >= 0
+ * missing <= tlength
+ * minimum reported amount of missing data is minreq
+ * reported amount of missing data is target length minus actual length */
+ ck_assert_int_ge(missing, 0);
+ ck_assert_int_le(missing, tlength);
+ ck_assert((missing == 0) || (missing >= minreq));
+ ck_assert((missing == 0) || (missing == tlength - length));
+}
+
START_TEST (memchunk_from_str_test) {
pa_mempool *p;
pa_memchunk chunk;