1
0
Fork 0

Adding upstream version 1.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-16 10:05:30 +01:00
parent a619319278
commit b3d79ba722
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
762 changed files with 7536 additions and 1096 deletions

View file

@ -12,7 +12,7 @@
main = executable(
'main-test',
['test.c'],
dependencies: [libnvme_dep, libuuid_dep],
dependencies: [libnvme_dep],
include_directories: [incdir, internal_incdir]
)
@ -56,3 +56,12 @@ mi_mctp = executable(
)
test('mi-mctp', mi_mctp)
uuid = executable(
'test-uuid',
['uuid.c'],
dependencies: libnvme_dep,
include_directories: [incdir, internal_incdir]
)
test('uuid', uuid)

View file

@ -308,7 +308,8 @@ static void test_admin_resp_err(nvme_mi_ep_t ep, struct test_peer *peer)
peer->tx_buf_len = 8;
rc = nvme_mi_admin_identify_ctrl(ctrl, &id);
assert(rc == 0x2);
assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI);
assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR);
}
/* test: all 4-byte aligned response sizes - should be decoded into the
@ -332,7 +333,8 @@ static void test_admin_resp_sizes(nvme_mi_ep_t ep, struct test_peer *peer)
for (i = 8; i <= 4096 + 8; i+=4) {
peer->tx_buf_len = i;
rc = nvme_mi_admin_identify_ctrl(ctrl, &id);
assert(rc == 2);
assert(nvme_status_get_type(rc) == NVME_STATUS_TYPE_MI);
assert(nvme_status_get_value(rc) == NVME_MI_RESP_INTERNAL_ERR);
}
nvme_mi_close_ctrl(ctrl);
@ -407,6 +409,7 @@ static void test_poll_timeout(nvme_mi_ep_t ep, struct test_peer *peer)
/* test: send a More Processing Required response, then the actual response */
struct mpr_tx_info {
int msg_no;
bool admin_quirk;
size_t final_len;
};
@ -422,6 +425,9 @@ static int tx_mpr(struct test_peer *peer, void *buf, size_t len)
case 1:
peer->tx_buf[4] = NVME_MI_RESP_MPR;
peer->tx_buf_len = 8;
if (tx_info->admin_quirk) {
peer->tx_buf_len = 20;
}
break;
case 2:
peer->tx_buf[4] = NVME_MI_RESP_SUCCESS;
@ -446,6 +452,7 @@ static void test_mpr_mi(nvme_mi_ep_t ep, struct test_peer *peer)
tx_info.msg_no = 1;
tx_info.final_len = sizeof(struct nvme_mi_mi_resp_hdr) + sizeof(ss_info);
tx_info.admin_quirk = false;
peer->tx_fn = tx_mpr;
peer->tx_data = &tx_info;
@ -463,6 +470,32 @@ static void test_mpr_admin(nvme_mi_ep_t ep, struct test_peer *peer)
tx_info.msg_no = 1;
tx_info.final_len = sizeof(struct nvme_mi_admin_resp_hdr) + sizeof(id);
tx_info.admin_quirk = false;
peer->tx_fn = tx_mpr;
peer->tx_data = &tx_info;
ctrl = nvme_mi_init_ctrl(ep, 1);
rc = nvme_mi_admin_identify_ctrl(ctrl, &id);
assert(rc == 0);
nvme_mi_close_ctrl(ctrl);
}
/* We have seen drives that send a MPR response as a full Admin message,
* rather than a MI message; these have a larger message body
*/
static void test_mpr_admin_quirked(nvme_mi_ep_t ep, struct test_peer *peer)
{
struct mpr_tx_info tx_info;
struct nvme_id_ctrl id;
nvme_mi_ctrl_t ctrl;
int rc;
tx_info.msg_no = 1;
tx_info.final_len = sizeof(struct nvme_mi_admin_resp_hdr) + sizeof(id);
tx_info.admin_quirk = true;
peer->tx_fn = tx_mpr;
peer->tx_data = &tx_info;
@ -638,6 +671,7 @@ struct test {
DEFINE_TEST(poll_timeout),
DEFINE_TEST(mpr_mi),
DEFINE_TEST(mpr_admin),
DEFINE_TEST(mpr_admin_quirked),
DEFINE_TEST(mpr_timeouts),
DEFINE_TEST(mpr_timeout_clamp),
DEFINE_TEST(mpr_mprt_zero),

1050
test/mi.c

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,6 @@
#include <string.h>
#include <stdbool.h>
#include <inttypes.h>
#include <uuid.h>
#include <libnvme.h>
#include <ccan/endian/endian.h>
@ -377,8 +376,8 @@ int main(int argc, char **argv)
nvme_ctrl_get_state(c));
nvme_ctrl_for_each_ns(c, n) {
char uuid_str[40];
uuid_t uuid;
char uuid_str[NVME_UUID_LEN_STRING];
unsigned char uuid[NVME_UUID_LEN];
printf(" `- %s lba size:%d lba max:%" PRIu64 "\n",
nvme_ns_get_name(n),
nvme_ns_get_lba_size(n),
@ -388,7 +387,7 @@ int main(int argc, char **argv)
printf(" nguid:");
print_hex(nvme_ns_get_nguid(n), 16);
nvme_ns_get_uuid(n, uuid);
uuid_unparse_lower(uuid, uuid_str);
nvme_uuid_to_string(uuid, uuid_str);
printf(" uuid:%s csi:%d\n", uuid_str,
nvme_ns_get_csi(n));
}

120
test/uuid.c Normal file
View file

@ -0,0 +1,120 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
/**
* This file is part of libnvme.
* Copyright (c) 2022 Daniel Wagner, SUSE Software Solutions
*/
#include <string.h>
#include <stdlib.h>
#include <ccan/array_size/array_size.h>
#include <libnvme.h>
static int test_rc;
struct test_data {
unsigned char uuid[NVME_UUID_LEN];
const char *str;
};
static struct test_data test_data[] = {
{ { 0 }, "00000000-0000-0000-0000-000000000000" },
{ { [0 ... 15] = 0xff }, "ffffffff-ffff-ffff-ffff-ffffffffffff" },
{ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0f, 0x10 },
"00010203-0405-0607-0809-0a0b0c0d0f10" },
};
static void check_str(const char *exp, const char *res)
{
if (!strcmp(res, exp))
return;
printf("ERROR: got '%s', expected '%s'\n", res, exp);
test_rc = 1;
}
static void print_uuid_hex(const unsigned char uuid[NVME_UUID_LEN])
{
for (int i = 0; i < NVME_UUID_LEN; i++)
printf("%02x", uuid[i]);
}
static void check_uuid(unsigned char exp[NVME_UUID_LEN],
unsigned char res[NVME_UUID_LEN])
{
if (!memcmp(exp, res, NVME_UUID_LEN))
return;
printf("ERROR: got '");
print_uuid_hex(exp);
printf("', expected '");
print_uuid_hex(res);
printf("'\n");
}
static void tostr_test(struct test_data *test)
{
char str[NVME_UUID_LEN_STRING];
if (nvme_uuid_to_string(test->uuid, str)) {
test_rc = 1;
printf("ERROR: nvme_uuid_to_string() failed\n");
return;
}
check_str(test->str, str);
}
static void fromstr_test(struct test_data *test)
{
unsigned char uuid[NVME_UUID_LEN];
if (nvme_uuid_from_string(test->str, uuid)) {
test_rc = 1;
printf("ERROR: nvme_uuid_from_string() failed\n");
return;
}
check_uuid(test->uuid, uuid);
}
static void random_uuid_test(void)
{
unsigned char uuid1[NVME_UUID_LEN], uuid2[NVME_UUID_LEN];
char str1[NVME_UUID_LEN_STRING], str2[NVME_UUID_LEN_STRING];
if (nvme_uuid_random(uuid1) || nvme_uuid_random(uuid2)) {
test_rc = 1;
printf("ERROR: nvme_uuid_random() failed\n");
return;
}
if (!memcmp(uuid1, uuid2, NVME_UUID_LEN)) {
test_rc = 1;
printf("ERROR: generated random numbers are equal\n");
return;
}
if (nvme_uuid_to_string(uuid1, str1) ||
nvme_uuid_to_string(uuid2, str2)) {
test_rc = 1;
printf("ERROR: could not stringify randomly generated UUID\n");
return;
}
printf("PASS: generated UUIDs %s %s\n", str1, str2);
}
int main(void)
{
for (int i = 0; i < ARRAY_SIZE(test_data); i++)
tostr_test(&test_data[i]);
for (int i = 0; i < ARRAY_SIZE(test_data); i++)
fromstr_test(&test_data[i]);
random_uuid_test();
return test_rc ? EXIT_FAILURE : EXIT_SUCCESS;
}