netmap: update unit tests

Revision r345269 introduced changes that triggered a regression on netmap
unit tests (tests/sys/netmap/ctrl-api-test.c).
This change updates the unit tests to remove the regression.

Reported by:	lwhsu
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D19639
This commit is contained in:
Vincenzo Maffione 2019-03-20 10:36:58 +00:00
parent b8c431f9c0
commit 5e874d26a2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=345323

View File

@ -146,12 +146,12 @@ struct TestContext {
uint32_t nr_hdr_len; /* for PORT_HDR_SET and PORT_HDR_GET */
uint32_t nr_first_cpu_id; /* vale polling */
uint32_t nr_num_polling_cpus; /* vale polling */
uint32_t sync_kloop_mode; /* sync-kloop */
int fd; /* netmap file descriptor */
void *csb; /* CSB entries (atok and ktoa) */
struct nmreq_option *nr_opt; /* list of options */
sem_t *sem; /* for thread synchronization */
struct nmport_d *nmport; /* nmport descriptor from libnetmap */
};
static struct TestContext ctx_;
@ -352,8 +352,11 @@ niocregif(struct TestContext *ctx, int netmap_api)
/* The 11 ABI is the one right before the introduction of the new NIOCCTRL
* ABI. The 11 ABI is useful to perform tests with legacy applications
* (which use the 11 ABI) and new kernel (which uses 12, or higher). */
#define NETMAP_API_NIOCREGIF 11
* (which use the 11 ABI) and new kernel (which uses 12, or higher).
* However, version 14 introduced a change in the layout of struct netmap_if,
* so that binary backward compatibility to 11 is not supported anymore.
*/
#define NETMAP_API_NIOCREGIF 14
static int
legacy_regif_default(struct TestContext *ctx)
@ -1113,7 +1116,7 @@ bad_extmem_option(struct TestContext *ctx)
pools_info_fill(&pools_info);
/* Request a large ring size, to make sure that the kernel
* rejects our request. */
pools_info.nr_ring_pool_objsize = (1 << 16);
pools_info.nr_ring_pool_objsize = (1 << 20);
return _extmem_option(ctx, &pools_info) < 0 ? 0 : -1;
}
@ -1140,6 +1143,10 @@ duplicate_extmem_options(struct TestContext *ctx)
save1 = e1;
save2 = e2;
strncpy(ctx->ifname_ext, "vale0:0", sizeof(ctx->ifname_ext));
ctx->nr_tx_slots = 16;
ctx->nr_rx_slots = 16;
ret = port_register_hwall(ctx);
if (ret >= 0) {
printf("duplicate option not detected\n");
@ -1322,51 +1329,58 @@ sync_kloop(struct TestContext *ctx)
static int
sync_kloop_eventfds(struct TestContext *ctx)
{
struct nmreq_opt_sync_kloop_eventfds *opt = NULL;
struct nmreq_option save;
struct nmreq_opt_sync_kloop_eventfds *evopt = NULL;
struct nmreq_opt_sync_kloop_mode modeopt;
struct nmreq_option evsave;
int num_entries;
size_t opt_size;
int ret, i;
memset(&modeopt, 0, sizeof(modeopt));
modeopt.nro_opt.nro_reqtype = NETMAP_REQ_OPT_SYNC_KLOOP_MODE;
modeopt.mode = ctx->sync_kloop_mode;
push_option(&modeopt.nro_opt, ctx);
num_entries = num_registered_rings(ctx);
opt_size = sizeof(*opt) + num_entries * sizeof(opt->eventfds[0]);
opt = calloc(1, opt_size);
opt->nro_opt.nro_next = 0;
opt->nro_opt.nro_reqtype = NETMAP_REQ_OPT_SYNC_KLOOP_EVENTFDS;
opt->nro_opt.nro_status = 0;
opt->nro_opt.nro_size = opt_size;
opt_size = sizeof(*evopt) + num_entries * sizeof(evopt->eventfds[0]);
evopt = calloc(1, opt_size);
evopt->nro_opt.nro_next = 0;
evopt->nro_opt.nro_reqtype = NETMAP_REQ_OPT_SYNC_KLOOP_EVENTFDS;
evopt->nro_opt.nro_status = 0;
evopt->nro_opt.nro_size = opt_size;
for (i = 0; i < num_entries; i++) {
int efd = eventfd(0, 0);
opt->eventfds[i].ioeventfd = efd;
evopt->eventfds[i].ioeventfd = efd;
efd = eventfd(0, 0);
opt->eventfds[i].irqfd = efd;
evopt->eventfds[i].irqfd = efd;
}
push_option(&opt->nro_opt, ctx);
save = opt->nro_opt;
push_option(&evopt->nro_opt, ctx);
evsave = evopt->nro_opt;
ret = sync_kloop_start_stop(ctx);
if (ret != 0) {
free(opt);
free(evopt);
clear_options(ctx);
return ret;
}
#ifdef __linux__
save.nro_status = 0;
evsave.nro_status = 0;
#else /* !__linux__ */
save.nro_status = EOPNOTSUPP;
evsave.nro_status = EOPNOTSUPP;
#endif /* !__linux__ */
ret = checkoption(&opt->nro_opt, &save);
free(opt);
ret = checkoption(&evopt->nro_opt, &evsave);
free(evopt);
clear_options(ctx);
return ret;
}
static int
sync_kloop_eventfds_all(struct TestContext *ctx)
sync_kloop_eventfds_all_mode(struct TestContext *ctx,
uint32_t sync_kloop_mode)
{
int ret;
@ -1375,9 +1389,17 @@ sync_kloop_eventfds_all(struct TestContext *ctx)
return ret;
}
ctx->sync_kloop_mode = sync_kloop_mode;
return sync_kloop_eventfds(ctx);
}
static int
sync_kloop_eventfds_all(struct TestContext *ctx)
{
return sync_kloop_eventfds_all_mode(ctx, 0);
}
static int
sync_kloop_eventfds_all_tx(struct TestContext *ctx)
{
@ -1398,6 +1420,27 @@ sync_kloop_eventfds_all_tx(struct TestContext *ctx)
return sync_kloop_eventfds(ctx);
}
static int
sync_kloop_eventfds_all_direct(struct TestContext *ctx)
{
return sync_kloop_eventfds_all_mode(ctx,
NM_OPT_SYNC_KLOOP_DIRECT_TX | NM_OPT_SYNC_KLOOP_DIRECT_RX);
}
static int
sync_kloop_eventfds_all_direct_tx(struct TestContext *ctx)
{
return sync_kloop_eventfds_all_mode(ctx,
NM_OPT_SYNC_KLOOP_DIRECT_TX);
}
static int
sync_kloop_eventfds_all_direct_rx(struct TestContext *ctx)
{
return sync_kloop_eventfds_all_mode(ctx,
NM_OPT_SYNC_KLOOP_DIRECT_RX);
}
static int
sync_kloop_nocsb(struct TestContext *ctx)
{
@ -1677,6 +1720,9 @@ static struct mytest tests[] = {
decltest(sync_kloop),
decltest(sync_kloop_eventfds_all),
decltest(sync_kloop_eventfds_all_tx),
decltest(sync_kloop_eventfds_all_direct),
decltest(sync_kloop_eventfds_all_direct_tx),
decltest(sync_kloop_eventfds_all_direct_rx),
decltest(sync_kloop_nocsb),
decltest(sync_kloop_csb_enable),
decltest(sync_kloop_conflict),