Commit 98594181 authored by Robin Murphy's avatar Robin Murphy Committed by Jason Gunthorpe

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: a9af47e3 ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP")
Link: https://lore.kernel.org/r/90e083045243ef407dd592bb1deec89cd1f4ddf2.1700153535.git.robin.murphy@arm.comSigned-off-by: default avatarRobin Murphy <robin.murphy@arm.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarJoao Martins <joao.m.martins@oracle.com>
Tested-by: default avatarJoao Martins <joao.m.martins@oracle.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 98b1cc82
...@@ -293,15 +293,13 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length, ...@@ -293,15 +293,13 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length,
__u64 bitmap_size, __u32 flags, __u64 bitmap_size, __u32 flags,
struct __test_metadata *_metadata) struct __test_metadata *_metadata)
{ {
unsigned long i, count, nbits = bitmap_size * BITS_PER_BYTE; unsigned long i, nbits = bitmap_size * BITS_PER_BYTE;
unsigned long nr = nbits / 2; unsigned long nr = nbits / 2;
__u64 out_dirty = 0; __u64 out_dirty = 0;
/* Mark all even bits as dirty in the mock domain */ /* Mark all even bits as dirty in the mock domain */
for (count = 0, i = 0; i < nbits; count += !(i % 2), i++) for (i = 0; i < nbits; i += 2)
if (!(i % 2)) set_bit(i, (unsigned long *)bitmap);
set_bit(i, (unsigned long *)bitmap);
ASSERT_EQ(nr, count);
test_cmd_mock_domain_set_dirty(fd, hwpt_id, length, iova, page_size, test_cmd_mock_domain_set_dirty(fd, hwpt_id, length, iova, page_size,
bitmap, &out_dirty); bitmap, &out_dirty);
...@@ -311,9 +309,10 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length, ...@@ -311,9 +309,10 @@ static int _test_mock_dirty_bitmaps(int fd, __u32 hwpt_id, size_t length,
memset(bitmap, 0, bitmap_size); memset(bitmap, 0, bitmap_size);
test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap, test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap,
flags); flags);
for (count = 0, i = 0; i < nbits; count += !(i % 2), i++) /* Beware ASSERT_EQ() is two statements -- braces are not redundant! */
for (i = 0; i < nbits; i++) {
ASSERT_EQ(!(i % 2), test_bit(i, (unsigned long *)bitmap)); ASSERT_EQ(!(i % 2), test_bit(i, (unsigned long *)bitmap));
ASSERT_EQ(count, out_dirty); }
memset(bitmap, 0, bitmap_size); memset(bitmap, 0, bitmap_size);
test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap, test_cmd_get_dirty_bitmap(fd, hwpt_id, length, iova, page_size, bitmap,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment