From patchwork Tue Dec 20 08:00:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 88556 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1578406qgi; Mon, 19 Dec 2016 23:04:00 -0800 (PST) X-Received: by 10.55.151.199 with SMTP id z190mr3828584qkd.166.1482217440664; Mon, 19 Dec 2016 23:04:00 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q34si1798864qtq.287.2016.12.19.23.04.00; Mon, 19 Dec 2016 23:04:00 -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 45DF662EDB; Tue, 20 Dec 2016 07:04:00 +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=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 9E6CE62EE1; Tue, 20 Dec 2016 07:01:00 +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 1EF2662EC8; Tue, 20 Dec 2016 07:00:50 +0000 (UTC) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by lists.linaro.org (Postfix) with ESMTPS id CA3A462EAA for ; Tue, 20 Dec 2016 07:00:45 +0000 (UTC) Received: by mail-lf0-f52.google.com with SMTP id c13so69792135lfg.0 for ; Mon, 19 Dec 2016 23:00:45 -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=oKzqkImMkhFCsFs5IQuxSZD+FjvKnf2ARwyBtbLgF9M=; b=BYzpxv6zjgyqoPszwVt4s3p9HPxEW2LfmlJ4/lvFTicAEUr/jmRAUj+rOuRYgs6tai Gwo7hCTdauNl93SPnWtGnMhFxbiv7yjb4d1ZAnJTDzO+VYnbNrPedmXaoX+FiDQ837Rl DqrEmI8ZGkxAsp8zQCtdxFQWnqAmAl9rOWbAyB6+GbxnfMOGi16LpT94pxLNflo7TLkz oaPbRGLyzQmJeCJ3GqgzUULGyMOKK1ETDRe3DfXTmg3k84GLS99fYtFtCfDmN7i8Czlp Am1yBwRJjmwkW6rh2j+fRTZV+rhVhC8YpnY4Ih1Qplc8D+o8f+SEQqRvS2gsGnIMGKfq Ut8w== X-Gm-Message-State: AKaTC0335vBxTAAMAgfOlQ5tVDVcN4EA5Qun73rfNM6hjMxhmwdmL21kcgWlwalZbGOQMQy/yk8= X-Received: by 10.25.28.21 with SMTP id c21mr6984221lfc.91.1482217244565; Mon, 19 Dec 2016 23:00:44 -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 f42sm4438503lji.2.2016.12.19.23.00.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Dec 2016 23:00:44 -0800 (PST) From: Christophe Milard To: francois.ozog@linaro.org, forrest.shi@linaro.org, mike.holmes@linaro.org, yi.he@linaro.org, bill.fischofer@linaro.org, lng-odp@lists.linaro.org Date: Tue, 20 Dec 2016 09:00:06 +0100 Message-Id: <1482220807-6139-5-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482220807-6139-1-git-send-email-christophe.milard@linaro.org> References: <1482220807-6139-1-git-send-email-christophe.milard@linaro.org> Subject: [lng-odp] [RFC API-NEXT PATCH 4/5] test: drv: shm: adding small 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" Tests for odpdrv_shm_sreserve() and odpdrv_shm_sfree are added, testing the ishm small memory unit allocator. Signed-off-by: Christophe Milard --- .../common_plat/validation/drv/drvshmem/drvshmem.c | 77 ++++++++++++++++++++++ .../common_plat/validation/drv/drvshmem/drvshmem.h | 1 + 2 files changed, 78 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 0247a03..c129693 100644 --- a/test/common_plat/validation/drv/drvshmem/drvshmem.c +++ b/test/common_plat/validation/drv/drvshmem/drvshmem.c @@ -21,6 +21,10 @@ #define STRESS_RANDOM_SZ 5 #define STRESS_ITERATION 5000 +#define TEST_SZ 1000 +#define SZ_1K 1024 +#define BUFF_PATTERN 0xA3 + typedef enum { STRESS_FREE, /* entry is free and can be allocated */ STRESS_BUSY, /* entry is being processed: don't touch */ @@ -762,11 +766,84 @@ void drvshmem_test_stress(void) CU_ASSERT(odpdrv_shm_print_all("After stress tests") == base); } +void drvshmem_test_small_basic(void) +{ + uint8_t *buff; + uint8_t *addrs[TEST_SZ]; + uint8_t length; + int i, j; + + /* alloc a 1k buffer, filling its contents: */ + buff = odpdrv_shm_sreserve(SZ_1K); + CU_ASSERT_PTR_NOT_NULL(buff); + for (i = 0; i < SZ_1K; i++) + buff[i] = BUFF_PATTERN; + odpdrv_shm_print_all("sreserve test: 1K reserved"); + + /* alloc as many buffer a possible on increseasing sz */ + for (i = 0; i < TEST_SZ; i++) { + length = i * 16; + addrs[i] = odpdrv_shm_sreserve(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_print_all("sreserve test: after many smalloc"); + + /* 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 = i * 16; + for (j = 0; j < length; j++) + CU_ASSERT(addrs[i][j] == + (uint8_t)(length & 0xFF)); + } + odpdrv_shm_sfree(addrs[i]); + } + odpdrv_shm_print_all("sreserve test: after 1/3 free:"); + + /* realloc them:*/ + for (i = 0; i < TEST_SZ; i += 3) { + length = i * 16; + addrs[i] = odpdrv_shm_sreserve(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_print_all("sreserve test: after realloc:"); + + /* 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 = i * 16; + for (j = 0; j < length; j++) + CU_ASSERT(addrs[i][j] == + (uint8_t)(length & 0xFF)) + } + odpdrv_shm_sfree(addrs[i]); + } + odpdrv_shm_print_all("sreserve test: after all but 1K free:"); + + /* check contents of our initial 1K buffer: */ + for (i = 0; i < SZ_1K; i++) + CU_ASSERT((buff[i] == BUFF_PATTERN)) + odpdrv_shm_sfree(buff); + + odpdrv_shm_print_all("sreserve test: after all free"); +} + 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_small_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 f4c26a1..0dcbccb 100644 --- a/test/common_plat/validation/drv/drvshmem/drvshmem.h +++ b/test/common_plat/validation/drv/drvshmem/drvshmem.h @@ -14,6 +14,7 @@ void drvshmem_test_basic(void); void drvshmem_test_reserve_after_fork(void); void drvshmem_test_singleva_after_fork(void); void drvshmem_test_stress(void); +void drvshmem_test_small_basic(void); /* test arrays: */ extern odp_testinfo_t drvshmem_suite[];