1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/* Copyright 2021, Fujitsu */
/*
* info-bind_addr.c -- unit tests of the info module
*
* API covered:
* - rpma_info_bind_addr()
*/
#include <stdlib.h>
#include <string.h>
#include "cmocka_headers.h"
#include "test-common.h"
#include "conn_req.h"
#include "info.h"
#include "librpma.h"
#include "info-common.h"
#include "mocks-rdma_cm.h"
#include "mocks-string.h"
#include <infiniband/verbs.h>
/*
* bind_addr__id_NULL -- NULL id is invalid
*/
static void
bind_addr__id_NULL(void **info_state_ptr)
{
struct info_state *istate = *info_state_ptr;
/* run test */
int ret = rpma_info_bind_addr(istate->info, NULL);
/* verify the result */
assert_int_equal(ret, RPMA_E_INVAL);
}
/*
* bind_addr__info_NULL -- NULL info is invalid
*/
static void
bind_addr__info_NULL(void **unused)
{
/* run test */
struct rdma_cm_id cmid = {0};
int ret = rpma_info_bind_addr(NULL, &cmid);
/* verify the result */
assert_int_equal(ret, RPMA_E_INVAL);
assert_int_equal(memcmp(&cmid, &Cmid_zero, sizeof(cmid)), 0);
}
/*
* bind_addr__id_info_NULL -- NULL id and info are invalid
*/
static void
bind_addr__id_info_NULL(void **unused)
{
/* run test */
int ret = rpma_info_bind_addr(NULL, NULL);
/* verify the result */
assert_int_equal(ret, RPMA_E_INVAL);
}
/*
* bind_addr__bind_addr_ERRNO -- rpma_info_bind_addr() fails
* with MOCK_ERRNO
*/
static void
bind_addr__bind_addr_ERRNO(void **info_state_ptr)
{
struct info_state *istate = *info_state_ptr;
/* configure mocks */
struct rdma_cm_id cmid = {0};
expect_value(rdma_bind_addr, id, &cmid);
expect_value(rdma_bind_addr, addr, MOCK_SRC_ADDR);
will_return(rdma_bind_addr, MOCK_ERRNO);
expect_value(__wrap_strerror, errnum, MOCK_ERRNO);
will_return(__wrap_strerror, MOCK_ERROR);
/* run test */
int ret = rpma_info_bind_addr(istate->info, &cmid);
/* verify the result */
assert_int_equal(ret, RPMA_E_PROVIDER);
assert_int_equal(memcmp(&cmid, &Cmid_zero, sizeof(cmid)), 0);
}
/*
* bind_addr__success -- happy day scenario
*/
static void
bind_addr__success(void **info_state_ptr)
{
struct info_state *istate = *info_state_ptr;
/* configure mocks */
struct rdma_cm_id cmid = {0};
expect_value(rdma_bind_addr, id, &cmid);
expect_value(rdma_bind_addr, addr, MOCK_SRC_ADDR);
will_return(rdma_bind_addr, MOCK_OK);
/* run test */
int ret = rpma_info_bind_addr(istate->info, &cmid);
/* verify the result */
assert_int_equal(ret, MOCK_OK);
assert_int_equal(memcmp(&cmid, &Cmid_zero, sizeof(cmid)), 0);
}
int
main(int argc, char *argv[])
{
const struct CMUnitTest tests[] = {
/* rpma_info_bind_addr() unit tests */
cmocka_unit_test_setup_teardown(bind_addr__id_NULL,
setup__new_passive, teardown__delete),
cmocka_unit_test(bind_addr__info_NULL),
cmocka_unit_test(bind_addr__id_info_NULL),
cmocka_unit_test_setup_teardown(bind_addr__bind_addr_ERRNO,
setup__new_passive, teardown__delete),
cmocka_unit_test_setup_teardown(bind_addr__success,
setup__new_passive, teardown__delete),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
|