From patchwork Fri Dec 12 16:38:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 42190 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BBF5926C77 for ; Fri, 12 Dec 2014 16:39:34 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id r20sf1422982wiv.5 for ; Fri, 12 Dec 2014 08:39:34 -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=Hqv9L+icatbmC4w33IqtQeBN5xKS/BFjZPlqwa2N6vk=; b=I8utRJ8G+y+4G2IXGbAJpuv7JQZ4dih6XZyQD0l8mKJ2ewg2cgiFCvjB538+xNK4vQ vDIqRHy0PwVzCpB87a65unUIC9zNEV8Jd5kMFuSgVQzE9nDZNSLw6c5Ku4vdoZy6aSx5 uq8lk1DBEtKGIe288D/KyI3hY4X4OcxGpF69MIBzEBJBGB7XfVGpEfZsh/lp0CsxAR0B ekQiczU+zr+LRGz6FrTGJssFKqxzdA3VLKCS2V9NOSHNW5ujgPq+3vuOFp8SDsXaRZij muTOlAIuUVtyZomCwKV7l2WnjP+mgTtlMmNlJT/5kpvlYKuMfm7IjFd8V2eWQTR/L+L3 QQSg== X-Gm-Message-State: ALoCoQkRG+ZRFRRZQFKSC785i+0sJ5L/rO67AZvXPOpzVAOl4uh5Ur7oPdaNvvcsX0okfIgboNpU X-Received: by 10.112.143.136 with SMTP id se8mr12985lbb.18.1418402374023; Fri, 12 Dec 2014 08:39:34 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.170 with SMTP id p10ls463681lal.35.gmail; Fri, 12 Dec 2014 08:39:33 -0800 (PST) X-Received: by 10.112.73.102 with SMTP id k6mr16510174lbv.75.1418402373762; Fri, 12 Dec 2014 08:39:33 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id q13si1947987laa.27.2014.12.12.08.39.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 12 Dec 2014 08:39:33 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id hz20so6275654lab.6 for ; Fri, 12 Dec 2014 08:39:33 -0800 (PST) X-Received: by 10.152.2.74 with SMTP id 10mr16135248las.38.1418402373313; Fri, 12 Dec 2014 08:39:33 -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 ru5csp29781lbb; Fri, 12 Dec 2014 08:39:32 -0800 (PST) X-Received: by 10.52.165.10 with SMTP id yu10mr9187683vdb.3.1418402371844; Fri, 12 Dec 2014 08:39:31 -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 m7si636845vcl.0.2014.12.12.08.39.30 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 12 Dec 2014 08:39:31 -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 1XzTFZ-0004KR-BX; Fri, 12 Dec 2014 16:39:29 +0000 Received: from mail-lb0-f174.google.com ([209.85.217.174]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XzTFC-0004HJ-EQ for lng-odp@lists.linaro.org; Fri, 12 Dec 2014 16:39:06 +0000 Received: by mail-lb0-f174.google.com with SMTP id 10so6171263lbg.19 for ; Fri, 12 Dec 2014 08:39:00 -0800 (PST) X-Received: by 10.112.166.101 with SMTP id zf5mr16910366lbb.42.1418402340600; Fri, 12 Dec 2014 08:39:00 -0800 (PST) Received: from localhost.localdomain ([80.77.38.170]) by mx.google.com with ESMTPSA id b4sm524127lbp.17.2014.12.12.08.38.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Dec 2014 08:38:59 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Fri, 12 Dec 2014 18:38:43 +0200 Message-Id: <1418402325-6798-3-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418402325-6798-1-git-send-email-taras.kondratiuk@linaro.org> References: <1418402325-6798-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 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.47 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 | 6 +- 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, 253 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 37e2594..6bf11bd 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -4,3 +4,4 @@ odp_init odp_queue odp_crypto odp_shm +odp_buffer diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index 8547085..81fd933 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,13 +6,15 @@ AM_LDFLAGS += -static if ODP_CUNIT_ENABLED TESTS = ${bin_PROGRAMS} check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_buffer odp_init_LDFLAGS = $(AM_LDFLAGS) odp_queue_LDFLAGS = $(AM_LDFLAGS) odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_crypto_LDFLAGS = $(AM_LDFLAGS) odp_shm_CFLAGS = $(AM_CFLAGS) odp_shm_LDFLAGS = $(AM_LDFLAGS) +odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer +odp_buffer_LDFLAGS = $(AM_LDFLAGS) endif dist_odp_init_SOURCES = odp_init.c @@ -22,3 +24,5 @@ dist_odp_crypto_SOURCES = crypto/odp_crypto_test_async_inp.c \ crypto/odp_crypto_test_rng.c \ odp_crypto.c common/odp_cunit_common.c dist_odp_shm_SOURCES = odp_shm.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..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, +};