From patchwork Tue Jan 3 15:10:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 89660 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp8024421qgi; Tue, 3 Jan 2017 06:15:42 -0800 (PST) X-Received: by 10.200.36.46 with SMTP id c43mr55660016qtc.260.1483452942280; Tue, 03 Jan 2017 06:15:42 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id v63si16525276qkb.318.2017.01.03.06.15.41; Tue, 03 Jan 2017 06:15:42 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id DB3CE60C32; Tue, 3 Jan 2017 14:15:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 6364060C4A; Tue, 3 Jan 2017 14:11:36 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 880DB60C0D; Tue, 3 Jan 2017 14:11:11 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id 16F0560BE6 for ; Tue, 3 Jan 2017 14:11:07 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id t196so286294819lff.3 for ; Tue, 03 Jan 2017 06:11:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xlx6Yj2OAvgVnwXInAgt5/ucWEOEY54ktSdP5hbP8W4=; b=NquL2Hl7JmtLyAcV8+sUtdIQZ+kp4v4RMrFKbZ7Q2EHA/CYvIumDE35qd03W9LrJ51 9cHmgY5Rtd2b82+LUs31MRFKI/08gCb3Oepkybm34CQ6gsvCekMAguZPSq2/5xq/qQu/ LTZtEBKsgN381mCDsXDFkmllPuzEWJkhtycW5KShwsAi+VLlkWkkyxXgImHG/VpTT9p9 s+Hb2qgZXmWMd4/VDHk4lPUkOkmCUBehZ8LixazzysAEuXBQu75yFNjQKTtc8NSr7jsN Hkq0PpM8E7DNC4Im2T27/zTRxlnqIdGs5+2zMq7r1vIJyBh5vTZRCjZxHQzHHuEzhZPe 0ncg== X-Gm-Message-State: AIkVDXLqaVyHLuT6D5nR09HXllRdXAWUcSH/D/83yt6V+nbwZrZCbAzdcoTZfMNzigoN8z/pW3o= X-Received: by 10.46.0.101 with SMTP id 98mr21478922lja.23.1483452665917; Tue, 03 Jan 2017 06:11:05 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-76-66.cust.bredband2.com. [83.233.76.66]) by smtp.gmail.com with ESMTPSA id a184sm16760057lfb.34.2017.01.03.06.11.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Jan 2017 06:11:05 -0800 (PST) From: Christophe Milard To: mike.holmes@linaro.org, bill.fischofer@linaro.org, yi.he@linaro.org, forrest.shi@linaro.org, francois.ozog@linaro.org, lng-odp@lists.linaro.org Date: Tue, 3 Jan 2017 16:10:14 +0100 Message-Id: <1483456215-40789-6-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1483456215-40789-1-git-send-email-christophe.milard@linaro.org> References: <1483456215-40789-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [API-NEXTv5 5/6] test: drv: shm: adding basic fixed size allocation tests X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Basic tests for odpdrv_shm_pool are added here, creating a fixed size pool and performing basic alloc/free on it Signed-off-by: Christophe Milard --- .../common_plat/validation/drv/drvshmem/drvshmem.c | 86 ++++++++++++++++++++++ .../common_plat/validation/drv/drvshmem/drvshmem.h | 1 + 2 files changed, 87 insertions(+) -- 2.7.4 diff --git a/test/common_plat/validation/drv/drvshmem/drvshmem.c b/test/common_plat/validation/drv/drvshmem/drvshmem.c index 5843573..d4dedea 100644 --- a/test/common_plat/validation/drv/drvshmem/drvshmem.c +++ b/test/common_plat/validation/drv/drvshmem/drvshmem.c @@ -853,12 +853,98 @@ void drvshmem_test_buddy_basic(void) odpdrv_shm_pool_destroy(pool); } +void drvshmem_test_slab_basic(void) +{ + odpdrv_shm_pool_param_t pool_params; + odpdrv_shm_pool_t pool, found_pool; + uint8_t *buff; + uint8_t *addrs[TEST_SZ]; + uint16_t length; + int i, j; + + /* create a pool and check that it can be looked up */ + pool_params.pool_size = POOL_SZ; + pool_params.min_alloc = SZ_1K; /* constant size will give slab */ + pool_params.max_alloc = SZ_1K; + pool = odpdrv_shm_pool_create(POOL_NAME, &pool_params); + found_pool = odpdrv_shm_pool_lookup(POOL_NAME); + CU_ASSERT(found_pool == pool); + + /* alloc a 1k buffer, filling its contents: */ + buff = odpdrv_shm_pool_alloc(pool, SZ_1K); + CU_ASSERT_PTR_NOT_NULL(buff); + for (i = 0; i < SZ_1K; i++) + buff[i] = BUFF_PATTERN; + odpdrv_shm_pool_print("buddy test: 1K reserved", pool); + + /* alloc as many 1K buffer a possible */ + for (i = 0; i < TEST_SZ; i++) { + length = SZ_1K; + addrs[i] = odpdrv_shm_pool_alloc(pool, length); + /* if alloc was success, fill buffer for later check */ + if (addrs[i]) { + for (j = 0; j < length; j++) + addrs[i][j] = (uint8_t)(length & 0xFF); + } + } + odpdrv_shm_pool_print("slab test: after many mallocs", pool); + + /* release every 3rth buffer, checking contents: */ + for (i = 0; i < TEST_SZ; i += 3) { + /* if buffer was allocated, check the pattern in it */ + if (addrs[i]) { + length = SZ_1K; + for (j = 0; j < length; j++) + CU_ASSERT(addrs[i][j] == + (uint8_t)(length & 0xFF)); + } + odpdrv_shm_pool_free(pool, addrs[i]); + } + odpdrv_shm_pool_print("slab test: after 1/3 free:", pool); + + /* realloc them:*/ + for (i = 0; i < TEST_SZ; i += 3) { + length = SZ_1K; + addrs[i] = odpdrv_shm_pool_alloc(pool, length); + /* if alloc was success, fill buffer for later check */ + if (addrs[i]) { + for (j = 0; j < length; j++) + addrs[i][j] = (uint8_t)(length & 0xFF); + } + } + odpdrv_shm_pool_print("slab test: after realloc:", pool); + + /* free all (except buff), checking contents: */ + for (i = 0; i < TEST_SZ; i++) { + /* if buffer was allocated, check the pattern in it */ + if (addrs[i]) { + length = SZ_1K; + for (j = 0; j < length; j++) + CU_ASSERT(addrs[i][j] == + (uint8_t)(length & 0xFF)) + } + odpdrv_shm_pool_free(pool, addrs[i]); + } + odpdrv_shm_pool_print("slab test: after all but 1K free:", pool); + + /* check contents of our initial 1K buffer: */ + for (i = 0; i < SZ_1K; i++) + CU_ASSERT((buff[i] == BUFF_PATTERN)) + odpdrv_shm_pool_free(pool, buff); + + odpdrv_shm_pool_print("slab test: after all free", pool); + + /* destroy pool: */ + odpdrv_shm_pool_destroy(pool); +} + odp_testinfo_t drvshmem_suite[] = { ODP_TEST_INFO(drvshmem_test_basic), ODP_TEST_INFO(drvshmem_test_reserve_after_fork), ODP_TEST_INFO(drvshmem_test_singleva_after_fork), ODP_TEST_INFO(drvshmem_test_stress), ODP_TEST_INFO(drvshmem_test_buddy_basic), + ODP_TEST_INFO(drvshmem_test_slab_basic), ODP_TEST_INFO_NULL, }; diff --git a/test/common_plat/validation/drv/drvshmem/drvshmem.h b/test/common_plat/validation/drv/drvshmem/drvshmem.h index ab45f7c..fdc1080 100644 --- a/test/common_plat/validation/drv/drvshmem/drvshmem.h +++ b/test/common_plat/validation/drv/drvshmem/drvshmem.h @@ -15,6 +15,7 @@ void drvshmem_test_reserve_after_fork(void); void drvshmem_test_singleva_after_fork(void); void drvshmem_test_stress(void); void drvshmem_test_buddy_basic(void); +void drvshmem_test_slab_basic(void); /* test arrays: */ extern odp_testinfo_t drvshmem_suite[];