1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 RehiveTech. All rights reserved.
13 * Each test can require and use some external resources. Usually, an external
14 * resource is a file or a filesystem sub-hierarchy. A resource is included
15 * inside the test executable.
18 #include <sys/queue.h>
23 #include <rte_common.h>
25 TAILQ_HEAD(resource_list, resource);
26 extern struct resource_list resource_list;
29 * Representation of a resource. It points to the resource's binary data.
30 * The semantics of the binary data are defined by the target test.
33 const char *name; /**< Unique name of the resource */
34 const char *begin; /**< Start of resource data */
35 const char *end; /**< End of resource data */
36 TAILQ_ENTRY(resource) next;
40 * @return size of the given resource
42 size_t resource_size(const struct resource *r);
45 * Find a resource by name in the global list of resources.
47 const struct resource *resource_find(const char *name);
50 * Write the raw data of the resource to the given file.
51 * @return 0 on success
53 int resource_fwrite(const struct resource *r, FILE *f);
56 * Write the raw data of the resource to the given file given by name.
57 * The name is relative to the current working directory.
58 * @return 0 on success
60 int resource_fwrite_file(const struct resource *r, const char *fname);
63 * Treat the given resource as a tar archive. Extract
64 * the archive to the current directory.
66 int resource_untar(const struct resource *res);
69 * Treat the given resource as a tar archive. Remove
70 * all files (related to the current directory) listed
73 int resource_rm_by_tar(const struct resource *res);
76 * Register a resource in the global list of resources.
77 * Not intended for direct use, please check the REGISTER_RESOURCE
80 void resource_register(struct resource *r);
83 * Definition of a resource linked externally (by means of the used toolchain).
84 * Only the base name of the resource is expected. The name refers to the
85 * linked pointers beg_<name> and end_<name> provided externally.
87 #define REGISTER_LINKED_RESOURCE(n) \
88 extern const char beg_ ##n; \
89 extern const char end_ ##n; \
90 REGISTER_RESOURCE(n, &beg_ ##n, &end_ ##n) \
93 * Definition of a resource described by its name, and pointers begin, end.
95 #define REGISTER_RESOURCE(n, b, e) \
96 static struct resource linkres_ ##n = { \
101 static void __attribute__((constructor, used)) resinitfn_ ##n(void) \
103 resource_register(&linkres_ ##n); \