Adding upstream version 1.12.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
9c1dc68a45
commit
a47f11de04
1005 changed files with 9469 additions and 1830 deletions
|
@ -1,7 +1,21 @@
|
|||
mock_conf = configuration_data()
|
||||
|
||||
mock_conf.set(
|
||||
'HAVE_GLIBC_IOCTL',
|
||||
cc.compiles(
|
||||
'''#include <sys/ioctl.h>
|
||||
int ioctl(int fd, unsigned long request, ...);
|
||||
''',
|
||||
name: 'ioctl has glibc-style prototype'
|
||||
),
|
||||
description: 'Is ioctl the glibc interface (rather than POSIX)'
|
||||
)
|
||||
|
||||
mock_ioctl = library(
|
||||
'mock-ioctl',
|
||||
['mock.c', 'util.c'],
|
||||
)
|
||||
dependencies: [dl_dep],
|
||||
c_args: ['-DHAVE_GLIBC_IOCTL=' + (mock_conf.get('HAVE_GLIBC_IOCTL') ? '1' : '0')])
|
||||
|
||||
# Add mock-ioctl to the LD_PRELOAD path so it overrides libc.
|
||||
# Append to LD_PRELOAD so existing libraries, e.g. libasan, are kept.
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "../../src/nvme/ioctl.h"
|
||||
#include "util.h"
|
||||
|
@ -118,18 +119,20 @@ void end_mock_cmds(void)
|
|||
})
|
||||
|
||||
#ifdef HAVE_GLIBC_IOCTL
|
||||
typedef int (*ioctl_func_t)(int, unsigned long, void *);
|
||||
int ioctl(int fd, unsigned long request, ...)
|
||||
#else
|
||||
typedef int (*ioctl_func_t)(int, int, void *);
|
||||
int ioctl(int fd, int request, ...)
|
||||
#endif
|
||||
{
|
||||
ioctl_func_t real_ioctl = NULL;
|
||||
struct mock_cmds *mock_cmds;
|
||||
bool result64;
|
||||
const struct mock_cmd *mock_cmd;
|
||||
va_list args;
|
||||
void *cmd;
|
||||
|
||||
check(fd == mock_fd, "got fd %d, expected %d", fd, mock_fd);
|
||||
switch (request) {
|
||||
case NVME_IOCTL_ADMIN_CMD:
|
||||
mock_cmds = &mock_admin_cmds;
|
||||
|
@ -148,16 +151,28 @@ int ioctl(int fd, int request, ...)
|
|||
result64 = true;
|
||||
break;
|
||||
default:
|
||||
fail("unexpected %s %lu", __func__, (unsigned long) request);
|
||||
#if HAVE_LIBC_LDSYM
|
||||
real_ioctl = dlsym(RTLD_NEXT, "ioctl");
|
||||
if (!real_ioctl)
|
||||
fail("Error: dlsym failed to find original ioctl\n");
|
||||
#else
|
||||
fail("Error: unhandled ioctl\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
va_start(args, request);
|
||||
cmd = va_arg(args, void *);
|
||||
va_end(args);
|
||||
|
||||
if (real_ioctl)
|
||||
return real_ioctl(fd, request, cmd);
|
||||
|
||||
check(fd == mock_fd, "got fd %d, expected %d", fd, mock_fd);
|
||||
check(mock_cmds->remaining_cmds,
|
||||
"unexpected %s command", mock_cmds->name);
|
||||
mock_cmd = mock_cmds->cmds++;
|
||||
mock_cmds->remaining_cmds--;
|
||||
|
||||
va_start(args, request);
|
||||
cmd = va_arg(args, void *);
|
||||
va_end(args);
|
||||
if (result64) {
|
||||
execute_ioctl((struct nvme_passthru_cmd64 *)cmd, mock_cmd);
|
||||
} else {
|
||||
|
@ -173,3 +188,9 @@ int ioctl(int fd, int request, ...)
|
|||
|
||||
return mock_cmd->err;
|
||||
}
|
||||
|
||||
/* mock io_uring_get_probe, just fail */
|
||||
struct io_uring_probe *io_uring_get_probe(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,17 @@ if cxx_available
|
|||
dependencies: libnvme_dep,
|
||||
include_directories: [incdir, internal_incdir]
|
||||
)
|
||||
|
||||
test('cpp-dump', cpp)
|
||||
|
||||
misc = executable(
|
||||
'test-misc',
|
||||
['misc.cc'],
|
||||
dependencies: libnvme_dep,
|
||||
include_directories: [incdir, internal_incdir]
|
||||
)
|
||||
test('cpp-misc', misc)
|
||||
|
||||
endif
|
||||
|
||||
register = executable(
|
||||
|
|
45
test/mi.c
45
test/mi.c
|
@ -566,8 +566,8 @@ static void test_admin_err_nvme_resp(nvme_mi_ep_t ep)
|
|||
| NVME_SC_DNR));
|
||||
}
|
||||
|
||||
/* invalid Admin command transfers */
|
||||
static int test_admin_invalid_formats_cb(struct nvme_mi_ep *ep,
|
||||
/* invalid command transfers */
|
||||
static int test_rejected_command_cb(struct nvme_mi_ep *ep,
|
||||
struct nvme_mi_req *req,
|
||||
struct nvme_mi_resp *resp,
|
||||
void *data)
|
||||
|
@ -588,7 +588,7 @@ static void test_admin_invalid_formats(nvme_mi_ep_t ep)
|
|||
size_t len;
|
||||
int rc;
|
||||
|
||||
test_set_transport_callback(ep, test_admin_invalid_formats_cb, NULL);
|
||||
test_set_transport_callback(ep, test_rejected_command_cb, NULL);
|
||||
|
||||
ctrl = nvme_mi_init_ctrl(ep, 1);
|
||||
assert(ctrl);
|
||||
|
@ -629,6 +629,44 @@ static void test_admin_invalid_formats(nvme_mi_ep_t ep)
|
|||
assert(rc != 0);
|
||||
}
|
||||
|
||||
static void test_mi_invalid_formats(nvme_mi_ep_t ep)
|
||||
{
|
||||
struct {
|
||||
struct nvme_mi_mi_req_hdr hdr;
|
||||
uint8_t data[4];
|
||||
} req = { 0 };
|
||||
struct nvme_mi_mi_resp_hdr resp = { 0 };
|
||||
nvme_mi_ctrl_t ctrl;
|
||||
size_t len;
|
||||
int rc;
|
||||
|
||||
test_set_transport_callback(ep, test_rejected_command_cb, NULL);
|
||||
|
||||
ctrl = nvme_mi_init_ctrl(ep, 1);
|
||||
assert(ctrl);
|
||||
|
||||
/* unaligned req size */
|
||||
len = 0;
|
||||
|
||||
rc = nvme_mi_mi_xfer(ep, &req.hdr, 1, &resp, &len);
|
||||
assert(rc != 0);
|
||||
|
||||
/* unaligned resp size */
|
||||
len = 1;
|
||||
rc = nvme_mi_mi_xfer(ep, &req.hdr, 0, &resp, &len);
|
||||
assert(rc != 0);
|
||||
|
||||
/* resp too large */
|
||||
len = 4096 + 4;
|
||||
rc = nvme_mi_mi_xfer(ep, &req.hdr, 0, &resp, &len);
|
||||
assert(rc != 0);
|
||||
|
||||
/* req and resp payloads */
|
||||
len = 4;
|
||||
rc = nvme_mi_mi_xfer(ep, &req.hdr, 4, &resp, &len);
|
||||
assert(rc != 0);
|
||||
}
|
||||
|
||||
/* test: header length too small */
|
||||
static int test_resp_hdr_small_cb(struct nvme_mi_ep *ep,
|
||||
struct nvme_mi_req *req,
|
||||
|
@ -2049,6 +2087,7 @@ struct test {
|
|||
DEFINE_TEST(endpoint_quirk_probe),
|
||||
DEFINE_TEST(admin_dlen_doff_req),
|
||||
DEFINE_TEST(admin_dlen_doff_resp),
|
||||
DEFINE_TEST(mi_invalid_formats),
|
||||
};
|
||||
|
||||
static void run_test(struct test *test, FILE *logfd, nvme_mi_ep_t ep)
|
||||
|
|
22
test/misc.cc
Normal file
22
test/misc.cc
Normal file
|
@ -0,0 +1,22 @@
|
|||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
/**
|
||||
* This file is part of libnvme.
|
||||
* Copyright (c) 2025 Daniel Wagner, SUSE LLC
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <libnvme.h>
|
||||
|
||||
static int minmax_test()
|
||||
{
|
||||
/*
|
||||
* Ensure libnvme doesn't spoil the namespace, e.g. by exposing a
|
||||
* min/max macro.
|
||||
*/
|
||||
return !(std::min(1, 2) == 1 && std::max(1, 2) == 2);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return minmax_test();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue