Skip to content

Commit 29d8868

Browse files
tursulinjgunthorpe
authored andcommitted
tools/testing/scatterlist: Show errors in human readable form
Instead of just asserting dump some more useful info about what the test saw versus what it expected to see. Link: https://lore.kernel.org/r/20201004154340.1080481-4-leon@kernel.org Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Maor Gottlieb <maorg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent efc5b2e commit 29d8868

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

  • tools/testing/scatterlist

tools/testing/scatterlist/main.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
#define MAX_PAGES (64)
77

8+
struct test {
9+
int alloc_ret;
10+
unsigned num_pages;
11+
unsigned *pfn;
12+
unsigned size;
13+
unsigned int max_seg;
14+
unsigned int expected_segments;
15+
};
16+
817
static void set_pages(struct page **pages, const unsigned *array, unsigned num)
918
{
1019
unsigned int i;
@@ -17,17 +26,32 @@ static void set_pages(struct page **pages, const unsigned *array, unsigned num)
1726

1827
#define pfn(...) (unsigned []){ __VA_ARGS__ }
1928

29+
static void fail(struct test *test, struct sg_table *st, const char *cond)
30+
{
31+
unsigned int i;
32+
33+
fprintf(stderr, "Failed on '%s'!\n\n", cond);
34+
35+
printf("size = %u, max segment = %u, expected nents = %u\nst->nents = %u, st->orig_nents= %u\n",
36+
test->size, test->max_seg, test->expected_segments, st->nents,
37+
st->orig_nents);
38+
39+
printf("%u input PFNs:", test->num_pages);
40+
for (i = 0; i < test->num_pages; i++)
41+
printf(" %x", test->pfn[i]);
42+
printf("\n");
43+
44+
exit(1);
45+
}
46+
47+
#define VALIDATE(cond, st, test) \
48+
if (!(cond)) \
49+
fail((test), (st), #cond);
50+
2051
int main(void)
2152
{
2253
const unsigned int sgmax = SCATTERLIST_MAX_SEGMENT;
23-
struct test {
24-
int alloc_ret;
25-
unsigned num_pages;
26-
unsigned *pfn;
27-
unsigned size;
28-
unsigned int max_seg;
29-
unsigned int expected_segments;
30-
} *test, tests[] = {
54+
struct test *test, tests[] = {
3155
{ -EINVAL, 1, pfn(0), PAGE_SIZE, PAGE_SIZE + 1, 1 },
3256
{ -EINVAL, 1, pfn(0), PAGE_SIZE, 0, 1 },
3357
{ -EINVAL, 1, pfn(0), PAGE_SIZE, sgmax + 1, 1 },
@@ -67,8 +91,8 @@ int main(void)
6791
if (test->alloc_ret)
6892
continue;
6993

70-
assert(st.nents == test->expected_segments);
71-
assert(st.orig_nents == test->expected_segments);
94+
VALIDATE(st.nents == test->expected_segments, &st, test);
95+
VALIDATE(st.orig_nents == test->expected_segments, &st, test);
7296

7397
sg_free_table(&st);
7498
}

0 commit comments

Comments
 (0)