From patchwork Fri Jun 28 11:40:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18179 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 811FA25E2D for ; Fri, 28 Jun 2013 11:40:38 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id hf12sf1355072vcb.5 for ; Fri, 28 Jun 2013 04:40:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=J+VB14B/EfT0bIu+AAbGqdFS4+yQCGjN9ogm6Js/gv4=; b=DXrmioEU/m7qSrYx003l1h1OqWuRYc3H0K7+vY+u45MjvUOg75haW3gT+TdUOddhZ0 WQyEYg2fhMs+m+CQd3hmfKDIvbeG5BeW4fcgvLq/eYYv4+aKgCKeSrMjA/IeTPx3Xxql xHWlH+3xk6R4v4z7VQ95PforUqkcjXbbZ4KV0ILG2OTDvsOXzxBQKX/SXaYRZApvRf/9 pD/2YBqSJmGeM2aeBFogekWcn61fKE5p+OxpzOePZBAfPQUhXq1AVucjFYNv8VTCg0m4 bATMKuHvnlJxRZFeY13KPJGcDgvqZg2GxMhd+TzHZcLCPbq1o8w4pDD8FK8gr5VbSuNG MVRg== X-Received: by 10.236.112.33 with SMTP id x21mr7175814yhg.57.1372419637884; Fri, 28 Jun 2013 04:40:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.14.169 with SMTP id q9ls1194045qec.88.gmail; Fri, 28 Jun 2013 04:40:37 -0700 (PDT) X-Received: by 10.58.49.130 with SMTP id u2mr5524791ven.7.1372419637785; Fri, 28 Jun 2013 04:40:37 -0700 (PDT) Received: from mail-vb0-f42.google.com (mail-vb0-f42.google.com [209.85.212.42]) by mx.google.com with ESMTPS id z2si1901824vcx.38.2013.06.28.04.40.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Jun 2013 04:40:37 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.42; Received: by mail-vb0-f42.google.com with SMTP id i3so1624201vbh.15 for ; Fri, 28 Jun 2013 04:40:37 -0700 (PDT) X-Received: by 10.58.215.200 with SMTP id ok8mr5448131vec.21.1372419637664; Fri, 28 Jun 2013 04:40:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp186086veb; Fri, 28 Jun 2013 04:40:37 -0700 (PDT) X-Received: by 10.194.91.194 with SMTP id cg2mr9783407wjb.53.1372419636530; Fri, 28 Jun 2013 04:40:36 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id en3si6488564wib.22.2013.06.28.04.40.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Jun 2013 04:40:36 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1UsX2W-0001Rd-Ck; Fri, 28 Jun 2013 12:40:32 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson , Markus Armbruster Subject: [PATCH 2/2] tests: Add test-bitops.c with some sextract tests Date: Fri, 28 Jun 2013 12:40:32 +0100 Message-Id: <1372419632-5521-3-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1372419632-5521-1-git-send-email-peter.maydell@linaro.org> References: <1372419632-5521-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQnOJvWOPRt33GeOO93S1NY7zjwqmw6UsV7HsWaw92HtI3M726aXBAKO9tU8GColZX6VZMxY X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add some simple test cases for the new sextract32 and sextract64 functions. Signed-off-by: Peter Maydell --- tests/Makefile | 2 ++ tests/test-bitops.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/test-bitops.c diff --git a/tests/Makefile b/tests/Makefile index c107489..73a3c81 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -44,6 +44,7 @@ check-unit-y += tests/test-cutils$(EXESUF) gcov-files-test-cutils-y += util/cutils.c check-unit-y += tests/test-mul64$(EXESUF) gcov-files-test-mul64-y = util/host-utils.c +check-unit-y += tests/test-bitops$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh @@ -118,6 +119,7 @@ tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marsh tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a +tests/test-bitops$(EXESUF): tests/test-bitops.o libqemuutil.a libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o libqos-obj-y += tests/libqos/i2c.o diff --git a/tests/test-bitops.c b/tests/test-bitops.c new file mode 100644 index 0000000..4e713e4 --- /dev/null +++ b/tests/test-bitops.c @@ -0,0 +1,75 @@ +/* + * Test bitops routines + * + * This work is licensed under the terms of the GNU LGPL, version 2 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#include +#include +#include "qemu/bitops.h" + +typedef struct { + uint32_t value; + int start; + int length; + int32_t result; +} S32Test; + +typedef struct { + uint64_t value; + int start; + int length; + int64_t result; +} S64Test; + +static const S32Test test_s32_data[] = { + { 0x38463983, 4, 4, -8 }, + { 0x38463983, 12, 8, 0x63 }, + { 0x38463983, 0, 32, 0x38463983 }, +}; + +static const S64Test test_s64_data[] = { + { 0x8459826734967223, 60, 4, -8 }, + { 0x8459826734967223, 0, 64, 0x8459826734967223 }, +}; + +static void test_sextract32(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_s32_data); i++) { + const S32Test *test = &test_s32_data[i]; + int32_t r = sextract32(test->value, test->start, test->length); + + g_assert_cmpint(r, ==, test->result); + } +} + +static void test_sextract64(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_s32_data); i++) { + const S32Test *test = &test_s32_data[i]; + int64_t r = sextract64(test->value, test->start, test->length); + + g_assert_cmpint(r, ==, test->result); + } + + for (i = 0; i < ARRAY_SIZE(test_s64_data); i++) { + const S64Test *test = &test_s64_data[i]; + int64_t r = sextract64(test->value, test->start, test->length); + + g_assert_cmpint(r, ==, test->result); + } +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/bitops/sextract32", test_sextract32); + g_test_add_func("/bitops/sextract64", test_sextract64); + return g_test_run(); +}