xref: /aosp_15_r20/external/zstd/contrib/linux-kernel/test/static_test.c (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui /*
2*01826a49SYabin Cui  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*01826a49SYabin Cui  * All rights reserved.
4*01826a49SYabin Cui  *
5*01826a49SYabin Cui  * This source code is licensed under both the BSD-style license (found in the
6*01826a49SYabin Cui  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*01826a49SYabin Cui  * in the COPYING file in the root directory of this source tree).
8*01826a49SYabin Cui  * You may select, at your option, one of the above-listed licenses.
9*01826a49SYabin Cui  */
10*01826a49SYabin Cui #include <stddef.h>
11*01826a49SYabin Cui #include <stdio.h>
12*01826a49SYabin Cui #include <stdlib.h>
13*01826a49SYabin Cui #include <string.h>
14*01826a49SYabin Cui 
15*01826a49SYabin Cui #include "decompress_sources.h"
16*01826a49SYabin Cui #include <linux/zstd.h>
17*01826a49SYabin Cui 
18*01826a49SYabin Cui #define CONTROL(x)                                                             \
19*01826a49SYabin Cui   do {                                                                         \
20*01826a49SYabin Cui     if (!(x)) {                                                                \
21*01826a49SYabin Cui       fprintf(stderr, "%s:%u: %s failed!\n", __FUNCTION__, __LINE__, #x);      \
22*01826a49SYabin Cui       abort();                                                                 \
23*01826a49SYabin Cui     }                                                                          \
24*01826a49SYabin Cui   } while (0)
25*01826a49SYabin Cui 
26*01826a49SYabin Cui 
27*01826a49SYabin Cui static const char kEmptyZstdFrame[] = {
28*01826a49SYabin Cui     0x28, 0xb5, 0x2f, 0xfd, 0x24, 0x00, 0x01, 0x00, 0x00, 0x99, 0xe9, 0xd8, 0x51
29*01826a49SYabin Cui };
30*01826a49SYabin Cui 
test_decompress_unzstd(void)31*01826a49SYabin Cui static void test_decompress_unzstd(void) {
32*01826a49SYabin Cui     fprintf(stderr, "Testing decompress unzstd... ");
33*01826a49SYabin Cui     {
34*01826a49SYabin Cui         size_t const wkspSize = zstd_dctx_workspace_bound();
35*01826a49SYabin Cui         void* wksp = malloc(wkspSize);
36*01826a49SYabin Cui         ZSTD_DCtx* dctx = zstd_init_dctx(wksp, wkspSize);
37*01826a49SYabin Cui         CONTROL(wksp != NULL);
38*01826a49SYabin Cui         CONTROL(dctx != NULL);
39*01826a49SYabin Cui         {
40*01826a49SYabin Cui           size_t const dSize = zstd_decompress_dctx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
41*01826a49SYabin Cui           CONTROL(!zstd_is_error(dSize));
42*01826a49SYabin Cui           CONTROL(dSize == 0);
43*01826a49SYabin Cui         }
44*01826a49SYabin Cui         free(wksp);
45*01826a49SYabin Cui     }
46*01826a49SYabin Cui     fprintf(stderr, "Ok\n");
47*01826a49SYabin Cui }
48*01826a49SYabin Cui 
main(void)49*01826a49SYabin Cui int main(void) {
50*01826a49SYabin Cui   test_decompress_unzstd();
51*01826a49SYabin Cui   return 0;
52*01826a49SYabin Cui }
53