From patchwork Thu Jan 8 21:35:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 42892 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 68D1E2055F for ; Thu, 8 Jan 2015 21:35:33 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf2814883lbv.1 for ; Thu, 08 Jan 2015 13:35:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=rpDOGaDSOMoKZGStpSj6ysbewvLYg2jesSW+nBd5KIA=; b=FTwnAbKAY+tfThar6aOVGMAtIabXrO5p0rKxyy2P4rwp4YWEdy2u3sY4pqgh8zDWOS 3Wm43kYIA3abuqPjdKaXUKAgBT8TXpJRP908FTtPm2tS7zMIwsblolYtV614rFv38QeB ui7raGaxXkpOzTCGZLgtj3C52wcOShNCNKFRfz2O9T2UYexPLh4BnqKDDgnaQEGd4Jsu AkYQobvrFiQJIV962Pw15XiCukGBdP7Q6SS95vijShGztt5IxBfKjvhD3+nDmTEekBxC 5OWfXEKJ3JlhN74c+N1y8SkqqVbVCB6rlCkao5b51GYXzpcqffXPMOr/mX3Vk8DB6Z74 X7Aw== X-Gm-Message-State: ALoCoQkGDzyHB8taqK0RwE+rxWyJYD8u4MLibJVbP8+YLfjzTkneIerE4ULkd6kAxhIda4JopQqy X-Received: by 10.180.108.165 with SMTP id hl5mr392075wib.7.1420752932401; Thu, 08 Jan 2015 13:35:32 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.11 with SMTP id lk11ls95967lac.8.gmail; Thu, 08 Jan 2015 13:35:32 -0800 (PST) X-Received: by 10.112.203.196 with SMTP id ks4mr17420391lbc.39.1420752932137; Thu, 08 Jan 2015 13:35:32 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id n3si10858912lah.45.2015.01.08.13.35.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 Jan 2015 13:35:32 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id gd6so11571837lab.3 for ; Thu, 08 Jan 2015 13:35:32 -0800 (PST) X-Received: by 10.112.180.135 with SMTP id do7mr17572259lbc.23.1420752931940; Thu, 08 Jan 2015 13:35:31 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp136372lbb; Thu, 8 Jan 2015 13:35:30 -0800 (PST) X-Received: by 10.140.16.50 with SMTP id 47mr19267279qga.105.1420752929602; Thu, 08 Jan 2015 13:35:29 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id o43si8794154qge.107.2015.01.08.13.35.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 08 Jan 2015 13:35:29 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y9Kjm-0001E1-K4; Thu, 08 Jan 2015 21:35:26 +0000 Received: from mail-lb0-f182.google.com ([209.85.217.182]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y9Kje-0001DX-KP for lng-odp@lists.linaro.org; Thu, 08 Jan 2015 21:35:18 +0000 Received: by mail-lb0-f182.google.com with SMTP id u10so5148560lbd.13 for ; Thu, 08 Jan 2015 13:35:12 -0800 (PST) X-Received: by 10.112.27.133 with SMTP id t5mr17724065lbg.45.1420752912390; Thu, 08 Jan 2015 13:35:12 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id ss8sm1402002lbb.22.2015.01.08.13.35.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jan 2015 13:35:11 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 8 Jan 2015 22:35:21 +0100 Message-Id: <1420752923-24198-2-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420752923-24198-1-git-send-email-ola.liljedahl@linaro.org> References: <1420752923-24198-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: timers patch Subject: [lng-odp] [PATCHv4 1/3] test: odp_timer_ping: removed X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ola.liljedahl@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Removed odp_timer_ping, it was neither a good test program nor a good ping program. Signed-off-by: Ola Liljedahl --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) test/api_test/.gitignore | 1 - test/api_test/Makefile.am | 5 +- test/api_test/odp_timer_ping.c | 404 ----------------------------------------- 3 files changed, 1 insertion(+), 409 deletions(-) delete mode 100644 test/api_test/odp_timer_ping.c diff --git a/test/api_test/.gitignore b/test/api_test/.gitignore index 7ba56c7..84159e1 100644 --- a/test/api_test/.gitignore +++ b/test/api_test/.gitignore @@ -1,4 +1,3 @@ odp_atomic odp_ring odp_shm -odp_timer_ping diff --git a/test/api_test/Makefile.am b/test/api_test/Makefile.am index faa08a1..86e1bc2 100644 --- a/test/api_test/Makefile.am +++ b/test/api_test/Makefile.am @@ -1,16 +1,14 @@ include $(top_srcdir)/test/Makefile.inc -bin_PROGRAMS = odp_atomic odp_shm odp_ring odp_timer_ping +bin_PROGRAMS = odp_atomic odp_shm odp_ring odp_atomic_CFLAGS = $(AM_CFLAGS) odp_shm_CFLAGS = $(AM_CFLAGS) odp_ring_CFLAGS = $(AM_CFLAGS) -odp_timer_ping_CFLAGS = $(AM_CFLAGS) odp_atomic_LDFLAGS = $(AM_LDFLAGS) -static odp_shm_LDFLAGS = $(AM_LDFLAGS) -static odp_ring_LDFLAGS = $(AM_LDFLAGS) -static -odp_timer_ping_LDFLAGS = $(AM_LDFLAGS) -static noinst_HEADERS = \ $(top_srcdir)/test/api_test/odp_atomic_test.h \ @@ -21,4 +19,3 @@ noinst_HEADERS = \ dist_odp_atomic_SOURCES = odp_atomic_test.c odp_common.c dist_odp_shm_SOURCES = odp_shm_test.c odp_common.c dist_odp_ring_SOURCES = odp_ring_test.c odp_common.c -dist_odp_timer_ping_SOURCES = odp_timer_ping.c odp_common.c diff --git a/test/api_test/odp_timer_ping.c b/test/api_test/odp_timer_ping.c deleted file mode 100644 index 576f946..0000000 --- a/test/api_test/odp_timer_ping.c +++ /dev/null @@ -1,404 +0,0 @@ -/* Copyright (c) 2014, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/** - * @file - * - * ODP timer ping example application. - * application open PF_INET socket, every ping send request - * will arm timer for some duration, if ping_ack rxvd with - * time band.. listen thread will cancel timer and free the - * tmo_buffer.. otherwise timer expiration event will exit - * application lead to test failure.. - * - two thread used, one listener other one sender. - * - run ./odp_timer - * In ubuntu, you need run using sudo ./odp_timer - * - so to tigger timeout explicitly.. ping with badipaddr - * Otherwise timeout may happen bcz of slow nw speed - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define MSG_POOL_SIZE (4*1024*1024) -#define BUF_SIZE 8 -#define PING_CNT 10 -#define PING_THRD 2 /* Send and Rx Ping thread */ - -/* Nanoseconds */ -#define RESUS 10000 -#define MINUS 10000 -#define MAXUS 10000000 - -static odp_timer_t test_timer_ping; -static odp_timer_tmo_t test_ping_tmo; - -#define PKTSIZE 64 -struct packet { - struct icmphdr hdr; - char msg[PKTSIZE-sizeof(struct icmphdr)]; -}; - -static int pid = -1; -static struct protoent *proto; - -static struct sockaddr_in dst_addr; - -/* local struct for ping_timer_thread argument */ -typedef struct { - pthrd_arg thrdarg; - int result; -} ping_arg_t; - -static int ping_sync_flag; - -static void dump_icmp_pkt(void *buf, int bytes, int pkt_cnt) -{ - struct iphdr *ip = buf; -#ifdef PKT_SEQ_DUMP - /* int i; */ - LOG_DBG("---dump icmp pkt_cnt %d------\n", pkt_cnt); - for (i = 0; i < bytes; i++) { - if (!(i & 15)) - ODP_DBG("\n %x: ", i); - ODP_DBG("%d ", ((unsigned char *)buf)[i]); - } - LOG_DBG("\n"); -#endif - char addrstr[INET6_ADDRSTRLEN]; - inet_ntop(AF_INET, &ip->daddr, addrstr, sizeof(addrstr)); - LOG_DBG("byte %d, Ack rxvd for msg_cnt [%d] from %s\n", bytes, pkt_cnt, - addrstr); -} - -static int listen_to_pingack(void) -{ - int sd, i; - struct sockaddr_in addr; - unsigned char buf[1024]; - int bytes, len; - int err = 0; - - sd = socket(PF_INET, SOCK_RAW, proto->p_proto); - if (sd < 0) { - LOG_ERR("Listener socket open failed\n"); - err = -1; - goto err; - } - - for (i = 0; i < PING_CNT; i++) { - - struct pollfd fd; - int res; - - fd.fd = sd; - fd.events = POLLIN; - res = poll(&fd, 1, 1000); /* 1000 ms timeout */ - - if (res == 0) { - LOG_DBG(" Rx timeout msg cnt [%d]\n", i); - err = -1; - } else if (res == -1) { - LOG_ERR("recvfrom error"); - err = -1; - goto err; - } else { - len = sizeof(addr); - - bzero(buf, sizeof(buf)); - bytes = recvfrom(sd, buf, sizeof(buf), 0, - (struct sockaddr *)&addr, - (socklen_t *)&len); - if (bytes > 0) { - /* pkt rxvd therefore cancel the timeout */ - if (odp_timer_cancel_tmo(test_timer_ping, - test_ping_tmo) != 0) { - LOG_ERR("cancel_tmo failed ..exiting listner thread\n"); - /* avoid exiting from here even if tmo - * failed for current ping, - * allow subsequent ping_rx request */ - err = -1; - - } - /* cruel bad hack used for sender, listner ipc.. - * euwww.. FIXME .. - */ - ping_sync_flag = true; - odp_buffer_free(test_ping_tmo); - dump_icmp_pkt(buf, bytes, i); - } - } - } - -err: - return err; -} - -static int send_ping_request(struct sockaddr_in *addr) -{ - const int val = 255; - uint32_t i, j; - int sd, cnt = 1; - struct packet pckt; - - uint64_t tick; - odp_queue_t queue; - odp_buffer_t buf; - - int err = 0; - - sd = socket(PF_INET, SOCK_RAW, proto->p_proto); - if (sd < 0) { - LOG_ERR("Sender socket open failed\n"); - return -1; - } - - if (setsockopt(sd, SOL_IP, IP_TTL, &val, sizeof(val)) != 0) { - LOG_ERR("Error setting TTL option\n"); - err = -1; - goto err; - } - if (fcntl(sd, F_SETFL, O_NONBLOCK) != 0) { - LOG_ERR("Request for nonblocking I/O failed\n"); - err = -1; - goto err; - } - - /* get the ping queue */ - queue = odp_queue_lookup("ping_timer_queue"); - - for (i = 0; i < PING_CNT; i++) { - /* prepare icmp pkt */ - bzero(&pckt, sizeof(pckt)); - pckt.hdr.type = ICMP_ECHO; - pckt.hdr.un.echo.id = pid; - - for (j = 0; j < sizeof(pckt.msg)-1; j++) - pckt.msg[j] = j+'0'; - - pckt.msg[j] = 0; - pckt.hdr.un.echo.sequence = cnt++; - pckt.hdr.checksum = odp_chksum(&pckt, sizeof(pckt)); - - - /* txmit the pkt */ - if (sendto(sd, &pckt, sizeof(pckt), 0, - (struct sockaddr *)addr, sizeof(*addr)) <= 0) { - LOG_ERR("sendto operation failed msg_cnt [%d]..exiting" - "sender thread\n", i); - err = -1; - goto err; - } - printf(" icmp_sent msg_cnt %d\n", i); - - /* arm the timer */ - tick = odp_timer_current_tick(test_timer_ping); - - tick += 1000; - test_ping_tmo = odp_timer_absolute_tmo(test_timer_ping, tick, - queue, - ODP_BUFFER_INVALID); - /* wait for timeout event */ - while ((buf = odp_queue_deq(queue)) == ODP_BUFFER_INVALID) { - /* flag true means ack rxvd.. a cruel hack as I - * am confused on method to get away from while - * loop in case of ack rxvd.. - * FIXME.. - */ - if (ping_sync_flag) { - ping_sync_flag = false; - LOG_DBG(" icmp_ack msg_cnt [%d]\n", i); - buf = ODP_BUFFER_INVALID; - break; - } - } - - /* free tmo_buf for timeout case */ - if (buf != ODP_BUFFER_INVALID) { - LOG_DBG(" timeout msg_cnt [%i]\n", i); - /* so to avoid seg fault commented */ - odp_buffer_free(buf); - err = -1; - } - } - -err: - close(sd); - return err; -} - -static void *send_ping(void *arg) -{ - ping_arg_t *parg = (ping_arg_t *)arg; - int thr; - - thr = odp_thread_id(); - - printf("Send Ping thread %i starts\n", thr); - - switch (parg->thrdarg.testcase) { - case ODP_TIMER_PING_TEST: - if (send_ping_request(&dst_addr) < 0) - parg->result = -1; - break; - default: - LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase); - } - - fflush(stdout); - - return parg; -} - -static void *rx_ping(void *arg) -{ - ping_arg_t *parg = (ping_arg_t *)arg; - int thr; - - thr = odp_thread_id(); - - printf("Rx Ping thread %i starts\n", thr); - - switch (parg->thrdarg.testcase) { - case ODP_TIMER_PING_TEST: - if (listen_to_pingack() < 0) - parg->result = -1; - break; - default: - LOG_ERR("Invalid test case [%d]\n", parg->thrdarg.testcase); - } - - fflush(stdout); - - return parg; -} - - -static int ping_init(int count, char *name[]) -{ - struct hostent *hname; - if (count != 2) { - LOG_ERR("usage: %s \n", name[0]); - return -1; - } - - if (count > 1) { - pid = getpid(); - proto = getprotobyname("ICMP"); - hname = gethostbyname(name[1]); - bzero(&dst_addr, sizeof(dst_addr)); - dst_addr.sin_family = hname->h_addrtype; - dst_addr.sin_port = 0; - inet_pton(AF_INET, name[1], &(dst_addr.sin_addr.s_addr)); - } - printf("ping to addr %s\n", name[1]); - - return 0; -} - -int main(int argc __attribute__((__unused__)), - char *argv[] __attribute__((__unused__))) -{ - odph_linux_pthread_t thread_tbl[MAX_WORKERS]; - ping_arg_t pingarg; - odp_queue_t queue; - odp_buffer_pool_t pool; - int i; - odp_buffer_pool_param_t params; - - if (odp_test_global_init() != 0) - return -1; - - odp_print_system_info(); - - if (ping_init(argc, argv) != 0) - return -1; - - /* - * Create message pool - */ - - params.buf_size = BUF_SIZE; - params.buf_align = 0; - params.num_bufs = MSG_POOL_SIZE/BUF_SIZE; - params.buf_type = ODP_BUFFER_TYPE_RAW; - - pool = odp_buffer_pool_create("msg_pool", ODP_SHM_NULL, ¶ms); - - if (pool == ODP_BUFFER_POOL_INVALID) { - LOG_ERR("Pool create failed.\n"); - return -1; - } - - /* - * Create a queue for timer test - */ - queue = odp_queue_create("ping_timer_queue", ODP_QUEUE_TYPE_SCHED, - NULL); - - if (queue == ODP_QUEUE_INVALID) { - LOG_ERR("Timer queue create failed.\n"); - return -1; - } - - test_timer_ping = odp_timer_create("ping_timer", pool, - RESUS*ODP_TIME_USEC, - MINUS*ODP_TIME_USEC, - MAXUS*ODP_TIME_USEC); - - if (test_timer_ping == ODP_TIMER_INVALID) { - LOG_ERR("Timer create failed.\n"); - return -1; - } - - odp_shm_print_all(); - - pingarg.thrdarg.testcase = ODP_TIMER_PING_TEST; - pingarg.thrdarg.numthrds = PING_THRD; - - pingarg.result = 0; - - memset(thread_tbl, 0, sizeof(thread_tbl)); - - /* create ping send and Receive thread */ - for (i = 0; i < PING_THRD; i++) { - void *(*run_thread) (void *); - - if (i == 0) - run_thread = send_ping; - else - run_thread = rx_ping; - - /* Create and launch worker threads */ - odph_linux_pthread_create(&thread_tbl[i], 1, i, - run_thread, (pthrd_arg *)&pingarg); - } - - /* Wait for worker threads to exit */ - odph_linux_pthread_join(thread_tbl, PING_THRD); - - LOG_DBG("ping timer test %s\n", (pingarg.result == 0) ? "passed" : - "failed"); - - printf("ODP ping timer test complete\n\n"); - - return 0; -}