Skip to content

Commit cac3782

Browse files
Meinersburmahesh-attarde
authored andcommitted
[Flang/Flang-RT] Fix OldUnit tests on Windows (llvm#150734)
Flang and Flang-RT have two flavours of unittests: 1. GTest unittests, using lit's `lit.formats.GoogleTest` format ending with `Tests${CMAKE_EXECUTABLE_SUFFIX}` 2. "non-GTest" or "OldUnit" unittests, a plain executable ending with `.test${CMAKE_EXECUTABLE_SUFFIX}` Both executables are emitted into the same unittests/ subdirectory. When running ... 1. `tests/Unit/lit.cfg.py`, only considers executable ending with `Tests` (or `Tests.exe` on Windows), hence skips the non-GTest tests. 2. `tests/NonGtestUnit/lit.cfg.py` considers all tests ending with `.test` or `.exe`. On Windows, The GTest unitests also end with `.exe`. In Flang-RT, `.exe` is considered an extension for non-GTest unitests which causes tests such as Flang's `RuntimeTests.exe` to be executed for both on Windows. This particular test includes a file write test, using a hard-coded filename `ucsfile`. If the two instances are executed concurrently, they might interfere with each other reading/writing `ucsfile` which results in a flaky test. This patch avoids the redundant execution by requiring the suffix `.test.exe` on Windows. lit has to be modified because it uses `os.path.splitext` the extract the extension, which would only recognize the last component. It was changed from the orginal `endswith` in c865abe for unknown reasons. In Flang, `.exe` is not considered a suffix for non-GTest unittests and hence they are not run at all. Fixing by also added `.test.exe` as valid suffix, like with Flang-RT. Unfortunately, the ` Evaluate/real.test.exe` test was failing on Windows: ``` FAIL: flang-OldUnit :: Evaluate/real.test.exe (3592 of 3592) ******************** TEST 'flang-OldUnit :: Evaluate/real.test.exe' FAILED ******************** ..\_src\flang\unittests\Evaluate\real.cpp:511: FAIL: FlagsToBits(prod.flags) == 0x18, not 0x10 0 0x800001 * 0xbf7ffffe ..\_src\flang\unittests\Evaluate\real.cpp:511: FAIL: FlagsToBits(prod.flags) == 0x18, not 0x10 0 0x800001 * 0x3f7ffffe ..\_src\flang\unittests\Evaluate\real.cpp:511: FAIL: FlagsToBits(prod.flags) == 0x18, not 0x10 0 0x80800001 * 0xbf7ffffe ..\_src\flang\unittests\Evaluate\real.cpp:511: FAIL: FlagsToBits(prod.flags) == 0x18, not 0x10 0 0x80800001 * 0x3f7ffffe ... ``` This is due to the `__x86_64__` macro not being set by Microsoft's cl.exe and hence floating point status flags not being read out. The equivalent macro for Microsofts compiler is `_M_X64` (or `_M_X64`).
1 parent 9189c29 commit cac3782

File tree

6 files changed

+9
-11
lines changed

6 files changed

+9
-11
lines changed

flang-rt/test/NonGtestUnit/lit.cfg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
config.name = "flang-rt-OldUnit"
99

1010
# suffixes: A list of file extensions to treat as test files.
11-
# On Windows, ".exe" also matches the GTests and will execited redundantly.
12-
config.suffixes = [".test", ".exe"]
11+
config.suffixes = [".test", ".test.exe"]
1312

1413
# test_source_root: The root path where unit test binaries are located.
1514
config.test_source_root = os.path.join(config.flangrt_binary_dir, "unittests")

flang/include/flang/Common/target-rounding.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct Rounding {
2121
// (viz., fail to set the Underflow flag when an inexact product of a
2222
// multiplication is rounded up to a normal number from a subnormal
2323
// in some rounding modes)
24-
#if __x86_64__ || __riscv || __loongarch__
24+
#if __x86_64__ || _M_X64 || __riscv || __loongarch__
2525
bool x86CompatibleBehavior{true};
2626
#else
2727
bool x86CompatibleBehavior{false};

flang/include/flang/Testing/fp-testing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ScopedHostFloatingPointEnvironment {
2727

2828
private:
2929
fenv_t originalFenv_;
30-
#if __x86_64__
30+
#if __x86_64__ || _M_X64
3131
unsigned int originalMxcsr;
3232
#endif
3333
};

flang/lib/Testing/fp-testing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#include <cstdio>
1212
#include <cstdlib>
1313
#include <cstring>
14-
#if __x86_64__
14+
#if __x86_64__ || _M_X64
1515
#include <xmmintrin.h>
1616
#endif
1717

1818
using Fortran::common::RealFlag;
1919
using Fortran::common::RoundingMode;
2020

2121
ScopedHostFloatingPointEnvironment::ScopedHostFloatingPointEnvironment(
22-
#if __x86_64__
22+
#if __x86_64__ || _M_X64
2323
bool treatSubnormalOperandsAsZero, bool flushSubnormalResultsToZero
2424
#else
2525
bool, bool
@@ -38,7 +38,7 @@ ScopedHostFloatingPointEnvironment::ScopedHostFloatingPointEnvironment(
3838
std::abort();
3939
}
4040

41-
#if __x86_64__
41+
#if __x86_64__ || _M_X64
4242
originalMxcsr = _mm_getcsr();
4343
unsigned int currentMxcsr{originalMxcsr};
4444
if (treatSubnormalOperandsAsZero) {
@@ -72,7 +72,7 @@ ScopedHostFloatingPointEnvironment::~ScopedHostFloatingPointEnvironment() {
7272
stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str());
7373
std::abort();
7474
}
75-
#if __x86_64__
75+
#if __x86_64__ || _M_X64
7676
_mm_setcsr(originalMxcsr);
7777
#endif
7878
}

flang/test/NonGtestUnit/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
config.name = "flang-OldUnit"
66

7-
config.suffixes = [".test"]
7+
config.suffixes = [".test", ".test.exe"]
88

99
config.test_source_root = os.path.join(config.flang_obj_root, "unittests")
1010
config.test_exec_root = config.test_source_root

llvm/utils/lit/lit/formats/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def getTestsForPath(self, testSuite, path_in_suite, litConfig, localConfig):
3434
if filename.startswith(".") or filename in localConfig.excludes:
3535
return
3636

37-
base, ext = os.path.splitext(filename)
38-
if ext in localConfig.suffixes:
37+
if any(filename.endswith(suffix) for suffix in localConfig.suffixes):
3938
yield lit.Test.Test(testSuite, path_in_suite, localConfig)
4039

4140
def getTestsInDirectory(self, testSuite, path_in_suite, litConfig, localConfig):

0 commit comments

Comments
 (0)