Skip to content

Commit bdb31a2

Browse files
committed
fabtests/unit: Fix issues with av_lookup_good
Combine declarations, fix calloc, make failure strings better. Signed-off-by: Zach Dworkin <[email protected]>
1 parent a1c071a commit bdb31a2

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

fabtests/unit/av_test.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -619,32 +619,24 @@ av_insert_stages(void)
619619
static int
620620
av_lookup_good(void)
621621
{
622-
int testret;
623-
int ret;
624-
int i, j, found, offset;
625-
struct fid_av *av;
626-
struct fi_av_attr attr;
622+
int testret, ret, i, j, found, offset;
623+
struct fid_av *av = NULL;
624+
struct fi_av_attr attr = {0};
627625
uint8_t addrbuf[4096];
628-
size_t buflen;
629626
uint8_t lookup_buf[4096];
630-
size_t lookup_len;
627+
size_t buflen, lookup_len;
631628
fi_addr_t *fi_addr;
632629

633630
testret = FAIL;
634-
635-
fi_addr = calloc(num_good_addr > 0 ? num_good_addr : 1,
636-
sizeof(fi_addr_t));
631+
fi_addr = calloc(num_good_addr, sizeof(*fi_addr));
637632
if (!fi_addr) {
638633
sprintf(err_buf, "malloc fi_addr failed");
639634
ret = -FI_ENOMEM;
640-
goto fail;
635+
goto done;
641636
}
642637

643-
memset(&attr, 0, sizeof(attr));
644638
attr.type = av_type;
645639
attr.count = num_good_addr;
646-
647-
av = NULL;
648640
ret = fi_av_open(domain, &attr, &av, NULL);
649641
if (ret != 0) {
650642
sprintf(err_buf, "fi_av_open(%s) = %d, %s",
@@ -664,15 +656,16 @@ av_lookup_good(void)
664656

665657
ret = fi_av_insert(av, addrbuf, num_good_addr, fi_addr, 0, NULL);
666658
if (ret != num_good_addr) {
667-
sprintf(err_buf, "fi_av_insert ret=%d, %s", ret,
668-
fi_strerror(-ret));
659+
sprintf(err_buf, "fi_av_insert ret=%d, expected %d", ret,
660+
num_good_addr);
669661
goto fail;
670662
}
671663

672664
for (i = 0; i < num_good_addr; i++) {
673665
if (fi_addr[i] == FI_ADDR_NOTAVAIL) {
674-
sprintf(err_buf, "fi_av_insert failed ret=%d, %s", ret,
675-
fi_strerror(-ret));
666+
sprintf(err_buf, "fi_addr[%d]=%ld, expected %d", i,
667+
fi_addr[i], i);
668+
goto fail;
676669
}
677670
}
678671

@@ -681,7 +674,7 @@ av_lookup_good(void)
681674
memset(lookup_buf, 0, sizeof(lookup_buf));
682675
lookup_len = sizeof(lookup_buf);
683676
ret = fi_av_lookup(av, fi_addr[i], &lookup_buf, &lookup_len);
684-
if (ret != 0) {
677+
if (ret) {
685678
sprintf(err_buf, "fi_av_lookup ret=%d, %s", ret,
686679
fi_strerror(-ret));
687680
goto fail;
@@ -707,9 +700,11 @@ av_lookup_good(void)
707700
}
708701

709702
testret = PASS;
703+
ret = FI_SUCCESS;
710704
fail:
711705
FT_CLOSE_FID(av);
712706
free(fi_addr);
707+
done:
713708
return TEST_RET_VAL(ret, testret);
714709
}
715710

0 commit comments

Comments
 (0)