Skip to content

tests: Fix stat tests on 32bit systems#7170

Open
yelninei wants to merge 2 commits into
libgit2:mainfrom
yelninei:file-offset-bits
Open

tests: Fix stat tests on 32bit systems#7170
yelninei wants to merge 2 commits into
libgit2:mainfrom
yelninei:file-offset-bits

Conversation

@yelninei
Copy link
Copy Markdown

On 32bit systems the git_fs_path_lstat from libgit2 by default uses 32bit stat
structs while the tests are being compiled with struct stat64 via
_FILE_OFFSET_BITS=64.

This discrepancy causes the "flaky" stat failures in tests.

The solution is to use the same _FILE_OFFSET_BITS as the library by
leaving it up to the user to define _FILE_OFFSET_BIT.

Also remove GITTEST_FLAKY_STAT (in as separate commit) as it should no longer be necessary.

Fixes: #7169

On 32bit systems the git_fs_path_lstat from libgit2 by default uses 32bit stat
structs while the tests are being compiled with struct stat64 via
_FILE_OFFSET_BITS=64.

This discrepancy causes the "flaky" stat failures in tests.

The solution is to use the same _FILE_OFFSET_BITS as the library by
leaving it up to the user to define _FILE_OFFSET_BIT.
This was caused by the tests being compiled with -D_FILE_OFFSET_BITS=64
which causes incompatibilities if libgit2 itself is not.

As this has been resolved the environment variable is no longer
necessary and can be removed.
@yelninei yelninei changed the title File offset bits tests: Fix stat tests on 32bit systems Dec 15, 2025
@yelninei
Copy link
Copy Markdown
Author

Would it be possible to run the ci on 32bit arm (which does not have the 64 bit time_t transition from debian 13) to see if this indeed fixes the issue?

@ethomson
Copy link
Copy Markdown
Member

One of the nightly builds is on a 32 bit arm platform — https://github.com/libgit2/libgit2/actions/runs/20870863585/job/59972059810

It hasn't seemed to be flaky. But maybe it's being compiled slightly differently than yours?

We build and test within containers on Linux so it may be possible to repro our environment locally and / or update the build environment to match your case.

@yelninei
Copy link
Copy Markdown
Author

For context of how I discovered this:

I caught this assert in https://github.com/libgit2/libgit2/blob/main/tests/libgit2/repo/init.c#L445 (on a 32bit hurd system, which has a different order in the stat struct than linux)

repo::init::extended_1 [tests/libgit2/repo/init.c:445]
cl_assert(S_ISDIR(st.st_mode));

Looking at the stat struct in a debugger it was completely garbled caused by enormous values in st_ino and st_size and then I found the FILE_OFFSET_BITS=64 only for the tests.

This test also has been marked as "flaky" on debian https://sources.debian.org/src/libgit2/1.9.2%2Bds-2/debian/patches/disable-flaky-stat-tests.patch probably for the same reason.

The problem is that git_fs_path_lstat and the test disagree on the size and layout of the stat struct.
For this I went with removing from the tests as compiling libgit2 with FILE_OFFSET_BITS=64 is probably an ABI change.

@yelninei
Copy link
Copy Markdown
Author

yelninei commented Jan 12, 2026

I am reading #4631

and am really confused what happened here.

It seems i encounter the same issue but in reverse (casting stat32 struct to stat64)

The other pr mentions that libgit2 used to be always compiled with _FILE_OFFSET_BITS=64 so putting it to the tests aswell made sense.

I think the timelime is something like this:

  • fac7eac : Compile tests with FILE_OFFSET_BITS=64
  • ef4ab29 : moved it from libgit2 from src/CMakeLists.txt to src/libgit2/CMakeLists.txt
  • 91ba089: Removed it from libgit2 entirely.
  • e7fce1b : introduces GITTEST_FLAKY_STAT
    -v1.5 is the earliest version with "flaky" stat tests.

@yelninei
Copy link
Copy Markdown
Author

@ethomson any update?

Either always set _FILE_OFFSET_BITS=64 or never, but this half solution is just full of issues in the default configuration

@ethomson
Copy link
Copy Markdown
Member

Sorry, I parked this since it had CI failures, but those seem unrelated.

Thanks for the timeline. It looks like we just erroneously removed it from the library itself. It's still defined by the tests and benchmarks.

We want to support 64 bit file sizes, I think that we should make sure that _FILE_OFFSET_BITS=64 is enabled everywhere.

@yelninei
Copy link
Copy Markdown
Author

Is there a way to set this globably somewhere with cmake?

reading the cmake documentation for add_definitions it seems to only apply to targets in the current directory

is this exposed in the api/abi or purely an implementation detail? (if yes it would need to be propagated from the library to make sure every user is also using FILE_OFFSET_BITS=64)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_FILE_OFFSET_BITS=64 breaks tests on 32bit systems

3 participants