libqos/qgraph: add qos_node_create_driver_named()
[qemu/ar7.git] / tests / qtest / libqos / qgraph_internal.h
blob974985dce9df45551fa90660d493196a6017792b
1 /*
2 * libqos driver framework
4 * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1 as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>
19 #ifndef QGRAPH_INTERNAL_H
20 #define QGRAPH_INTERNAL_H
22 /* This header is declaring additional helper functions defined in
23 * qgraph.c
24 * It should not be included in tests
27 #include "qgraph.h"
29 typedef struct QOSGraphMachine QOSGraphMachine;
30 typedef enum QOSEdgeType QOSEdgeType;
31 typedef enum QOSNodeType QOSNodeType;
33 /* callback called when the walk path algorithm found a
34 * valid path
36 typedef void (*QOSTestCallback) (QOSGraphNode *path, int len);
38 /* edge types*/
39 enum QOSEdgeType {
40 QEDGE_CONTAINS,
41 QEDGE_PRODUCES,
42 QEDGE_CONSUMED_BY
45 /* node types*/
46 enum QOSNodeType {
47 QNODE_MACHINE,
48 QNODE_DRIVER,
49 QNODE_INTERFACE,
50 QNODE_TEST
53 /* Graph Node */
54 struct QOSGraphNode {
55 QOSNodeType type;
56 bool available; /* set by QEMU via QMP, used during graph walk */
57 bool visited; /* used during graph walk */
58 char *name; /* used to identify the node */
59 char *qemu_name; /* optional: see qos_node_create_driver_named() */
60 char *command_line; /* used to start QEMU at test execution */
61 union {
62 struct {
63 QOSCreateDriverFunc constructor;
64 } driver;
65 struct {
66 QOSCreateMachineFunc constructor;
67 } machine;
68 struct {
69 QOSTestFunc function;
70 void *arg;
71 QOSBeforeTest before;
72 bool subprocess;
73 } test;
74 } u;
76 /**
77 * only used when traversing the path, never rely on that except in the
78 * qos_traverse_graph callback function
80 QOSGraphEdge *path_edge;
83 /**
84 * qos_graph_get_node(): returns the node mapped to that @key.
85 * It performs an hash map search O(1)
87 * Returns: on success: the %QOSGraphNode
88 * otherwise: #NULL
90 QOSGraphNode *qos_graph_get_node(const char *key);
92 /**
93 * qos_graph_has_node(): returns #TRUE if the node
94 * has map has a node mapped to that @key.
96 bool qos_graph_has_node(const char *node);
98 /**
99 * qos_graph_get_node_type(): returns the %QOSNodeType
100 * of the node @node.
101 * It performs an hash map search O(1)
102 * Returns: on success: the %QOSNodeType
103 * otherwise: #-1
105 QOSNodeType qos_graph_get_node_type(const char *node);
108 * qos_graph_get_node_availability(): returns the availability (boolean)
109 * of the node @node.
111 bool qos_graph_get_node_availability(const char *node);
114 * qos_graph_get_edge(): returns the edge
115 * linking of the node @node with @dest.
117 * Returns: on success: the %QOSGraphEdge
118 * otherwise: #NULL
120 QOSGraphEdge *qos_graph_get_edge(const char *node, const char *dest);
123 * qos_graph_edge_get_type(): returns the edge type
124 * of the edge @edge.
126 * Returns: on success: the %QOSEdgeType
127 * otherwise: #-1
129 QOSEdgeType qos_graph_edge_get_type(QOSGraphEdge *edge);
132 * qos_graph_edge_get_dest(): returns the name of the node
133 * pointed as destination of edge @edge.
135 * Returns: on success: the destination
136 * otherwise: #NULL
138 char *qos_graph_edge_get_dest(QOSGraphEdge *edge);
141 * qos_graph_has_edge(): returns #TRUE if there
142 * exists an edge from @start to @dest.
144 bool qos_graph_has_edge(const char *start, const char *dest);
147 * qos_graph_edge_get_arg(): returns the args assigned
148 * to that @edge.
150 * Returns: on success: the arg
151 * otherwise: #NULL
153 void *qos_graph_edge_get_arg(QOSGraphEdge *edge);
156 * qos_graph_edge_get_after_cmd_line(): returns the edge
157 * command line that will be added after all the node arguments
158 * and all the before_cmd_line arguments.
160 * Returns: on success: the char* arg
161 * otherwise: #NULL
163 char *qos_graph_edge_get_after_cmd_line(QOSGraphEdge *edge);
166 * qos_graph_edge_get_before_cmd_line(): returns the edge
167 * command line that will be added before the node command
168 * line argument.
170 * Returns: on success: the char* arg
171 * otherwise: #NULL
173 char *qos_graph_edge_get_before_cmd_line(QOSGraphEdge *edge);
176 * qos_graph_edge_get_extra_device_opts(): returns the arg
177 * command line that will be added to the node command
178 * line argument.
180 * Returns: on success: the char* arg
181 * otherwise: #NULL
183 char *qos_graph_edge_get_extra_device_opts(QOSGraphEdge *edge);
186 * qos_graph_edge_get_name(): returns the name
187 * assigned to the destination node (different only)
188 * if there are multiple devices with the same node name
189 * e.g. a node has two "generic-sdhci", "emmc" and "sdcard"
190 * there will be two edges with edge_name ="emmc" and "sdcard"
192 * Returns always the char* edge_name
194 char *qos_graph_edge_get_name(QOSGraphEdge *edge);
197 * qos_graph_get_machine(): returns the machine assigned
198 * to that @node name.
200 * It performs a search only trough the list of machines
201 * (i.e. the QOS_ROOT child).
203 * Returns: on success: the %QOSGraphNode
204 * otherwise: #NULL
206 QOSGraphNode *qos_graph_get_machine(const char *node);
209 * qos_graph_has_machine(): returns #TRUE if the node
210 * has map has a node mapped to that @node.
212 bool qos_graph_has_machine(const char *node);
216 * qos_print_graph(): walks the graph and prints
217 * all machine-to-test paths.
219 void qos_print_graph(void);
222 * qos_graph_foreach_test_path(): executes the Depth First search
223 * algorithm and applies @fn to all discovered paths.
225 * See qos_traverse_graph() in qgraph.c for more info on
226 * how it works.
228 void qos_graph_foreach_test_path(QOSTestCallback fn);
231 * qos_get_machine_type(): return QEMU machine type for a machine node.
232 * This function requires every machine @name to be in the form
233 * <arch>/<machine_name>, like "arm/raspi2" or "x86_64/pc".
235 * The function will validate the format and return a pointer to
236 * @machine to <machine_name>. For example, when passed "x86_64/pc"
237 * it will return "pc".
239 * Note that this function *does not* allocate any new string.
241 char *qos_get_machine_type(char *name);
244 * qos_delete_cmd_line(): delete the
245 * command line present in node mapped with key @name.
247 * This function is called when the QMP query returns a node with
248 * { "abstract" : true } attribute.
250 void qos_delete_cmd_line(const char *name);
253 * qos_graph_node_set_availability(): sets the node identified
254 * by @node with availability @av.
256 void qos_graph_node_set_availability(const char *node, bool av);
258 #endif