From patchwork Mon Jan 28 22:09:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 216384 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 BEC3B2C0095 for ; Tue, 29 Jan 2013 09:09:44 +1100 (EST) Received: from localhost ([::1]:34603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzwta-0004RR-PC for incoming@patchwork.ozlabs.org; Mon, 28 Jan 2013 17:09:42 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzwtC-00046B-Fd for qemu-devel@nongnu.org; Mon, 28 Jan 2013 17:09:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tzwt9-0001YC-1V for qemu-devel@nongnu.org; Mon, 28 Jan 2013 17:09:18 -0500 Received: from mail-qc0-f179.google.com ([209.85.216.179]:51523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tzwt8-0001Y6-S7 for qemu-devel@nongnu.org; Mon, 28 Jan 2013 17:09:14 -0500 Received: by mail-qc0-f179.google.com with SMTP id b40so1560406qcq.10 for ; Mon, 28 Jan 2013 14:09:14 -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=NzLRS725Dg//OzgiP8X3fLdoQIFD4XOtVu2idJXzYjk=; b=S3FkMOIxaXV7B6OkWfnXyYf8MNqu37SjFOmtAgym92/ejSwonQYKsBFZQMQJPDx5jD LxzYmJRGWm+HPEqJWqDBWGYjsnKhARUj1v22dYsZ/86MXncRnn1bKGA1ivbwedmTPuJ0 EpBWw+m2JXiU3Wz4qsXLZ1k3FuLUU2CZ7UwABlNDwk1v/4in7B90wQbSQSFVxXtE2oMQ kkHK+HXMvjtwaa/VeljuXygxbAJvJts6c0IhB20Fv03Dz1IOLKGUQy7kaiNk+6Lpd5p7 ua8zvacqcV9xghmOIy4d+KthDZIIH53P6sKnMAyRLJOzch0YauB247e+tWeZjGz/TYUN Furw== X-Received: by 10.49.71.204 with SMTP id x12mr20146640qeu.47.1359410954493; Mon, 28 Jan 2013 14:09:14 -0800 (PST) Received: from anchor.twiddle.home.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id v10sm6679792qaa.15.2013.01.28.14.09.12 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 28 Jan 2013 14:09:13 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2013 14:09:03 -0800 Message-Id: <1359410943-20057-4-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1359410943-20057-1-git-send-email-rth@twiddle.net> References: <1359410943-20057-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.216.179 Cc: Blue Swirl , afaerber@suse.de 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 | 7 +++++- tests/test-mul64.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/test-mul64.c diff --git a/tests/Makefile b/tests/Makefile index 442b286..e695ef6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -45,6 +45,8 @@ gcov-files-test-aio-$(CONFIG_WIN32) = aio-win32.c gcov-files-test-aio-$(CONFIG_POSIX) = aio-posix.c check-unit-y += tests/test-thread-pool$(EXESUF) gcov-files-test-thread-pool-y = thread-pool.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 @@ -72,7 +74,8 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/test-coroutine.o tests/test-string-output-visitor.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-qmp-commands.o tests/test-visitor-serialization.o \ + tests/test-mul64.o test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o @@ -108,6 +111,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..6abf57c --- /dev/null +++ b/tests/test-mul64.c @@ -0,0 +1,69 @@ +/* + * 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 }, + { -1ull, 2, 1, -2ull }, + { -1ull, -1ull, -2ull, 1 }, + { 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 }, + { 0x1122334455667788ll, 0x1122334455667788ull, + 0x01258F60BBC2975Cll, 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_u_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(); +}