From patchwork Thu Mar 12 16:03:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 45735 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f197.google.com (mail-we0-f197.google.com [74.125.82.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 00216214BF for ; Thu, 12 Mar 2015 16:04:07 +0000 (UTC) Received: by wesq59 with SMTP id q59sf12451679wes.1 for ; Thu, 12 Mar 2015 09:04:07 -0700 (PDT) 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:cc: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=MbuH4R6QpwQwJQt+aDHn+3Q3cg6fieCzbZkhq5nvWbA=; b=cHA2MYu+3SDprezXeOJmo8Fg3/ZrgwBx31EJRkIvzaWZPsFZLbp1H2XenCVbmcNuLD ACYJy7qZ8YnZjwavnHuDDzDZFmEnAHNWhkTbFUrKhdELFeBPnFkY2KGM1in6w0RqHlxI GdXjGtMzAT2+x0pkNvbsSO2DYDYcSO8WWl8G5S1roL3Csn44EHe2QuCndGyhZus3GScN 5KaPQUdydElVxgiE4t9z1WPIloYq6lU7EZVvTIB9ARR6gx8p81IA9AV0hxVEDQ+YV6Vg k2sg0j0HTx0aLCURYf2zk95S/IJ04vPBCuVR4Xr241iLZ3fVEGd2tW4CT22ZdCo/iNpI VKTw== X-Gm-Message-State: ALoCoQmZSV94ZgsNLp0vAutPmgg29hBi+5gEZqwyPRrYhuH9MO32Kc3VMFXkN9FwOyubnDlKgGhM X-Received: by 10.181.29.66 with SMTP id ju2mr9667913wid.1.1426176247342; Thu, 12 Mar 2015 09:04:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.4.38 with SMTP id cb6ls260528lad.97.gmail; Thu, 12 Mar 2015 09:04:07 -0700 (PDT) X-Received: by 10.152.9.200 with SMTP id c8mr38875548lab.67.1426176247101; Thu, 12 Mar 2015 09:04:07 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id x6si4779686lal.29.2015.03.12.09.04.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Mar 2015 09:04:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbdu10 with SMTP id u10so16972569lbd.4 for ; Thu, 12 Mar 2015 09:04:07 -0700 (PDT) X-Received: by 10.112.147.229 with SMTP id tn5mr6076921lbb.106.1426176246955; Thu, 12 Mar 2015 09:04:06 -0700 (PDT) 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.35.133 with SMTP id h5csp322051lbj; Thu, 12 Mar 2015 09:04:06 -0700 (PDT) X-Received: by 10.55.24.159 with SMTP id 31mr26657736qky.74.1426176245357; Thu, 12 Mar 2015 09:04:05 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id b4si6974907qcf.8.2015.03.12.09.04.04 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 12 Mar 2015 09:04:05 -0700 (PDT) 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 1YW5ac-00057P-73; Thu, 12 Mar 2015 16:04:02 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YW5aW-00057B-Bo for lng-odp@lists.linaro.org; Thu, 12 Mar 2015 16:03:56 +0000 Received: by lbjf15 with SMTP id f15so16979029lbj.2 for ; Thu, 12 Mar 2015 09:03:50 -0700 (PDT) X-Received: by 10.112.8.101 with SMTP id q5mr33922176lba.19.1426176230449; Thu, 12 Mar 2015 09:03:50 -0700 (PDT) Received: from macmini.lan (78-82-119-153.tn.glocalnet.net. [78.82.119.153]) by mx.google.com with ESMTPSA id rn9sm1396288lbb.23.2015.03.12.09.03.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Mar 2015 09:03:49 -0700 (PDT) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 12 Mar 2015 17:03:29 +0100 Message-Id: <1426176209-8745-1-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: timers patch Cc: Petri Savolainen Subject: [lng-odp] [PATCHv2] validation: timer: added cancel test 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.217.179 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 Add basic timer cancel test that checks that everything is OK when a timer is reset and then cancelled before expiration. Signed-off-by: Petri Savolainen Signed-off-by: Ola Liljedahl Reviewed-by: Ola Liljedahl Reviewed-by: Bill Fischofer --- v2: Enabled test of odp_timeout_user_ptr(). Added test of odp_timeout_timer(). Rephrased commit message. test/validation/odp_timer.c | 85 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c index b625b80..10dd10f 100644 --- a/test/validation/odp_timer.c +++ b/test/validation/odp_timer.c @@ -124,6 +124,90 @@ static void test_timeout_pool_free(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } +static void test_odp_timer_cancel(void) +{ + odp_pool_t pool; + odp_pool_param_t params; + odp_timer_pool_param_t tparam; + odp_timer_pool_t tp; + odp_queue_t queue; + odp_timer_t tim; + odp_event_t ev; + odp_timeout_t tmo; + odp_timer_set_t rc; + uint64_t tick; + + params.tmo.num = 1; + params.type = ODP_POOL_TIMEOUT; + pool = odp_pool_create("tmo_pool_for_cancel", ODP_SHM_NULL, ¶ms); + + if (pool == ODP_POOL_INVALID) + CU_FAIL_FATAL("Timeout pool create failed"); + + tparam.res_ns = 100 * ODP_TIME_MSEC; + tparam.min_tmo = 1 * ODP_TIME_SEC; + tparam.max_tmo = 10 * ODP_TIME_SEC; + tparam.num_timers = 1; + tparam.priv = 0; + tparam.clk_src = ODP_CLOCK_CPU; + tp = odp_timer_pool_create("timer_pool0", &tparam); + if (tp == ODP_TIMER_POOL_INVALID) + CU_FAIL_FATAL("Timer pool create failed"); + + /* Start all created timer pools */ + odp_timer_pool_start(); + + queue = odp_queue_create("timer_queue", ODP_QUEUE_TYPE_POLL, NULL); + if (queue == ODP_QUEUE_INVALID) + CU_FAIL_FATAL("Queue create failed"); + + #define USER_PTR ((void *)0xdead) + tim = odp_timer_alloc(tp, queue, USER_PTR); + if (tim == ODP_TIMER_INVALID) + CU_FAIL_FATAL("Failed to allocate timer"); + + ev = odp_timeout_to_event(odp_timeout_alloc(pool)); + if (ev == ODP_EVENT_INVALID) + CU_FAIL_FATAL("Failed to allocate timeout"); + + tick = odp_timer_ns_to_tick(tp, 2 * ODP_TIME_SEC); + + rc = odp_timer_set_rel(tim, tick, &ev); + if (rc != ODP_TIMER_SUCCESS) + CU_FAIL_FATAL("Failed to set timer (relative time)"); + + ev = ODP_EVENT_INVALID; + if (odp_timer_cancel(tim, &ev) != 0) + CU_FAIL_FATAL("Failed to cancel timer (relative time)"); + + if (ev == ODP_EVENT_INVALID) + CU_FAIL_FATAL("Cancel did not return event"); + + tmo = odp_timeout_from_event(ev); + if (tmo == ODP_TIMEOUT_INVALID) + CU_FAIL_FATAL("Cancel did not return timeout"); + + if (odp_timeout_timer(tmo) != tim) + CU_FAIL("Cancel invalid tmo.timer"); + + if (odp_timeout_user_ptr(tmo) != USER_PTR) + CU_FAIL("Cancel invalid tmo.user_ptr"); + + odp_timeout_free(tmo); + + ev = odp_timer_free(tim); + if (ev != ODP_EVENT_INVALID) + CU_FAIL_FATAL("Free returned event"); + + odp_timer_pool_destroy(tp); + + if (odp_queue_destroy(queue) != 0) + CU_FAIL_FATAL("Failed to destroy queue"); + + if (odp_pool_destroy(pool) != 0) + CU_FAIL_FATAL("Failed to destroy pool"); +} + /* @private Handle a received (timeout) event */ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) { @@ -444,6 +528,7 @@ static void test_odp_timer_all(void) CU_TestInfo test_odp_timer[] = { {"test_timeout_pool_alloc", test_timeout_pool_alloc}, {"test_timeout_pool_free", test_timeout_pool_free}, + {"test_odp_timer_cancel", test_odp_timer_cancel}, {"test_odp_timer_all", test_odp_timer_all}, CU_TEST_INFO_NULL, };