4 * Copyright(c) 2016 RehiveTech. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of RehiveTech nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 * Each test can require and use some external resources. Usually, an external
43 * resource is a file or a filesystem sub-hierarchy. A resource is included
44 * inside the test executable.
47 #include <sys/queue.h>
52 #include <rte_common.h>
54 TAILQ_HEAD(resource_list, resource);
55 extern struct resource_list resource_list;
58 * Representation of a resource. It points to the resource's binary data.
59 * The semantics of the binary data are defined by the target test.
62 const char *name; /**< Unique name of the resource */
63 const char *begin; /**< Start of resource data */
64 const char *end; /**< End of resource data */
65 TAILQ_ENTRY(resource) next;
69 * @return size of the given resource
71 size_t resource_size(const struct resource *r);
74 * Find a resource by name in the global list of resources.
76 const struct resource *resource_find(const char *name);
79 * Write the raw data of the resource to the given file.
80 * @return 0 on success
82 int resource_fwrite(const struct resource *r, FILE *f);
85 * Write the raw data of the resource to the given file given by name.
86 * The name is relative to the current working directory.
87 * @return 0 on success
89 int resource_fwrite_file(const struct resource *r, const char *fname);
92 * Treat the given resource as a tar archive. Extract
93 * the archive to the current directory.
95 int resource_untar(const struct resource *res);
98 * Treat the given resource as a tar archive. Remove
99 * all files (related to the current directory) listed
100 * in the tar archive.
102 int resource_rm_by_tar(const struct resource *res);
105 * Register a resource in the global list of resources.
106 * Not intended for direct use, please check the REGISTER_RESOURCE
109 void resource_register(struct resource *r);
112 * Definition of a resource linked externally (by means of the used toolchain).
113 * Only the base name of the resource is expected. The name refers to the
114 * linked pointers beg_<name> and end_<name> provided externally.
116 #define REGISTER_LINKED_RESOURCE(n) \
117 extern const char beg_ ##n; \
118 extern const char end_ ##n; \
119 REGISTER_RESOURCE(n, &beg_ ##n, &end_ ##n) \
122 * Definition of a resource described by its name, and pointers begin, end.
124 #define REGISTER_RESOURCE(n, b, e) \
125 static struct resource linkres_ ##n = { \
126 .name = RTE_STR(n), \
130 static void __attribute__((constructor, used)) resinitfn_ ##n(void) \
132 resource_register(&linkres_ ##n); \