9af8415609a0fe244278b510ec765c1893d98743
[dpdk.git] / app / test / resource.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016 RehiveTech. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #ifndef _RESOURCE_H_
35 #define _RESOURCE_H_
36
37 /**
38  * @file
39  *
40  * Test Resource API
41  *
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.
45  */
46
47 #include <sys/queue.h>
48 #include <stddef.h>
49
50 #include <rte_eal.h>
51 #include <rte_common.h>
52
53 TAILQ_HEAD(resource_list, resource);
54 extern struct resource_list resource_list;
55
56 /**
57  * Representation of a resource. It points to the resource's binary data.
58  * The semantics of the binary data are defined by the target test.
59  */
60 struct resource {
61         const char *name;  /**< Unique name of the resource */
62         const char *begin; /**< Start of resource data */
63         const char *end;   /**< End of resource data */
64         TAILQ_ENTRY(resource) next;
65 };
66
67 /**
68  * @return size of the given resource
69  */
70 size_t resource_size(const struct resource *r);
71
72 /**
73  * Find a resource by name in the global list of resources.
74  */
75 const struct resource *resource_find(const char *name);
76
77 /**
78  * Register a resource in the global list of resources.
79  * Not intended for direct use, please check the REGISTER_RESOURCE
80  * macro.
81  */
82 void resource_register(struct resource *r);
83
84 /**
85  * Definition of a resource described by its name, and pointers begin, end.
86  */
87 #define REGISTER_RESOURCE(n, b, e) \
88 static struct resource linkres_ ##n = {       \
89         .name = RTE_STR(n),     \
90         .begin = b,             \
91         .end = e,               \
92 };                              \
93 static void __attribute__((constructor, used)) resinitfn_ ##n(void) \
94 {                               \
95         resource_register(&linkres_ ##n);  \
96 }
97
98 #endif