From patchwork Fri Dec 19 20:56:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42500 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4D5AF26C6B for ; Fri, 19 Dec 2014 20:57:22 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf1218230lbj.3 for ; Fri, 19 Dec 2014 12:57:20 -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=7HDhzDotAkfDrAg5FJ8gKnlYTUrJSDBafobiYJoCTbI=; b=R5UUyP8MvOIgjIeJi0HshyXtoga7b+pycavsIaVM2LzleBJiqaLFZubK1rACHkG4Lq chndvEVH7Lq7X0vNsZXDX8uL1XLheKWlyV2Bywe0CYvcbPtOhnwZvX5s/hqQN72+rOUm xL5klJ1S5tr6MkZsEtVPdM2+Zx4bW5QSXtofE9WY3xVLHUS2eBwKlGmBUREILQytqtiN Ul0Fvh3Tg+1HKY2/TJWs3VIdjxg1U+UQmJ5ZYxznCJC7yoRisTdEkhf5a0feMk0e0b/a J4KRCipjA8MgceLK5Ei/GaCJDk8GOfTh+/7M6WYSOAnFyMarvyumAM9gMN+ozkeO4lgc y/0Q== X-Gm-Message-State: ALoCoQkIu7xYcpjeQSBleFQMt7pF0VgXGI6R+bwr4eZb7u+xLigAowlwM91Jat5/xizg0NThqStG X-Received: by 10.112.138.234 with SMTP id qt10mr1380766lbb.4.1419022640898; Fri, 19 Dec 2014 12:57:20 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.101 with SMTP id z5ls34932laz.99.gmail; Fri, 19 Dec 2014 12:57:20 -0800 (PST) X-Received: by 10.152.164.232 with SMTP id yt8mr9847943lab.7.1419022640516; Fri, 19 Dec 2014 12:57:20 -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 jh3si11123131lbc.5.2014.12.19.12.57.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Dec 2014 12:57:20 -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 q1so1490150lam.5 for ; Fri, 19 Dec 2014 12:57:20 -0800 (PST) X-Received: by 10.112.159.129 with SMTP id xc1mr9816882lbb.24.1419022640410; Fri, 19 Dec 2014 12:57:20 -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 ru5csp390523lbb; Fri, 19 Dec 2014 12:57:19 -0800 (PST) X-Received: by 10.229.140.72 with SMTP id h8mr17435091qcu.25.1419022638733; Fri, 19 Dec 2014 12:57:18 -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 b31si12959092qga.66.2014.12.19.12.57.17 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 19 Dec 2014 12:57:18 -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 1Y24br-0000ky-Lg; Fri, 19 Dec 2014 20:57:15 +0000 Received: from mail-la0-f42.google.com ([209.85.215.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y24bh-0000jD-0f for lng-odp@lists.linaro.org; Fri, 19 Dec 2014 20:57:05 +0000 Received: by mail-la0-f42.google.com with SMTP id gd6so1534013lab.1 for ; Fri, 19 Dec 2014 12:56:59 -0800 (PST) X-Received: by 10.112.201.72 with SMTP id jy8mr9694683lbc.65.1419022619149; Fri, 19 Dec 2014 12:56:59 -0800 (PST) Received: from localhost.localdomain ([80.77.38.170]) by mx.google.com with ESMTPSA id a1sm3020243lbi.11.2014.12.19.12.56.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Dec 2014 12:56:58 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Fri, 19 Dec 2014 22:56:49 +0200 Message-Id: <1419022611-28989-2-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1419022611-28989-1-git-send-email-taras.kondratiuk@linaro.org> References: <1419022611-28989-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 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 Reviewed-and-tested-by: Bill Fischofer 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_tests.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_tests.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 a12fdfa..e7e6fec 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,3 +19,5 @@ 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 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..6f5eaf7 --- /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_tests.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_tests.h b/test/validation/buffer/odp_buffer_tests.h new file mode 100644 index 0000000..4184fb5 --- /dev/null +++ b/test/validation/buffer/odp_buffer_tests.h @@ -0,0 +1,21 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_BUFFER_TESTS_H_ +#define ODP_BUFFER_TESTS_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_TESTS_H_ */ diff --git a/test/validation/odp_buffer.c b/test/validation/odp_buffer.c new file mode 100644 index 0000000..daa30ca --- /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_tests.h" + +CU_SuiteInfo odp_testsuites[] = { + { .pName = "buffer Pool tests", + .pTests = buffer_pool_tests, + }, + CU_SUITE_INFO_NULL, +};