From: Martin Wilck <mwilck@suse.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [PATCH v3 17/24] tests: add unit tests for bitmask functions
Date: Mon, 10 Dec 2018 10:49:52 +0100 [thread overview]
Message-ID: <20181210094959.11338-18-mwilck@suse.com> (raw)
In-Reply-To: <20181210094959.11338-1-mwilck@suse.com>
Add unit tests for the bitmask management functions the previous
patch added in util.h.
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
tests/util.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
diff --git a/tests/util.c b/tests/util.c
index 839effd2..e6d4b9ab 100644
--- a/tests/util.c
+++ b/tests/util.c
@@ -26,6 +26,8 @@
#include "globals.c"
+#define BITARR_SZ 4
+
static void test_basenamecpy_good0(void **state)
{
char dst[10];
@@ -139,6 +141,100 @@ static void test_basenamecpy_bad5(void **state)
assert_int_equal(basenamecpy("baz/qux", NULL, sizeof(dst)), 0);
}
+static void test_bitmask_1(void **state)
+{
+ uint64_t arr[BITARR_SZ];
+ int i, j, k, m, b;
+
+ memset(arr, 0, sizeof(arr));
+
+ for (j = 0; j < BITARR_SZ; j++) {
+ for (i = 0; i < 64; i++) {
+ b = 64 * j + i;
+ assert(!is_bit_set_in_array(b, arr));
+ set_bit_in_array(b, arr);
+ for (k = 0; k < BITARR_SZ; k++) {
+ printf("b = %d j = %d k = %d a = %"PRIx64"\n",
+ b, j, k, arr[k]);
+ if (k == j)
+ assert_int_equal(arr[j], 1ULL << i);
+ else
+ assert_int_equal(arr[k], 0ULL);
+ }
+ for (m = 0; m < 64; m++)
+ if (i == m)
+ assert(is_bit_set_in_array(64 * j + m,
+ arr));
+ else
+ assert(!is_bit_set_in_array(64 * j + m,
+ arr));
+ clear_bit_in_array(b, arr);
+ assert(!is_bit_set_in_array(b, arr));
+ for (k = 0; k < BITARR_SZ; k++)
+ assert_int_equal(arr[k], 0ULL);
+ }
+ }
+}
+
+static void test_bitmask_2(void **state)
+{
+ uint64_t arr[BITARR_SZ];
+ int i, j, k, m, b;
+
+ memset(arr, 0, sizeof(arr));
+
+ for (j = 0; j < BITARR_SZ; j++) {
+ for (i = 0; i < 64; i++) {
+ b = 64 * j + i;
+ assert(!is_bit_set_in_array(b, arr));
+ set_bit_in_array(b, arr);
+ for (m = 0; m < 64; m++)
+ if (m <= i)
+ assert(is_bit_set_in_array(64 * j + m,
+ arr));
+ else
+ assert(!is_bit_set_in_array(64 * j + m,
+ arr));
+ assert(is_bit_set_in_array(b, arr));
+ for (k = 0; k < BITARR_SZ; k++) {
+ if (k < j || (k == j && i == 63))
+ assert_int_equal(arr[k], ~0ULL);
+ else if (k > j)
+ assert_int_equal(arr[k], 0ULL);
+ else
+ assert_int_equal(
+ arr[k],
+ (1ULL << (i + 1)) - 1);
+ }
+ }
+ }
+ for (j = 0; j < BITARR_SZ; j++) {
+ for (i = 0; i < 64; i++) {
+ b = 64 * j + i;
+ assert(is_bit_set_in_array(b, arr));
+ clear_bit_in_array(b, arr);
+ for (m = 0; m < 64; m++)
+ if (m <= i)
+ assert(!is_bit_set_in_array(64 * j + m,
+ arr));
+ else
+ assert(is_bit_set_in_array(64 * j + m,
+ arr));
+ assert(!is_bit_set_in_array(b, arr));
+ for (k = 0; k < BITARR_SZ; k++) {
+ if (k < j || (k == j && i == 63))
+ assert_int_equal(arr[k], 0ULL);
+ else if (k > j)
+ assert_int_equal(arr[k], ~0ULL);
+ else
+ assert_int_equal(
+ arr[k],
+ ~((1ULL << (i + 1)) - 1));
+ }
+ }
+ }
+}
+
int test_basenamecpy(void)
{
const struct CMUnitTest tests[] = {
@@ -156,6 +252,8 @@ int test_basenamecpy(void)
cmocka_unit_test(test_basenamecpy_bad3),
cmocka_unit_test(test_basenamecpy_bad4),
cmocka_unit_test(test_basenamecpy_bad5),
+ cmocka_unit_test(test_bitmask_1),
+ cmocka_unit_test(test_bitmask_2),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
--
2.19.2
next prev parent reply other threads:[~2018-12-10 9:49 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-10 9:49 [PATCH v3 00/24] multipath-tools: improve logging at -v3 Martin Wilck
2018-12-10 9:49 ` [PATCH v3 01/24] tests/hwtable: set multipath_dir in local configuration Martin Wilck
2018-12-10 9:49 ` [PATCH v3 02/24] tests/hwtable: adjust to new checker API Martin Wilck
2018-12-10 9:49 ` [PATCH v3 03/24] multipath-tools: decrease verbosity of state messages Martin Wilck
2018-12-10 9:49 ` [PATCH v3 04/24] libmultipath: decrease verbosity of pathinfo messages Martin Wilck
2018-12-10 9:49 ` [PATCH v3 05/24] libmultipath: decrease verbosity of TUR checker messages Martin Wilck
2018-12-10 9:49 ` [PATCH v3 06/24] libmultipath: avoid frequent messages from filter_property() Martin Wilck
2018-12-10 9:49 ` [PATCH v3 07/24] libmultipath: decrease log level of "disassembled" messages Martin Wilck
2018-12-10 9:49 ` [PATCH v3 08/24] libmultipath: decrease log level of word splitting Martin Wilck
2018-12-10 9:49 ` [PATCH v3 09/24] libmultipath: increase log level of map removal Martin Wilck
2018-12-10 9:49 ` [PATCH v3 10/24] multipathd: decrease log level of checker timing Martin Wilck
2018-12-10 9:49 ` [PATCH v3 11/24] libmultipath: decrease log level of "prioritizer refcount" message Martin Wilck
2018-12-10 9:49 ` [PATCH v3 12/24] libmpathpersist/update_map_pr: decrease log level for nop Martin Wilck
2018-12-10 9:49 ` [PATCH v3 13/24] libmultipath: simplify devt2devname() Martin Wilck
2018-12-10 9:49 ` [PATCH v3 14/24] libmultipath: decrease log level for failed VPD c9 Martin Wilck
2018-12-10 9:49 ` [PATCH v3 15/24] libmultipath: adopt_paths: check for size match Martin Wilck
2018-12-10 9:49 ` [PATCH v3 16/24] libmultipath: coalesce_paths: fix size mismatch handling Martin Wilck
2018-12-10 9:49 ` Martin Wilck [this message]
2018-12-10 9:49 ` [PATCH v3 18/24] multipathd: uev_remove_path: remove redundant orphan_paths call Martin Wilck
2018-12-10 9:49 ` [PATCH v3 19/24] libmultipath: improve logging from orphan_paths Martin Wilck
2018-12-10 9:49 ` [PATCH v3 20/24] libmultipath: avoid syslog loglevel > LOG_DEBUG Martin Wilck
2018-12-10 9:49 ` [PATCH v3 21/24] coalesce_paths(): use symbolic return value Martin Wilck
2018-12-10 9:49 ` [PATCH v3 22/24] domap(): " Martin Wilck
2018-12-10 9:49 ` [PATCH v3 23/24] multipathd: simplify retry logic in ev_add_path() Martin Wilck
2018-12-10 9:49 ` [PATCH v3 24/24] multipath: use symbolic return value and exit code Martin Wilck
2018-12-11 17:43 ` [PATCH v3 00/24] multipath-tools: improve logging at -v3 Benjamin Marzinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181210094959.11338-18-mwilck@suse.com \
--to=mwilck@suse.com \
--cc=christophe.varoqui@opensvc.com \
--cc=dm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox