85 Commits

Author SHA1 Message Date
Dag-Erling Smørgrav
8295366f94 test_main: Add option to list tests
The test runner already lists available tests if it fails to parse the
command line, but add a -l option to explicitly do this without also
printing an error message and a summary of options.
2025-12-06 14:45:40 +01:00
Dag-Erling Smørgrav
8fff509f1a Replace system() with posix_spawn() if available
Some platforms disallow system() due to its perceived insecurity.
Luckily, we can be just as insecure using the more palatable
posix_spawn() instead!
2025-10-14 19:17:53 +02:00
Eisuke Kawashima
7fdf32b6b2
fix: remove extra ';' outside of functions 2025-09-26 19:41:30 +09:00
Chris Brown
e099b418e3 revert test verbosity change 2025-08-09 16:43:55 -04:00
Chris Brown
9e7af6f21c increase test verbosity 2025-08-09 15:28:34 -04:00
Chris Brown
fb859e6d3f add test 2025-08-08 20:15:35 -04:00
Benoit Pierre
864c904442 test_utils: factorize canProg implementations 2025-06-08 00:05:58 +02:00
Benoit Pierre
dcf5475661 test_utils: fix canRunCommand implementation
Do not unconditionally cache the result of the first call (and
reused it for subsequent calls). Thankfully, the function is
only called once.
2025-06-08 00:05:34 +02:00
Martin Matuska
1311a438a3 test_utils/test_main.c: satisfy -Wstrict-prototypes 2025-06-01 23:35:05 +02:00
Tobias Stoeckmann
e70e24a738 test_utils: Reset all locale related entries
Reset current locale settings through setlocale and also all
environment variables which might affect test cases which
spawn children through systemf which in turn would call setlocale
on their own, e.g. bsdtar.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-30 17:32:02 +02:00
Martin Matuska
9eacf09a86 tests: accept underscore in arbitrary third-party version strings
Fixes #2626
2025-05-23 13:20:25 +02:00
Nicholas Vinson
6dd27bc4a3
test_utils/test_main.c: increase logfilename bf sz
Increase logfilename buffer size from 64 to 256. This aligns the buffer
size with the size limits found in Windows and Linux.
2025-05-17 11:45:20 -04:00
Graham Percival
b580147278
Fix #endif comments for header guards (#2567) 2025-04-06 14:16:24 -07:00
ljdarj
de77e6d671
Moving the tests' CRC-32 function to test_utils. (#2390)
Following up from #2284, putting the tests' CRC-32 implementation in
test_utils and having all tests use it.
2025-03-07 19:21:23 -08:00
Graham Percival
42565b88b5
Cast (mode_t)mode for POSIX functions (#2476) 2025-01-06 16:44:40 -08:00
Silent
14b8803c40
Fix a Y2038 bug by replacing Int32x32To64 with regular multiplication (#2471)
`Int32x32To64` macro internally truncates the arguments to int32, while
`time_t` is 64-bit on most/all modern platforms. Therefore, usage of
this macro creates a Year 2038 bug.

I detailed this issue a while ago in a writeup, and spotted the same
issue in this repository when updating the list of affected
repositories:
<https://cookieplmonster.github.io/2022/02/17/year-2038-problem/>

A few more notes:
1. I changed all uses of `Int32x32To64` en masse, even though at least
one of them was technically OK and used with int32 parameters only. IMO
better safe than sorry.
2. This is untested, but it's a small enough change that I hope the CI
success is a good enough indicator.
2025-01-01 08:31:35 -08:00
Graham Percival
edcae6c164
Fix compiler nitpicks (#2465) 2024-12-30 08:30:42 -08:00
Graham Percival
4ce9c2f4be
Add more casts for %c, %o, and %x (#2463) 2024-12-29 10:20:24 -08:00
Graham Percival
a2086b67d8
Add more casts for %o (#2461) 2024-12-29 10:18:06 -08:00
Graham Percival
14221c7ba2
Add straightforward casts for %o and %x (#2458) 2024-12-28 16:29:47 -08:00
Graham Percival
a659a44a85
Fix format strings (#2457) 2024-12-28 11:03:17 -08:00
Graham Percival
af4a3562cd
Reject relative path for test refdir (#2445) 2024-12-24 11:51:50 -08:00
Mostyn Bramley-Moore
7efa99bdb1
ci: make skipped tests more obvious (#2430)
Previously skipped tests were reported like this when running the *_test
binaries:
```
 4: test_acl_platform_nfs4                                          ok (S)
```

Let's make this more obvious:
```
  4: test_acl_platform_nfs4                                         skipped
```
2024-12-08 18:08:34 -08:00
Mostyn Bramley-Moore
8ac45a813e
Report skipped tests to cmake/ctest (#2429)
This plumbing is required for cmake/ctest to recognise and report
skipped tests.

Now skipped tests in cmake ci jobs are reported like so:
```
          Start   7: libarchive_test_acl_platform_posix1e_read
    7/785 Test   #7: libarchive_test_acl_platform_posix1e_read ................................***Skipped   0.02 sec
```

And there is a list of skipped tests shown at the end of the test run.
2024-12-08 18:07:49 -08:00
ljdarj
e37d378186
Moving the tests' integer reading functions to test_utils. (#2410)
Moving the tests' integer reading functions to test_utils so that they
all use the same as well as moving the few using the archive_endian
functions over to the test_utils helper.

Follow-up from libarchive#2390.
2024-11-16 17:42:27 -08:00
Dag-Erling Smørgrav
a90e9d84ec
Miscellaneous code cleanup (#2285)
This fixes various code quality issues I encountered while chasing a
memory leak reported by test automation. I failed to reproduce the
memory leak, but I hope you find this useful nonetheless.
2024-10-04 08:45:58 -07:00
Tobias Stoeckmann
69c171a5ab
Fix Visual Studio compiler warnings (64 bit) (#2189)
Some warnings are specific to 64 bit systems. Compiled with Visual
Studio 2022 on Windows 11 x64.

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
2024-05-14 19:55:51 -07:00
Tobias Stoeckmann
3085a3e9d3
[Windows] Fix test compilation warnings with Visual Studio (#2178)
Fixes all test-related compiler warnings with Visual Studio 2022 on
Windows 11.

Contains some changes from
https://github.com/libarchive/libarchive/pull/2095.

CC: @dunhor

---------

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
2024-05-12 12:26:19 -07:00
Tim Kientzle
8acb738db6
Overhaul Zip end-of-data marker parsing (#2042)
This significantly changes how end-of-data markers are parsed.

In particular, the spec allows the end-of-data marker to have either
32-bit or 64-bit size values, and there is basically no indication which
is being used. (The spec mentions "Zip64 mode" in many places, but there
is no definitive way for a Zip reader to know whether the writer is
using this mode or not. My mis-reading of another part of the spec
caused me to believe that the Zip64 Extra Data field was such a marker,
but I've been patiently corrected. ;-)

So a Zip reader just has to guess: Try every possible end-of-data marker
format and accept it if any of the four possible forms is correct. In
libarchive's case, this required some non-trivial additional refactoring
to ensure that the CRC32, compressed size, and uncompressed size
statistics are always updated _before_ we need to look for an
end-of-data marker.

This generally follows the strategy outlined by Mark Adler for his
`sunzip` streaming unzip implementation.

While testing this, I played with pmqs/zipdetails which pointed out a
discrepancy in how libarchive writes the `UT` extra field. I folded a
fix for that in here as well.

Resolves #1834

TODO: It would be nice to augment the test suite with some static files
created by Java's implementation to verify that we can read those when
they hold entries of +/- 4GiB. The existing
`test_write_format_zip_large` uses an ad hoc RLE encoding trick to
exercise writing and reading back multi-gigabyte entries. I wonder if
that could be generalized to support deflate-compressed Zip data stored
in test files?
2024-03-23 17:07:08 -07:00
AtariDreams
616c7dca2b
Replace __LA_DEAD with __LA_NORETURN (#2000)
Also add the MSC_VER version of the macro.
2023-12-04 08:29:29 -08:00
Brooks Davis
7dde502899
VCSid removal (#2017)
The libarchive source tree is littered with `__FBSDID("$FreeBSD.*")` and
'$FreeBSD$' tags left over from extracting it from FreeBSD's Subversion
repo. They never made sense for a git repo as git doesn't expand them
and FreeBSD has now removed `$FreeBSD$` from most local source files so
these stand out.

In addition to `__FBSDID` I've removed `__RCSID` which was used once for
a `$NetBSD$` expansion. There might be more of a case to be made for
preserving this one as a diff-reduction measure, but it seems mostly
pointless.

This builds and tests pass except for
libarchive_test_read_disk_directory_traversals which failed on master as
well.
2023-11-20 17:41:49 -08:00
AtariDreams
2edd881950
Use calloc arguments that correspond with the variable's true purpose (#1993)
First argument is number of times to allocate a region of the second
size, which is the size of the element being allocated.
2023-10-18 11:29:11 -07:00
Steve Lhomme
d9a7d05561 tests: use CreateFileA for char* filenames
In case the code is compiled with the UNICODE define.
2023-07-14 00:30:42 +02:00
Rosen Penev
0348e24bab
replace time64 functions with normal ones (#1830)
Otherwise there are 32/64-bit pointer conversions going on. In Windows
since MSVC2005, time_t has been 64-bit. MinGW needs a hack to get 64-bit
time_t.

Signed-off-by: Rosen Penev <rosenp@gmail.com>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2023-01-09 15:15:55 +01:00
Rosen Penev
2e9bcba706
further cleanup _localtime64_s (#1824)
These were missing from 2d329073435d36065ce30bfd29428f6a45e41016

Signed-off-by: Rosen Penev <rosenp@gmail.com>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-12-28 23:05:16 +01:00
Rosen Penev
2d32907343
cleanup _localtime64_s (#1820)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-12-20 13:48:42 +01:00
Martin Matuska
0eac3985f0 test_main.c: omit always-true comparsion
Reported by: CodeQL
Code Scanning Alert: 127
2022-12-08 16:26:37 +01:00
Martin Matuska
0d7cc9a041 tests: silence localtime() CodeQL warnings
Use localtime_r() or _localtime64_s() if available
2022-12-08 00:24:33 +01:00
Martin Matuska
673d82c57c tests: silence more CodeQL warnings in test_utils/test_main.c
Catch one more uncatched strcpy() and strcat()
2022-12-08 00:04:54 +01:00
Martin Matuska
43e1fe8e30 tests: silence some CodeQL warnings in test_utils/test_main.c
Use fchmod() instead of chmod() if available
Use strncpy() and strncat() instead of strcpy() and strcat()
2022-12-07 16:11:56 +01:00
Sean McBride
8ddc25de87 Fixed issue #1743: Changed sprintf to safer snprintf
Also changed a few vsprintf to vsnprintf.

Most cases were trivial, one private function was changed to take the buffer length, one case required some fancy arithmetic.
2022-06-22 22:23:20 -04:00
Martin Matuska
700dc6844a tests: fix style in test_utils/test_main.c 2022-02-08 08:27:11 +01:00
Tim Kientzle
e93b6c3009 Reorganize test code a bit
A few guiding principles:
* Each test source file includes ONLY "test.h" to make it easy
  to create new tests.
* Each test suite has a "test.h" that includes "test_util/test_common.h"
  to get access to all the common testing utility functions.

So "test_common.h" is then responsible for including
any smaller headers that declare specific pieces of
shared test functionality.

I've also pulled some test filtering logic that was _only_ used
in test_main.c into that file, and repurposed "test_utils.[ch]"
for common utility code.  (Eventually, a lot of the assertion
helpers currently in "test_main.c" should probably be organized
into one or more source files of their own.)
2022-02-01 19:33:41 -08:00
Alex Richardson
10a9214ac6 Avoid millions of rand() calls() when running tests
Many tests use a loop calling rand() to fill buffers with test data. As
these calls cannot be inlined, this adds up to noticeable overhead:
For example, running on QEMU RISC-V the test_write_format_7zip_large_copy
test took ~22 seconds before and with this change it's ~17 seconds.
This change uses a simpler xorshift64 random number generator that can be
inlined into the loop filling the data buffer. By default the seed for this
RNG is rand(), but it can be overwritten by setting the TEST_RANDOM_SEED
environment variable.

For a native build the difference is much less noticeable, but it's still
measurable: test_write_format_7zip_large_copy takes 314.9 ms ± 3.9 ms
before and 227.8 ms ± 5.8 ms after (i.e. 38% faster for that test).
2022-01-15 13:47:21 +00:00
jiat75
0f744f4e13 added missing checks for canLzip, canLzma, and canXz 2021-10-04 21:55:18 +08:00
Owen W. Taylor
9a952fe5a2 Avoid getcwd(0, PATH_MAX) for GNU libc
Recent versions of GNU libc and GCC produce a warning on getcwd(0, PATH_MAX):

 test_main.c: In function ‘get_refdir’:
 test_main.c:3684:8: error: argument 1 is null but the corresponding size argument 2 value is 4096 [-Werror=nonnull]
   3684 |  pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */

This is because getcwd() is marked with the 'write_only (1, 2)' attribute.

Using the alternate getcwd(NULL, 0) path which is supported by GNU libc avoids this.
2021-05-12 16:44:11 -04:00
Luis Henriques
12e7a1443d tests: add new assertion for chmod() 2020-09-25 10:12:11 +01:00
Kyle Evans
2ba0dbe8cd tests: mark failed_filename and tests static to fix WARNS=6 build
Observed on FreeBSD with a higher WARNS level on bsdcat/tests, these two
variables should be private to test_main.c in order to appease the build.
2020-09-08 13:58:32 -05:00
zoulasc
343642bcd2
Add printf attributes to the printflike functions used in tests and fix
the format errors.

Closes #1318
2020-01-23 00:19:32 +01:00
zoulasc
7e2c279835 - Add the NetBSD-specific config.h
- Use --help instead of -V when -V exits with non-zero code
- Double the string size to prevent truncation
2020-01-16 15:29:57 -05:00