From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 5FBF34C92 for ; Thu, 8 Nov 2018 13:36:57 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Nov 2018 04:36:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,478,1534834800"; d="scan'208";a="94645704" Received: from sivswdev02.ir.intel.com (HELO localhost.localdomain) ([10.237.217.46]) by FMSMGA003.fm.intel.com with ESMTP; 08 Nov 2018 04:36:56 -0800 From: Konstantin Ananyev To: dev@dpdk.org Cc: Konstantin Ananyev Date: Thu, 8 Nov 2018 12:36:44 +0000 Message-Id: <1541680604-17245-3-git-send-email-konstantin.ananyev@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1541680604-17245-1-git-send-email-konstantin.ananyev@intel.com> References: <1541680604-17245-1-git-send-email-konstantin.ananyev@intel.com> Subject: [dpdk-dev] [PATCH 2/2] test/bpf: add test for immediate load 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: Thu, 08 Nov 2018 12:36:58 -0000 New test-case to cover (BPF_LD | BPF_IMM | EBPF_DW) instruction. Signed-off-by: Konstantin Ananyev --- test/test/test_bpf.c | 108 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/test/test/test_bpf.c b/test/test/test_bpf.c index fa17c4f74..1d50401aa 100644 --- a/test/test/test_bpf.c +++ b/test/test/test_bpf.c @@ -48,6 +48,12 @@ struct dummy_vect8 { #define TEST_JCC_3 5678 #define TEST_JCC_4 TEST_FILL_1 +#define TEST_IMM_1 UINT64_MAX +#define TEST_IMM_2 ((uint64_t)INT64_MIN) +#define TEST_IMM_3 ((uint64_t)INT64_MAX + INT32_MAX) +#define TEST_IMM_4 ((uint64_t)UINT32_MAX) +#define TEST_IMM_5 ((uint64_t)UINT32_MAX + 1) + struct bpf_test { const char *name; size_t arg_sz; @@ -268,6 +274,94 @@ test_load1_check(uint64_t rc, const void *arg) return cmp_res(__func__, v, rc, dft, dft, sizeof(*dft)); } +/* load immediate test-cases */ +static const struct ebpf_insn test_ldimm1_prog[] = { + + { + .code = (BPF_LD | BPF_IMM | EBPF_DW), + .dst_reg = EBPF_REG_0, + .imm = (uint32_t)TEST_IMM_1, + }, + { + .imm = TEST_IMM_1 >> 32, + }, + { + .code = (BPF_LD | BPF_IMM | EBPF_DW), + .dst_reg = EBPF_REG_3, + .imm = (uint32_t)TEST_IMM_2, + }, + { + .imm = TEST_IMM_2 >> 32, + }, + { + .code = (BPF_LD | BPF_IMM | EBPF_DW), + .dst_reg = EBPF_REG_5, + .imm = (uint32_t)TEST_IMM_3, + }, + { + .imm = TEST_IMM_3 >> 32, + }, + { + .code = (BPF_LD | BPF_IMM | EBPF_DW), + .dst_reg = EBPF_REG_7, + .imm = (uint32_t)TEST_IMM_4, + }, + { + .imm = TEST_IMM_4 >> 32, + }, + { + .code = (BPF_LD | BPF_IMM | EBPF_DW), + .dst_reg = EBPF_REG_9, + .imm = (uint32_t)TEST_IMM_5, + }, + { + .imm = TEST_IMM_5 >> 32, + }, + /* return sum */ + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_3, + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_5, + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_7, + }, + { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_9, + }, + { + .code = (BPF_JMP | EBPF_EXIT), + }, +}; + +static int +test_ldimm1_check(uint64_t rc, const void *arg) +{ + uint64_t v1, v2; + + v1 = TEST_IMM_1; + v2 = TEST_IMM_2; + v1 += v2; + v2 = TEST_IMM_3; + v1 += v2; + v2 = TEST_IMM_4; + v1 += v2; + v2 = TEST_IMM_5; + v1 += v2; + + return cmp_res(__func__, v1, rc, arg, arg, 0); +} + + /* alu mul test-cases */ static const struct ebpf_insn test_mul1_prog[] = { @@ -1726,6 +1820,20 @@ static const struct bpf_test tests[] = { .prepare = test_load1_prepare, .check_result = test_load1_check, }, + { + .name = "test_ldimm1", + .arg_sz = sizeof(struct dummy_offset), + .prm = { + .ins = test_ldimm1_prog, + .nb_ins = RTE_DIM(test_ldimm1_prog), + .prog_arg = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(struct dummy_offset), + }, + }, + .prepare = test_store1_prepare, + .check_result = test_ldimm1_check, + }, { .name = "test_mul1", .arg_sz = sizeof(struct dummy_vect8), -- 2.17.1