15129044dSC.J. Collier/*-
25129044dSC.J. Collier *   BSD LICENSE
35129044dSC.J. Collier *
45129044dSC.J. Collier *   Copyright 2014 6WIND S.A.
55129044dSC.J. Collier *
65129044dSC.J. Collier *   Redistribution and use in source and binary forms, with or without
75129044dSC.J. Collier *   modification, are permitted provided that the following conditions
85129044dSC.J. Collier *   are met:
95129044dSC.J. Collier *
105129044dSC.J. Collier *     * Redistributions of source code must retain the above copyright
115129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer.
125129044dSC.J. Collier *     * Redistributions in binary form must reproduce the above copyright
135129044dSC.J. Collier *       notice, this list of conditions and the following disclaimer in
145129044dSC.J. Collier *       the documentation and/or other materials provided with the
155129044dSC.J. Collier *       distribution.
165129044dSC.J. Collier *     * Neither the name of 6WIND S.A nor the names of its contributors
175129044dSC.J. Collier *       may be used to endorse or promote products derived from this
185129044dSC.J. Collier *       software without specific prior written permission.
195129044dSC.J. Collier *
205129044dSC.J. Collier *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
215129044dSC.J. Collier *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
225129044dSC.J. Collier *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
235129044dSC.J. Collier *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
245129044dSC.J. Collier *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
255129044dSC.J. Collier *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
265129044dSC.J. Collier *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
275129044dSC.J. Collier *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
285129044dSC.J. Collier *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
295129044dSC.J. Collier *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
305129044dSC.J. Collier *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
315129044dSC.J. Collier */
325129044dSC.J. Collier
335129044dSC.J. Collier#include <stdio.h>
345129044dSC.J. Collier#include <stdlib.h>
355129044dSC.J. Collier#include <string.h>
365129044dSC.J. Collier#include <sys/queue.h>
375129044dSC.J. Collier
385129044dSC.J. Collier#include <rte_debug.h>
395129044dSC.J. Collier#include <rte_devargs.h>
405129044dSC.J. Collier
415129044dSC.J. Collier#include "test.h"
425129044dSC.J. Collier
435129044dSC.J. Collier/* clear devargs list that was modified by the test */
445129044dSC.J. Collierstatic void free_devargs_list(void)
455129044dSC.J. Collier{
465129044dSC.J. Collier	struct rte_devargs *devargs;
475129044dSC.J. Collier
485129044dSC.J. Collier	while (!TAILQ_EMPTY(&devargs_list)) {
495129044dSC.J. Collier		devargs = TAILQ_FIRST(&devargs_list);
505129044dSC.J. Collier		TAILQ_REMOVE(&devargs_list, devargs, next);
515129044dSC.J. Collier		free(devargs->args);
525129044dSC.J. Collier		free(devargs);
535129044dSC.J. Collier	}
545129044dSC.J. Collier}
555129044dSC.J. Collier
565129044dSC.J. Collierstatic int
575129044dSC.J. Colliertest_devargs(void)
585129044dSC.J. Collier{
595129044dSC.J. Collier	struct rte_devargs_list save_devargs_list;
605129044dSC.J. Collier	struct rte_devargs *devargs;
615129044dSC.J. Collier
625129044dSC.J. Collier	/* save the real devargs_list, it is restored at the end of the test */
635129044dSC.J. Collier	save_devargs_list = devargs_list;
645129044dSC.J. Collier	TAILQ_INIT(&devargs_list);
655129044dSC.J. Collier
665129044dSC.J. Collier	/* test valid cases */
675129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "08:00.1") < 0)
685129044dSC.J. Collier		goto fail;
695129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "0000:5:00.0") < 0)
705129044dSC.J. Collier		goto fail;
715129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI, "04:00.0,arg=val") < 0)
725129044dSC.J. Collier		goto fail;
735129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI, "0000:01:00.1") < 0)
745129044dSC.J. Collier		goto fail;
755129044dSC.J. Collier	if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 2)
765129044dSC.J. Collier		goto fail;
775129044dSC.J. Collier	if (rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 2)
785129044dSC.J. Collier		goto fail;
795129044dSC.J. Collier	if (rte_eal_devargs_type_count(RTE_DEVTYPE_VIRTUAL) != 0)
805129044dSC.J. Collier		goto fail;
813d9b7210SChristian Ehrhardt	if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, "net_ring0") < 0)
825129044dSC.J. Collier		goto fail;
833d9b7210SChristian Ehrhardt	if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, "net_ring1,key=val,k2=val2") < 0)
845129044dSC.J. Collier		goto fail;
855129044dSC.J. Collier	if (rte_eal_devargs_type_count(RTE_DEVTYPE_VIRTUAL) != 2)
865129044dSC.J. Collier		goto fail;
875129044dSC.J. Collier	free_devargs_list();
885129044dSC.J. Collier
895129044dSC.J. Collier	/* check virtual device with argument parsing */
903d9b7210SChristian Ehrhardt	if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, "net_ring1,k1=val,k2=val2") < 0)
915129044dSC.J. Collier		goto fail;
925129044dSC.J. Collier	devargs = TAILQ_FIRST(&devargs_list);
933d9b7210SChristian Ehrhardt	if (strncmp(devargs->virt.drv_name, "net_ring1",
945129044dSC.J. Collier			sizeof(devargs->virt.drv_name)) != 0)
955129044dSC.J. Collier		goto fail;
965129044dSC.J. Collier	if (!devargs->args || strcmp(devargs->args, "k1=val,k2=val2") != 0)
975129044dSC.J. Collier		goto fail;
985129044dSC.J. Collier	free_devargs_list();
995129044dSC.J. Collier
1005129044dSC.J. Collier	/* check PCI device with empty argument parsing */
1015129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "04:00.1") < 0)
1025129044dSC.J. Collier		goto fail;
1035129044dSC.J. Collier	devargs = TAILQ_FIRST(&devargs_list);
1045129044dSC.J. Collier	if (devargs->pci.addr.domain != 0 ||
1055129044dSC.J. Collier		devargs->pci.addr.bus != 4 ||
1065129044dSC.J. Collier		devargs->pci.addr.devid != 0 ||
1075129044dSC.J. Collier		devargs->pci.addr.function != 1)
1085129044dSC.J. Collier		goto fail;
1095129044dSC.J. Collier	if (!devargs->args || strcmp(devargs->args, "") != 0)
1105129044dSC.J. Collier		goto fail;
1115129044dSC.J. Collier	free_devargs_list();
1125129044dSC.J. Collier
1135129044dSC.J. Collier	/* test error case: bad PCI address */
1145129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "08:1") == 0)
1155129044dSC.J. Collier		goto fail;
1165129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "00.1") == 0)
1175129044dSC.J. Collier		goto fail;
1185129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "foo") == 0)
1195129044dSC.J. Collier		goto fail;
1205129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, ",") == 0)
1215129044dSC.J. Collier		goto fail;
1225129044dSC.J. Collier	if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, "000f:0:0") == 0)
1235129044dSC.J. Collier		goto fail;
1245129044dSC.J. Collier
1255129044dSC.J. Collier	devargs_list = save_devargs_list;
1265129044dSC.J. Collier	return 0;
1275129044dSC.J. Collier
1285129044dSC.J. Collier fail:
1295129044dSC.J. Collier	free_devargs_list();
1305129044dSC.J. Collier	devargs_list = save_devargs_list;
1315129044dSC.J. Collier	return -1;
1325129044dSC.J. Collier}
1335129044dSC.J. Collier
1349ecc306dSRicardo SalvetiREGISTER_TEST_COMMAND(devargs_autotest, test_devargs);
135