Skip to content

Commit d311be8

Browse files
committed
test: move test_peer->rx_fn function to transmit path
We currently have the peer->rx_fn called after libnvme has sent data to the NVMe device, as a way for the test to check the sent data and modify a response accordingly. However, for testing More Processing Required responses, we will have two TXes for a single RX. So, move the rx_fn callback to the TX side (ie, when libnvme calls recvmsg). This allows the test to provide TX-specific data for each call. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent e451d1e commit d311be8

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

test/mi-mctp.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ static struct test_peer {
5252
ssize_t tx_rc; /* if zero, return the recvmsg len */
5353
int tx_errno;
5454

55-
/* Optional, called after RX, may set tx_buf according to request.
56-
* Return value stored in rx_res, may be used by test */
57-
rx_test_fn rx_fn;
58-
void *rx_data;
59-
int rx_res;
55+
/* Optional, called before TX, may set tx_buf according to request.
56+
* Return value stored in tx_res, may be used by test */
57+
rx_test_fn tx_fn;
58+
void *tx_data;
59+
int tx_fn_res;
6060

6161
/* store sd from socket() setup */
6262
int sd;
@@ -112,19 +112,6 @@ ssize_t __wrap_sendmsg(int sd, const struct msghdr *hdr, int flags)
112112

113113
test_peer.rx_buf_len = pos;
114114

115-
116-
if (test_peer.rx_fn) {
117-
test_peer.rx_res = test_peer.rx_fn(&test_peer,
118-
test_peer.rx_buf,
119-
test_peer.rx_buf_len);
120-
} else {
121-
/* set up a few default response fields; caller may have
122-
* initialised the rest of the response */
123-
test_peer.tx_buf[0] = NVME_MI_MSGTYPE_NVME;
124-
test_peer.tx_buf[1] = test_peer.rx_buf[1] | (NVME_MI_ROR_RSP << 7);
125-
test_set_tx_mic(&test_peer);
126-
}
127-
128115
errno = test_peer.rx_errno;
129116

130117
return test_peer.rx_rc ?: (pos - 1);
@@ -136,6 +123,18 @@ ssize_t __wrap_recvmsg(int sd, struct msghdr *hdr, int flags)
136123

137124
assert(sd == test_peer.sd);
138125

126+
if (test_peer.tx_fn) {
127+
test_peer.tx_fn_res = test_peer.tx_fn(&test_peer,
128+
test_peer.rx_buf,
129+
test_peer.rx_buf_len);
130+
} else {
131+
/* set up a few default response fields; caller may have
132+
* initialised the rest of the response */
133+
test_peer.tx_buf[0] = NVME_MI_MSGTYPE_NVME;
134+
test_peer.tx_buf[1] = test_peer.rx_buf[1] | (NVME_MI_ROR_RSP << 7);
135+
test_set_tx_mic(&test_peer);
136+
}
137+
139138
/* scatter buf into iovec */
140139
for (i = 0, pos = 1; i < hdr->msg_iovlen && pos < test_peer.tx_buf_len;
141140
i++) {
@@ -183,7 +182,7 @@ static void test_tx_none(nvme_mi_ep_t ep, struct test_peer *peer)
183182
int rc;
184183

185184
peer->tx_buf_len = 0;
186-
peer->rx_fn = tx_none;
185+
peer->tx_fn = tx_none;
187186

188187
rc = nvme_mi_mi_read_mi_data_subsys(ep, &ss_info);
189188
assert(rc != 0);

0 commit comments

Comments
 (0)