Skip to content

Commit 9859418

Browse files
rmurphy-armjgunthorpe
authored andcommitted
iommufd/selftest: Fix _test_mock_dirty_bitmaps()
The ASSERT_EQ() macro sneakily expands to two statements, so the loop here needs braces to ensure it captures both and actually terminates the test upon failure. Where these tests are currently failing on my arm64 machine, this reduces the number of logged lines from a rather unreasonable ~197,000 down to 10. While we're at it, we can also clean up the tautologous "count" calculations whose assertions can never fail unless mathematics and/or the C language become fundamentally broken. Fixes: a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") Link: https://lore.kernel.org/r/90e083045243ef407dd592bb1deec89cd1f4ddf2.1700153535.git.robin.murphy@arm.com Signed-off-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Joao Martins <joao.m.martins@oracle.com> Tested-by: Joao Martins <joao.m.martins@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 98b1cc8 commit 9859418

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

tools/testing/selftests/iommu/iommufd_utils.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,13 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length,
293293
__u64 bitmap_size, __u32 flags,
294294
struct __test_metadata *_metadata)
295295
{
296-
unsigned long i, count, nbits = bitmap_size * BITS_PER_BYTE;
296+
unsigned long i, nbits = bitmap_size * BITS_PER_BYTE;
297297
unsigned long nr = nbits / 2;
298298
__u64 out_dirty = 0;
299299

300300
/* Mark all even bits as dirty in the mock domain */
301-
for (count = 0, i = 0; i < nbits; count += !(i % 2), i++)
302-
if (!(i % 2))
303-
set_bit(i, (unsigned long *)bitmap);
304-
ASSERT_EQ(nr, count);
301+
for (i = 0; i < nbits; i += 2)
302+
set_bit(i, (unsigned long *)bitmap);
305303

306304
test_cmd_mock_domain_set_dirty(fd, hwpt_id, length, iova, page_size,
307305
bitmap, &out_dirty);
@@ -311,9 +309,10 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length,
311309
memset(bitmap, 0, bitmap_size);
312310
test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap,
313311
flags);
314-
for (count = 0, i = 0; i < nbits; count += !(i % 2), i++)
312+
/* Beware ASSERT_EQ() is two statements -- braces are not redundant! */
313+
for (i = 0; i < nbits; i++) {
315314
ASSERT_EQ(!(i % 2), test_bit(i, (unsigned long *)bitmap));
316-
ASSERT_EQ(count, out_dirty);
315+
}
317316

318317
memset(bitmap, 0, bitmap_size);
319318
test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap,

0 commit comments

Comments
 (0)