main.cpp revision d8967fb1
1/*
2 * Copyright (c) 2016  Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <iostream>
17#include <gtest/gtest.h>
18#include <gmock/gmock.h>
19
20#include <rte_common.h>
21#include <rte_eal.h>
22#include <rte_ethdev.h>
23#include <rte_cycles.h>
24#include <rte_lcore.h>
25#include <rte_mbuf.h>
26#include <rte_errno.h>
27
28#include <tle_version.h>
29
30#include "test_common.h"
31
32struct rte_mempool *mbuf_pool;
33char binpath[PATH_MAX];
34
35int
36main(int argc, char *argv[])
37{
38	uint8_t nb_ports = 1;
39	int rc = 0;
40	char *slash;
41
42	/* Initialize GoogleTest&Mock and parse any args */
43	testing::InitGoogleMock(&argc, argv);
44	/* Initialize EAL */
45	int ret = rte_eal_init(argc, argv);
46	if (ret < 0)
47		rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
48	argc -= ret;
49	argv += ret;
50
51	printf("%s UT\n", tle_version);
52
53	/* get the path of binary and save in a global variable to be used later*/
54	realpath(argv[0], binpath);
55	slash = NULL;
56	slash = strrchr(binpath, '/');
57	if (strcmp(binpath, "") != 0 && slash != NULL)
58		binpath[slash - binpath] = 0;
59
60	/*
61	 * Creates a new mempool in memory to hold the mbufs.
62	 * Multiplied by 2 because of mempeool to be used for packet
63	 * fragmentation purposes.
64	 */
65	mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL",
66		2 * NUM_MBUFS * nb_ports, MBUF_CACHE_SIZE, 0,
67		RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
68	if (mbuf_pool == NULL) {
69		rc = -rte_errno;
70		printf("Mempool was not created, rc=%d\n", rc);
71		return rc;
72	}
73
74	return RUN_ALL_TESTS();
75}
76