From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C655D1B198 for ; Fri, 8 Jun 2018 10:42:52 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jun 2018 01:42:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,490,1520924400"; d="scan'208";a="47424179" Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain) ([10.237.217.46]) by orsmga007.jf.intel.com with ESMTP; 08 Jun 2018 01:42:51 -0700 From: Konstantin Ananyev To: dev@dpdk.org Cc: Konstantin Ananyev Date: Fri, 8 Jun 2018 09:42:35 +0100 Message-Id: <1528447355-29411-4-git-send-email-konstantin.ananyev@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1528447355-29411-1-git-send-email-konstantin.ananyev@intel.com> References: <1528447355-29411-1-git-send-email-konstantin.ananyev@intel.com> To: dev@dpdk.org Subject: [dpdk-dev] [PATCH 3/3] test/bpf: add new test-case for external function call X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jun 2018 08:42:53 -0000 Signed-off-by: Konstantin Ananyev --- test/test/test_bpf.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/test/test/test_bpf.c b/test/test/test_bpf.c index 1e9caef95..fa17c4f74 100644 --- a/test/test/test_bpf.c +++ b/test/test/test_bpf.c @@ -1551,6 +1551,138 @@ static const struct rte_bpf_xsym test_call1_xsym[] = { }, }; +static const struct ebpf_insn test_call2_prog[] = { + + { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = -(int32_t)sizeof(struct dummy_offset), + }, + { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_2, + .src_reg = EBPF_REG_10, + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_K), + .dst_reg = EBPF_REG_2, + .imm = -2 * (int32_t)sizeof(struct dummy_offset), + }, + { + .code = (BPF_JMP | EBPF_CALL), + .imm = 0, + }, + { + .code = (BPF_LDX | BPF_MEM | EBPF_DW), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + .off = -(int32_t)(sizeof(struct dummy_offset) - + offsetof(struct dummy_offset, u64)), + }, + { + .code = (BPF_LDX | BPF_MEM | BPF_W), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_10, + .off = -(int32_t)(sizeof(struct dummy_offset) - + offsetof(struct dummy_offset, u32)), + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_1, + }, + { + .code = (BPF_LDX | BPF_MEM | BPF_H), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + .off = -(int32_t)(2 * sizeof(struct dummy_offset) - + offsetof(struct dummy_offset, u16)), + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_1, + }, + { + .code = (BPF_LDX | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + .off = -(int32_t)(2 * sizeof(struct dummy_offset) - + offsetof(struct dummy_offset, u8)), + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_1, + }, + { + .code = (BPF_JMP | EBPF_EXIT), + }, + +}; + +static void +dummy_func2(struct dummy_offset *a, struct dummy_offset *b) +{ + uint64_t v; + + v = 0; + a->u64 = v++; + a->u32 = v++; + a->u16 = v++; + a->u8 = v++; + b->u64 = v++; + b->u32 = v++; + b->u16 = v++; + b->u8 = v++; +} + +static int +test_call2_check(uint64_t rc, const void *arg) +{ + uint64_t v; + struct dummy_offset a, b; + + RTE_SET_USED(arg); + + dummy_func2(&a, &b); + v = a.u64 + a.u32 + b.u16 + b.u8; + + if (v != rc) { + printf("%s@%d: invalid return value " + "expected=0x%" PRIx64 ", actual=0x%" PRIx64 "\n", + __func__, __LINE__, v, rc); + return -1; + } + return 0; +} + +static const struct rte_bpf_xsym test_call2_xsym[] = { + { + .name = RTE_STR(dummy_func2), + .type = RTE_BPF_XTYPE_FUNC, + .func = { + .val = (void *)dummy_func2, + .nb_args = 2, + .args = { + [0] = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(struct dummy_offset), + }, + [1] = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(struct dummy_offset), + }, + }, + }, + }, +}; + static const struct bpf_test tests[] = { { .name = "test_store1", @@ -1710,6 +1842,24 @@ static const struct bpf_test tests[] = { /* for now don't support function calls on 32 bit platform */ .allow_fail = (sizeof(uint64_t) != sizeof(uintptr_t)), }, + { + .name = "test_call2", + .arg_sz = sizeof(struct dummy_offset), + .prm = { + .ins = test_call2_prog, + .nb_ins = RTE_DIM(test_call2_prog), + .prog_arg = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(struct dummy_offset), + }, + .xsym = test_call2_xsym, + .nb_xsym = RTE_DIM(test_call2_xsym), + }, + .prepare = test_store1_prepare, + .check_result = test_call2_check, + /* for now don't support function calls on 32 bit platform */ + .allow_fail = (sizeof(uint64_t) != sizeof(uintptr_t)), + }, }; static int -- 2.13.6