From patchwork Sat Feb 16 20:47:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 221034 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DDA9A2C007C for ; Sun, 17 Feb 2013 08:04:40 +1100 (EST) Received: from localhost ([::1]:52155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6ofx-00084C-Py for incoming@patchwork.ozlabs.org; Sat, 16 Feb 2013 15:48:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6ofE-000670-FO for qemu-devel@nongnu.org; Sat, 16 Feb 2013 15:47:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6ofA-00084K-89 for qemu-devel@nongnu.org; Sat, 16 Feb 2013 15:47:16 -0500 Received: from mail-da0-f50.google.com ([209.85.210.50]:48378) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6ofA-000840-1Y for qemu-devel@nongnu.org; Sat, 16 Feb 2013 15:47:12 -0500 Received: by mail-da0-f50.google.com with SMTP id h15so1899612dan.23 for ; Sat, 16 Feb 2013 12:47:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=bfwvMNWYGjctcajK8whPMyFKk8qCUMZ+uFyzToDeMRM=; b=QHghA8Pgu2Y42Efr4WTZNJd4aLo+259BFQvyW27raqdk0oe76y3HOz25Boq4G/BBSA 5wpUc3oUJZbQlpaUrdGkBQjloGRTA+kuE6sxh4ooaSznVPBVrWJzfPYPNSQ0uAJiAzCh 4cusHyyvB9XZRNP/6altB3L/xllTpi0sCLlPLph3SD0Y29YYzV4ZJRBsJdbgILdeQgG3 8mNvd+BYHqzFPOW1X51+U4xwgK3VRyMLKOjeEzrSttiyEuv+LZwNHpfO1X/tVeD0Ip44 +tpFIQ/Qd6aghzeE7k8R3Sf8cwhBRWfe1jEbvS8XWRY8xKfYlNCHw4Vr616oBCs3xysT 8/qQ== X-Received: by 10.68.189.103 with SMTP id gh7mr17254605pbc.92.1361047631103; Sat, 16 Feb 2013 12:47:11 -0800 (PST) Received: from anchor.twiddle.net (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id kc15sm8961940pbb.5.2013.02.16.12.47.09 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 16 Feb 2013 12:47:10 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 16 Feb 2013 12:47:01 -0800 Message-Id: <1361047621-27480-4-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361047621-27480-1-git-send-email-rth@twiddle.net> References: <1361047621-27480-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.50 Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH 3/3] tests: Add unit tests for mulu64 and muls64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Richard Henderson --- tests/Makefile | 6 ++++- tests/test-mul64.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/test-mul64.c diff --git a/tests/Makefile b/tests/Makefile index a2d62b8..567e36e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -54,6 +54,8 @@ check-unit-y += tests/test-xbzrle$(EXESUF) gcov-files-test-xbzrle-y = xbzrle.c 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-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh @@ -82,7 +84,7 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/test-string-input-visitor.o tests/test-qmp-output-visitor.o \ tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \ tests/test-qmp-commands.o tests/test-visitor-serialization.o \ - tests/test-x86-cpuid.o + tests/test-x86-cpuid.o tests/test-mul64.o test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o @@ -124,6 +126,8 @@ tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi- tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) qapi-types.o qapi-visit.o libqemuutil.a libqemustub.a 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/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/fdc-test$(EXESUF): tests/fdc-test.o diff --git a/tests/test-mul64.c b/tests/test-mul64.c new file mode 100644 index 0000000..a0a17f7 --- /dev/null +++ b/tests/test-mul64.c @@ -0,0 +1,70 @@ +/* + * Test 64x64 -> 128 multiply subroutines + * + * 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/host-utils.h" +#include "qemu/osdep.h" + + +typedef struct { + uint64_t a, b; + uint64_t rh, rl; +} Test; + +static const Test test_u_data[] = { + { 1, 1, 0, 1 }, + { 10000, 10000, 0, 100000000 }, + { 0xffffffffffffffffULL, 2, 1, 0xfffffffffffffffeULL }, + { 0xffffffffffffffffULL, 0xffffffffffffffffULL, + 0xfffffffffffffffeULL, 0x0000000000000001ULL }, + { 0x1122334455667788ull, 0x8877665544332211ull, + 0x092228fb777ae38full, 0x0a3e963337c60008ull }, +}; + +static const Test test_s_data[] = { + { 1, 1, 0, 1 }, + { 1, -1, -1, -1 }, + { -10, -10, 0, 100 }, + { 10000, 10000, 0, 100000000 }, + { -1, 2, -1, -2 }, + { 0x1122334455667788ULL, 0x1122334455667788ULL, + 0x01258f60bbc2975cULL, 0x1eace4a3c82fb840ULL }, +}; + +static void test_u(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_u_data); ++i) { + uint64_t rl, rh; + mulu64(&rl, &rh, test_u_data[i].a, test_u_data[i].b); + g_assert_cmpuint(rl, ==, test_u_data[i].rl); + g_assert_cmpuint(rh, ==, test_u_data[i].rh); + } +} + +static void test_s(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(test_s_data); ++i) { + uint64_t rl, rh; + muls64(&rl, &rh, test_s_data[i].a, test_s_data[i].b); + g_assert_cmpuint(rl, ==, test_s_data[i].rl); + g_assert_cmpint(rh, ==, test_s_data[i].rh); + } +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/host-utils/mulu64", test_u); + g_test_add_func("/host-utils/muls64", test_s); + return g_test_run(); +}