Skip to content

Commit 897b0d5

Browse files
authored
Reapply "[Windows] Run native unit tests in CI (#13923)"
Differential Revision: D82345075 Pull Request resolved: #14287
1 parent b5523cd commit 897b0d5

File tree

31 files changed

+236
-112
lines changed

31 files changed

+236
-112
lines changed

.ci/scripts/setup-windows.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
param (
2-
[string]$editable = $false
2+
[string]$editable = "false"
33
)
44

55
conda create --yes --quiet -n et python=3.12

.ci/scripts/unittest-windows.ps1

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
param (
2-
[string]$editable = $false
2+
[string]$buildMode = "Release"
33
)
44

55
Set-PSDebug -Trace 1
66
$ErrorActionPreference = 'Stop'
77
$PSNativeCommandUseErrorActionPreference = $true
88

9-
# Run pytest with coverage
10-
# pytest -n auto --cov=./ --cov-report=xml
11-
pytest -v --full-trace -c pytest-windows.ini
9+
# Run native unit tests (via ctest)
10+
New-Item -Path "test-build" -ItemType Directory
11+
cd "test-build"
12+
13+
cmake .. --preset windows -B . -DEXECUTORCH_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=$buildMode
1214
if ($LASTEXITCODE -ne 0) {
13-
Write-Host "Pytest invocation was unsuccessful. Exit code: $LASTEXITCODE."
15+
Write-Host "CMake configuration was unsuccessful. Exit code: $LASTEXITCODE."
16+
exit $LASTEXITCODE
17+
}
18+
19+
cmake --build . -j8 --config $buildMode --verbose
20+
if ($LASTEXITCODE -ne 0) {
21+
Write-Host "CMake build was unsuccessful. Exit code: $LASTEXITCODE."
1422
exit $LASTEXITCODE
1523
}
24+
25+
ctest -j8 . --build-config $buildMode --output-on-failure -E "method_test|tensor_parser_test"
26+
if ($LASTEXITCODE -ne 0) {
27+
Write-Host "CTest run was unsuccessful. Exit code: $LASTEXITCODE."
28+
exit $LASTEXITCODE
29+
}
30+
31+
cd ..
32+
33+
# Run pytest
34+
pytest -v -c pytest-windows.ini
35+
if ($LASTEXITCODE -ne 0) {
36+
Write-Host "Pytest invocation was unsuccessful. Exit code: $LASTEXITCODE."
37+
exit $LASTEXITCODE
38+
}

.github/workflows/_unittest.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ jobs:
6969
\$ErrorActionPreference = 'Stop'
7070
\$PSNativeCommandUseErrorActionPreference = \$true
7171
72-
.ci/scripts/setup-windows.ps1
72+
.ci/scripts/setup-windows.ps1 -editable "${{ inputs.editable }}"
73+
if (\$LASTEXITCODE -ne 0) {
74+
Write-Host "Setup failed. Exit code: \$LASTEXITCODE."
75+
exit \$LASTEXITCODE
76+
}
7377
74-
powershell .ci/scripts/unittest-windows.ps1 -editable "${{ inputs.editable }}"
78+
.ci/scripts/unittest-windows.ps1 -buildMode "${{ inputs.build-mode }}"
79+
if (\$LASTEXITCODE -ne 0) {
80+
Write-Host "Unit tests failed. Exit code: \$LASTEXITCODE."
81+
exit \$LASTEXITCODE
82+
}
7583
}"

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,5 +1032,5 @@ jobs:
10321032
10331033
.ci/scripts/setup-windows.ps1
10341034
1035-
powershell .ci/scripts/test_model.ps1 -modelName ${{ matrix.model }} -backend ${{ matrix.backend }}
1035+
.ci/scripts/test_model.ps1 -modelName ${{ matrix.model }} -backend ${{ matrix.backend }}
10361036
}"

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ endif()
143143

144144
# -ffunction-sections -fdata-sections: breaks function and data into sections so
145145
# they can be properly gc'd. -s: strip symbol.
146-
set(CMAKE_CXX_FLAGS_RELEASE
147-
"-ffunction-sections -fdata-sections ${CMAKE_CXX_FLAGS_RELEASE}"
148-
)
146+
if(WIN32)
147+
set(CMAKE_CXX_FLAGS_RELEASE "/Gy /Gw ${CMAKE_CXX_FLAGS_RELEASE}")
148+
else()
149+
set(CMAKE_CXX_FLAGS_RELEASE
150+
"-ffunction-sections -fdata-sections ${CMAKE_CXX_FLAGS_RELEASE}"
151+
)
152+
endif()
149153
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
150154
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
151155
endif()

backends/xnnpack/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ foreach(fbs_file ${_xnnpack_schema__srcs})
5959
)
6060
endforeach()
6161

62-
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
62+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
6363
set(MV_COMMAND
6464
powershell -Command
6565
"Move-Item -Path ${_xnnpack_flatbuffer__outputs} -Destination ${_xnnpack_schema__outputs} -Force"

export/target_recipes.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,32 @@
1111
selection and combine multiple backends optimally for target hardware.
1212
"""
1313

14+
import sys
1415
from typing import Dict, List
1516

16-
import coremltools as ct
17+
if sys.platform != "win32":
18+
import coremltools as ct
19+
from executorch.backends.apple.coreml.recipes import CoreMLRecipeType
1720

1821
# pyre-ignore
19-
from executorch.backends.apple.coreml.recipes import CoreMLRecipeType
2022
from executorch.backends.xnnpack.recipes import XNNPackRecipeType
2123
from executorch.export.recipe import ExportRecipe, RecipeType
2224

2325

2426
## IOS Target configs
2527
# The following list of recipes are not exhaustive for CoreML; refer to CoreMLRecipeType for more detailed recipes.
26-
IOS_CONFIGS: Dict[str, List[RecipeType]] = {
27-
# pyre-ignore
28-
"ios-arm64-coreml-fp32": [CoreMLRecipeType.FP32, XNNPackRecipeType.FP32],
29-
# pyre-ignore
30-
"ios-arm64-coreml-fp16": [CoreMLRecipeType.FP16],
31-
# pyre-ignore
32-
"ios-arm64-coreml-int8": [CoreMLRecipeType.PT2E_INT8_STATIC],
33-
}
28+
IOS_CONFIGS: Dict[str, List[RecipeType]] = (
29+
{
30+
# pyre-ignore
31+
"ios-arm64-coreml-fp32": [CoreMLRecipeType.FP32, XNNPackRecipeType.FP32],
32+
# pyre-ignore
33+
"ios-arm64-coreml-fp16": [CoreMLRecipeType.FP16],
34+
# pyre-ignore
35+
"ios-arm64-coreml-int8": [CoreMLRecipeType.PT2E_INT8_STATIC],
36+
}
37+
if sys.platform != "win32"
38+
else {}
39+
)
3440

3541

3642
def _create_target_recipe(

export/tests/test_target_recipes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@
77
# pyre-strict
88

99
import logging
10+
import sys
1011
import unittest
1112

1213
import torch
13-
from executorch.backends.apple.coreml.recipes import CoreMLRecipeProvider # pyre-ignore
1414
from executorch.backends.xnnpack.recipes.xnnpack_recipe_provider import (
1515
XNNPACKRecipeProvider,
1616
)
1717
from executorch.export import export, recipe_registry
1818
from executorch.export.target_recipes import get_ios_recipe
1919
from executorch.runtime import Runtime
2020

21+
if sys.platform != "win32":
22+
from executorch.backends.apple.coreml.recipes import ( # pyre-ignore
23+
CoreMLRecipeProvider,
24+
)
25+
2126

2227
class TestTargetRecipes(unittest.TestCase):
2328
"""Test target recipes."""
@@ -26,12 +31,14 @@ def setUp(self) -> None:
2631
torch._dynamo.reset()
2732
super().setUp()
2833
recipe_registry.register_backend_recipe_provider(XNNPACKRecipeProvider())
29-
# pyre-ignore
30-
recipe_registry.register_backend_recipe_provider(CoreMLRecipeProvider())
34+
if sys.platform != "win32":
35+
# pyre-ignore
36+
recipe_registry.register_backend_recipe_provider(CoreMLRecipeProvider())
3137

3238
def tearDown(self) -> None:
3339
super().tearDown()
3440

41+
@unittest.skipIf(sys.platform == "win32", "Core ML is not available on Windows.")
3542
def test_ios_fp32_recipe_with_xnnpack_fallback(self) -> None:
3643
# Linear ops skipped by coreml but handled by xnnpack
3744
class Model(torch.nn.Module):
@@ -107,6 +114,7 @@ def forward(self, x, y):
107114
et_output = session.run_method("forward", example_inputs[0])
108115
logging.info(f"et output {et_output}")
109116

117+
@unittest.skipIf(sys.platform == "win32", "Core ML is not available on Windows.")
110118
def test_ios_quant_recipes(self) -> None:
111119
class Model(torch.nn.Module):
112120
def __init__(self):

extension/evalue_util/test/print_evalue_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ TEST(PrintEvalueTest, UnelidedBoolLists) {
267267
// case; the other scalar types use the same underlying code, so they don't
268268
// need to test this again.
269269
{
270-
EValue value(ArrayRef<bool>(list.data(), 0ul));
270+
EValue value(ArrayRef<bool>(list.data(), static_cast<size_t>(0ul)));
271271
expect_output(value, "(len=0)[]");
272272
}
273273
{
@@ -419,7 +419,7 @@ TEST(PrintEvalueTest, UnelidedDoubleLists) {
419419
std::array<double, 6> list = {-2.2, -1, 0, INFINITY, NAN, 3.3};
420420

421421
{
422-
EValue value(ArrayRef<double>(list.data(), 0ul));
422+
EValue value(ArrayRef<double>(list.data(), static_cast<size_t>(0ul)));
423423
expect_output(value, "(len=0)[]");
424424
}
425425
{

extension/flat_tensor/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ add_custom_command(
2323
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
2424
COMMAND
2525
${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAddMul"
26-
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
26+
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}"
2727
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
2828
)
2929

0 commit comments

Comments
 (0)