From patchwork Fri Apr 15 07:21:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Elo, Matias \(Nokia - FI/Espoo\)" X-Patchwork-Id: 65879 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1027799qge; Fri, 15 Apr 2016 00:26:16 -0700 (PDT) X-Received: by 10.140.98.163 with SMTP id o32mr23638844qge.46.1460705175999; Fri, 15 Apr 2016 00:26:15 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d107si7444839qga.46.2016.04.15.00.26.15; Fri, 15 Apr 2016 00:26:15 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE dis=NONE) header.from=nokia.com Received: by lists.linaro.org (Postfix, from userid 109) id A38DE61E50; Fri, 15 Apr 2016 07:26:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id E77F867522; Fri, 15 Apr 2016 07:21:55 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 568F4674CC; Fri, 15 Apr 2016 07:21:46 +0000 (UTC) Received: from demumfd001.nsn-inter.net (demumfd001.nsn-inter.net [93.183.12.32]) by lists.linaro.org (Postfix) with ESMTPS id A3BE567414 for ; Fri, 15 Apr 2016 07:21:20 +0000 (UTC) Received: from demuprx016.emea.nsn-intra.net ([10.150.129.55]) by demumfd001.nsn-inter.net (8.15.2/8.15.2) with ESMTPS id u3F7LIE4027118 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 15 Apr 2016 07:21:19 GMT Received: from 10.144.19.15 ([10.144.104.112]) by demuprx016.emea.nsn-intra.net (8.12.11.20060308/8.12.11) with ESMTP id u3F7LEvY001646 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Fri, 15 Apr 2016 09:21:18 +0200 From: Matias Elo To: lng-odp@lists.linaro.org Date: Fri, 15 Apr 2016 10:21:11 +0300 Message-Id: <1460704874-21163-9-git-send-email-matias.elo@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460704874-21163-1-git-send-email-matias.elo@nokia.com> References: <1460704874-21163-1-git-send-email-matias.elo@nokia.com> X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-size: 5352 X-purgate-ID: 151667::1460704879-00001B3D-68F7CE07/0/0 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 08/11] validation: pktio: add pktin timestamping test X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Add validation test for packet input timestamping. Tests also odp_pktin_ts_res() and odp_pktin_ts_from_ns(). Signed-off-by: Matias Elo --- test/validation/pktio/pktio.c | 133 ++++++++++++++++++++++++++++++++++++++++++ test/validation/pktio/pktio.h | 2 + 2 files changed, 135 insertions(+) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 162156a..51829bf 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -26,6 +26,11 @@ #define TX_BATCH_LEN 4 #define MAX_QUEUES 128 +#define PKTIN_TS_INTERVAL (50 * ODP_TIME_MSEC_IN_NS) +#define PKTIN_TS_MIN_RES 1000 +#define PKTIN_TS_MAX_RES 10000000000 +#define PKTIN_TS_CMP_RES 1 + #undef DEBUG_STATS /** interface names used for testing */ @@ -1646,6 +1651,132 @@ void pktio_test_send_on_ronly(void) CU_ASSERT_FATAL(ret == 0); } +int pktio_check_pktin_ts(void) +{ + odp_pktio_t pktio; + odp_pktio_capability_t capa; + odp_pktio_param_t pktio_param; + int ret; + + odp_pktio_param_init(&pktio_param); + pktio_param.in_mode = ODP_PKTIN_MODE_DIRECT; + + pktio = odp_pktio_open(iface_name[0], pool[0], &pktio_param); + if (pktio == ODP_PKTIO_INVALID) + return ODP_TEST_INACTIVE; + + ret = odp_pktio_capability(pktio, &capa); + (void)odp_pktio_close(pktio); + + if (ret < 0 || !capa.config.pktin.bit.ts_all) + return ODP_TEST_INACTIVE; + + return ODP_TEST_ACTIVE; +} + +void pktio_test_pktin_ts(void) +{ + odp_pktio_t pktio_tx, pktio_rx; + odp_pktio_t pktio[MAX_NUM_IFACES]; + odp_pktio_capability_t capa; + odp_pktio_config_t config; + odp_pktout_queue_t pktout_queue; + odp_pktin_queue_t pktin_queue; + odp_packet_t pkt_tbl[TX_BATCH_LEN]; + odp_packet_t tmp_pkt[TX_BATCH_LEN]; + uint32_t pkt_seq[TX_BATCH_LEN]; + uint64_t ns1, ns2; + uint64_t res; + uint64_t tmo; + odp_time_t ts_prev; + odp_time_t ts; + int num_rx = 0; + int ret; + int i; + + CU_ASSERT_FATAL(num_ifaces >= 1); + + /* Open and configure interfaces */ + for (i = 0; i < num_ifaces; ++i) { + pktio[i] = create_pktio(i, ODP_PKTIN_MODE_DIRECT, + ODP_PKTOUT_MODE_DIRECT); + CU_ASSERT_FATAL(pktio[i] != ODP_PKTIO_INVALID); + + CU_ASSERT_FATAL(odp_pktio_capability(pktio[i], &capa) == 0); + CU_ASSERT_FATAL(capa.config.pktin.bit.ts_all); + + odp_pktio_config_init(&config); + config.pktin.bit.ts_all = 1; + CU_ASSERT_FATAL(odp_pktio_config(pktio[i], &config) == 0); + + CU_ASSERT_FATAL(odp_pktio_start(pktio[i]) == 0); + } + + for (i = 0; i < num_ifaces; i++) + _pktio_wait_linkup(pktio[i]); + + pktio_tx = pktio[0]; + pktio_rx = (num_ifaces > 1) ? pktio[1] : pktio_tx; + + /* Test odp_pktin_ts_res() and odp_pktin_ts_from_ns() */ + res = odp_pktin_ts_res(pktio_tx); + CU_ASSERT(res > PKTIN_TS_MIN_RES); + CU_ASSERT(res < PKTIN_TS_MAX_RES); + ns1 = 100; + ts = odp_pktin_ts_from_ns(pktio_tx, ns1); + ns2 = odp_time_to_ns(ts); + /* Allow some arithmetic tolerance */ + CU_ASSERT((ns2 <= (ns1 + PKTIN_TS_CMP_RES)) && + (ns2 >= (ns1 - PKTIN_TS_CMP_RES))); + + ret = create_packets(pkt_tbl, pkt_seq, TX_BATCH_LEN, pktio_tx, + pktio_rx); + CU_ASSERT_FATAL(ret == TX_BATCH_LEN); + + ret = odp_pktout_queue(pktio_tx, &pktout_queue, 1); + CU_ASSERT_FATAL(ret > 0); + + ret = odp_pktin_queue(pktio_rx, &pktin_queue, 1); + CU_ASSERT_FATAL(ret > 0); + + tmo = odp_pktin_wait_time(ODP_TIME_SEC_IN_NS); + /* Send packets one at a time and add delay between the packets */ + for (i = 0; i < TX_BATCH_LEN; i++) { + CU_ASSERT_FATAL(odp_pktout_send(pktout_queue, + &pkt_tbl[i], 1) == 1); + + ret = odp_pktin_recv_tmo(pktin_queue, &tmp_pkt[i], 1, tmo); + + if (ret != 1) + break; + + if (pktio_pkt_seq(tmp_pkt[i]) == pkt_seq[num_rx] && + odp_packet_has_ts(tmp_pkt[i])) + pkt_tbl[num_rx++] = tmp_pkt[i]; + else + odp_packet_free(tmp_pkt[i]); + + odp_time_wait_ns(PKTIN_TS_INTERVAL); + } + + CU_ASSERT(num_rx == TX_BATCH_LEN); + + ts_prev = ODP_TIME_NULL; + for (i = 0; i < num_rx; i++) { + ts = odp_packet_ts(pkt_tbl[i]); + + CU_ASSERT(odp_time_cmp(ts, ts_prev) > 0); + + ts_prev = ts; + odp_packet_free(pkt_tbl[i]); + } + + for (i = 0; i < num_ifaces; i++) { + CU_ASSERT_FATAL(odp_pktio_stop(pktio[i]) == 0); + CU_ASSERT_FATAL(odp_pktio_close(pktio[i]) == 0); + } +} + static int create_pool(const char *iface, int num) { char pool_name[ODP_POOL_NAME_LEN]; @@ -1778,6 +1909,8 @@ odp_testinfo_t pktio_suite_unsegmented[] = { ODP_TEST_INFO(pktio_test_recv_multi_event), ODP_TEST_INFO_CONDITIONAL(pktio_test_statistics_counters, pktio_check_statistics_counters), + ODP_TEST_INFO_CONDITIONAL(pktio_test_pktin_ts, + pktio_check_pktin_ts), ODP_TEST_INFO_NULL }; diff --git a/test/validation/pktio/pktio.h b/test/validation/pktio/pktio.h index 4bc2980..33f8649 100644 --- a/test/validation/pktio/pktio.h +++ b/test/validation/pktio/pktio.h @@ -40,6 +40,8 @@ void pktio_test_sched_multi_event(void); void pktio_test_recv_multi_event(void); int pktio_check_statistics_counters(void); void pktio_test_statistics_counters(void); +int pktio_check_pktin_ts(void); +void pktio_test_pktin_ts(void); /* test arrays: */ extern odp_testinfo_t pktio_suite[];