From patchwork Wed May 9 03:46:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 10388071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D20360153 for ; Wed, 9 May 2018 03:55:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 597AC28F4E for ; Wed, 9 May 2018 03:55:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C92028F70; Wed, 9 May 2018 03:55:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D245E28F4E for ; Wed, 9 May 2018 03:55:15 +0000 (UTC) Received: from localhost ([::1]:54304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGGCB-0002p7-0Z for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 May 2018 23:55:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGG4e-0004Ws-Vb for qemu-devel@nongnu.org; Tue, 08 May 2018 23:47:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGG4b-0002o6-U1 for qemu-devel@nongnu.org; Tue, 08 May 2018 23:47:29 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:36921) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGG4b-0002nA-OI for qemu-devel@nongnu.org; Tue, 08 May 2018 23:47:25 -0400 Received: by mail-qt0-x242.google.com with SMTP id q13-v6so43174505qtp.4 for ; Tue, 08 May 2018 20:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ptblSVSLZSN149j2r/rN1eYutb0i07T08aMWR08Lue0=; b=TFSLrte1g/77MFEUjqoy3crKlSKIO1MGz03ab3GzdEakh52QheKAzYQCLubrrblLza 6/EupBuGAvG3pCOxpkcVSHBIcd3e6qYFJu+Jx8zbb5EQEwKyQ5dKy8ZeVd1L9omVZl1w GWVU2wvyarQkqQ/3TwDoPoYH8sDSIm2Ie35CSR4LQyedERBofVIBZDExlDu3dtyydO3u fy4l9BQ5bd2xiFcPx8Ya8/sueUqhL7gqM4s+NfjZrAWOhIDOonPTH0gqBP2SoZJ5NOHp nyeixseaIT2GJy0tDqE97rOUIkOdQnowML44YZ3Ex2t2tmfMUQf5EY93TksVpQPN0hkr 6JDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ptblSVSLZSN149j2r/rN1eYutb0i07T08aMWR08Lue0=; b=lOm9bvo76tZo8zsuAn5KSOUJDJhNn3T4CSnXrIxpAxuy+gMzaxE+aqUeWiUjWNQGAW 9AouUWBZxD8Jz91Vhf9YpPMNkNbUrfBlpGjMNfyhHkWhM/gDD1DoNG3aOex460bVu9iN 8z90ydEUo6NvhpfoZB2nxhPCsX51g/ZdaKf8aHsIalK9vf+CuispEgicILdGksTIcuMg vR4hrDVlXfP9W15JPBFIY3k56y7g9nPJtfqSaSvLdLJQ6ERdHNCjWnjAPknrQEofQFS9 fy5yeQ1OJa4q1aQUUYq79jxo8NUfbm7diVe+hO3K17OSOxpmoNjgLvEY88zmuNtR3/0t mSEA== X-Gm-Message-State: ALQs6tBdXsXrU32Poe4/MdsMn8dKr0AeGSTg4Ucn/leGEnKCgzgVYeC/ Am6a4HO8WzP0ihol06hFebI= X-Google-Smtp-Source: AB8JxZqugoFWc6Ksm9cCsIYuwyBs69/b8l58Q58gSbzaY0lZoKC9wJxXP8u3D3MtZO5TU8zyvtyevA== X-Received: by 2002:ac8:35b0:: with SMTP id k45-v6mr37742534qtb.81.1525837645084; Tue, 08 May 2018 20:47:25 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id w12-v6sm14497002qtb.80.2018.05.08.20.47.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 20:47:24 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E . Iglesias" Date: Wed, 9 May 2018 00:46:50 -0300 Message-Id: <20180509034658.26455-7-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509034658.26455-1-f4bug@amsat.org> References: <20180509034658.26455-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PATCH v2 06/14] sdcard: Add test_sd_verify_cksum_frame136() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Alistair Francis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Per the Physical Layer Simplified Spec. "3.6 Bus Protocol": There are two types of Data packet format for the SD card. (1) Usual data (8-bit width): The usual data (8-bit width) are sent in LSB (Least Significant Byte) first, MSB (Most Significant Byte) last sequence. But in the individual byte, it is MSB (Most Significant Bit) first, LSB (Least Significant Bit) last. (2) Wide width data (SD Memory Register): The wide width data is shifted from the MSB bit. Since the SD frames use different byte order, we use the lm32 target for big-endian qtesting, and aarch64 for the little-endian qtesting. Signed-off-by: Philippe Mathieu-Daudé --- tests/sdcard-test.c | 35 +++++++++++++++++++++++++++++++++++ tests/Makefile.include | 4 ++++ 2 files changed, 39 insertions(+) create mode 100644 tests/sdcard-test.c diff --git a/tests/sdcard-test.c b/tests/sdcard-test.c new file mode 100644 index 0000000000..c59af28382 --- /dev/null +++ b/tests/sdcard-test.c @@ -0,0 +1,35 @@ +/* + * QTest testcase for SD protocol and cards + * + * Examples taken from: + * + * - Physical Layer Simplified Specification (chap. 4.5: Cyclic Redundancy Code) + * - http://wiki.seabright.co.nz/wiki/SdCardProtocol.html + * + * Tests written by Philippe Mathieu-Daudé + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "libqtest.h" +#include "hw/sd/sd.h" + +static void test_sd_response_frame136_crc7(void) +{ + uint8_t buf[16]; + + /* response to CMD2 ALL_SEND_CID */ + memcpy(&buf, "\x1d\x41\x44\x53\x44\x20\x20\x20\x10\xa0\x40\x0b\xc1\x00\x88", + sizeof(buf)); + buf[15] = sd_frame136_calc_checksum(buf); + g_assert_cmphex(buf[15], ==, 0xad); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + qtest_add_func("sd/prepare_resp136_crc7", test_sd_response_frame136_crc7); + + return g_test_run(); +} diff --git a/tests/Makefile.include b/tests/Makefile.include index 3b9a5e31a2..34230b150e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -384,6 +384,9 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF) check-qtest-aarch64-y = tests/numa-test$(EXESUF) check-qtest-aarch64-y += tests/sdhci-test$(EXESUF) check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF) +check-qtest-aarch64-y += tests/sdcard-test$(EXESUF) + +check-qtest-lm32-y += tests/sdcard-test$(EXESUF) check-qtest-microblazeel-y = $(check-qtest-microblaze-y) @@ -835,6 +838,7 @@ tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) tests/numa-test$(EXESUF): tests/numa-test.o tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o tests/boot-sector.o tests/acpi-utils.o tests/sdhci-test$(EXESUF): tests/sdhci-test.o $(libqos-pc-obj-y) +tests/sdcard-test$(EXESUF): tests/sdcard-test.o hw/sd/sdmmc-internal.o tests/migration/stress$(EXESUF): tests/migration/stress.o $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@")