Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/mock: pass thru unknown ioctls #917

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions test/ioctl/mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -118,18 +119,20 @@
})

#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;
Expand All @@ -148,16 +151,24 @@
result64 = true;
break;
default:
fail("unexpected %s %lu", __func__, (unsigned long) request);
real_ioctl = dlsym(RTLD_NEXT, "ioctl");
if (!real_ioctl)
fail("Error: dlsym failed to find original ioctl\n");

Check failure on line 156 in test/ioctl/mock.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Prefer using '"%s...", __func__' to using 'ioctl', this function's name, in a string
}

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 {
Expand Down