From 9e1923e84d0803b27ae07e46f0d177cfbc52e0cb Mon Sep 17 00:00:00 2001 From: Martin Matuska Date: Sun, 7 Apr 2019 01:54:42 +0200 Subject: [PATCH] Fix remaining MinGW tests Enable tests on MinGW CI builds --- .cirrus.yml | 8 ++++-- build/ci/travis_ci.sh | 3 +-- cpio/test/test_format_newc.c | 5 ++++ cpio/test/test_option_L_upper.c | 8 ++++-- cpio/test/test_option_a.c | 5 ++++ .../test_read_disk_directory_traversals.c | 23 +++++++++++++++++ tar/test/test_option_C_mtree.c | 17 ++++++++++++- tar/test/test_strip_components.c | 3 ++- test_utils/test_main.c | 25 ++++++++++++++++--- 9 files changed, 86 insertions(+), 11 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index d3627afc9..acf4c8a28 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -51,14 +51,13 @@ Windows_MinGW_task: prepare_script: - choco install -y --no-progress mingw - choco install -y --no-progress --installargs 'ADD_CMAKE_TO_PATH=User' cmake - - choco install -y --no-progress wget - refreshenv - mkdir build_ci\mingw zlib_script: - refreshenv - mkdir build_ci\libs - cd build_ci\libs - - wget "https://www.zlib.net/zlib-1.2.11.tar.gz" + - curl -o zlib-1.2.11.tar.gz "https://www.zlib.net/zlib-1.2.11.tar.gz" - tar -x -z -f zlib-1.2.11.tar.gz - cd zlib-1.2.11 - cmake -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE="Release" . @@ -72,3 +71,8 @@ Windows_MinGW_task: - refreshenv - cd build_ci\mingw - mingw32-make + test_script: + - refreshenv + - copy build_ci\libs\zlib-1.2.11\libzlib.dll build_ci\mingw\bin\ + - cd build_ci\mingw + - mingw32-make test diff --git a/build/ci/travis_ci.sh b/build/ci/travis_ci.sh index e51a67931..abbdd8d38 100755 --- a/build/ci/travis_ci.sh +++ b/build/ci/travis_ci.sh @@ -21,8 +21,7 @@ case "$UNAME" in set -x cmake -G "MSYS Makefiles" -D CMAKE_C_COMPILER="${CC}" -D CMAKE_MAKE_PROGRAM="mingw32-make" -D CMAKE_BUILD_TYPE="Release" "${SRCDIR}" mingw32-make - # The MinGW tests time out on Travis CI, disable for now - #mingw32-make test + mingw32-make test set +x else echo "Unknown or unspecified build type: ${BS}" diff --git a/cpio/test/test_format_newc.c b/cpio/test/test_format_newc.c index 2c6694267..6c981f6ac 100644 --- a/cpio/test/test_format_newc.c +++ b/cpio/test/test_format_newc.c @@ -233,7 +233,12 @@ DEFINE_TEST(test_format_newc) assert(is_hex(e, 110)); assertEqualMem(e + 0, "070701", 6); /* Magic */ assert(is_hex(e + 6, 8)); /* ino */ +#if defined(_WIN32) && !defined(CYGWIN) + /* Mode: Group members bits and others bits do not work. */ + assertEqualInt(0xa180, from_hex(e + 14, 8) & 0xffc0); +#else assertEqualInt(0xa1ff, from_hex(e + 14, 8)); /* Mode */ +#endif assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ assertEqualMem(e + 38, "00000001", 8); /* nlink */ diff --git a/cpio/test/test_option_L_upper.c b/cpio/test/test_option_L_upper.c index 7fd10cefc..bf3a9c430 100644 --- a/cpio/test/test_option_L_upper.c +++ b/cpio/test/test_option_L_upper.c @@ -30,8 +30,10 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_L.c,v 1.2 2008/08/24 06:21 * tests won't run on Windows. */ #if defined(_WIN32) && !defined(__CYGWIN__) #define CAT "type" +#define SEP "\\" #else #define CAT "cat" +#define SEP "/" #endif DEFINE_TEST(test_option_L_upper) @@ -77,7 +79,8 @@ DEFINE_TEST(test_option_L_upper) assertMakeDir("unpack", 0755); assertChdir("unpack"); - r = systemf(CAT " ../archive.out | %s -i >unpack.out 2>unpack.err", testprog); + r = systemf(CAT " .." SEP "archive.out | %s -i >unpack.out 2>unpack.err", testprog); + failure("Error invoking %s -i", testprog); assertEqualInt(r, 0); assertTextFileContents("1 block\n", "unpack.err"); @@ -92,7 +95,8 @@ DEFINE_TEST(test_option_L_upper) assertMakeDir("unpack-L", 0755); assertChdir("unpack-L"); - r = systemf(CAT " ../archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog); + r = systemf(CAT " .." SEP "archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog); + failure("Error invoking %s -i < archive-L.out", testprog); assertEqualInt(r, 0); assertTextFileContents("1 block\n", "unpack-L.err"); diff --git a/cpio/test/test_option_a.c b/cpio/test/test_option_a.c index 296387777..e96bdf3ca 100644 --- a/cpio/test/test_option_a.c +++ b/cpio/test/test_option_a.c @@ -71,8 +71,13 @@ test_create(void) * #ifdef this section out. Most of the test below is * still valid. */ memset(×, 0, sizeof(times)); +#if defined(_WIN32) && !defined(CYGWIN) + times.actime = 86400; + times.modtime = 86400; +#else times.actime = 1; times.modtime = 3; +#endif assertEqualInt(0, utime(files[i].name, ×)); /* Record whatever atime the file ended up with. */ diff --git a/libarchive/test/test_read_disk_directory_traversals.c b/libarchive/test/test_read_disk_directory_traversals.c index 1e41c3caa..7dd19157d 100644 --- a/libarchive/test/test_read_disk_directory_traversals.c +++ b/libarchive/test/test_read_disk_directory_traversals.c @@ -40,7 +40,30 @@ atimeIsUpdated(void) { const char *fn = "fs_noatime"; struct stat st; +#if defined(_WIN32) && !defined(CYGWIN) + char *buff = NULL; + char *ptr; + int r; + r = systemf("fsutil behavior query disableLastAccess > query_atime"); + if (r == 0) { + buff = slurpfile(NULL, "query_atime"); + if (buff != NULL) { + ptr = buff; + while(*ptr != '\0' && !isdigit(*ptr)) { + ptr++; + } + if (*ptr == '0') { + free(buff); + return(1); + } else if (*ptr == '1' || *ptr == '2') { + free(buff); + return(0); + } + free(buff); + } + } +#endif if (!assertMakeFile(fn, 0666, "a")) return (0); if (!assertUtimes(fn, 1, 0, 1, 0)) diff --git a/tar/test/test_option_C_mtree.c b/tar/test/test_option_C_mtree.c index caf8044bf..f09030668 100644 --- a/tar/test/test_option_C_mtree.c +++ b/tar/test/test_option_C_mtree.c @@ -36,6 +36,9 @@ DEFINE_TEST(test_option_C_mtree) p0 = NULL; char *content = "./foo type=file uname=root gname=root mode=0755\n"; char *filename = "output.tar"; +#if defined(_WIN32) && !defined(CYGWIN) + char *p; +#endif /* an absolute path to mtree file */ char *mtree_file = "/METALOG.mtree"; @@ -48,9 +51,21 @@ DEFINE_TEST(test_option_C_mtree) assertMakeDir("bar", 0775); assertMakeFile("bar/foo", 0777, "abc"); - r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path); +#if defined(_WIN32) && !defined(CYGWIN) + p = absolute_path; + while(*p != '\0') { + if (*p == '/') + *p = '\\'; + p++; + } + r = systemf("%s -cf %s -C bar @%s >step1.out 2>step1.err", testprog, filename, absolute_path); failure("Error invoking %s -cf %s -C bar @%s", testprog, filename, absolute_path); +#else + r = systemf("%s -cf %s -C bar \"@%s\" >step1.out 2>step1.err", testprog, filename, absolute_path); + failure("Error invoking %s -cf %s -C bar \"@%s\"", testprog, filename, absolute_path); +#endif + assertEqualInt(r, 0); assertEmptyFile("step1.out"); assertEmptyFile("step1.err"); diff --git a/tar/test/test_strip_components.c b/tar/test/test_strip_components.c index e1d71ddc5..caf45a3e1 100644 --- a/tar/test/test_strip_components.c +++ b/tar/test/test_strip_components.c @@ -64,9 +64,10 @@ DEFINE_TEST(test_strip_components) failure("d0/d1/s2 is a symlink to something that won't be extracted"); /* If platform supports symlinks, target/s2 is a broken symlink. */ /* If platform does not support symlink, target/s2 doesn't exist. */ - assertFileNotExists("target/s2"); if (canSymlink()) assertIsSymlink("target/s2", "d2/f1"); + else + assertFileNotExists("target/s2"); failure("d0/d1/d2 should be extracted"); assertIsDir("target/d2", -1); diff --git a/test_utils/test_main.c b/test_utils/test_main.c index 91effdf58..cd4c772b8 100644 --- a/test_utils/test_main.c +++ b/test_utils/test_main.c @@ -1717,16 +1717,30 @@ is_symlink(const char *file, int line, REPARSE_DATA_BUFFER *buf; size_t len, len2; wchar_t *linknamew, *contentsw; + const char *p; + char *s, *pn; int ret = 0; BYTE *indata; DWORD flag = FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT; - if (contents == NULL) - return (0); + /* Replace slashes with backslashes in pathname */ + pn = malloc((strlen(pathname) + 1) * sizeof(char)); + p = pathname; + s = pn; + while(*p != '\0') { + if(*p == '/') + *s = '\\'; + else + *s = *p; + p++; + s++; + } + *s = '\0'; - h = CreateFileA(pathname, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, + h = CreateFileA(pn, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, flag, NULL); + free(pn); if (h == INVALID_HANDLE_VALUE) return (0); @@ -1747,6 +1761,11 @@ is_symlink(const char *file, int line, return (0); } + if (contents == NULL) { + free(indata); + return (1); + } + len = buf->SymbolicLinkReparseBuffer.SubstituteNameLength; linknamew = malloc(len + sizeof(wchar_t)); -- 2.47.2