Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

tests: Fix stat tests on 32bit systems#7170

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

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

Conversation

@yelninei
Copy link

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
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
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
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
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.

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

2 participants