From patchwork Tue Dec 27 14:46:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Maier X-Patchwork-Id: 1719689 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=I9G0XfYe; 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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NhHY15PmJz23dD for ; Wed, 28 Dec 2022 01:46:45 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9B93B8532C; Tue, 27 Dec 2022 15:46:40 +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="I9G0XfYe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2C34F8532F; Tue, 27 Dec 2022 15:46:39 +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 (mx0b-00105401.pphosted.com [67.231.152.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 B35D7852F0 for ; Tue, 27 Dec 2022 15:46:36 +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=5360bf17f7=brandon.maier@collins.com Received: from pps.filterd (m0081755.ppops.net [127.0.0.1]) by mx0b-00105401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 2BREiC4G006415; Tue, 27 Dec 2022 14:46:35 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=RV7IYAibpdfOAVmrZgdUL2x7mmlN+4bbUfQRvjiyY9s=; b=I9G0XfYe6jKacmPCTqiIX8iEU5678rF7kPCdd/N26dYZTQytt5VUjFppzwB536G6XUrY bl3CiQ9TYf/8bHyGftKzOtYouxtBcuV5WmVRsDKT4b511Xc5UC9LcNXhmO/hQErqj0w6 ftlkHmAJMppMowMEgTk1jRRUdfhpbS7hgoWnECSYmWTohk4cQlE3LO/9OXSoJswcVcuz cOj2p/ZGKMwHe1QMlJl2cPl6Fk0fTNQJgGVKExQC4EZB6bKbd7LWQEctF7O9rQ9drzZJ g0xSvQzrhQ5tz0/lRdR6z6msrJcNuo9I9mTwJ1MpID4R4J7Fvigs/roSqTsqLny77O4P 4A== Received: from xmnpv38.utc.com ([167.17.239.12]) by mx0b-00105401.pphosted.com with ESMTP id 3mpb3dedv3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Dec 2022 14:46:34 +0000 Received: from qusnwaff.utcapp.com (qusnwaff.utcapp.com [10.161.48.102]) by xmnpv38.utc.com (8.16.1.2/8.16.1.2) with ESMTPS id 2BREkXL0180072 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Dec 2022 14:46:33 GMT Received: from crulimr01.rockwellcollins.com ([10.172.224.19]) by qusnwaff.utcapp.com (8.16.1.2/8.16.1.2) with ESMTPS id 2BREkWeH023664 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 27 Dec 2022 14:46:33 GMT X-Received: from kirk.rockwellcollins.lab (kirk.rockwellcollins.lab [10.148.204.208]) by crulimr01.rockwellcollins.com (Postfix) with ESMTP id BFCC060561; Tue, 27 Dec 2022 08:46:32 -0600 (CST) From: Brandon Maier To: u-boot@lists.denx.de Cc: Tom Rini , Brandon Maier Subject: [PATCH v2 2/2] test: compression: add zstd uncompression test Date: Tue, 27 Dec 2022 08:46:13 -0600 Message-Id: <20221227144613.48752-2-brandon.maier@collins.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221227144613.48752-1-brandon.maier@collins.com> References: <20221227144613.48752-1-brandon.maier@collins.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: OubgbmqcrsDg8FCtZkwOgZELNSXkloke X-Proofpoint-GUID: OubgbmqcrsDg8FCtZkwOgZELNSXkloke X-Proofpoint-Spam-Details: rule=outbound_default_notspam policy=outbound_default score=0 phishscore=0 malwarescore=0 clxscore=1015 suspectscore=0 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212270120 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 --- test/Kconfig | 2 +- test/compression.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/test/Kconfig b/test/Kconfig index a6b463e4d06..dd2f082ce63 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -64,7 +64,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..c3e8c8c51ae 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 = 197; + #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);