Skip to content

Commit a56e704

Browse files
committed
mi: Add Admin error test
Ensure we handle an error response through the Admin command path. Signed-off-by: Jeremy Kerr <[email protected]>
1 parent fdf8ea3 commit a56e704

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

test/mi.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,60 @@ static void test_admin_id(nvme_mi_ep_t ep)
260260
assert(rc == 0);
261261
}
262262

263+
/* test: simple NVMe error response */
264+
static int test_admin_err_resp_cb(struct nvme_mi_ep *ep,
265+
struct nvme_mi_req *req,
266+
struct nvme_mi_resp *resp,
267+
void *data)
268+
{
269+
__u8 ror, mt, *hdr;
270+
271+
assert(req->hdr->type == NVME_MI_MSGTYPE_NVME);
272+
273+
ror = req->hdr->nmp >> 7;
274+
mt = req->hdr->nmp >> 3 & 0x7;
275+
assert(ror == NVME_MI_ROR_REQ);
276+
assert(mt == NVME_MI_MT_ADMIN);
277+
278+
/* do we have enough for a mi header? */
279+
assert(req->hdr_len == sizeof(struct nvme_mi_admin_req_hdr));
280+
281+
/* inspect response as raw bytes */
282+
hdr = (__u8 *)req->hdr;
283+
assert(hdr[4] == nvme_admin_identify);
284+
285+
/* we need at least 8 bytes for error information */
286+
assert(resp->hdr_len >= 8);
287+
288+
/* create error response */
289+
hdr = (__u8 *)resp->hdr;
290+
hdr[4] = 0x02; /* status: internal error */
291+
hdr[5] = 0;
292+
hdr[6] = 0;
293+
hdr[7] = 0;
294+
resp->hdr_len = 8;
295+
resp->data_len = 0;
296+
297+
test_transport_resp_calc_mic(resp);
298+
299+
return 0;
300+
}
301+
302+
static void test_admin_err_resp(nvme_mi_ep_t ep)
303+
{
304+
struct nvme_id_ctrl id;
305+
nvme_mi_ctrl_t ctrl;
306+
int rc;
307+
308+
test_set_transport_callback(ep, test_admin_err_resp_cb, NULL);
309+
310+
ctrl = nvme_mi_init_ctrl(ep, 1);
311+
assert(ctrl);
312+
313+
rc = nvme_mi_admin_identify_ctrl(ctrl, &id);
314+
assert(rc != 0);
315+
}
316+
263317
#define DEFINE_TEST(name) { #name, test_ ## name }
264318
struct test {
265319
const char *name;
@@ -269,6 +323,7 @@ struct test {
269323
DEFINE_TEST(transport_fail),
270324
DEFINE_TEST(invalid_crc),
271325
DEFINE_TEST(admin_id),
326+
DEFINE_TEST(admin_err_resp),
272327
};
273328

274329
static void print_log_buf(FILE *logfd)

0 commit comments

Comments
 (0)