Skip to content

Commit 01908e9

Browse files
Add basic check that the correct number of tests is built (dotnet#19290)
Fixes #19286
1 parent 525b5e1 commit 01908e9

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

build-test.cmd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ for /l %%G in (1, 1, %__BuildLoopCount%) do (
335335
set __AppendToLog=true
336336
)
337337

338+
REM Check that we've built about as many tests as we expect. This is primarily intended to prevent accidental changes that cause us to build
339+
REM drastically fewer Pri-1 tests than expected.
340+
echo %__MsgPrefix%Check the managed tests build
341+
call %__DotnetHost% msbuild %__ProjectDir%\tests\runtest.proj /t:CheckTestBuild /p:CLRTestPriorityToBuild=%__Priority% %__msbuildArgs% %__unprocessedBuildArgs%
342+
if errorlevel 1 (
343+
echo %__MsgPrefix%Error: build failed.
344+
exit /b 1
345+
)
346+
338347
:SkipManagedBuild
339348

340349
REM =========================================================================================

build-test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ build_Tests()
252252
echo "${__MsgPrefix}Error: build failed. Refer to the build log files for details (above)"
253253
exit 1
254254
else
255+
echo "Checking the Managed Tests Build..."
256+
257+
if [ -n __priority1 ]; then
258+
__Priority=1
259+
else
260+
__Priority=0
261+
fi
262+
build_Tests_internal "Check_Test_Build" "${__ProjectDir}/tests/runtest.proj" "Check Test Build" "/t:CheckTestBuild /p:CLRTestPriorityToBuild=$__Priority"
263+
264+
if [ $? -ne 0 ]; then
265+
echo "${__MsgPrefix}Error: Check Test Build failed."
266+
exit 1
267+
fi
268+
255269
echo "Managed tests build success!"
256270
fi
257271

tests/runtest.proj

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<Target Name="FindCmdDirectories" DependsOnTargets="GetListOfTestCmds">
2828

2929
<Error Condition="!Exists('$(XunitTestBinBase)')"
30-
Text="$(XunitTestBinBase) does not exist. Please run buildtest.cmd from the (repo root)\tests at least once to get the tests built." />
30+
Text="$(XunitTestBinBase) does not exist. Please run build-test.cmd from the repo root at least once to get the tests built." />
3131

3232
<ItemGroup>
3333

@@ -54,6 +54,29 @@
5454

5555
</Target>
5656

57+
<!-- Target to check the test build, to see if it looks ok. We've had several cases where a change inadvertently and drastically changes
58+
the set of tests that are built, and that change is unnoticed. The most common case is for a build of the Priority 1 tests
59+
to only build the Priority 0 tests. This target is run after a test build to verify that the basic number of tests that were
60+
built is basically what was expected. When this was written, there were about 2500 Priority 0 tests and about 12270 Priority 1
61+
tests (differing slightly based on platform). We currently check that the number of Priority 0 tests is greater than 2000 and
62+
less than 3000, and the number of Priority 1 tests is greater than 12000.
63+
-->
64+
<Target Name="CheckTestBuild" DependsOnTargets="GetListOfTestCmds">
65+
<Error Condition="!Exists('$(XunitTestBinBase)')"
66+
Text="$(XunitTestBinBase) does not exist. Please run build-test.cmd from the repo root at least once to get the tests built." />
67+
68+
<PropertyGroup>
69+
<TestCount>@(AllRunnableTestPaths->Count())</TestCount>
70+
</PropertyGroup>
71+
72+
<Message Text="Found $(TestCount) built tests"/>
73+
74+
<Error Condition="'$(CLRTestPriorityToBuild)' == '0' and '$(TestCount)' &lt;= 2000" Text="Unexpected test count. Expected &gt; 2000, found $(TestCount).'" />
75+
<Error Condition="'$(CLRTestPriorityToBuild)' == '0' and '$(TestCount)' &gt;= 3000" Text="Unexpected test count. Expected &lt; 3000, found $(TestCount).'" />
76+
<Error Condition="'$(CLRTestPriorityToBuild)' == '1' and '$(TestCount)' &lt;= 12000" Text="Unexpected test count. Expected &gt; 12000, found $(TestCount).'" />
77+
<Error Condition="'$(CLRTestPriorityToBuild)' != '0' and '$(CLRTestPriorityToBuild)' != '1'" Text="Unknown priority $(CLRTestPriorityToBuild)" />
78+
</Target>
79+
5780
<Import Project="$(__Exclude)" Condition="'$(__Exclude)' != '' AND '$(XunitTestBinBase)' != ''" />
5881
<PropertyGroup>
5982
<HaveExcludes>False</HaveExcludes>

0 commit comments

Comments
 (0)