93 Commits
Author SHA1 Message Date
Dustin L. Howett 617d422c86 test: make Windows file assertions act like lstat
I've removed our lstat shim and replaced all uses with my_GetFileInformationByName.
2026-07-07 10:24:00 -05:00
Dag-Erling Smørgrav d4fa1de0ad test: Fix off-by-one in bounds check
Fixes:		0e4fa9ff0d ("test: promote the win32-repairing systemf wrapper to all systemf calls")
2026-06-24 18:25:00 +02:00
Dustin L. Howett 0e4fa9ff0d test: promote the win32-repairing systemf wrapper to all systemf calls 2026-06-15 15:08:02 -05:00
Tim Kientzle e46e2c389a [test_utils] Fix a minor UB
(UBSan occasionally finds something interesting and
often reports whacky non-bugs like this one. "Fixing"
it will make the real UB bugs easier to identify, so...)

According to C's integer promotion rules, `unsigned short` gets
promoted to _signed_ `int`, and shifting into the sign bit of an `int`
is technically UB.  Explicit cast to `unsigned` quiets UBSan.
2026-05-07 21:50:50 -07:00
Tim Kientzle 28b670d1ed Clarify the test harness usage 2026-05-05 14:45:26 -07:00
Dag-Erling Smørgrav bfa16c05a2 test_main: Staticize some variables
These variables are not used outside test_main, so they should be static.

Fixes:		a252c60308 ("test_main: Run tests as unprivileged user")
2026-04-17 18:46:59 +02:00
Dag-Erling Smørgrav a252c60308 test_main: Run tests as unprivileged user
If run as root (as is the case in CI), switch to an unprivileged user
(default: nobody) before running each test, and switch back after.
This makes it possible to write tests that rely on file permissions.

Note that tests that use the UID or GID must now check the EUID / EGID
instead as they will be different while the test is running.  The only
way to avoid that is to run each test case in a child process, which
would hugely increase the complexity of test_run().
2026-03-02 12:42:05 +01:00
Dag-Erling Smørgrav 0de2f8ee8d test_main: Add assertChown 2026-03-02 12:42:05 +01:00
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 StoeckmannandDuncan Horn 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 StoeckmannandDuncan Horn 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 2d32907343

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