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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
* libqos driver framework
*
* Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>
*/
#ifndef QGRAPH_INTERNAL_H
#define QGRAPH_INTERNAL_H
/* This header is declaring additional helper functions defined in
* qgraph.c
* It should not be included in tests
*/
#include "qgraph.h"
typedef struct QOSGraphMachine QOSGraphMachine;
typedef enum QOSEdgeType QOSEdgeType;
typedef enum QOSNodeType QOSNodeType;
/* callback called when the walk path algorithm found a
* valid path
*/
typedef void (*QOSTestCallback) (QOSGraphNode *path, int len);
/* edge types*/
enum QOSEdgeType {
QEDGE_CONTAINS,
QEDGE_PRODUCES,
QEDGE_CONSUMED_BY
};
/* node types*/
enum QOSNodeType {
QNODE_MACHINE,
QNODE_DRIVER,
QNODE_INTERFACE,
QNODE_TEST
};
/* Graph Node */
struct QOSGraphNode {
QOSNodeType type;
bool available; /* set by QEMU via QMP, used during graph walk */
bool visited; /* used during graph walk */
char *name; /* used to identify the node */
char *qemu_name; /* optional: see qos_node_create_driver_named() */
char *command_line; /* used to start QEMU at test execution */
union {
struct {
QOSCreateDriverFunc constructor;
} driver;
struct {
QOSCreateMachineFunc constructor;
} machine;
struct {
QOSTestFunc function;
void *arg;
QOSBeforeTest before;
bool subprocess;
} test;
} u;
/**
* only used when traversing the path, never rely on that except in the
* qos_traverse_graph callback function
*/
QOSGraphEdge *path_edge;
};
/**
* qos_graph_get_node(): returns the node mapped to that @key.
* It performs an hash map search O(1)
*
* Returns: on success: the %QOSGraphNode
* otherwise: #NULL
*/
QOSGraphNode *qos_graph_get_node(const char *key);
/**
* qos_graph_has_node(): returns #TRUE if the node
* has map has a node mapped to that @key.
*/
bool qos_graph_has_node(const char *node);
/**
* qos_graph_get_node_type(): returns the %QOSNodeType
* of the node @node.
* It performs an hash map search O(1)
* Returns: on success: the %QOSNodeType
* otherwise: #-1
*/
QOSNodeType qos_graph_get_node_type(const char *node);
/**
* qos_graph_get_node_availability(): returns the availability (boolean)
* of the node @node.
*/
bool qos_graph_get_node_availability(const char *node);
/**
* qos_graph_get_edge(): returns the edge
* linking of the node @node with @dest.
*
* Returns: on success: the %QOSGraphEdge
* otherwise: #NULL
*/
QOSGraphEdge *qos_graph_get_edge(const char *node, const char *dest);
/**
* qos_graph_edge_get_type(): returns the edge type
* of the edge @edge.
*
* Returns: on success: the %QOSEdgeType
* otherwise: #-1
*/
QOSEdgeType qos_graph_edge_get_type(QOSGraphEdge *edge);
/**
* qos_graph_edge_get_dest(): returns the name of the node
* pointed as destination of edge @edge.
*
* Returns: on success: the destination
* otherwise: #NULL
*/
char *qos_graph_edge_get_dest(QOSGraphEdge *edge);
/**
* qos_graph_has_edge(): returns #TRUE if there
* exists an edge from @start to @dest.
*/
bool qos_graph_has_edge(const char *start, const char *dest);
/**
* qos_graph_edge_get_arg(): returns the args assigned
* to that @edge.
*
* Returns: on success: the arg
* otherwise: #NULL
*/
void *qos_graph_edge_get_arg(QOSGraphEdge *edge);
/**
* qos_graph_edge_get_after_cmd_line(): returns the edge
* command line that will be added after all the node arguments
* and all the before_cmd_line arguments.
*
* Returns: on success: the char* arg
* otherwise: #NULL
*/
char *qos_graph_edge_get_after_cmd_line(QOSGraphEdge *edge);
/**
* qos_graph_edge_get_before_cmd_line(): returns the edge
* command line that will be added before the node command
* line argument.
*
* Returns: on success: the char* arg
* otherwise: #NULL
*/
char *qos_graph_edge_get_before_cmd_line(QOSGraphEdge *edge);
/**
* qos_graph_edge_get_extra_device_opts(): returns the arg
* command line that will be added to the node command
* line argument.
*
* Returns: on success: the char* arg
* otherwise: #NULL
*/
char *qos_graph_edge_get_extra_device_opts(QOSGraphEdge *edge);
/**
* qos_graph_edge_get_name(): returns the name
* assigned to the destination node (different only)
* if there are multiple devices with the same node name
* e.g. a node has two "generic-sdhci", "emmc" and "sdcard"
* there will be two edges with edge_name ="emmc" and "sdcard"
*
* Returns always the char* edge_name
*/
char *qos_graph_edge_get_name(QOSGraphEdge *edge);
/**
* qos_graph_get_machine(): returns the machine assigned
* to that @node name.
*
* It performs a search only trough the list of machines
* (i.e. the QOS_ROOT child).
*
* Returns: on success: the %QOSGraphNode
* otherwise: #NULL
*/
QOSGraphNode *qos_graph_get_machine(const char *node);
/**
* qos_graph_has_machine(): returns #TRUE if the node
* has map has a node mapped to that @node.
*/
bool qos_graph_has_machine(const char *node);
/**
* qos_print_graph(): walks the graph and prints
* all machine-to-test paths.
*/
void qos_print_graph(void);
/**
* qos_graph_foreach_test_path(): executes the Depth First search
* algorithm and applies @fn to all discovered paths.
*
* See qos_traverse_graph() in qgraph.c for more info on
* how it works.
*/
void qos_graph_foreach_test_path(QOSTestCallback fn);
/**
* qos_get_machine_type(): return QEMU machine type for a machine node.
* This function requires every machine @name to be in the form
* <arch>/<machine_name>, like "arm/raspi2" or "x86_64/pc".
*
* The function will validate the format and return a pointer to
* @machine to <machine_name>. For example, when passed "x86_64/pc"
* it will return "pc".
*
* Note that this function *does not* allocate any new string.
*/
char *qos_get_machine_type(char *name);
/**
* qos_delete_cmd_line(): delete the
* command line present in node mapped with key @name.
*
* This function is called when the QMP query returns a node with
* { "abstract" : true } attribute.
*/
void qos_delete_cmd_line(const char *name);
/**
* qos_graph_node_set_availability(): sets the node identified
* by @node with availability @av.
*/
void qos_graph_node_set_availability(const char *node, bool av);
/*
* Prepends a '#' character in front for not breaking TAP output format.
*/
#define qos_printf(...) printf("# " __VA_ARGS__)
/*
* Intended for printing something literally, i.e. for appending text as is
* to a line already been started by qos_printf() before.
*/
#define qos_printf_literal printf
#endif
|