From patchwork Thu Jan 12 16:27:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Maier X-Patchwork-Id: 1725261 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=collins.com header.i=@collins.com header.a=rsa-sha256 header.s=POD051818 header.b=V1tTfgud; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Nt92n05xqz23fd for ; Fri, 13 Jan 2023 03:28:17 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5101A85351; Thu, 12 Jan 2023 17:28:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=collins.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=collins.com header.i=@collins.com header.b="V1tTfgud"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4A7F9852B6; Thu, 12 Jan 2023 17:28:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mx0a-00105401.pphosted.com (mx0a-00105401.pphosted.com [67.231.144.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 99C7985423 for ; Thu, 12 Jan 2023 17:28:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=collins.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=63763cfc40=brandon.maier@collins.com Received: from pps.filterd (m0072139.ppops.net [127.0.0.1]) by mx0a-00105401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 30CGNQa0005276; Thu, 12 Jan 2023 16:27:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=collins.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=POD051818; bh=I4G4ZNFlomLooav6v55JLDwnTmWm4uL+7LrDhliAUys=; b=V1tTfgudsuVxCv7aBmQTQF6DwWCJtu00ptmJpbxHrkMYFzjtjKED38p3+B8UC5pCstsV lpf+tOCJhTAb71ZwEVNcG6O3M0wLfM/f5+dwp3vkaLMB2DWnA6j+L9eob3XFTEsoDwO/ e6dJTTQ6YVoNC9qFNJrRYtrGa+AKWyYBHtQ15qBfQS4jYMiTwODK77s1Yt2jr0sYKKCZ CRaqDzOJCF6B98gzyZDE7SJMgZLVXgnl1NV0qjMXavIhMx+JlQ7I6KfHPs4/CWmjy0ag v1m3girQm8Gj38PxeZ8M1BOI+rCaVacIvTfGEqMw7h0eAIFid56gTjak1YgmcJPmfonA xw== Received: from xnwpv38.utc.com ([167.17.239.18]) by mx0a-00105401.pphosted.com with ESMTP id 3n27efpmvg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Jan 2023 16:27:57 +0000 Received: from qusnwadv.utcapp.com (QUSNWADV.utcapp.com [10.161.48.86]) by xnwpv38.utc.com (8.16.1.2/8.16.1.2) with ESMTPS id 30CGRuvL143170 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Jan 2023 16:27:56 GMT Received: from ciulimr02.rockwellcollins.com ([10.172.224.19]) by qusnwadv.utcapp.com (8.16.1.2/8.16.1.2) with ESMTPS id 30CGRtMj026020 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 12 Jan 2023 16:27:56 GMT X-Received: from kirk.rockwellcollins.lab (kirk.rockwellcollins.lab [10.148.204.208]) by ciulimr02.rockwellcollins.com (Postfix) with ESMTP id 881BC20094; Thu, 12 Jan 2023 10:27:55 -0600 (CST) From: Brandon Maier To: u-boot@lists.denx.de Cc: Tom Rini , Brandon Maier Subject: [PATCH v4 2/2] test: compression: add zstd uncompression test Date: Thu, 12 Jan 2023 10:27:46 -0600 Message-Id: <20230112162746.27767-2-brandon.maier@collins.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230112162746.27767-1-brandon.maier@collins.com> References: <20230112162746.27767-1-brandon.maier@collins.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: wksRroU_kGAmUjne0HOth9NP7x5v5VpH X-Proofpoint-GUID: wksRroU_kGAmUjne0HOth9NP7x5v5VpH X-Proofpoint-Spam-Details: rule=outbound_default_notspam policy=outbound_default score=0 clxscore=1015 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 spamscore=0 adultscore=0 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301120119 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Signed-off-by: Brandon Maier --- v2: - added zstd uncompression test v3: - use sizeof() instead of magic number for length --- test/Kconfig | 2 +- test/compression.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/test/Kconfig b/test/Kconfig index 9f4641ae6bc..465028265b2 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -69,7 +69,7 @@ endif config UT_COMPRESSION bool "Unit test for compression" depends on UNIT_TEST - depends on CMDLINE && GZIP_COMPRESSED && BZIP2 && LZMA && LZO && LZ4 + depends on CMDLINE && GZIP_COMPRESSED && BZIP2 && LZMA && LZO && LZ4 && ZSTD default y help Enables tests for compression and decompression routines for simple diff --git a/test/compression.c b/test/compression.c index 82e29c9b86b..eae1884938f 100644 --- a/test/compression.c +++ b/test/compression.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -22,6 +23,7 @@ #include #include +#include #include #include #include @@ -121,6 +123,23 @@ static const char lz4_compressed[] = "\x9d\x12\x8c\x9d"; static const unsigned long lz4_compressed_size = 276; +/* zstd -19 -c /tmp/plain.txt > /tmp/plain.zst */ +static const char zstd_compressed[] = + "\x28\xb5\x2f\xfd\x64\x5e\x00\xbd\x05\x00\x02\x0e\x26\x1a\x70\x17" + "\xb8\x0d\x0c\x53\x5c\x9d\x97\xee\xa0\x5d\x84\x89\x3f\x5c\x7a\x78" + "\x00\x80\x80\x0f\xe8\xdf\xaf\x06\x66\xd0\x23\xa6\x7a\x64\x8e\xf4" + "\x0d\x5b\x47\x65\x26\x7e\x81\xdd\x0b\xe7\x5a\x95\x3d\x49\xcc\x67" + "\xe0\x2d\x46\x58\xb6\xac\x64\x16\xf2\xe0\xf8\x16\x17\xaf\xda\x8f" + "\x37\xc0\xc3\x0d\x3b\x89\x57\x15\x1e\x46\x46\x12\x9a\x84\xbe\xa6" + "\xab\xcf\x50\x90\x5f\x78\x01\xd2\xc0\x51\x72\x59\x0b\xea\xab\xf2" + "\xd4\x2b\x2d\x26\x7c\x10\x66\x78\x42\x64\x45\x3f\xa5\x15\x6f\xbd" + "\x4a\x61\xe1\xc8\x27\xc0\xe3\x95\x0c\xf9\xca\x7c\xf5\x13\x30\xc3" + "\x1a\x7c\x7d\xa4\x17\x0b\xff\x14\xa6\x7a\x95\xa0\x34\xbc\xce\x21" + "\x78\x36\x23\x33\x11\x09\x00\x60\x13\x00\x63\xa3\x8e\x28\x94\x55" + "\x15\xb6\x26\x68\x05\x4f\x23\x12\xee\x53\x55\x2d\x44\x2f\x54\x95" + "\x01\xe4\xf4\x6e\xfa"; +static const unsigned long zstd_compressed_size = sizeof(zstd_compressed) - 1; + #define TEST_BUFFER_SIZE 512 @@ -296,6 +315,45 @@ static int uncompress_using_lz4(struct unit_test_state *uts, return (ret != 0); } +static int compress_using_zstd(struct unit_test_state *uts, + void *in, unsigned long in_size, + void *out, unsigned long out_max, + unsigned long *out_size) +{ + /* There is no zstd compression in u-boot, so fake it. */ + ut_asserteq(in_size, strlen(plain)); + ut_asserteq_mem(plain, in, in_size); + + if (zstd_compressed_size > out_max) + return -1; + + memcpy(out, zstd_compressed, zstd_compressed_size); + if (out_size) + *out_size = zstd_compressed_size; + + return 0; +} + +static int uncompress_using_zstd(struct unit_test_state *uts, + void *in, unsigned long in_size, + void *out, unsigned long out_max, + unsigned long *out_size) +{ + struct abuf in_buf, out_buf; + int ret; + + abuf_init_set(&in_buf, in, in_size); + abuf_init_set(&out_buf, out, out_max); + + ret = zstd_decompress(&in_buf, &out_buf); + if (ret >= 0) { + *out_size = ret; + ret = 0; + } + + return ret; +} + #define errcheck(statement) if (!(statement)) { \ fprintf(stderr, "\tFailed: %s\n", #statement); \ ret = 1; \ @@ -440,6 +498,13 @@ static int compression_test_lz4(struct unit_test_state *uts) } COMPRESSION_TEST(compression_test_lz4, 0); +static int compression_test_zstd(struct unit_test_state *uts) +{ + return run_test(uts, "zstd", compress_using_zstd, + uncompress_using_zstd); +} +COMPRESSION_TEST(compression_test_zstd, 0); + static int compress_using_none(struct unit_test_state *uts, void *in, unsigned long in_size, void *out, unsigned long out_max, @@ -530,6 +595,12 @@ static int compression_test_bootm_lz4(struct unit_test_state *uts) } COMPRESSION_TEST(compression_test_bootm_lz4, 0); +static int compression_test_bootm_zstd(struct unit_test_state *uts) +{ + return run_bootm_test(uts, IH_COMP_ZSTD, compress_using_zstd); +} +COMPRESSION_TEST(compression_test_bootm_zstd, 0); + static int compression_test_bootm_none(struct unit_test_state *uts) { return run_bootm_test(uts, IH_COMP_NONE, compress_using_none);