From: Jan Viktorin Date: Mon, 13 Jun 2016 15:07:38 +0000 (+0200) Subject: app/test: support resources externally linked X-Git-Tag: spdx-start~6775 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=ab64f5df8004d7187613a542bf3df29de49f597f;p=dpdk.git app/test: support resources externally linked To include resources from other source that the C source code we can take advantage of the objcopy behaviour, i.e. packing of an arbitrary file as an object file that is linked to the target program. A linked object file is always accessible as a pair extern const char beg_; extern const char end_; (extern const char siz_;) A unit test that packs the resource.c source file is included. Signed-off-by: Jan Viktorin --- diff --git a/app/test/Makefile b/app/test/Makefile index 1a13fb2999..fe67eeec00 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -33,6 +33,24 @@ include $(RTE_SDK)/mk/rte.vars.mk ifeq ($(CONFIG_RTE_APP_TEST),y) +# Define an externally linked resource. A linked resource is an arbitrary +# file that is linked into the test binary. The application refers to this +# resource by name. The linked generates identifiers beg_ and end_ +# for referencing by the C code. +# +# Parameters: , +define linked_resource +SRCS-y += $(1).res.o +$(1).res.o: $(2) + $(OBJCOPY) -I binary -B $(RTE_OBJCOPY_ARCH) -O $(RTE_OBJCOPY_TARGET) \ + --rename-section \ + .data=.rodata,alloc,load,data,contents,readonly \ + --redefine-sym _binary__dev_stdin_start=beg_$(1) \ + --redefine-sym _binary__dev_stdin_end=end_$(1) \ + --redefine-sym _binary__dev_stdin_size=siz_$(1) \ + /dev/stdin $$@ < $$< +endef + # # library name # @@ -45,6 +63,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) := commands.c SRCS-y += test.c SRCS-y += resource.c SRCS-y += test_resource.c +$(eval $(call linked_resource,test_resource_c,resource.c)) SRCS-y += test_pci.c SRCS-y += test_prefetch.c SRCS-y += test_byteorder.c diff --git a/app/test/resource.h b/app/test/resource.h index 9af8415609..966fc2428a 100644 --- a/app/test/resource.h +++ b/app/test/resource.h @@ -81,6 +81,16 @@ const struct resource *resource_find(const char *name); */ void resource_register(struct resource *r); +/** + * Definition of a resource linked externally (by means of the used toolchain). + * Only the base name of the resource is expected. The name refers to the + * linked pointers beg_ and end_ provided externally. + */ +#define REGISTER_LINKED_RESOURCE(n) \ +extern const char beg_ ##n; \ +extern const char end_ ##n; \ +REGISTER_RESOURCE(n, &beg_ ##n, &end_ ##n) \ + /** * Definition of a resource described by its name, and pointers begin, end. */ diff --git a/app/test/test_resource.c b/app/test/test_resource.c index 69391ad49e..b397fa8f20 100644 --- a/app/test/test_resource.c +++ b/app/test/test_resource.c @@ -60,11 +60,29 @@ static int test_resource_dpdk(void) return 0; } +REGISTER_LINKED_RESOURCE(test_resource_c); + +static int test_resource_c(void) +{ + const struct resource *r; + + r = resource_find("test_resource_c"); + TEST_ASSERT_NOT_NULL(r, "No test_resource_c found"); + TEST_ASSERT(!strcmp(r->name, "test_resource_c"), + "Found resource %s, expected test_resource_c", + r->name); + + return 0; +} + static int test_resource(void) { if (test_resource_dpdk()) return -1; + if (test_resource_c()) + return -1; + return 0; }