--- src/libvirt_private.syms | 1 + src/util/virbitmap.c | 17 +++++++++++++++++ src/util/virbitmap.h | 3 +++ tests/virbitmaptest.c | 33 ++++++++++++++++++++++++++++++++- 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b7b9631..6b831b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1046,6 +1046,7 @@ virBitmapEqual; virBitmapFormat; virBitmapFree; virBitmapGetBit; +virBitmapIsAllClear; virBitmapIsAllSet; virBitmapNew; virBitmapNewCopy; diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 21509ac..998c302 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -591,6 +591,23 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap) } /** + * virBitmapIsAllClear: + * @bitmap: the bitmap to check + * + * check if all bits in @bitmap are clear + */ +bool virBitmapIsAllClear(virBitmapPtr bitmap) +{ + int i; + + for (i = 0; i < bitmap->map_len; i++) + if (bitmap->map[i] != 0) + return false; + + return true; +} + +/** * virBitmapNextSetBit: * @bitmap: the bitmap * @pos: the position after which to search for a set bit diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 044c7a6..b682523 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -100,6 +100,9 @@ void virBitmapClearAll(virBitmapPtr bitmap) bool virBitmapIsAllSet(virBitmapPtr bitmap) ATTRIBUTE_NONNULL(1); +bool virBitmapIsAllClear(virBitmapPtr bitmap) + ATTRIBUTE_NONNULL(1); + ssize_t virBitmapNextSetBit(virBitmapPtr bitmap, ssize_t pos) ATTRIBUTE_NONNULL(1); diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 95d010a..3067f6e 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -125,6 +125,8 @@ static int test2(const void *data ATTRIBUTE_UNUSED) goto error; virBitmapClearAll(bitmap); + if (!virBitmapIsAllClear(bitmap)) + goto error; if (testBit(bitmap, 0, size - 1, false) < 0) goto error; if (virBitmapCountBits(bitmap) != 0) @@ -154,6 +156,9 @@ static int test3(const void *data ATTRIBUTE_UNUSED) if (!virBitmapIsAllSet(bitmap)) goto error; + virBitmapClearAll(bitmap); + if (!virBitmapIsAllClear(bitmap)) + goto error; ret = 0; error: @@ -196,6 +201,9 @@ static int test4(const void *data ATTRIBUTE_UNUSED) if (virBitmapNextClearBit(bitmap, i) != -1) goto error; + if (!virBitmapIsAllClear(bitmap)) + goto error; + virBitmapFree(bitmap); bitmap = NULL; @@ -406,6 +414,10 @@ static int test7(const void *v ATTRIBUTE_UNUSED) if (!virBitmapIsAllSet(bitmap)) goto error; + virBitmapClearAll(bitmap); + if (!virBitmapIsAllClear(bitmap)) + goto error; + virBitmapFree(bitmap); } @@ -416,6 +428,24 @@ error: return -1; } +static int test8(const void *v ATTRIBUTE_UNUSED) +{ + virBitmapPtr bitmap = NULL; + char data[108] = {0x00,}; + + bitmap = virBitmapNewData(data, sizeof(data)); + if (!bitmap) + goto error; + + if (!virBitmapIsAllClear(bitmap)) + goto error; + + return 0; +error: + virBitmapFree(bitmap); + return -1; +} + static int mymain(void) { @@ -435,7 +465,8 @@ mymain(void) ret = -1; if (virtTestRun("test7", 1, test7, NULL) < 0) ret = -1; - + if (virtTestRun("test8", 1, test8, NULL) < 0) + ret = -1; return ret; } -- 1.8.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list