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 #include "qemu/osdep.h"
22 #include "qapi/qmp/qdict.h"
23 #include "qapi/qmp/qbool.h"
24 #include "qapi/qmp/qstring.h"
25 #include "qemu/module.h"
26 #include "qapi/qmp/qlist.h"
29 #include "qgraph_internal.h"
30 #include "qos_external.h"
32 static void machine_apply_to_node(const char *name
)
34 char *machine_name
= g_strconcat(qtest_get_arch(), "/", name
, NULL
);
36 qos_graph_node_set_availability(machine_name
, true);
40 void machines_apply_to_node(MachineInfoList
*mach_info
)
42 MachineInfoList
*tail
;
44 for (tail
= mach_info
; tail
; tail
= tail
->next
) {
45 machine_apply_to_node(tail
->value
->name
);
46 if (tail
->value
->alias
) {
47 machine_apply_to_node(tail
->value
->alias
);
52 static void type_apply_to_node(const char *name
, bool is_abstract
)
54 qos_graph_node_set_availability(name
, true);
56 qos_delete_cmd_line(name
);
60 void types_apply_to_node(ObjectTypeInfoList
*type_info
)
62 ObjectTypeInfoList
*tail
;
64 for (tail
= type_info
; tail
; tail
= tail
->next
) {
65 type_apply_to_node(tail
->value
->name
, tail
->value
->abstract
);
69 static QGuestAllocator
*get_machine_allocator(QOSGraphObject
*obj
)
71 return obj
->get_driver(obj
, "memory");
75 * allocate_objects(): given an array of nodes @arg,
76 * walks the path invoking all constructors and
77 * passing the corresponding parameter in order to
78 * continue the objects allocation.
79 * Once the test is reached, return the object it consumes.
81 * Since the machine and QEDGE_CONSUMED_BY nodes allocate
82 * memory in the constructor, g_test_queue_destroy is used so
83 * that after execution they can be safely free'd. (The test's
84 * ->before callback is also welcome to use g_test_queue_destroy).
86 * Note: as specified in walk_path() too, @arg is an array of
87 * char *, where arg[0] is a pointer to the command line
88 * string that will be used to properly start QEMU when executing
89 * the test, and the remaining elements represent the actual objects
90 * that will be allocated.
92 void *allocate_objects(QTestState
*qts
, char **path
, QGuestAllocator
**p_alloc
)
95 QGuestAllocator
*alloc
;
96 QOSGraphObject
*parent
= NULL
;
102 node
= qos_graph_get_node(path
[current
]);
103 g_assert(node
->type
== QNODE_MACHINE
);
105 obj
= qos_machine_new(node
, qts
);
106 qos_object_queue_destroy(obj
);
108 alloc
= get_machine_allocator(obj
);
114 if (node
->type
!= QNODE_INTERFACE
) {
115 qos_object_start_hw(obj
);
119 /* follow edge and get object for next node constructor */
121 edge
= qos_graph_get_edge(path
[current
- 1], path
[current
]);
122 node
= qos_graph_get_node(path
[current
]);
124 if (node
->type
== QNODE_TEST
) {
125 g_assert(qos_graph_edge_get_type(edge
) == QEDGE_CONSUMED_BY
);
129 switch (qos_graph_edge_get_type(edge
)) {
131 obj
= parent
->get_driver(parent
, path
[current
]);
134 case QEDGE_CONSUMED_BY
:
135 edge_arg
= qos_graph_edge_get_arg(edge
);
136 obj
= qos_driver_new(node
, obj
, alloc
, edge_arg
);
137 qos_object_queue_destroy(obj
);
141 obj
= parent
->get_device(parent
, path
[current
]);