diff options
author | Jia Tan <jiat0218@gmail.com> | 2022-10-05 23:54:12 +0800 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2022-10-06 17:34:27 +0300 |
commit | 84963318952064a93bfc52edd6b0ef70593384ee (patch) | |
tree | c89b493e4f8c3cde1644c4e2e2810cdf35a358db | |
parent | Tests: Include mythread.h in the tests that use MYTHREAD_ENABLED. (diff) | |
download | xz-84963318952064a93bfc52edd6b0ef70593384ee.tar.xz |
Tests: Fix compilation issues.
test_bcj_exact_size, test_check, test_hardware, and test_index will
all now compile and skip properly if encoders or decoders are disabled.
Also fixed a small typo (disabed -> disabled).
Thanks to Sebastian Andrzej Siewior.
-rw-r--r-- | tests/test_bcj_exact_size.c | 20 | ||||
-rw-r--r-- | tests/test_check.c | 8 | ||||
-rw-r--r-- | tests/test_hardware.c | 2 | ||||
-rw-r--r-- | tests/test_index.c | 6 | ||||
-rw-r--r-- | tests/test_memlimit.c | 16 | ||||
-rw-r--r-- | tests/test_vli.c | 13 |
6 files changed, 56 insertions, 9 deletions
diff --git a/tests/test_bcj_exact_size.c b/tests/test_bcj_exact_size.c index 39b34c3d..0115ca60 100644 --- a/tests/test_bcj_exact_size.c +++ b/tests/test_bcj_exact_size.c @@ -18,6 +18,15 @@ static void test_exact_size(void) { +#if !defined(HAVE_ENCODERS) || !defined(HAVE_DECODERS) + assert_skip("Encoder or decoder support disabled"); +#else + if (!lzma_filter_encoder_is_supported(LZMA_FILTER_POWERPC) + || !lzma_filter_decoder_is_supported( + LZMA_FILTER_POWERPC)) + assert_skip("PowerPC BCJ encoder and/or decoder " + "is disabled"); + // Something to be compressed const uint8_t in[16] = "0123456789ABCDEF"; @@ -71,12 +80,16 @@ test_exact_size(void) if (strm.total_out < sizeof(in)) strm.avail_out = 1; } +#endif } static void test_empty_block(void) { +#ifndef HAVE_DECODERS + assert_skip("Decoder support disabled"); +#else // An empty file with one Block using PowerPC BCJ and LZMA2. size_t in_size; uint8_t *empty_bcj_lzma2 = tuktest_file_from_srcdir( @@ -92,6 +105,7 @@ test_empty_block(void) LZMA_OK); assert_uint_eq(in_pos, in_size); assert_uint_eq(out_pos, 0); +#endif } @@ -100,12 +114,6 @@ main(int argc, char **argv) { tuktest_start(argc, argv); - if (!lzma_filter_encoder_is_supported(LZMA_FILTER_POWERPC) - || !lzma_filter_decoder_is_supported( - LZMA_FILTER_POWERPC)) - tuktest_early_skip("PowerPC BCJ encoder and/or decoder " - "is disabled"); - tuktest_run(test_exact_size); tuktest_run(test_empty_block); diff --git a/tests/test_check.c b/tests/test_check.c index cbe6917d..3c3a6e46 100644 --- a/tests/test_check.c +++ b/tests/test_check.c @@ -157,6 +157,9 @@ test_lzma_check_size(void) static void test_lzma_get_check_st(void) { +#ifndef HAVE_DECODERS + assert_skip("Decoder support disabled"); +#else const uint32_t flags = LZMA_TELL_ANY_CHECK | LZMA_TELL_UNSUPPORTED_CHECK | LZMA_TELL_NO_CHECK; @@ -230,6 +233,7 @@ test_lzma_get_check_st(void) #endif lzma_end(&strm); +#endif } @@ -237,7 +241,9 @@ static void test_lzma_get_check_mt(void) { #ifndef MYTHREAD_ENABLED - assert_skip("Threading support disabed"); + assert_skip("Threading support disabled"); +#elif !defined(HAVE_DECODERS) + assert_skip("Decoder support disabled"); #else const uint32_t flags = LZMA_TELL_ANY_CHECK | LZMA_TELL_UNSUPPORTED_CHECK | diff --git a/tests/test_hardware.c b/tests/test_hardware.c index ee4434c1..c72d9b28 100644 --- a/tests/test_hardware.c +++ b/tests/test_hardware.c @@ -32,7 +32,7 @@ static void test_lzma_cputhreads(void) { #ifndef MYTHREAD_ENABLED - assert_skip("Threading support disabed"); + assert_skip("Threading support disabled"); #else if (lzma_cputhreads() == 0) assert_skip("Could not determine cpu core count"); diff --git a/tests/test_index.c b/tests/test_index.c index d9e63dd0..31b958d5 100644 --- a/tests/test_index.c +++ b/tests/test_index.c @@ -211,6 +211,7 @@ test_read(lzma_index *i) static void test_code(lzma_index *i) { +#if defined(HAVE_ENCODERS) && defined(HAVE_DECODERS) const size_t alloc_size = 128 * 1024; uint8_t *buf = malloc(alloc_size); expect(buf != NULL); @@ -275,6 +276,9 @@ test_code(lzma_index *i) lzma_index_end(d, NULL); free(buf); +#else + (void)i; +#endif } @@ -633,6 +637,7 @@ test_locate(void) static void test_corrupt(void) { +#if defined(HAVE_ENCODERS) && defined(HAVE_DECODERS) const size_t alloc_size = 128 * 1024; uint8_t *buf = malloc(alloc_size); expect(buf != NULL); @@ -668,6 +673,7 @@ test_corrupt(void) lzma_end(&strm); free(buf); +#endif } diff --git a/tests/test_memlimit.c b/tests/test_memlimit.c index b5f91472..4e16903d 100644 --- a/tests/test_memlimit.c +++ b/tests/test_memlimit.c @@ -26,6 +26,9 @@ static uint8_t out[8192]; static void test_memlimit_stream_decoder(void) { +#ifndef HAVE_DECODERS + assert_skip("Decoder support disabled"); +#else lzma_stream strm = LZMA_STREAM_INIT; assert_lzma_ret(lzma_stream_decoder(&strm, MEMLIMIT_TOO_LOW, 0), LZMA_OK); @@ -48,6 +51,7 @@ test_memlimit_stream_decoder(void) assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END); lzma_end(&strm); +#endif } @@ -55,7 +59,9 @@ static void test_memlimit_stream_decoder_mt(void) { #ifndef MYTHREAD_ENABLED - assert_skip("Threading support disabed"); + assert_skip("Threading support disabled"); +#elif !defined(HAVE_DECODERS) + assert_skip("Decoder support disabled"); #else lzma_stream strm = LZMA_STREAM_INIT; lzma_mt mt = { @@ -90,6 +96,9 @@ test_memlimit_stream_decoder_mt(void) static void test_memlimit_alone_decoder(void) { +#ifndef HAVE_DECODERS + assert_skip("Decoder support disabled"); +#else size_t alone_size; uint8_t *alone_buf = tuktest_file_from_srcdir( "files/good-unknown_size-with_eopm.lzma", &alone_size); @@ -112,12 +121,16 @@ test_memlimit_alone_decoder(void) assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END); lzma_end(&strm); +#endif } static void test_memlimit_auto_decoder(void) { +#ifndef HAVE_DECODERS + assert_skip("Decoder support disabled"); +#else lzma_stream strm = LZMA_STREAM_INIT; assert_lzma_ret(lzma_auto_decoder(&strm, MEMLIMIT_TOO_LOW, 0), LZMA_OK); @@ -137,6 +150,7 @@ test_memlimit_auto_decoder(void) assert_lzma_ret(lzma_code(&strm, LZMA_FINISH), LZMA_STREAM_END); lzma_end(&strm); +#endif } diff --git a/tests/test_vli.c b/tests/test_vli.c index 3cf027a8..793dcf2e 100644 --- a/tests/test_vli.c +++ b/tests/test_vli.c @@ -70,6 +70,7 @@ test_lzma_vli_size(void) } +#ifdef HAVE_ENCODERS // Helper function for test_lzma_vli_encode // Encodes an input VLI and compares against a pre-computed value static void @@ -108,11 +109,15 @@ encode_multi_call_mode(lzma_vli input, const uint8_t *expected, assert_uint_eq(vli_pos, expected_len); assert_array_eq(out, expected, expected_len); } +#endif static void test_lzma_vli_encode(void) { +#ifndef HAVE_ENCODERS + assert_skip("Encoder support disabled"); +#else size_t vli_pos = 0; uint8_t out[LZMA_VLI_BYTES_MAX]; uint8_t zeros[LZMA_VLI_BYTES_MAX]; @@ -189,9 +194,11 @@ test_lzma_vli_encode(void) sizeof(eight_bytes)); encode_multi_call_mode(nine_byte_value, nine_bytes, sizeof(nine_bytes)); +#endif } +#ifdef HAVE_DECODERS static void decode_single_call_mode(const uint8_t *input, uint32_t input_len, lzma_vli expected) @@ -227,10 +234,15 @@ decode_multi_call_mode(const uint8_t *input, uint32_t input_len, assert_uint_eq(vli_pos, input_len); assert_uint_eq(out, expected); } +#endif + static void test_lzma_vli_decode(void) { +#ifndef HAVE_DECODERS + assert_skip("Decoder support disabled"); +#else lzma_vli out = 0; size_t in_pos = 0; @@ -295,6 +307,7 @@ test_lzma_vli_decode(void) eight_byte_value); decode_multi_call_mode(nine_bytes, sizeof(nine_bytes), nine_byte_value); +#endif } |