Commit Graph

251 Commits

Author SHA1 Message Date
Jia Tan ee2f483500 Tests: Minor cleanups to OSS-Fuzz files.
Most of these fixes are small typos and tweaks. A few were caused by bad
advice from me. Here is the summary of what is changed:

- Author line edits

- Small comment changes/additions

- Using the return value in the error messages in the fuzz targets'
  coder initialization code

- Removed fuzz_encode_stream.options. This set a max length, which may
  prevent some worthwhile code paths from being properly exercised.

- Removed the max_len option from fuzz_decode_stream.options for the
  same reason as fuzz_encode_stream. The alone decoder fuzz target still
  has this restriction.

- Altered the dictionary contents for fuzz_lzma.dict. Instead of keeping
  the properties static and varying the dictionary size, the properties
  are varied and the dictionary size is kept small. The dictionary size
  doesn't have much impact on the code paths but the properties do.

Closes: https://github.com/tukaani-project/xz/pull/73
2023-12-07 20:06:57 +08:00
Maksym Vatsyk 483bb90eec Tests: Add fuzz_encode_stream ossfuzz target.
This fuzz target handles .xz stream encoding. The first byte of input
is used to dynamically set the preset level in order to increase the
fuzz coverage of complex critical code paths.
2023-12-07 20:06:57 +08:00
Maksym Vatsyk 7ca8c9869d Tests: Add fuzz_decode_alone OSS-Fuzz target
This fuzz target that handles LZMA alone decoding. A new fuzz
dictionary .dict was also created with common LZMA header values to
help speed up the discovery of valid headers.
2023-12-07 20:06:57 +08:00
Maksym Vatsyk 37581a77ad Tests: Update OSS-Fuzz Makefile.
All .c files can be built as separate fuzz targets. This simplifies
the Makefile by allowing us to use wildcards instead of having a
Makefile target for each fuzz target.
2023-12-07 20:06:54 +08:00
Maksym Vatsyk 28ce6a1c2a Tests: Move common OSS-Fuzz target code to .h file. 2023-12-07 20:06:54 +08:00
Maksym Vatsyk bf0521ea15 Tests: Rename OSS-Fuzz files. 2023-12-07 20:06:51 +08:00
Kian-Meng Ang 3b3023e00b Tests: Fix typos 2023-11-30 23:08:05 +08:00
Jia Tan ca278eb2b7 Tests: Create test_suffix.sh.
This tests some complicated interactions with the --suffix= option.
The suffix option must be used with --format=raw, but can optionally
be used to override the default .xz suffix.

This test also verifies some recent bugs have been correctly solved
and to hopefully avoid further regressions in the future.
2023-11-18 01:56:05 +08:00
Jia Tan 299920bab9 Tests: Fix typo in a comment. 2023-11-17 20:04:58 +08:00
Jia Tan bbb42412da Build: Remove Gnulib dependency from tests.
The tests do not use any Gnulib replacements so they do not need to link
libgnu.a or have /lib in the include path.
2023-09-26 00:47:26 +08:00
Jia Tan 74c3449d8b Tests: Improve invalid unpadded size check in test_lzma_index_append().
This check was extended to test the code added to fix a failing assert
in ae5c07b22a.
2023-08-28 23:14:45 +08:00
Jia Tan 2544274a8b Tests: Improve comments in test_index.c. 2023-08-28 23:05:55 +08:00
Jia Tan cd678a6077 Tests: Style fixes to test_lzip_decoder.c. 2023-08-03 20:10:21 +08:00
Dimitri Papadopoulos Orfanos 42df7c7aa1
Docs: Fix typos found by codespell 2023-07-31 20:02:21 +08:00
Jia Tan 39a32d36fc Tests: Skip .lz files in test_files.sh if not configured.
Previously if the lzip decoder was not configured then test_files.sh
would pass the lzip tests instead of skipping them.
2023-07-21 18:05:44 +08:00
Jia Tan 194d12724b Tests: Add ARM64 filter test to test_compress.sh. 2023-07-20 22:11:13 +08:00
Jia Tan a6583726e5 Tests: Use new --filters option in test_compress.sh 2023-07-17 23:34:55 +08:00
Jia Tan 2c189bb00a Tests: Improve feature testing for skipping.
Fixed a bug where test_compress_* would all fail if arm64 or armthumb
filters were enabled for compression but arm was disabled. Since the
grep tests only checked for "define HAVE_ENCODER_ARM", this would match
on HAVE_ENCODER_ARM64 or HAVE_ENCODER_ARMTHUMB.

Now the config.h feature test requires " 1" at the end to prevent the
prefix problem. have_feature() was also updated for this even though
there were known current bugs affecting it. This is just in case future
features have a similar prefix problem.
2023-07-14 21:30:25 +08:00
Jia Tan 66bdcfa85f Tests: Fix memory leaks in test_index.
Several tests were missing calls to lzma_index_end() to clean up the
lzma_index structs. The memory leaks were discovered by using
-fsanitize=address with GCC.
2023-06-29 00:07:16 +08:00
Jia Tan fe3bd438fb Tests: Fix memory leaks in test_block_header.
test_block_header was not properly freeing the filter options between
calls to lzma_block_header_decode(). The memory leaks were discovered by
using -fsanitize=address with GCC.
2023-06-29 00:07:05 +08:00
Jia Tan 1b7661faa4 Tests: Remove unused macros and functions. 2023-03-13 20:49:53 +08:00
Jia Tan af55191102 liblzma: Defines masks for return values from lzma_index_checks(). 2023-03-13 20:49:53 +08:00
Jia Tan 8f38cdd9ab Tests: Refactors existing lzma_index tests.
Converts the existing lzma_index tests into tuktests and covers every
API function from index.h except for lzma_file_info_decoder, which can
be tested in the future.
2023-03-13 20:49:53 +08:00
Jia Tan 9aa7fdeb04 Tests: Small tweak to test-vli.c.
The static global variables can be disabled if encoders and decoders
are not built. If they are not disabled and -Werror is used, it will
cause an usused warning as an error.
2023-02-24 21:11:18 +08:00
Jia Tan e01f01b9af Tests: Create test_filter_str.c.
Tests lzma_str_to_filters(), lzma_str_from_filters(), and
lzma_str_list_filters() API functions.
2023-02-03 00:42:27 +08:00
Lasse Collin bfc3a0a8ac Tests: Fix warnings from clang --Wassign-enum.
Explicitly casting the integer to lzma_check silences the warning.
Since such an invalid value is needed in multiple tests, a constant
INVALID_LZMA_CHECK_ID was added to tests.h.

The use of 0x1000 for lzma_block.check wasn't optimal as if
the underlying type is a char then 0x1000 will be truncated to 0.
However, in these test cases the value is ignored, thus even with
such truncation the test would have passed.
2023-01-12 04:14:18 +02:00
Lasse Collin 49245bb31e Tests: Silence warnings from -Wsign-conversion.
Note that assigning an unsigned int to lzma_check doesn't warn
on GNU/Linux x86-64 since the enum type is unsigned on that
platform. The enum can be signed on some other platform though
so it's best to use enumeration type lzma_check in these situations.
2023-01-12 03:56:24 +02:00
Lasse Collin a0e7fb1c1e Tests: test_lzip_decoder: Remove trailing white-space. 2023-01-12 03:04:28 +02:00
Lasse Collin c0f8d6782f Tests: test_lzip_decoder: Silence warnings from -Wsign-conversion. 2023-01-12 03:03:55 +02:00
Jia Tan 8c0f115cc4 Tests: Fix test_filter_flags copy/paste error. 2023-01-11 20:58:31 +08:00
Jia Tan 25035813d1 Tests: Fix type-limits warning in test_filter_flags.
This only occurs in test_filter_flags when the BCJ filters are not
configured and built. In this case, ARRAY_SIZE() returns 0 and causes a
type-limits warning with the loop variable since an unsigned number will
always be >= 0.
2023-01-11 20:42:29 +08:00
Jia Tan 765354b50c Tests: Fix unused function warning in test_block_header.
One of the global arrays of filters was only used in a test that
required both encoders and decoders to be configured in the build.
2023-01-11 01:18:50 +08:00
Jia Tan 7c23c05bef Tests: Fix unused function warning in test_index_hash.
test_index_hash does not use fill_index_hash() unless both encoders
and decoders are configured in the build.
2023-01-11 01:08:03 +08:00
Lasse Collin 0c210ca7f4 Tests: test_filter_flags: Clean up minor issues.
Here are the list of the most significant issues addressed:
- Avoid using internal common.h header. It's not good to copy the
constants like this but common.h cannot be included for use outside
of liblzma. This is the quickest thing to do that could be fixed later.

- Omit the INIT_FILTER macro. Initialization should be done with just
regular designated initializers.

- Use start_offset = 257 for BCJ tests. It demonstrates that Filter
Flags encoder and decoder don't validate the options thoroughly.
257 is valid only for the x86 filter. This is a bit silly but
not a significant problem in practice because the encoder and
decoder initialization functions will catch bad alignment still.
Perhaps this should be fixed but it's not urgent and doesn't need
to be in 5.4.x.

- Various tweaks to comments such as filter id -> Filter ID
2023-01-09 20:35:20 +08:00
Jia Tan 5c9fdd3bf5 Tests: Refactors existing filter flags tests.
Converts the existing filter flags tests into tuktests.
2023-01-09 20:35:20 +08:00
Lasse Collin 0e1545fea3 Tests: tuktest.h: Support tuktest_malloc(0).
It's not needed in XZ Utils at least for now. It's good to support
it still because if such use is needed later, it wouldn't be
caught on GNU/Linux since malloc(0) from glibc returns non-NULL.
2023-01-08 00:32:29 +02:00
Jia Tan 6fd39664de
Merge pull request #7 from tukaani-project/tuktest_index_hash
Tuktest index hash
2023-01-07 00:10:50 +08:00
Lasse Collin fc0c788469 Tests: test_index_hash: Add an assert_uint_eq(). 2023-01-06 17:58:48 +02:00
Lasse Collin d550304f53 Tests: test_index_hash: Fix a memory leak. 2023-01-06 17:55:06 +02:00
Lasse Collin 02608f74ea Tests: test_index_hash: Don't treat pointers as booleans. 2023-01-06 17:53:03 +02:00
Lasse Collin 056766c860 Tests: test_index_hash: Fix a typo in a comment. 2023-01-06 17:51:41 +02:00
Lasse Collin 873e684028 Tests: test_index_hash: Avoid the variable name "index".
It can trigger warnings from -Wshadow on some systems.
2023-01-06 17:44:29 +02:00
Lasse Collin d1f24c3587 Tests: test_index_hash: Use the word "Record" instead of "entry". 2023-01-06 17:35:50 +02:00
Lasse Collin b93f7c5cbb Tests: test_index_hash: Tweak comments and style.
The words defined in the .xz file format specification
begin with capital letter to emphasize that they have
a specific meaning.
2023-01-06 17:35:05 +02:00
Lasse Collin c48b24fc06 Tests: test_index_hash: Use INDEX_INDICATOR constant instead of 0. 2023-01-06 17:17:37 +02:00
Lasse Collin aafd67fba0 Tests: Adjust style in test_compress.sh. 2023-01-04 18:40:28 +02:00
Jia Tan 52380678f4
Tests: Replace non portable shell parameter expansion
The shell parameter expansion using # and ## is not supported in
Solaris 10 Bourne shell (/bin/sh). Even though this is POSIX, it is not fully
portable, so we should avoid it.
2023-01-04 23:58:58 +08:00
Jia Tan 3959162bae Tests: Creates test_index_hash.c
Tests all API functions exported from index_hash.h. Does not have a
dedicated test for lzma_index_hash_end.
2023-01-02 22:20:04 +08:00
Lasse Collin dfecda8752 Tests: test_check: Test corner cases of CLMUL CRC64. 2022-12-30 20:10:08 +02:00
Lasse Collin ce96bb2043 Tests: Clarify a comment in test_lzip_decoder.c. 2022-12-30 19:36:49 +02:00
Jia Tan 7c9ff5f166 Tests: Adds lzip decoder tests 2022-12-30 23:34:31 +08:00
Lasse Collin 177ece1c8e Tests: Fix a typo in tests/files/README. 2022-12-13 12:30:45 +02:00
Lasse Collin 60f45bdbaa Tests: Add two ARM64 test files. 2022-12-13 12:30:09 +02:00
Lasse Collin c8ef089c14 Tests: Test the .lz files in test_files.sh. 2022-11-09 14:32:33 +02:00
Lasse Collin c8f70ebb46 Tests: Add .lz (lzip) test files. 2022-11-09 14:31:21 +02:00
Lasse Collin 05c72de06f Tests: test_files.sh: Make it not fail if features were disabled at build.
It now tries to test as many files as easily possible.
The exit status indicates skipping if any of the files were
skipped. This way it is easy to notice if something is being
skipped when it isn't expected.
2022-10-27 15:49:18 +03:00
Lasse Collin b3459327a5 Tests: test_files.sh: Suppress an expected warning from the log.
xz (but not xzdec) will normally warn about unsupported check
but since we are testing specifically such a file, it's better
to silence that warning so that it doesn't look suspicious in
test_files.sh.log.

The use of -q and -Q in xzdec is just for consistency and
doesn't affect the result at least for now.
2022-10-27 15:30:13 +03:00
Lasse Collin 798c86e423 Tests: test_files.sh: Print the reason for skipping if xz & xzdec missing. 2022-10-27 15:27:50 +03:00
Lasse Collin c1dd8524e1 Tests: Keep test_compress_* working when some filters are unavailable. 2022-10-27 01:12:40 +03:00
Jia Tan ce30ada919 Tests: test_bcj_exact_size skips properly now if PowerPC filter disabled. 2022-10-26 20:12:01 +03:00
Lasse Collin 89c5cfcaca Tests: Test also unsupported-*.xz. 2022-10-26 00:05:57 +03:00
Lasse Collin 424ac91c7e Tests: Skip tests in test_*.sh if encoders and/or decoders are disabled.
This isn't perfect as the scripts can still fail if only
certain filters are disabled. This is still an improvement
as now "make check" has better behavior when all encoders
or decoders are disabled.

Grepping ../config.h is simple and fairly clean but it only
works if config.h was created. CMake builds don't create
config.h but they don't use these test scripts either.

Thanks to Sebastian Andrzej Siewior for reporting the problem.
Thanks to Jia Tan for the original patch which grepped xz
error messages instead of config.h.
2022-10-19 19:39:35 +03:00
Lasse Collin ca8bf9d7c5 Test: Remove the (exit 1) lines.
I suspect that I used these in the original version because
Autoconf's manual describes that such a trick is needed in
some specific situations for portability reasons. None of those
situations listed on Autoconf 2.71 manual apply to these test
scripts though so this cleans them up.
2022-10-19 19:03:50 +03:00
Lasse Collin 82fcb7cfc1 Tests: Fix a warning in test_memlimit.c when decoders are disabled. 2022-10-19 17:14:57 +03:00
Jia Tan 6a86e81cab Tests: Refactor test_stream_flags.c.
Converts test_stream_flags to tuktest. Also the test will now
compile and skip properly if encoders or decoders are disabled.

Thanks to Sebastian Andrzej Siewior.
2022-10-06 22:06:17 +03:00
Jia Tan 827ac5b482 Tests: Refactor test_block_header.c.
test_block_header now achieves higher test coverage. Also the
test will now compile and skip properly if encoders or decoders
are disabled.

Thanks to Sebastian Andrzej Siewior.
2022-10-06 21:51:48 +03:00
Jia Tan 8496331895 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.
2022-10-06 17:34:27 +03:00
Lasse Collin 7dcabeec63 Tests: Include mythread.h in the tests that use MYTHREAD_ENABLED. 2022-10-05 16:20:47 +03:00
Jia Tan 6ca5c354bd Tests: Fix compilation error when threading support has been disabled.
Now tests that require threading are skipped when threading
support has been disabled.

Thanks to Sebastian Andrzej Siewior.
2022-10-05 16:10:21 +03:00
Jia Tan afd5a8bf53 Tests: Create a test for the lzma_index_cat bug. 2022-09-28 15:34:23 +03:00
Lasse Collin 5a4d3548ab Tests: Add test_memlimit.c to test restarting after LZMA_MEMLIMIT_ERROR. 2022-09-28 11:12:07 +03:00
Lasse Collin c3592d0a55 Tests: Add a test file for lzma_index_append() integer overflow bug.
This test fails before commit 18d7facd38.

test_files.sh now runs xz -l for bad-3-index-uncomp-overflow.xz
because only then the previously-buggy code path gets tested.
Normal decompression doesn't use lzma_index_append() at all.
Instead, lzma_index_hash functions are used and those already
did the overflow check.
2022-09-16 17:08:53 +03:00
Lasse Collin f2d084fe3f Tests: Silence warnings about unused functions from tuktest.h.
Warnings about unused tuktest_run_test conveniently tell which
test programs haven't been converted to tuktest.h yet but I
silenced that warning too for now anyway.

It is fine to use __attribute__((__unused__)) even when the
function is actually used because the attribute only means
that the function might be unused.
2022-09-09 14:12:30 +03:00
Lasse Collin 2d2201bc63 Tests: Add the .lzma files to test_files.sh. 2022-07-14 20:33:05 +03:00
Lasse Collin ce5549a591 Tests: Add .lzma test files. 2022-07-14 19:37:42 +03:00
Jia Tan d1bfa3dc70 Created script to generate code coverage reports.
The script uses lcov and genhtml after running the tests
to show the code coverage statistics. The script will create
a coverage directory where it is run. It can be run both in
and out of the source directory.
2022-07-10 22:42:22 +03:00
Jia Tan 86a30b0255 Tests: Add more tests into test_check. 2022-06-16 17:39:59 +03:00
Lasse Collin 82e30fed66 Tests: Use char[][24] array for enum_strings_lzma_ret.
Array of pointers to short strings is a bit pointless here
and now it's fully const.
2022-06-16 15:02:57 +03:00
Lasse Collin 5ba9459e6c Tests: tuktest.h: Add tuktest_error_impl to help with error conditions. 2022-06-16 14:12:14 +03:00
Lasse Collin b339892668 Tests: tuktest.h: Rename file_from_* and use tuktest_malloc there. 2022-06-16 13:29:59 +03:00
Lasse Collin d8b63a0ad6 Tests: tuktest.h: Add malloc wrapper with automatic freeing. 2022-06-16 13:08:19 +03:00
Lasse Collin 1d51536a4b Tests: tuktest.h: Move a function. 2022-06-16 11:47:37 +03:00
Lasse Collin 70c7555f64 Tests: test_vli: Remove an invalid test-assertion.
lzma_vli is unsigned so trying a signed value results in
a compiler warning from -Wsign-conversion. (lzma_vli)-1
equals to LZMA_VLI_UNKNOWN anyway which is the next assertion.
2022-06-14 22:21:15 +03:00
Lasse Collin 154b73c5a1 Tests: test_vli: Add const where appropriate. 2022-06-14 22:17:01 +03:00
Jia Tan a08f5ccf6b Created tests for all functions exported in vli.h
Achieved 100% code coverage vli_encoder.c, vli_decoder.c, and vli_size.c
2022-06-14 22:00:34 +03:00
Lasse Collin 00e3613f12 Tests: Use good-1-empty-bcj-lzma2.xz in test_bcj_exact_size.
It's much nicer this way so that the test data isn't a hardcoded
table inside the C file.
2022-06-14 21:29:21 +03:00
Lasse Collin 86bab755be Tests: Add file reading helpers to tuktest.h. 2022-06-14 21:26:13 +03:00
Lasse Collin 83d2337b72 Tests: tuktest.h: Move a printf from a macro to a helper function. 2022-06-14 18:21:57 +03:00
Lasse Collin f9e8176ea7 Tests: Add test file good-1-empty-bcj-lzma2.xz.
This is from test_bcj_exact_size.c.
It's good to have it as a standalone file.
2022-06-14 17:20:49 +03:00
Jia Tan aa75c5563a Tests: Created tests for hardware functions.
Created tests for all API functions exported in
src/liblzma/api/lzma/hardware.h. The tests are fairly trivial
but are helpful because they will inform users if their machines
cannot support these functions. They also improve the code
coverage metrics.
2022-06-10 16:58:47 +03:00
Lasse Collin 5c8ffdca20 Tests: Convert test_check to tuktest.
Thanks to Jia Tan for help with all the tests.
2022-06-02 21:06:58 +03:00
Lasse Collin faf5ff8899 Tests: Convert test_block_header to tuktest. 2022-06-02 20:45:05 +03:00
Lasse Collin 754d39fbeb Tests: Convert test_bcj_exact_size to tuktest.
The compress() and decompress() functions were merged because
the later depends on the former so they need to be a single
test case.
2022-06-02 20:28:23 +03:00
Lasse Collin 96da21470f Tests: Include tuktest.h in tests.h.
This breaks -Werror because none of the tests so far use
tuktest.h and thus there are warnings about unused variables
and functions.
2022-06-02 20:27:00 +03:00
Lasse Collin df71ba1c99 Tests: Add tuktest.h mini-test-framework. 2022-06-02 20:25:21 +03:00
Lasse Collin 9a6dd6d46f Tests: Split test_compress.sh into separate test unit for each file.
test_compress.sh now takes one command line argument:
a filename to be tested. If it begins with "compress_generated_"
the file will be created with create_compress_files.

This will allow parallel execution of the slow tests.
2022-05-23 21:31:20 +03:00
Lasse Collin c7758ac9c7 Test: Make create_compress_files.c a little more flexible.
If a command line argument is given, then only the test file
of that type is created. It's quite dumb in sense that unknown
names don't give an error but it's good enough here.

Also use EXIT_FAILURE instead of 1 as exit status for errors.
2022-05-23 20:59:47 +03:00
Lasse Collin 4a8e4a7b0a Tests: Remove unneeded commented lines from test_compress.sh. 2022-05-23 20:17:42 +03:00
Lasse Collin 2ee50d150e Tests: Remove progress indicator from test_compress.sh.
It will be useless with Automake's parallel tests.
2022-05-23 20:16:00 +03:00
Lasse Collin 555de11873 Tests: Add bad-1-lzma2-11.xz. 2022-02-20 19:38:55 +02:00