Merge pull request #6262 from libgit2/ethomson/zero_stat tests: support flaky stat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 0ac8b8b..69b691e 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -248,6 +248,7 @@ jobs:
-e CMAKE_GENERATOR \
-e CMAKE_OPTIONS \
-e GITTEST_NEGOTIATE_PASSWORD \
+ -e GITTEST_FLAKY_STAT \
-e PKG_CONFIG_PATH \
-e SKIP_NEGOTIATE_TESTS \
-e SKIP_SSH_TESTS \
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 4f24be6..c26e1e2 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -247,6 +247,7 @@ jobs:
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON
RUN_INVASIVE_TESTS: true
SKIP_PROXY_TESTS: true
+ GITTEST_FLAKY_STAT: true
os: ubuntu-latest
- name: "Linux (arm64, Bionic, GCC, OpenSSL)"
container:
@@ -305,6 +306,7 @@ jobs:
-e CMAKE_GENERATOR \
-e CMAKE_OPTIONS \
-e GITTEST_NEGOTIATE_PASSWORD \
+ -e GITTEST_FLAKY_STAT \
-e PKG_CONFIG_PATH \
-e SKIP_NEGOTIATE_TESTS \
-e SKIP_SSH_TESTS \
diff --git a/tests/libgit2/diff/workdir.c b/tests/libgit2/diff/workdir.c
index a3e9290..20e0009 100644
--- a/tests/libgit2/diff/workdir.c
+++ b/tests/libgit2/diff/workdir.c
@@ -1238,6 +1238,7 @@ void test_diff_workdir__can_diff_empty_file(void)
git_tree *tree;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_patch *patch;
+ struct stat st = {0};
g_repo = cl_git_sandbox_init("attr_index");
@@ -1252,13 +1253,10 @@ void test_diff_workdir__can_diff_empty_file(void)
/* empty contents of file */
cl_git_rewritefile("attr_index/README.txt", "");
-#if !defined(__arm__) || !defined(GIT_ARCH_32)
- {
- struct stat st;
- cl_git_pass(git_fs_path_lstat("attr_index/README.txt", &st));
- cl_assert(st.st_size == 0);
- }
-#endif
+ cl_git_pass(git_fs_path_lstat("attr_index/README.txt", &st));
+
+ if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
+ cl_assert_equal_sz(0, st.st_size);
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
cl_assert_equal_i(3, (int)git_diff_num_deltas(diff));
diff --git a/tests/util/copy.c b/tests/util/copy.c
index 9b9f6ba..2613730 100644
--- a/tests/util/copy.c
+++ b/tests/util/copy.c
@@ -4,7 +4,7 @@
void test_copy__file(void)
{
- struct stat st;
+ struct stat st = {0};
const char *content = "This is some stuff to copy\n";
cl_git_mkfile("copy_me", content);
@@ -13,7 +13,9 @@ void test_copy__file(void)
cl_git_pass(git_fs_path_lstat("copy_me_two", &st));
cl_assert(S_ISREG(st.st_mode));
- cl_assert(strlen(content) == (size_t)st.st_size);
+
+ if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
+ cl_assert_equal_sz(strlen(content), (size_t)st.st_size);
cl_git_pass(p_unlink("copy_me_two"));
cl_git_pass(p_unlink("copy_me"));
@@ -21,7 +23,7 @@ void test_copy__file(void)
void test_copy__file_in_dir(void)
{
- struct stat st;
+ struct stat st = {0};
const char *content = "This is some other stuff to copy\n";
cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", 0775, GIT_MKDIR_PATH));
@@ -38,7 +40,9 @@ void test_copy__file_in_dir(void)
cl_git_pass(git_fs_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st));
cl_assert(S_ISREG(st.st_mode));
- cl_assert(strlen(content) == (size_t)st.st_size);
+
+ if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
+ cl_assert_equal_sz(strlen(content), (size_t)st.st_size);
cl_git_pass(git_futils_rmdir_r("an_dir", NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(!git_fs_path_isdir("an_dir"));
@@ -97,11 +101,15 @@ void test_copy__tree(void)
cl_assert(git_fs_path_isfile("t1/c/d/f4"));
cl_assert(!git_fs_path_isfile("t1/c/d/.f5"));
+ memset(&st, 0, sizeof(struct stat));
cl_git_pass(git_fs_path_lstat("t1/c/f3", &st));
cl_assert(S_ISREG(st.st_mode));
- cl_assert(strlen(content) == (size_t)st.st_size);
+
+ if (!cl_is_env_set("GITTEST_FLAKY_STAT"))
+ cl_assert_equal_sz(strlen(content), (size_t)st.st_size);
#ifndef GIT_WIN32
+ memset(&st, 0, sizeof(struct stat));
cl_git_pass(git_fs_path_lstat("t1/c/d/l1", &st));
cl_assert(S_ISLNK(st.st_mode));
#endif
@@ -127,6 +135,7 @@ void test_copy__tree(void)
cl_assert(git_fs_path_isfile("t2/c/d/.f5"));
#ifndef GIT_WIN32
+ memset(&st, 0, sizeof(struct stat));
cl_git_fail(git_fs_path_lstat("t2/c/d/l1", &st));
#endif