Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/BuildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ jobs:
sccache --version
# ENABLE_CACHE controls automatic ccache discovery; the explicit sccache launcher stays enabled.
# The heavy unit tests are compiled four to a file (docs/BUILD_TIME_STUDY.md); the portability and sanitizer jobs keep one object per test file.
# The unit tests run as four Catch2 shards instead of one process per scenario (docs/TEST_TIERS.md).
- name: Configure
run: >-
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DWEBFRONT_EMBED_CEF=OFF -DWEBFRONT_ENABLE_TESTING=ON
-DENABLE_CACHE=OFF -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
-DCMAKE_CXX_SCAN_FOR_MODULES=OFF
-DWEBFRONT_TEST_UNITY_BATCH=4
-DWEBFRONT_TEST_UNIT_SHARDS=4
-DWEBFRONT_TEST_REPRODUCIBILITY=${{ env.WEBFRONT_REPRODUCIBILITY }}
${{ env.FULL_TIER == 'true' && '' || '-DWEBFRONT_MSVC_ANALYZE=OFF -DWEBFRONT_BUILD_EXAMPLES=OFF' }}
${{ matrix.options }}
Expand Down Expand Up @@ -183,18 +185,21 @@ jobs:
# The fast tier (docs/TEST_TIERS.md): unit tests only, so a plain regression is reported before the browser suite starts.
- name: Fast tests
shell: bash
run: ctest --test-dir build -C ${{ matrix.build_type }} -L fast --parallel 4 --output-on-failure --no-tests=error
run: >-
ctest --test-dir build -C ${{ matrix.build_type }} -L fast --parallel 4 --output-on-failure --no-tests=error
--output-junit "${{ github.workspace }}/build/fast-results.xml"
- name: Capture CTest dependency graph
shell: bash
run: ctest --test-dir build --show-only=json-v1 > build/ctest-graph.json
- name: Test C++ and native browser integration
# The fast tier has just run: a single pass does not run it again; the three passes of the complete tier do.
# Only Linux trusted fixtures need the sandbox opt-out on hosted runners.
env: ${{ matrix.test_env }}
run: >-
python3 test/tools/MeasureCommand.py --output build/suite-resources.json --
cmake -DBUILD_DIR=build -DCONFIG=${{ matrix.build_type }}
-DREPEAT=${{ (github.event_name == 'schedule' || (github.event_name == 'pull_request' && github.base_ref == 'master') || (github.event_name == 'workflow_dispatch' && inputs.repeat_desktop_tests)) && '3' || '1' }}
-DLABEL_EXCLUDE=${{ (github.event_name == 'schedule' || (github.event_name == 'pull_request' && github.base_ref == 'master') || (github.event_name == 'workflow_dispatch' && inputs.repeat_desktop_tests)) && 'none' || 'portability' }}
'-DLABEL_EXCLUDE=${{ (github.event_name == 'schedule' || (github.event_name == 'pull_request' && github.base_ref == 'master') || (github.event_name == 'workflow_dispatch' && inputs.repeat_desktop_tests)) && 'none' || '^(portability|fast)$' }}'
-P test/cmake/RunTestSuite.cmake
- name: Repeat WebKitGTK pointer tests with suite display sharing enabled
if: runner.os == 'Linux'
Expand Down Expand Up @@ -277,6 +282,8 @@ jobs:
name: test-log-${{ runner.os }}
path: |
build/test-results-*.xml
build/fast-results.xml
build/unit-results-*.xml
build/ctest-graph.json
build/embedded-cache-probe.txt
build/test/unit/consumer-build/.ninja_log
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ these entries stays in the GitHub releases and the Git history.
### Changed

- Open the developer page on the interface, over the whole window, once the project has a preview; the terminal moves to a floating, movable window behind a tab on the right edge that shows the session's state, and keeps its session when collapsed. Its shortcut is F9, or the manifest's new optional `developer.terminalShortcut`. Environment sources 0.9.1, not published yet (#539, `docs/DEVELOPER_ENVIRONMENT.md`).
- Run the unit tests as a few processes instead of one per scenario with `-DWEBFRONT_TEST_UNIT_SHARDS=<n>`: each of the `n` CTest cases is a Catch2 shard that reports every scenario in `unit-results-<shard>.xml`. The default still registers one CTest case per scenario; the desktop CI jobs pass 4 and no longer run the fast tier twice on a pull request (#543).

### Fixed

Expand Down
17 changes: 13 additions & 4 deletions docs/TEST_TIERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ ctest --test-dir build -L portability # the portability tie
cmake -DBUILD_DIR=build -DLABEL_EXCLUDE=portability -P test/cmake/RunTestSuite.cmake
```

`RunTestSuite.cmake` runs every test unless `LABEL_EXCLUDE` names a label; the CI standard tier passes
`portability`. A local run before a change is declared complete (see `AGENTS.md`) runs everything.
`RunTestSuite.cmake` runs every test unless `LABEL_EXCLUDE` gives a regular expression of labels to leave out. The CI
standard tier passes `^(portability|fast)$`, because its fast step has just run the fast tier. A local run before a
change is declared complete (see `AGENTS.md`) runs everything.

By default every Catch2 scenario is a CTest case of its own, which `ctest -R` selects by name, and a process of its
own: more than 500 of them. `-DWEBFRONT_TEST_UNIT_SHARDS=4`, which the desktop CI jobs pass, registers four cases
`UnitTests-0` to `UnitTests-3` instead, each a Catch2 shard that runs a quarter of the scenarios in one process and
writes the result of each to `unit-results-<shard>.xml` in the build directory. The shards run the scenarios in their
declaration order, which is what makes four processes started separately split them without overlap. Scenarios then
share a process: `test/unit/ScenarioIsolation.cpp` restores the process-wide state a scenario may change. Run directly,
`tests` draws a random order and prints its seed, which `tests --rng-seed <seed>` replays.

## Following a browser test live

Expand Down Expand Up @@ -81,8 +90,8 @@ A pull request into `master` must pass all of: the desktop jobs, `portability` (
leg), `sanitizers` and `web-integration`. GitHub only enforces this once the checks are marked required in the branch
protection rules of `master`; the workflow cannot set that itself.

The fast tier does not replace the others: the unit tests are also part of the standard run, so a pull request still
reports one complete result.
The fast tier runs once on a pull request: the step that follows it runs everything else, and a failed fast step
fails the job before the browser suite starts. The three passes of the complete tier run the fast tier again each time.

The shared frontend lifecycle runner has a 45-second watchdog which reports the last observed stage and exits with a failure
status when the interface thread cannot be unwound. Forced process exit does not itself terminate browser subprocesses; they
Expand Down
12 changes: 10 additions & 2 deletions test/cmake/CheckTestSuiteRepetition.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,23 @@ enable_testing()
add_test(NAME Standard COMMAND "${CMAKE_COMMAND}" -E true)
add_test(NAME Portable COMMAND "${CMAKE_COMMAND}" -E false)
set_tests_properties(Portable PROPERTIES LABELS portability)
add_test(NAME Quick COMMAND "${CMAKE_COMMAND}" -E false)
set_tests_properties(Quick PROPERTIES LABELS fast)
]=])
run_bounded(COMMAND "${CMAKE_COMMAND}" -S "${WORK}/labels/source" -B "${WORK}/labels/build")
if(NOT result EQUAL 0)
message(FATAL_ERROR "Label fixture configure failed: ${output}${error}")
endif()
# The exclusion is a regular expression of labels: the standard tier of the CI leaves two of them out.
run_bounded(COMMAND "${CMAKE_COMMAND}" -DBUILD_DIR=${WORK}/labels/build -DCONFIG=Release "-DLABEL_EXCLUDE=^(portability|fast)$"
-P "${ROOT}/test/cmake/RunTestSuite.cmake")
if(NOT result EQUAL 0 OR "${output}${error}" MATCHES "Portable|Quick")
message(FATAL_ERROR "The excluded labels must not run: ${output}${error}")
endif()
run_bounded(COMMAND "${CMAKE_COMMAND}" -DBUILD_DIR=${WORK}/labels/build -DCONFIG=Release -DLABEL_EXCLUDE=portability
-P "${ROOT}/test/cmake/RunTestSuite.cmake")
if(NOT result EQUAL 0 OR "${output}${error}" MATCHES "Portable")
message(FATAL_ERROR "The excluded label must not run: ${output}${error}")
if(result EQUAL 0 OR "${output}${error}" MATCHES "Portable" OR NOT "${output}${error}" MATCHES "Quick")
message(FATAL_ERROR "Only the excluded label must be left out: ${output}${error}")
endif()
run_bounded(COMMAND "${CMAKE_COMMAND}" -DBUILD_DIR=${WORK}/labels/build -DCONFIG=Release
-P "${ROOT}/test/cmake/RunTestSuite.cmake")
Expand Down
24 changes: 22 additions & 2 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ list(APPEND TESTS_LIST FileSystemTests.cpp NativeFSTests.cpp DownloadsTests.cpp
list(APPEND TESTS_LIST DefaultFSTests.cpp StdnetShutdownTests.cpp SafePathTests.cpp UISubscribersTests.cpp)
list(APPEND TESTS_LIST ReadBindingTests.cpp ViewAssociationTests.cpp BroadcastTests.cpp WebFrontTests.cpp WebLinkTests.cpp CEFPathsTests.cpp CEFMacrosTests.cpp)
list(APPEND TESTS_LIST DeveloperTests.cpp WfDriverTests.cpp AutomationTests.cpp AutomationChannelTests.cpp AutomationStdioTests.cpp AutomationDiscoveryTests.cpp JasmineConsumerTests.cpp HostTests.cpp LifeTests.cpp StructuredShutdownTests.cpp JsFunctionSenderTests.cpp ApplicationTaskTests.cpp DeferredCallTests.cpp)
list(APPEND TESTS_LIST FrontendUrlTests.cpp ApplicationUrlTests.cpp FrontendContractTests.cpp UIExecutorTests.cpp NativeWindowTests.cpp CommandsTests.cpp EmbeddedCoreAssetsTests.cpp)
list(APPEND TESTS_LIST ScenarioIsolation.cpp FrontendUrlTests.cpp ApplicationUrlTests.cpp FrontendContractTests.cpp UIExecutorTests.cpp NativeWindowTests.cpp CommandsTests.cpp EmbeddedCoreAssetsTests.cpp)
if(WEBFRONT_USE_MDDLOG)
list(APPEND TESTS_LIST MddlogLoggerTests.cpp MddlogTransportTests.cpp)
endif()
Expand Down Expand Up @@ -84,7 +84,27 @@ endif()

include(${Catch2_SOURCE_DIR}/extras/Catch.cmake)
# Labels select the tiers (docs/TEST_TIERS.md): fast unit tests, browser integration, portability across toolchains.
catch_discover_tests(tests PROPERTIES TIMEOUT 60 LABELS fast)
# One CTest case per scenario starts one process per scenario: more than 500, which is most of the run time of the unit
# tests (docs/TEST_PERFORMANCE.md). WEBFRONT_TEST_UNIT_SHARDS runs them as that many processes instead, each a Catch2
# shard that writes the result of every scenario to a JUnit report. The default keeps one case per scenario, which
# `ctest -R` filters by name.
set(WEBFRONT_TEST_UNIT_SHARDS 0 CACHE STRING "Run the unit tests as this many CTest cases; 0 registers one case per scenario")
if(NOT WEBFRONT_TEST_UNIT_SHARDS MATCHES "^[0-9]+$")
message(FATAL_ERROR "WEBFRONT_TEST_UNIT_SHARDS must be a non-negative integer, not '${WEBFRONT_TEST_UNIT_SHARDS}'")
endif()
if(WEBFRONT_TEST_UNIT_SHARDS GREATER 0)
math(EXPR _last_shard "${WEBFRONT_TEST_UNIT_SHARDS} - 1")
foreach(_shard RANGE ${_last_shard})
# Catch2 shards the sorted list: the processes must sort alike, which a random order drawn by each would not.
add_test(NAME UnitTests-${_shard} COMMAND tests --order decl --shard-count ${WEBFRONT_TEST_UNIT_SHARDS} --shard-index ${_shard}
--reporter console::out=-::colour-mode=none
--reporter "junit::out=${CMAKE_BINARY_DIR}/unit-results-${_shard}.xml")
# The scenarios of a shard share its time limit; the slowest of them takes a few seconds.
set_tests_properties(UnitTests-${_shard} PROPERTIES TIMEOUT 600 LABELS fast)
endforeach()
else()
catch_discover_tests(tests PROPERTIES TIMEOUT 60 LABELS fast)
endif()

# The developer journey type-checks the declaration this tool writes from the hand-described settings (#383).
add_executable(forms_declaration FormsDeclaration.cpp)
Expand Down
36 changes: 36 additions & 0 deletions test/unit/ScenarioIsolation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0 OR CECILL-B
/// @brief Gives every scenario the process-wide state a process of its own would have, so that the scenarios pass in any
/// order within one process (WEBFRONT_TEST_UNIT_SHARDS, #543).
#include <webfront/tooling/Logger.hpp>

#include <catch2/catch_test_case_info.hpp>
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_registrars.hpp>

#include <array>

namespace {

/// The enabled severities are global: a scenario that raises them makes the next one log, and a connected browser is
/// sent what is logged at the debug level.
class ScenarioIsolation : public Catch::EventListenerBase {
public:
using Catch::EventListenerBase::EventListenerBase;

void testRunStarting(const Catch::TestRunInfo&) override {
for (std::size_t index = 0; index != severities.size(); ++index)
initial[index] = webfront::log::is(severities[index]);
}
void testCaseStarting(const Catch::TestCaseInfo&) override {
for (std::size_t index = 0; index != severities.size(); ++index)
webfront::log::set(severities[index], initial[index]);
}

private:
static constexpr std::array severities{webfront::log::Error, webfront::log::Warn, webfront::log::Info, webfront::log::Debug};
std::array<bool, 4> initial{};
};

} // namespace

CATCH_REGISTER_LISTENER(ScenarioIsolation)
Loading