From patchwork Thu Jul 16 16:25:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 51190 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B6FD822A8A for ; Thu, 16 Jul 2015 16:31:56 +0000 (UTC) Received: by wizo10 with SMTP id o10sf5876947wiz.0 for ; Thu, 16 Jul 2015 09:31:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to: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=ay2Kaan7n9oJ6ykdzrwu1v/G7D2i1iJcYRCv69ibMRA=; b=Cg8nVCwpEk+TOYlp7RX9wIJLmfDjAhvg0fcPPRqNvssltqvbQmLXgNGvWWzuhjj5Kv lWPOyYKSf1YfWv9lj5k9BVXJW8wgG7RT2sS40gva6m65SQo8cAgZ84mSK0bj0Ueu7G7i REPx7dekMjWektwK/UoBDIuA4Afpm3Gch5UIdaW3sEzxP0wlB/nbqKQ/6EwNwYb5/odp TBe7CrGPfNMbIBGBSZ4M+J2RVZx4QOhqmrncwztQ+vWmJpgsMPJGcl5F0+tNJLd8i8dp jyHBHUyKsuuNfWgCBrZjVYU88mYJGk5zPNusd083HRPj0jN1M49/x+y+4dYV2r06KXYW iKKg== X-Gm-Message-State: ALoCoQkhQ4BSl0IJ5phu2wuBT7OkbJc17MGzN2tYnA5ydtzCDTLDk1FSFHqbhfMzapby/BVRaUUf X-Received: by 10.194.209.180 with SMTP id mn20mr5255161wjc.5.1437064316103; Thu, 16 Jul 2015 09:31:56 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.108 with SMTP id ud12ls390325lac.43.gmail; Thu, 16 Jul 2015 09:31:55 -0700 (PDT) X-Received: by 10.112.142.105 with SMTP id rv9mr2622277lbb.11.1437064315929; Thu, 16 Jul 2015 09:31:55 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id j5si7358556laf.127.2015.07.16.09.31.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2015 09:31:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbbpo10 with SMTP id po10so46822562lbb.3 for ; Thu, 16 Jul 2015 09:31:55 -0700 (PDT) X-Received: by 10.152.5.197 with SMTP id u5mr9318954lau.76.1437064315777; Thu, 16 Jul 2015 09:31:55 -0700 (PDT) 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.108.230 with SMTP id hn6csp365125lbb; Thu, 16 Jul 2015 09:31:54 -0700 (PDT) X-Received: by 10.55.42.4 with SMTP id q4mr6450241qkh.60.1437064313619; Thu, 16 Jul 2015 09:31:53 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k39si10170988qgk.87.2015.07.16.09.31.52; Thu, 16 Jul 2015 09:31:53 -0700 (PDT) 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; Received: by lists.linaro.org (Postfix, from userid 109) id C759961FA1; Thu, 16 Jul 2015 16:31:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal 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 ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 149DA620B7; Thu, 16 Jul 2015 16:27:04 +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 33844620B7; Thu, 16 Jul 2015 16:26:52 +0000 (UTC) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by lists.linaro.org (Postfix) with ESMTPS id E5F0F61DBF for ; Thu, 16 Jul 2015 16:26:13 +0000 (UTC) Received: by widic2 with SMTP id ic2so19713097wid.0 for ; Thu, 16 Jul 2015 09:26:13 -0700 (PDT) X-Received: by 10.194.120.230 with SMTP id lf6mr22017099wjb.41.1437063973145; Thu, 16 Jul 2015 09:26:13 -0700 (PDT) Received: from e106441.cambridge.arm.com ([2001:41d0:a:3cb4::abcd]) by smtp.gmail.com with ESMTPSA id be9sm13889153wjb.26.2015.07.16.09.26.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jul 2015 09:26:12 -0700 (PDT) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Thu, 16 Jul 2015 17:25:46 +0100 Message-Id: <1437063949-24456-7-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1437063949-24456-1-git-send-email-stuart.haslam@linaro.org> References: <1437063949-24456-1-git-send-email-stuart.haslam@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 6/9] validation: refactor cpumask tests X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stuart.haslam@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.217.180 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 Refactor the cpumask tests a bit so that they may be resused to perform the thrmask testing. Signed-off-by: Stuart Haslam --- test/validation/cpumask/cpumask.h | 6 + test/validation/cpumask/mask_common.c | 478 +++++++++++++++++----------------- test/validation/cpumask/mask_common.h | 52 ++-- 3 files changed, 282 insertions(+), 254 deletions(-) diff --git a/test/validation/cpumask/cpumask.h b/test/validation/cpumask/cpumask.h index c0d19a9..d24ea06 100644 --- a/test/validation/cpumask/cpumask.h +++ b/test/validation/cpumask/cpumask.h @@ -4,4 +4,10 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#ifndef _ODP_CPUMASK_TEST_H_ +#define _ODP_CPUMASK_TEST_H_ + +unsigned max_supported_num_in_mask(void); int cpumask_main(void); + +#endif diff --git a/test/validation/cpumask/mask_common.c b/test/validation/cpumask/mask_common.c index e10b2fe..fce7725 100644 --- a/test/validation/cpumask/mask_common.c +++ b/test/validation/cpumask/mask_common.c @@ -5,27 +5,27 @@ */ #include + #include "odp_cunit_common.h" #include "mask_common.h" /* - * The following string are used to build cpu masks with - * odp_cpumask_from_str(). Both 0x prefixed and non prefixed - * hex values are supported by odp_cpumask_from_str() + * The following strings are used to build masks with odp_*mask_from_str(). + * Both 0x prefixed and non prefixed hex values are supported. */ -#define TEST_MASK_NO_CPU "0x0" -#define TEST_MASK_CPU_0 "0x1" -#define TEST_MASK_CPU_1 "0x2" -#define TEST_MASK_CPU_2 "0x4" -#define TEST_MASK_CPU_0_2 "0x5" -#define TEST_MASK_CPU_0_3 "0x9" -#define TEST_MASK_CPU_1_2 "0x6" -#define TEST_MASK_CPU_1_3 "0xA" -#define TEST_MASK_CPU_0_1_2 "0x7" -#define TEST_MASK_CPU_0_2_4_6 "0x55" -#define TEST_MASK_CPU_1_2_4_6 "0x56" - -#define TEST_MASK_CPU_0_NO_PREFIX "1" +#define TEST_MASK_NONE "0x0" +#define TEST_MASK_0 "0x1" +#define TEST_MASK_1 "0x2" +#define TEST_MASK_2 "0x4" +#define TEST_MASK_0_2 "0x5" +#define TEST_MASK_0_3 "0x9" +#define TEST_MASK_1_2 "0x6" +#define TEST_MASK_1_3 "0xA" +#define TEST_MASK_0_1_2 "0x7" +#define TEST_MASK_0_2_4_6 "0x55" +#define TEST_MASK_1_2_4_6 "0x56" + +#define TEST_MASK_0_NO_PREFIX "1" /* padding pattern used to check buffer overflow: */ #define FILLING_PATTERN 0x55 @@ -45,26 +45,26 @@ static unsigned int stringlen(const char *str) } /* - * builds a string containing a 0x prefixed hex number - * where a single bit (corresponding to cpu) is set. + * builds a string containing a 0x prefixed hex number where a single bit + * (corresponding to a cpu or thread) is set. * The string is null terminated. - * cpu_to_str(0) returns "0x1". - * cpu_to_str(10) returns "0x400". - * The buffer should be at least ceil(cpu/4)+3 bytes long, - * to accommodate with 4 cpus per nibble + "0x" prefix + null. + * bit_set_str(0) returns "0x1". + * bit_set_str(10) returns "0x400". + * The buffer should be at least ceil(offs/4)+3 bytes long, + * to accommodate with 4 bits per nibble + "0x" prefix + null. */ -#define CPUS_PER_NIBBLE 4 -static void cpu_to_str(char *buff, int cpu) +#define BITS_PER_NIBBLE 4 +static void bit_set_str(char *buff, int offs) { const char *hex_nibble = "1248"; int i = 0; buff[i++] = '0'; buff[i++] = 'x'; - buff[i++] = hex_nibble[cpu % CPUS_PER_NIBBLE]; - while (cpu > 3) { + buff[i++] = hex_nibble[offs % BITS_PER_NIBBLE]; + while (offs > 3) { buff[i++] = '0'; - cpu -= CPUS_PER_NIBBLE; + offs -= BITS_PER_NIBBLE; } buff[i++] = 0; /* null */ } @@ -74,16 +74,16 @@ static void cpu_to_str(char *buff, int cpu) */ unsigned mask_capacity(void) { - odp_cpumask_t mask; + _odp_mask_t mask; - odp_cpumask_setall(&mask); + _odp_mask_setall(&mask); - return odp_cpumask_count(&mask); + return _odp_mask_count(&mask); } -void cpumask_test_odp_cpumask_to_from_str(void) +MASK_TESTFUNC(to_from_str) { - odp_cpumask_t mask; + _odp_mask_t mask; int32_t str_sz; unsigned int buf_sz; /* buf size for the 2 following bufs */ char *buf_in; @@ -108,14 +108,14 @@ void cpumask_test_odp_cpumask_to_from_str(void) buf_out[i] = FILLING_PATTERN; /* generate a hex string with that cpu set: */ - cpu_to_str(buf_in, cpu); + bit_set_str(buf_in, cpu); /* generate mask: */ - odp_cpumask_from_str(&mask, buf_in); + _odp_mask_from_str(&mask, buf_in); /* reverse cpu mask computation to get string back: */ - str_sz = odp_cpumask_to_str(&mask, buf_out, - stringlen(buf_in) + 1); + str_sz = _odp_mask_to_str(&mask, buf_out, + stringlen(buf_in) + 1); /* check that returned size matches original (with NULL): */ CU_ASSERT(str_sz == (int32_t)stringlen(buf_in) + 1); @@ -132,8 +132,8 @@ void cpumask_test_odp_cpumask_to_from_str(void) buf_out[i] = FILLING_PATTERN; /* check for buffer overflow when too small buffer given: */ - odp_cpumask_from_str(&mask, TEST_MASK_CPU_0); - str_sz = odp_cpumask_to_str(&mask, buf_out, stringlen(TEST_MASK_CPU_0)); + _odp_mask_from_str(&mask, TEST_MASK_0); + str_sz = _odp_mask_to_str(&mask, buf_out, stringlen(TEST_MASK_0)); CU_ASSERT(str_sz == -1); @@ -141,332 +141,332 @@ void cpumask_test_odp_cpumask_to_from_str(void) CU_ASSERT(buf_out[i] == FILLING_PATTERN); /* check for handling of missing "0x" prefix: */ - odp_cpumask_from_str(&mask, TEST_MASK_CPU_0_NO_PREFIX); + _odp_mask_from_str(&mask, TEST_MASK_0_NO_PREFIX); - str_sz = odp_cpumask_to_str(&mask, buf_out, - stringlen(TEST_MASK_CPU_0) + 1); + str_sz = _odp_mask_to_str(&mask, buf_out, + stringlen(TEST_MASK_0) + 1); - CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_CPU_0, - stringlen(TEST_MASK_CPU_0) + 1); + CU_ASSERT_NSTRING_EQUAL(buf_out, TEST_MASK_0, + stringlen(TEST_MASK_0) + 1); free(buf_out); free(buf_in); } -void cpumask_test_odp_cpumask_equal(void) +MASK_TESTFUNC(equal) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask3, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3)); + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask3, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + CU_ASSERT_FALSE(_odp_mask_equal(&mask1, &mask3)); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3)); + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_0_2); + _odp_mask_from_str(&mask3, TEST_MASK_1_2); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + CU_ASSERT_FALSE(_odp_mask_equal(&mask1, &mask3)); if (mask_capacity() < 8) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2_4_6); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_2_4_6); - odp_cpumask_from_str(&mask3, TEST_MASK_CPU_1_2_4_6); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); - CU_ASSERT_FALSE(odp_cpumask_equal(&mask1, &mask3)); + _odp_mask_from_str(&mask1, TEST_MASK_0_2_4_6); + _odp_mask_from_str(&mask2, TEST_MASK_0_2_4_6); + _odp_mask_from_str(&mask3, TEST_MASK_1_2_4_6); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); + CU_ASSERT_FALSE(_odp_mask_equal(&mask1, &mask3)); } -void cpumask_test_odp_cpumask_zero(void) +MASK_TESTFUNC(zero) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; + _odp_mask_t mask1; + _odp_mask_t mask2; - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_zero(&mask2); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_zero(&mask2); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); } -void cpumask_test_odp_cpumask_set(void) +MASK_TESTFUNC(set) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; + _odp_mask_t mask1; + _odp_mask_t mask2; - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_set(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_set(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0_3); - odp_cpumask_set(&mask1, 3); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_from_str(&mask2, TEST_MASK_0_3); + _odp_mask_set(&mask1, 3); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); /* make sure that re-asserting a cpu has no impact: */ - odp_cpumask_set(&mask1, 3); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_set(&mask1, 3); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); } -void cpumask_test_odp_cpumask_clr(void) +MASK_TESTFUNC(clr) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; + _odp_mask_t mask1; + _odp_mask_t mask2; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_clr(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_clr(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_clr(&mask1, 2); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_clr(&mask1, 2); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_clr(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_clr(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); /* make sure that re-clearing a cpu has no impact: */ - odp_cpumask_clr(&mask1, 0); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_clr(&mask1, 0); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); } -void cpumask_test_odp_cpumask_isset(void) +MASK_TESTFUNC(isset) { - odp_cpumask_t mask1; + _odp_mask_t mask1; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_isset(&mask1, 0)); + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_isset(&mask1, 0)); - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 0)); + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT_FALSE(_odp_mask_isset(&mask1, 0)); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - CU_ASSERT(odp_cpumask_isset(&mask1, 0)); - CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 1)); - CU_ASSERT(odp_cpumask_isset(&mask1, 2)); - CU_ASSERT_FALSE(odp_cpumask_isset(&mask1, 3)); + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + CU_ASSERT(_odp_mask_isset(&mask1, 0)); + CU_ASSERT_FALSE(_odp_mask_isset(&mask1, 1)); + CU_ASSERT(_odp_mask_isset(&mask1, 2)); + CU_ASSERT_FALSE(_odp_mask_isset(&mask1, 3)); } -void cpumask_test_odp_cpumask_count(void) +MASK_TESTFUNC(count) { - odp_cpumask_t mask1; + _odp_mask_t mask1; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_count(&mask1) == 1); + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_count(&mask1) == 1); - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_count(&mask1) == 0); + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_count(&mask1) == 0); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - CU_ASSERT(odp_cpumask_count(&mask1) == 2); + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + CU_ASSERT(_odp_mask_count(&mask1) == 2); } -void cpumask_test_odp_cpumask_and(void) +MASK_TESTFUNC(and) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; - odp_cpumask_t mask4; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; + _odp_mask_t mask4; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_2); - odp_cpumask_and(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_1_2); + _odp_mask_from_str(&mask4, TEST_MASK_2); + _odp_mask_and(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); } -void cpumask_test_odp_cpumask_or(void) +MASK_TESTFUNC(or) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; - odp_cpumask_t mask4; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; + _odp_mask_t mask4; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0_1_2); - odp_cpumask_or(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); + _odp_mask_from_str(&mask1, TEST_MASK_0_2); + _odp_mask_from_str(&mask2, TEST_MASK_1); + _odp_mask_from_str(&mask4, TEST_MASK_0_1_2); + _odp_mask_or(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); } -void cpumask_test_odp_cpumask_xor(void) +MASK_TESTFUNC(xor) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; - odp_cpumask_t mask3; - odp_cpumask_t mask4; - - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_0); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_0); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); - - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask2, TEST_MASK_NO_CPU); - odp_cpumask_from_str(&mask4, TEST_MASK_NO_CPU); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); + _odp_mask_t mask1; + _odp_mask_t mask2; + _odp_mask_t mask3; + _odp_mask_t mask4; + + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_0); + _odp_mask_from_str(&mask4, TEST_MASK_0); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); + + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + _odp_mask_from_str(&mask2, TEST_MASK_NONE); + _odp_mask_from_str(&mask4, TEST_MASK_NONE); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_2); - odp_cpumask_from_str(&mask2, TEST_MASK_CPU_1_2); - odp_cpumask_from_str(&mask4, TEST_MASK_CPU_1); - odp_cpumask_xor(&mask3, &mask1, &mask2); - CU_ASSERT(odp_cpumask_equal(&mask3, &mask4)); + _odp_mask_from_str(&mask1, TEST_MASK_2); + _odp_mask_from_str(&mask2, TEST_MASK_1_2); + _odp_mask_from_str(&mask4, TEST_MASK_1); + _odp_mask_xor(&mask3, &mask1, &mask2); + CU_ASSERT(_odp_mask_equal(&mask3, &mask4)); } -void cpumask_test_odp_cpumask_copy(void) +MASK_TESTFUNC(copy) { - odp_cpumask_t mask1; - odp_cpumask_t mask2; + _odp_mask_t mask1; + _odp_mask_t mask2; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - odp_cpumask_copy(&mask2, &mask1); - CU_ASSERT(odp_cpumask_equal(&mask1, &mask2)); + _odp_mask_from_str(&mask1, TEST_MASK_0); + _odp_mask_copy(&mask2, &mask1); + CU_ASSERT(_odp_mask_equal(&mask1, &mask2)); } -void cpumask_test_odp_cpumask_first(void) +MASK_TESTFUNC(first) { - odp_cpumask_t mask1; + _odp_mask_t mask1; /* check when there is no first */ - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_first(&mask1) == -1); + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_first(&mask1) == -1); /* single CPU case: */ - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_first(&mask1) == 0); + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_first(&mask1) == 0); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3); - CU_ASSERT(odp_cpumask_first(&mask1) == 1); + _odp_mask_from_str(&mask1, TEST_MASK_1_3); + CU_ASSERT(_odp_mask_first(&mask1) == 1); } -void cpumask_test_odp_cpumask_last(void) +MASK_TESTFUNC(last) { - odp_cpumask_t mask1; + _odp_mask_t mask1; /* check when there is no last: */ - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_last(&mask1) == -1); + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_last(&mask1) == -1); /* single CPU case: */ - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_last(&mask1) == 0); + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_last(&mask1) == 0); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3); - CU_ASSERT(odp_cpumask_last(&mask1) == 3); + _odp_mask_from_str(&mask1, TEST_MASK_1_3); + CU_ASSERT(_odp_mask_last(&mask1) == 3); } -void cpumask_test_odp_cpumask_next(void) +MASK_TESTFUNC(next) { unsigned int i; int expected[] = {1, 3, 3, -1}; - odp_cpumask_t mask1; + _odp_mask_t mask1; /* case when the mask does not contain any CPU: */ - odp_cpumask_from_str(&mask1, TEST_MASK_NO_CPU); - CU_ASSERT(odp_cpumask_next(&mask1, -1) == -1); + _odp_mask_from_str(&mask1, TEST_MASK_NONE); + CU_ASSERT(_odp_mask_next(&mask1, -1) == -1); /* case when the mask just contain CPU 0: */ - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_0); - CU_ASSERT(odp_cpumask_next(&mask1, -1) == 0); - CU_ASSERT(odp_cpumask_next(&mask1, 0) == -1); + _odp_mask_from_str(&mask1, TEST_MASK_0); + CU_ASSERT(_odp_mask_next(&mask1, -1) == 0); + CU_ASSERT(_odp_mask_next(&mask1, 0) == -1); if (mask_capacity() < 4) return; - odp_cpumask_from_str(&mask1, TEST_MASK_CPU_1_3); + _odp_mask_from_str(&mask1, TEST_MASK_1_3); for (i = 0; i < sizeof(expected) / sizeof(int); i++) - CU_ASSERT(odp_cpumask_next(&mask1, i) == expected[i]); + CU_ASSERT(_odp_mask_next(&mask1, i) == expected[i]); } -void cpumask_test_odp_cpumask_setall(void) +MASK_TESTFUNC(setall) { - int num_cpus; - int max_cpus = mask_capacity(); - odp_cpumask_t mask; + int num; + int max = mask_capacity(); + _odp_mask_t mask; - odp_cpumask_setall(&mask); - num_cpus = odp_cpumask_count(&mask); + _odp_mask_setall(&mask); + num = _odp_mask_count(&mask); - CU_ASSERT(num_cpus > 0); - CU_ASSERT(num_cpus >= max_cpus); + CU_ASSERT(num > 0); + CU_ASSERT(num <= max); } diff --git a/test/validation/cpumask/mask_common.h b/test/validation/cpumask/mask_common.h index 17cae45..8e9602a 100644 --- a/test/validation/cpumask/mask_common.h +++ b/test/validation/cpumask/mask_common.h @@ -7,22 +7,44 @@ #ifndef ODP_MASK_COMMON_H_ #define ODP_MASK_COMMON_H_ +#include "cpumask.h" +typedef odp_cpumask_t _odp_mask_t; +#define MASK_API_PREFIX(n) odp_cpumask_##n +#define MASK_TESTFUNC(n) void cpumask_test_odp_cpumask_ ## n(void) + +#define _odp_mask_from_str MASK_API_PREFIX(from_str) +#define _odp_mask_to_str MASK_API_PREFIX(to_str) +#define _odp_mask_equal MASK_API_PREFIX(equal) +#define _odp_mask_zero MASK_API_PREFIX(zero) +#define _odp_mask_set MASK_API_PREFIX(set) +#define _odp_mask_clr MASK_API_PREFIX(clr) +#define _odp_mask_isset MASK_API_PREFIX(isset) +#define _odp_mask_count MASK_API_PREFIX(count) +#define _odp_mask_and MASK_API_PREFIX(and) +#define _odp_mask_or MASK_API_PREFIX(or) +#define _odp_mask_xor MASK_API_PREFIX(xor) +#define _odp_mask_copy MASK_API_PREFIX(copy) +#define _odp_mask_first MASK_API_PREFIX(first) +#define _odp_mask_next MASK_API_PREFIX(next) +#define _odp_mask_last MASK_API_PREFIX(last) +#define _odp_mask_setall MASK_API_PREFIX(setall) + unsigned mask_capacity(void); -void cpumask_test_odp_cpumask_to_from_str(void); -void cpumask_test_odp_cpumask_equal(void); -void cpumask_test_odp_cpumask_zero(void); -void cpumask_test_odp_cpumask_set(void); -void cpumask_test_odp_cpumask_clr(void); -void cpumask_test_odp_cpumask_isset(void); -void cpumask_test_odp_cpumask_count(void); -void cpumask_test_odp_cpumask_and(void); -void cpumask_test_odp_cpumask_or(void); -void cpumask_test_odp_cpumask_xor(void); -void cpumask_test_odp_cpumask_copy(void); -void cpumask_test_odp_cpumask_first(void); -void cpumask_test_odp_cpumask_last(void); -void cpumask_test_odp_cpumask_next(void); -void cpumask_test_odp_cpumask_setall(void); +MASK_TESTFUNC(to_from_str); +MASK_TESTFUNC(equal); +MASK_TESTFUNC(zero); +MASK_TESTFUNC(set); +MASK_TESTFUNC(clr); +MASK_TESTFUNC(isset); +MASK_TESTFUNC(count); +MASK_TESTFUNC(and); +MASK_TESTFUNC(or); +MASK_TESTFUNC(xor); +MASK_TESTFUNC(copy); +MASK_TESTFUNC(first); +MASK_TESTFUNC(last); +MASK_TESTFUNC(next); +MASK_TESTFUNC(setall); #endif