From patchwork Thu Dec 18 12:11:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42442 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C7C5E26C8B for ; Thu, 18 Dec 2014 12:12:23 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf666895wgh.1 for ; Thu, 18 Dec 2014 04:12:23 -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=vkov9ZdPFu6K/f16NBukFywNRvKIeKB+6qQYPrYUEvE=; b=Cvbd/p3MiqBEELOu0NXID1HgfUNXXNkpIythKPca13MAtSZrxXLL4lw7i5fDUDE0SX 4tpZCDyllGtFKApS2jPT5s5esnesh+0iaSzJlWpPrtuTADYVCDrSWIjSo+JfWQO3/bf+ N+0TDfqD4EPYNuDeCCJzfbFtHYmD3R96syyPdM+EIPP7V6Gpn2894vD7oXMFaejPm5x9 hE5A/jIa9XAO7UTQeKtORsUa3b7nxSz8l1NqGa3W9jBzREsgR+YPT/+KbhbFPlK/Gvcx 2lyIg2PkADGj5vt6vA3L35gDa5x4FS5ARF2/HES6n6ucfd4o95xaCUv3T8YQ7xTIX3Cc 6gNw== X-Gm-Message-State: ALoCoQmHSbe45BYpfbpL+SSzR7/qHllCkSOzKUtGc5Sul3T9gZXZBfyy8tgY+OQBzU0JZkfu+95m X-Received: by 10.180.7.226 with SMTP id m2mr357666wia.5.1418904743078; Thu, 18 Dec 2014 04:12:23 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.176 with SMTP id az16ls949229lab.87.gmail; Thu, 18 Dec 2014 04:12:22 -0800 (PST) X-Received: by 10.112.132.2 with SMTP id oq2mr1906795lbb.11.1418904742689; Thu, 18 Dec 2014 04:12:22 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id y1si6712259lbb.41.2014.12.18.04.12.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 18 Dec 2014 04:12:22 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id q1so869585lam.5 for ; Thu, 18 Dec 2014 04:12:22 -0800 (PST) X-Received: by 10.112.130.132 with SMTP id oe4mr1902408lbb.82.1418904742559; Thu, 18 Dec 2014 04:12:22 -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.142.69 with SMTP id ru5csp1683814lbb; Thu, 18 Dec 2014 04:12:21 -0800 (PST) X-Received: by 10.229.196.70 with SMTP id ef6mr2859820qcb.31.1418904740364; Thu, 18 Dec 2014 04:12:20 -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 b10si7969460qab.34.2014.12.18.04.12.19 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 18 Dec 2014 04:12:20 -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 1Y1ZwI-0003kF-7p; Thu, 18 Dec 2014 12:12:18 +0000 Received: from mail-la0-f50.google.com ([209.85.215.50]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y1Zw4-0003ed-4a for lng-odp@lists.linaro.org; Thu, 18 Dec 2014 12:12:04 +0000 Received: by mail-la0-f50.google.com with SMTP id pn19so858120lab.23 for ; Thu, 18 Dec 2014 04:11:58 -0800 (PST) X-Received: by 10.112.150.136 with SMTP id ui8mr1955912lbb.60.1418904718528; Thu, 18 Dec 2014 04:11:58 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id xk7sm1731858lbb.7.2014.12.18.04.11.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Dec 2014 04:11:57 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org, bill.fischofer@linaro.org Date: Thu, 18 Dec 2014 14:11:46 +0200 Message-Id: <1418904708-1412-2-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418904708-1412-1-git-send-email-taras.kondratiuk@linaro.org> References: <1418904708-1412-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 1/3] validation: buffer: add initial buffer pool tests 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: taras.kondratiuk@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.46 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 Signed-off-by: Taras Kondratiuk --- test/validation/.gitignore | 1 + test/validation/Makefile.am | 5 +- test/validation/buffer/odp_buffer_pool_test.c | 212 +++++++++++++++++++++++++ test/validation/buffer/odp_buffer_testsuites.h | 21 +++ test/validation/odp_buffer.c | 14 ++ 5 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 test/validation/buffer/odp_buffer_pool_test.c create mode 100644 test/validation/buffer/odp_buffer_testsuites.h create mode 100644 test/validation/odp_buffer.c diff --git a/test/validation/.gitignore b/test/validation/.gitignore index 32834ae..cc05f30 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -5,3 +5,4 @@ odp_queue odp_crypto odp_schedule odp_shm +odp_buffer diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index d616c8c..d2ca969 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,8 +6,9 @@ AM_LDFLAGS += -static if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_buffer odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto +odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer endif dist_odp_init_SOURCES = odp_init.c @@ -18,6 +19,8 @@ dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ odp_crypto.c common/odp_cunit_common.c dist_odp_shm_SOURCES = odp_shm.c common/odp_cunit_common.c dist_odp_schedule_SOURCES = odp_schedule.c common/odp_cunit_common.c +dist_odp_buffer_SOURCES = buffer/odp_buffer_pool_test.c \ + odp_buffer.c common/odp_cunit_common.c #For Linux generic the unimplemented crypto API functions break the #regression TODO: https://bugs.linaro.org/show_bug.cgi?id=975 diff --git a/test/validation/buffer/odp_buffer_pool_test.c b/test/validation/buffer/odp_buffer_pool_test.c new file mode 100644 index 0000000..b41fe4d --- /dev/null +++ b/test/validation/buffer/odp_buffer_pool_test.c @@ -0,0 +1,212 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "odp_buffer_testsuites.h" + +static int pool_name_number = 1; +static const int default_buffer_size = 1500; +static const int default_buffer_num = 1000; + +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type) +{ + odp_buffer_pool_t pool; + char pool_name[ODP_BUFFER_POOL_NAME_LEN]; + odp_buffer_pool_param_t params = { + .buf_size = buf_size, + .buf_align = ODP_CACHE_LINE_SIZE, + .num_bufs = buf_num, + .buf_type = buf_type, + }; + + snprintf(pool_name, sizeof(pool_name), + "test_buffer_pool-%d", pool_name_number++); + + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + return pool; +} + +static void pool_create_destroy_type(int type) +{ + odp_buffer_pool_t pool; + pool = pool_create(default_buffer_num, default_buffer_size, type); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +static void pool_create_destroy_raw(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_RAW); +} + +static void pool_create_destroy_packet(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_PACKET); +} + +static void pool_create_destroy_timeout(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_TIMEOUT); +} + +static void pool_create_destroy_any(void) +{ + pool_create_destroy_type(ODP_BUFFER_TYPE_ANY); +} + +static void pool_create_destroy_raw_shm(void) +{ + odp_buffer_pool_t pool; + odp_shm_t test_shm; + odp_buffer_pool_param_t params = { + .buf_size = 1500, + .buf_align = ODP_CACHE_LINE_SIZE, + .num_bufs = 10, + .buf_type = ODP_BUFFER_TYPE_RAW, + }; + + test_shm = odp_shm_reserve("test_shm", + params.buf_size * params.num_bufs * 2, + ODP_CACHE_LINE_SIZE, + 0); + CU_ASSERT_FATAL(test_shm != ODP_SHM_INVALID); + + pool = odp_buffer_pool_create("test_shm_pool", test_shm, ¶ms); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); + CU_ASSERT(odp_shm_free(test_shm) == 0); +} + +static void pool_lookup_info_print(void) +{ + odp_buffer_pool_t pool; + const char pool_name[] = "pool_for_lookup_test"; + odp_buffer_pool_info_t info; + odp_buffer_pool_param_t params = { + .buf_size = default_buffer_size, + .buf_align = ODP_CACHE_LINE_SIZE, + .num_bufs = default_buffer_num, + .buf_type = ODP_BUFFER_TYPE_RAW, + }; + + pool = odp_buffer_pool_create(pool_name, ODP_SHM_INVALID, ¶ms); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + pool = odp_buffer_pool_lookup(pool_name); + CU_ASSERT_FATAL(pool != ODP_BUFFER_POOL_INVALID); + + CU_ASSERT_FATAL(odp_buffer_pool_info(pool, &info) == 0); + CU_ASSERT(strncmp(pool_name, info.name, sizeof(pool_name)) == 0); + CU_ASSERT(info.shm == ODP_SHM_INVALID); + CU_ASSERT(params.buf_size <= info.params.buf_size); + CU_ASSERT(params.buf_align <= info.params.buf_align); + CU_ASSERT(params.num_bufs <= info.params.num_bufs); + CU_ASSERT(params.buf_type == info.params.buf_type); + + odp_buffer_pool_print(pool); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +static void pool_alloc_buffer_type(int type) +{ + odp_buffer_pool_t pool; + const int buf_num = 3; + const size_t buf_size = 1500; + odp_buffer_t buffer[buf_num]; + int buf_index; + char wrong_type = 0, wrong_size = 0; + + pool = pool_create(buf_num, buf_size, type); + odp_buffer_pool_print(pool); + + /* Try to allocate buf_num buffers from the pool */ + for (buf_index = 0; buf_index < buf_num; buf_index++) { + buffer[buf_index] = odp_buffer_alloc(pool); + if (buffer[buf_index] == ODP_BUFFER_INVALID) + break; + if (odp_buffer_type(buffer[buf_index]) != type) + wrong_type = 1; + if (odp_buffer_size(buffer[buf_index]) < buf_size) + wrong_size = 1; + if (wrong_type || wrong_size) + odp_buffer_print(buffer[buf_index]); + } + + /* Check that the pool had at least buf_num buffers */ + CU_ASSERT(buf_index == buf_num); + /* buf_index points out of buffer[] or it point to an invalid buffer */ + buf_index--; + + /* Check that the pool had correct buffers */ + CU_ASSERT(wrong_type == 0); + CU_ASSERT(wrong_size == 0); + + for (; buf_index >= 0; buf_index--) + odp_buffer_free(buffer[buf_index]); + + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +static void pool_alloc_buffer_raw(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_RAW); +} + +static void pool_alloc_buffer_packet(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_PACKET); +} + +static void pool_alloc_buffer_timeout(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_TIMEOUT); +} + +static void pool_alloc_buffer_any(void) +{ + pool_alloc_buffer_type(ODP_BUFFER_TYPE_ANY); +} + +static void pool_free_buffer(void) +{ + odp_buffer_pool_t pool; + odp_buffer_t buffer; + pool = pool_create(1, 64, ODP_BUFFER_TYPE_RAW); + + /* Allocate the only buffer from the pool */ + buffer = odp_buffer_alloc(pool); + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); + + /** @todo: is it correct to assume the pool had only one buffer? */ + CU_ASSERT_FATAL(odp_buffer_alloc(pool) == ODP_BUFFER_INVALID) + + odp_buffer_free(buffer); + + /* Check that the buffer was returned back to the pool */ + buffer = odp_buffer_alloc(pool); + CU_ASSERT_FATAL(buffer != ODP_BUFFER_INVALID); + + odp_buffer_free(buffer); + CU_ASSERT(odp_buffer_pool_destroy(pool) == 0); +} + +CU_TestInfo buffer_pool_tests[] = { + _CU_TEST_INFO(pool_create_destroy_raw), + _CU_TEST_INFO(pool_create_destroy_packet), + _CU_TEST_INFO(pool_create_destroy_timeout), + _CU_TEST_INFO(pool_create_destroy_any), + _CU_TEST_INFO(pool_create_destroy_raw_shm), + _CU_TEST_INFO(pool_lookup_info_print), + _CU_TEST_INFO(pool_alloc_buffer_raw), + _CU_TEST_INFO(pool_alloc_buffer_packet), + _CU_TEST_INFO(pool_alloc_buffer_timeout), + _CU_TEST_INFO(pool_alloc_buffer_any), + _CU_TEST_INFO(pool_free_buffer), + CU_TEST_INFO_NULL, +}; diff --git a/test/validation/buffer/odp_buffer_testsuites.h b/test/validation/buffer/odp_buffer_testsuites.h new file mode 100644 index 0000000..08fb4e0 --- /dev/null +++ b/test/validation/buffer/odp_buffer_testsuites.h @@ -0,0 +1,21 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_BUFFER_TESTSUITES_H_ +#define ODP_BUFFER_TESTSUITES_H_ + +#include +#include +#include "odp_cunit_common.h" + +/* Helper macro for CU_TestInfo initialization */ +#define _CU_TEST_INFO(test_func) {#test_func, test_func} + +extern CU_TestInfo buffer_pool_tests[]; + +odp_buffer_pool_t pool_create(int buf_num, int buf_size, int buf_type); + +#endif /* ODP_BUFFER_TESTSUITES_H_ */ diff --git a/test/validation/odp_buffer.c b/test/validation/odp_buffer.c new file mode 100644 index 0000000..bfd9f6d --- /dev/null +++ b/test/validation/odp_buffer.c @@ -0,0 +1,14 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "odp_buffer_testsuites.h" + +CU_SuiteInfo odp_testsuites[] = { + { .pName = "buffer Pool tests", + .pTests = buffer_pool_tests, + }, + CU_SUITE_INFO_NULL, +};