-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
147 lines (129 loc) · 2.93 KB
/
test.c
File metadata and controls
147 lines (129 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <ctype.h>
#include <limits.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "test.h"
static pthread_mutex_t printf_mutex;
int tprintf(const char *format, ...)
{
va_list args;
va_start(args, format);
pthread_mutex_lock(&printf_mutex);
vprintf(format, args);
pthread_mutex_unlock(&printf_mutex);
va_end(args);
return 0;
}
static struct test_config *tconfs = NULL;
/* We hardcode everything now, we can make it configured through
* file in future when we do more complex testing
*/
void free_configs(struct test_config *confs)
{
int i;
if (!confs)
return;
for (i=0; i<confs->num_pktgens; i++)
if (confs->configs[i].entries)
free(confs->configs[i].entries);
free(confs->configs);
free(confs);
}
struct test_config *init_configs()
{
struct test_config *confs;
int i;
struct request_entry *entry;
confs = calloc(1, sizeof(struct test_config));
if (!confs)
return NULL;
confs->num_apps = APPS_NUM;
confs->num_pktgens = PKTG_NUM;
confs->configs = calloc(confs->num_pktgens,
sizeof(struct request_config));
if (!confs->configs)
{
free(confs);
return NULL;
}
for (i = 0; i < confs->num_pktgens; i++)
{
struct request_config *rconf = &confs->configs[i];
rconf->entnum = PKTG_CONFIG_NUM;
entry = calloc(rconf->entnum, sizeof(struct request_entry));
if (!entry)
goto error;
rconf->entries = (struct request_entry *)entry;
/* Hardcode the config now, assume it takes 200 cycle,
* which is similar to 64 byte packet, for the packet handling
* and we have 128 burst flow.
*/
rconf->entries[0].size = 128;
rconf->entries[0].duration = 200;
}
return confs;
error:
free_configs(confs);
return NULL;
}
int main(int argc, char *argv[])
{
int c;
/* By default, 2 seconds */
int duration = 2;
opterr = 0;
while ((c = getopt (argc, argv, "t:")) != -1)
{
switch (c)
{
case 't':
{
char *eptr;
errno = 0;
duration = strtol(optarg, &eptr, 0);
printf("duration is %d\n", duration);
if ((errno == ERANGE && (duration== LONG_MAX || duration== LONG_MIN))
|| (eptr && *eptr))
{
printf("Error value\n");
return -1;
}
break;
}
case '?':
if (optopt == 't')
printf("Option -t requires an duration argument.\n");
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort();
}
}
pthread_mutex_init(&printf_mutex, NULL);
tconfs = init_configs();
initRequests(PKTG_NUM);
app_loop = gen_loop = 1;
init_dpdk_apps(tconfs->num_apps);
init_pktgens(tconfs->num_pktgens, tconfs->configs);
sleep(duration);
app_loop = gen_loop = 0;
/* We stop the generator first */
wait_pktgen_done();
wait_dpdk_done();
dumpAppResults();
dumpGenResults();
free_dpdk_apps();
free_pktgens();
freeRequests();
free_configs(tconfs);
return 0;
}