From 6f411e4ab882e5c771f4e791114fc9d42e24207c Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Thu, 18 Jul 2024 17:51:06 +0100 Subject: [PATCH] Restore integtests and add to CI as warning comment on failure (#7404) * Add coverage for both targets * Use var for test bins * Disable cmake-format comment fiddling * Refactor GUI source config * Use bin var for tests * Remove unused member * Add integration tests to CI * Use modern cmake args * Use max threads for build * Use better var name for CPU core count * Split build and configure steps * Combine tests into action and add a PR comment * Fixed yaml indentation in action * Pass GITHUB_TOKEN * Update coverage paths for SonarCloud * Don't ignore return codes * Add shell * Run Valgrind on integ tests * Use header for tests * Save test results in table * Move setup step outside of action * Change logic of creating PR comment * Remove header formatting * Use emojis for simplicity * Run build wrapper in build dir * Use default make target * Pass secrets * Fixed SonarScanner warnings * Don't allow unit tests to fail * Fixed typo * Update sonar scanner paths * Fixed line endings * Use step output * Improve exclusion glob * Exclude files from coverage * Restore simpler pattern * Set temp file path * Coverage tests * Re-create comment at start of job * Append table header * Add setup action * Checkout before action * Re-add projectBaseDir * Restore original sonar scanner * Use bash syntax for if * Remove unused `shell` * Add missing shell for valgrind action * Restore new sonar scanner config * Add missing shell * Run only MainWindowTests * Test with big change * More changes * Move to correct dir * Remove test code * Disable broken integ tests * Switch coverage to front of filename * Remove filter * Refactor status step * Disable segfault test * Fixed: No status showing * Add link to workflows * Add test code for coverage * Revert "Add test code for coverage" This reverts commit c42309349b64f7828f2ca89149b30c5b0f93478a. * Get workflow run URL * Add missing shell * Use dynamic URL in valgrind comment * Revert "Revert "Add test code for coverage"" This reverts commit 9cff58b7ea5c581681ae6d6660c073bd76ba99aa. * Test with commented out code * Reintroduce 6 lines for coverage * Test code to pass scanner * Test code to pass scanner (take 2) * Simplify to 2 new lines * Add another line * Trim changes to only 3 lines * Add task for all tests * Surface warning on failure * Simplify build-wrapper step and move settings from web UI to CI * Add missing line delims * Also run tests action on Windows and macOS * Add names to action steps * Add timeout for test steps * Add failure warning for integ tests * Remove space * Disable failing test on macOS * Disable problem matcher * Simplify names * Disable freezing test on Windows * Disable failing integ test on Windows * Add build-kill task * Ignore kill result on Windows * Delete test code * Update ChangeLog * Move timeout to workflow step --- .github/actions/dist-upload/action.yml | 15 +++-- .github/actions/run-tests-setup/action.yml | 39 +++++++++++ .github/actions/run-tests/action.yml | 66 +++++++++++++++++++ .github/actions/run-valgrind/action.yml | 41 ++++++++++++ .github/workflows/ci.yml | 38 ++++++++--- .github/workflows/sonarcloud-analysis.yml | 61 ++++++++++++----- .github/workflows/valgrind-analysis.yml | 48 +++++++------- .vscode/launch.json | 2 +- .vscode/tasks.json | 33 +++++++--- ChangeLog | 1 + cmake-format.yaml | 3 +- cmake/Definitions.cmake | 3 + cmake/Libraries.cmake | 22 +++++-- src/gui/src/MainWindow.cpp | 1 + src/gui/src/QIpcClient.cpp | 1 + src/test/CMakeLists.txt | 48 ++++++++------ src/test/integtests/CMakeLists.txt | 2 +- src/test/integtests/gui/MainWindowTests.cpp | 7 +- src/test/integtests/main.cpp | 28 ++++---- src/test/integtests/net/NetworkTests.cpp | 6 +- .../platform/MSWindowsKeyStateTests.cpp | 5 ++ .../integtests/platform/OSXClipboardTests.cpp | 5 ++ .../platform/XWindowsClipboardTests.cpp | 5 ++ .../platform/XWindowsKeyStateTests.cpp | 4 ++ src/test/unittests/CMakeLists.txt | 2 +- src/test/unittests/main.cpp | 9 +-- 26 files changed, 382 insertions(+), 113 deletions(-) create mode 100644 .github/actions/run-tests-setup/action.yml create mode 100644 .github/actions/run-tests/action.yml create mode 100644 .github/actions/run-valgrind/action.yml diff --git a/.github/actions/dist-upload/action.yml b/.github/actions/dist-upload/action.yml index 3145d40d8..b60a276d5 100644 --- a/.github/actions/dist-upload/action.yml +++ b/.github/actions/dist-upload/action.yml @@ -3,24 +3,31 @@ description: "Uploads the package from the dist dir to GitHub artifacts or Googl inputs: use_github: description: "Whether to upload to GitHub artifacts" + required: true use_gdrive: description: "Whether to upload to Google Drive" + required: true github-target-filename: description: "Filename to upload (GitHub artifacts)" + required: true gdrive-target-base-dir: description: "Base directory to upload (Google Drive)" + required: true gdrive-secret-key: description: "Google Drive secret key" + required: true gdrive-parent-folder-id: description: "Google Drive parent folder ID" + required: true package-version: description: "Package version appended to the Google Drive dir" + required: true runs: using: "composite" @@ -44,16 +51,16 @@ runs: echo "SHORT_VERSION=$SHORT_VERSION" >> $GITHUB_ENV shell: bash - # Upload to GitHub - - if: ${{ inputs.use_github == 'true' }} + - name: Upload to GitHub + if: ${{ inputs.use_github == 'true' }} uses: actions/upload-artifact@v4 with: name: ${{ inputs.github-target-filename }} path: ./dist retention-days: 3 - # Upload to Google Drive - - if: ${{ inputs.use_gdrive == 'true' }} + - name: Upload to Google Drive + if: ${{ inputs.use_gdrive == 'true' }} uses: symless/gdrive-upload@target-glob with: credentials: ${{ inputs.gdrive-secret-key }} diff --git a/.github/actions/run-tests-setup/action.yml b/.github/actions/run-tests-setup/action.yml new file mode 100644 index 000000000..7d0460751 --- /dev/null +++ b/.github/actions/run-tests-setup/action.yml @@ -0,0 +1,39 @@ +name: "Run tests (setup)" +description: "Sets up the PR comment for tests" + +inputs: + GITHUB_TOKEN: + description: "The GitHub token to use for authentication" + required: true + +runs: + using: "composite" + + steps: + - name: Get workflow URL + id: workflow-url + run: | + repo_url="${{ github.server_url }}/${{ github.repository }}" + echo "url=$repo_url/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT + shell: bash + + - name: Begin PR comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + header: tests + recreate: true + message: | + ## Test results + See [workflow run](${{ steps.workflow-url.outputs.url }}) for test output. + + # Neccesary since the first comment has an annoying comment. + - name: Append table header + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + header: tests + append: true + message: | + | Job name | Unit tests | Integration tests | + | --- | --- | --- | diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml new file mode 100644 index 000000000..b3b0bf539 --- /dev/null +++ b/.github/actions/run-tests/action.yml @@ -0,0 +1,66 @@ +name: "Run tests" +description: "Runs both unit tests and integration tests and appends to a PR comment" + +inputs: + GITHUB_TOKEN: + description: "The GitHub token to use for authentication" + required: true + + job: + description: "The job name to append to the PR comment" + default: "unknown" + +runs: + using: "composite" + + steps: + - name: Unit tests + id: unittests + env: + QT_QPA_PLATFORM: offscreen + run: ./build/bin/unittests + shell: bash + continue-on-error: true + + - name: Integration tests + id: integtests + env: + QT_QPA_PLATFORM: offscreen + run: | + ./build/bin/integtests + result=$? + + if [ $result -ne 0 ]; then + echo "::warning ::Integration tests failed with code: $result" + fi + shell: bash + continue-on-error: true + + - name: Get test results + id: results + run: | + pass="✅ Pass" + fail="❌ Fail" + unittests_outcome="${{ steps.unittests.outcome }}" + integtests_outcome="${{ steps.integtests.outcome }}" + unittests=$( [ "$unittests_outcome" = "success" ] && echo $pass || echo $fail ) + integtests=$( [ "$integtests_outcome" = "success" ] && echo $pass || echo $fail ) + echo "unittests=$unittests" >> $GITHUB_OUTPUT + echo "integtests=$integtests" >> $GITHUB_OUTPUT + shell: bash + + - name: Append to PR comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + header: tests + append: true + message: | + | ${{ inputs.job }} | ${{ steps.results.outputs.unittests }} | ${{ steps.results.outputs.integtests }} | + + - name: Check test outcome + if: steps.unittests.outcome == 'failure' + run: | + echo "Unit tests failed" + exit 1 + shell: bash diff --git a/.github/actions/run-valgrind/action.yml b/.github/actions/run-valgrind/action.yml new file mode 100644 index 000000000..93eda12e5 --- /dev/null +++ b/.github/actions/run-valgrind/action.yml @@ -0,0 +1,41 @@ +name: "Run Valgrind" +description: "Runs Valgrind against a specified target and parses a summary" + +inputs: + executable: + description: "The executable to run under Valgrind" + required: true + +outputs: + summary: + description: "The parsed Valgrind summary" + value: ${{ steps.parse.outputs.summary }} + +runs: + using: "composite" + + steps: + - name: Valgrind + id: run + env: + QT_QPA_PLATFORM: offscreen + run: | + valgrind \ + --leak-check=full \ + --show-leak-kinds=all \ + --track-origins=yes \ + --verbose \ + ${{ inputs.executable }} \ + 2>&1 | tee valgrind.log + shell: bash + continue-on-error: true + + - name: Parse output + id: parse + run: | + echo "summary<> $GITHUB_OUTPUT + echo "$(grep -A 2 "HEAP SUMMARY:" valgrind.log)" >> $GITHUB_OUTPUT + echo >> $GITHUB_OUTPUT + echo "$(awk '/LEAK SUMMARY/,/ERROR SUMMARY/' valgrind.log)" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55365c2de..98b3f8d83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,18 @@ env: UPLOAD_TO_GDRIVE: ${{ github.event_name != 'pull_request' }} jobs: + setup: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: ./.github/actions/run-tests-setup + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + windows: name: ${{ matrix.target.name }} runs-on: ${{ matrix.target.runs-on }} @@ -75,8 +87,12 @@ jobs: - name: Build run: cmake --build build -j8 - - name: Test - run: ./build/bin/unittests + - name: Tests + uses: ./.github/actions/run-tests + timeout-minutes: 2 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + job: ${{ matrix.target.name }} - name: Package if: ${{ vars.SYNERGY_ENABLE_PACKAGING && env.PACKAGE_BUILD == 'true' }} @@ -142,8 +158,12 @@ jobs: - name: Build run: cmake --build build -j8 - - name: Test - run: ./build/bin/unittests + - name: Tests + uses: ./.github/actions/run-tests + timeout-minutes: 2 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + job: ${{ matrix.target.name }} - name: Package if: ${{ vars.SYNERGY_ENABLE_PACKAGING && env.PACKAGE_BUILD == 'true' }} @@ -243,10 +263,12 @@ jobs: - name: Build run: cmake --build build -j8 - - name: Test - env: - QT_QPA_PLATFORM: offscreen - run: ./build/bin/unittests + - name: Tests + uses: ./.github/actions/run-tests + timeout-minutes: 2 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + job: linux-${{ matrix.distro.name }} - name: Package if: ${{ vars.SYNERGY_ENABLE_PACKAGING && env.PACKAGE_BUILD == 'true' }} diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index 52b1fc0f5..5b9d90dd5 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -27,7 +27,7 @@ jobs: SONAR_SCANNER_VERSION: 6.1.0.4477 SONAR_SCANNER_OPTS: -server SONAR_SCANNER_URL_BASE: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli - SONAR_SCANNER_THREADS: 32 + CPU_CORE_COUNT: 32 steps: - name: Checkout @@ -35,6 +35,9 @@ jobs: with: submodules: "recursive" + # Fetch all history for SonarScanner blame data + fetch-depth: 0 + - name: Config Git safe dir run: git config --global --add safe.directory $GITHUB_WORKSPACE @@ -53,38 +56,64 @@ jobs: - name: Install build-wrapper run: | - curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ + file="build-wrapper-linux-x86.zip" + url="https://sonarcloud.io/static/cpp/$file" + curl --create-dirs -sSLo $HOME/.sonar/$file $url + unzip -o $HOME/.sonar/$file -d $HOME/.sonar/ + + - name: Configure + run: cmake -B build --preset=linux-debug -DENABLE_COVERAGE=ON - name: Build run: | export PATH=$HOME/.sonar/build-wrapper-linux-x86:$PATH - mkdir -p build - cd build - cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON .. - build-wrapper-linux-x86-64 --out-dir bw-output make -j + build-wrapper-linux-x86-64 --out-dir bw-output cmake --build build -j${CPU_CORE_COUNT} - - name: Make coverage + - name: Unit tests coverage + env: + QT_QPA_PLATFORM: offscreen + run: cmake --build build --target coverage-unittests + + - name: Integration tests coverage env: QT_QPA_PLATFORM: offscreen run: | - cd build - make coverage + cmake --build build --target coverage-integtests + result=$? + + if [ $result -ne 0 ]; then + echo "::warning ::Integration tests failed with code: $result" + fi + continue-on-error: true + + - name: Get coverage report paths + id: coverage-paths + run: | + unittests=$(find build -name coverage-unittests.xml) + integtests=$(find build -name coverage-integtests.xml) + paths="${unittests}${integtests:+,$integtests}" + if [ -z "$paths" ]; then + echo "Error: No coverage files found" + exit 1 + fi + echo "csv=$paths" >> $GITHUB_OUTPUT - name: Run SonarScanner run: | export PATH=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64/bin:$PATH - cd build sonar-scanner \ -Dsonar.organization=symless \ -Dsonar.projectKey=symless_synergy-core \ - -Dsonar.sources=. \ - -Dsonar.projectBaseDir=../ \ + -Dsonar.sources=scripts,src/cmd,src/gui,src/lib \ + -Dsonar.tests=src/test \ -Dsonar.exclusions=ext/**,build/** \ - -Dsonar.cfamily.build-wrapper-output=bw-output \ + -Dsonar.coverage.exclusions=ext/**,scripts/**,src/test/** \ + -Dsonar.cpd.exclusions=**/*Test*.cpp \ -Dsonar.host.url=https://sonarcloud.io \ - -Dsonar.coverageReportPaths=build/coverage.xml \ - -Dsonar.cfamily.threads=${{ env.SONAR_SCANNER_THREADS }} + -Dsonar.coverageReportPaths=${{ steps.coverage-paths.outputs.csv }} \ + -Dsonar.cfamily.compile-commands=build/compile_commands.json \ + -Dsonar.cfamily.threads=${{ env.CPU_CORE_COUNT }} \ + -Dsonar.python.version=3.10 env: SONAR_TOKEN: ${{secrets.SONAR_TOKEN}} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/valgrind-analysis.yml b/.github/workflows/valgrind-analysis.yml index d8c28027c..b79a35cf3 100644 --- a/.github/workflows/valgrind-analysis.yml +++ b/.github/workflows/valgrind-analysis.yml @@ -39,37 +39,41 @@ jobs: - name: Build run: cmake --build build -j8 - - name: Run Valgrind on unit tests - env: - QT_QPA_PLATFORM: offscreen - run: | - valgrind \ - --leak-check=full \ - --show-leak-kinds=all \ - --track-origins=yes \ - --verbose \ - ./build/bin/unittests \ - 2>&1 | tee valgrind.log + - name: Valgrind unit tests + id: unittests + uses: ./.github/actions/run-valgrind + with: + executable: ./build/bin/unittests - - name: Parse summary - id: parse + - name: Valgrind integration tests + id: integtests + uses: ./.github/actions/run-valgrind + with: + executable: ./build/bin/integtests + + - name: Get workflow URL + id: workflow-url run: | - echo "summary<> $GITHUB_OUTPUT - echo "$(grep -A 2 "HEAP SUMMARY:" valgrind.log)" >> $GITHUB_OUTPUT - echo >> $GITHUB_OUTPUT - echo "$(awk '/LEAK SUMMARY/,/ERROR SUMMARY/' valgrind.log)" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT + repo_url="${{ github.server_url }}/${{ github.repository }}" + echo "url=$repo_url/actions/runs/${{ github.run_id }}" >> $GITHUB_OUTPUT + shell: bash - name: Append to PR comment uses: marocchino/sticky-pull-request-comment@v2 - env: - URL: https://github.com/symless/synergy-core/actions/workflows/valgrind-analysis.yml with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} recreate: true + header: valgrind message: | ## Valgrind summary - See [workflow output](${{ env.URL }}) for full `valgrind` output. + See [workflow run](${{ steps.workflow-url.outputs.url }}) for full `valgrind` output. + + ### Unit tests ``` - ${{ steps.parse.outputs.summary }} + ${{ steps.unittests.outputs.summary }} + ``` + + ### Integration tests + ``` + ${{ steps.integtests.outputs.summary }} ``` diff --git a/.vscode/launch.json b/.vscode/launch.json index 409d2e85b..ca1e56e0e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "lldb", "request": "launch", "program": "${workspaceFolder}/build/bin/synergy", - "preLaunchTask": "build" + "preLaunchTask": "build-kill" }, { "name": "unittests lldb", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e9d78ce96..10615f208 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,8 +2,8 @@ "version": "2.0.0", "tasks": [ { - "type": "cmake", "label": "build", + "type": "cmake", "command": "build", "targets": ["all"], "preset": "${command:cmake.activeBuildPresetName}", @@ -13,23 +13,40 @@ } }, { - "type": "cmake", "label": "clean", + "type": "cmake", "command": "build", "targets": ["clean"], "preset": "${command:cmake.activeBuildPresetName}", "group": "build" }, { - "label": "reinstall windows daemon", + "label": "tests", + "dependsOn": ["unittests", "integtests"], + "problemMatcher": [] + }, + { + "label": "kill", "type": "shell", - "command": "python scripts/windows_daemon.py", - "dependsOn": ["build"] + "command": "killall synergy; killall synergyc; killall synergys || true", + "windows": { + "command": "taskkill /F /IM synergy.exe /IM synergyc.exe /IM synergys.exe; $true" + } + }, + { + "label": "build-kill", + "dependsOn": ["build", "kill"] }, { "label": "gui", "type": "process", "command": "${workspaceFolder}/build/bin/synergy", + "dependsOn": ["build", "kill"] + }, + { + "label": "windows daemon", + "type": "shell", + "command": "python scripts/windows_daemon.py", "dependsOn": ["build"] }, { @@ -37,7 +54,7 @@ "type": "shell", "command": "find . -name '*.gcda' -delete", "windows": { - "command": "$null" // no-op + "command": "$null" }, "presentation": { "reveal": "silent" @@ -68,14 +85,14 @@ "dependsOn": ["build", "clean-gcda"] }, { - "label": "unittests (all)", + "label": "unittests", "type": "shell", "command": "python", "args": ["./scripts/tests.py", "--unit-tests", "--ignore-return-code"], "dependsOn": ["build", "clean-gcda"] }, { - "label": "integtests (all)", + "label": "integtests", "type": "shell", "command": "python", "args": ["./scripts/tests.py", "--integ-tests", "--ignore-return-code"], diff --git a/ChangeLog b/ChangeLog index 642a28249..49dff1d9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -55,6 +55,7 @@ Enhancements: - #7389 Correct Qt macOS target and drop `Core5Compat` lib - #7401 Run Valgrind on unit tests in CI to detect memory leaks - #7403 Solve low hanging reliability and maintainability issues +- #7404 Restore integtests and add to CI as warning comment on failure # 1.14.6 diff --git a/cmake-format.yaml b/cmake-format.yaml index 35d07f0e2..55be7e342 100644 --- a/cmake-format.yaml +++ b/cmake-format.yaml @@ -6,4 +6,5 @@ format: max_pargs_hwrap: 4 markup: - first_comment_is_literal: true + # Disable formatting of comments entirely, as this is annoying. + enable_markup: false diff --git a/cmake/Definitions.cmake b/cmake/Definitions.cmake index 1245ea024..159a1b241 100644 --- a/cmake/Definitions.cmake +++ b/cmake/Definitions.cmake @@ -30,6 +30,9 @@ macro(configure_definitions) configure_options() configure_python() + set(INTEG_TESTS_BIN integtests) + set(UNIT_TESTS_BIN unittests) + if("${VERSION_URL}" STREQUAL "") set(VERSION_URL "https://api.symless.com/version?version=v1") endif() diff --git a/cmake/Libraries.cmake b/cmake/Libraries.cmake index a0c6a4f85..ea590395c 100644 --- a/cmake/Libraries.cmake +++ b/cmake/Libraries.cmake @@ -319,15 +319,29 @@ macro(configure_test_libs) message(STATUS "Enabling code coverage") include(cmake/CodeCoverage.cmake) append_coverage_compiler_flags() + set(test_exclude ext/* build/* src/test/*) + set(test_src ${PROJECT_SOURCE_DIR}/src) + setup_target_for_coverage_gcovr_xml( NAME - coverage + coverage-${INTEG_TESTS_BIN} EXECUTABLE - unittests + ${INTEG_TESTS_BIN} BASE_DIRECTORY - "${PROJECT_SOURCE_DIR}/src" + ${test_src} EXCLUDE - "ext/*") + ${test_exclude}) + + setup_target_for_coverage_gcovr_xml( + NAME + coverage-${UNIT_TESTS_BIN} + EXECUTABLE + ${UNIT_TESTS_BIN} + BASE_DIRECTORY + ${test_src} + EXCLUDE + ${test_exclude}) + else() message(STATUS "Code coverage is disabled") endif() diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 909ab7594..110382584 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -205,6 +205,7 @@ MainWindow::~MainWindow() { } void MainWindow::open() { + std::array trayMenu = { m_pActionStartSynergy, m_pActionStopSynergy, nullptr, m_pActionMinimize, m_pActionRestore, nullptr, diff --git a/src/gui/src/QIpcClient.cpp b/src/gui/src/QIpcClient.cpp index 515ac8ed3..e5db7d0d0 100644 --- a/src/gui/src/QIpcClient.cpp +++ b/src/gui/src/QIpcClient.cpp @@ -54,6 +54,7 @@ QIpcClient::~QIpcClient() { } void QIpcClient::connected() { + sendHello(); infoMessage("connection established"); } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index cc682af00..f550d3dbc 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -60,24 +60,6 @@ macro(set_sources) list(APPEND headers ${mock_headers}) list(APPEND sources ${mock_sources}) - file(GLOB_RECURSE gui_sources ${gui_dir}/*.cpp) - - file(GLOB activation_sources ${gui_dir}/*Activation* ${gui_dir}/*License*) - if(NOT ENABLE_LICENSING) - list(REMOVE_ITEM gui_sources ${activation_sources}) - endif() - - # remove main gui as the test already has its own main. - file(GLOB gui_main ${gui_dir}/main.cpp) - list(REMOVE_ITEM gui_sources ${gui_main}) - - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - file(GLOB mac_gui_sources ${gui_dir}/*.mm) - list(APPEND gui_sources ${mac_gui_sources}) - endif() - - list(APPEND sources ${gui_sources}) - if(ADD_HEADERS_TO_SOURCES) list(APPEND sources ${headers}) endif() @@ -86,11 +68,12 @@ macro(set_sources) list(APPEND sources ${CMAKE_BINARY_DIR}/src/version.rc) endif() - add_platform_sources() + append_platform_sources() + append_gui_sources() endmacro() -macro(add_platform_sources) +macro(append_platform_sources) set(platform_dir ${CMAKE_CURRENT_SOURCE_DIR}/platform) @@ -117,6 +100,31 @@ macro(add_platform_sources) endmacro() +# TODO: compile gui sources into a single shared lib to reduce compile time. +# currently the gui is compiled 3 times (gui exe, unit tests, and integ tests). +# this might be tricky, since the qt moc generator seems to get easily confused. +macro(append_gui_sources) + + file(GLOB_RECURSE gui_sources ${gui_dir}/*.cpp) + + file(GLOB activation_sources ${gui_dir}/*Activation* ${gui_dir}/*License*) + if(NOT ENABLE_LICENSING) + list(REMOVE_ITEM gui_sources ${activation_sources}) + endif() + + # remove main gui as the test already has its own main. + file(GLOB gui_main ${gui_dir}/main.cpp) + list(REMOVE_ITEM gui_sources ${gui_main}) + + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + file(GLOB mac_gui_sources ${gui_dir}/*.mm) + list(APPEND gui_sources ${mac_gui_sources}) + endif() + + list(APPEND sources ${gui_sources}) + +endmacro() + macro(config_test_deps) set(CMAKE_AUTOMOC ON) diff --git a/src/test/integtests/CMakeLists.txt b/src/test/integtests/CMakeLists.txt index 82b350ac6..545cc255e 100644 --- a/src/test/integtests/CMakeLists.txt +++ b/src/test/integtests/CMakeLists.txt @@ -15,6 +15,6 @@ # along with this program. If not, see . config_test() -set(target integtests) +set(target ${INTEG_TESTS_BIN}) add_executable(${target} ${sources}) target_link_libraries(${target} ${test_libs}) diff --git a/src/test/integtests/gui/MainWindowTests.cpp b/src/test/integtests/gui/MainWindowTests.cpp index 51c9d4b5c..ec25d9f6b 100644 --- a/src/test/integtests/gui/MainWindowTests.cpp +++ b/src/test/integtests/gui/MainWindowTests.cpp @@ -15,6 +15,9 @@ * along with this program. If not, see . */ +// TODO: fix randomly freezing on windows +#ifndef WIN32 + #include "MainWindow.h" #include "test/shared/gui/QtTest.h" @@ -28,8 +31,6 @@ public: QtTest::SetUpTestSuite(); qRegisterMetaType("Edition"); } - - static std::shared_ptr s_app; }; class TestMainWindow { @@ -82,3 +83,5 @@ TEST_F(MainWindowTests, checkSecureSocket_match_expectTrue) { EXPECT_TRUE(result); } + +#endif diff --git a/src/test/integtests/main.cpp b/src/test/integtests/main.cpp index 5389aafc0..7052dd96a 100644 --- a/src/test/integtests/main.cpp +++ b/src/test/integtests/main.cpp @@ -29,10 +29,8 @@ #define LOCK_TIMEOUT 30 -using namespace std; - -void lock(string lockFile); -void unlock(string lockFile); +void lock(const std::string &lockFile); +void unlock(const std::string &lockFile); int main(int argc, char **argv) { #if SYSAPI_WIN32 @@ -46,9 +44,10 @@ int main(int argc, char **argv) { Log log; log.setFilter(kDEBUG2); - string lockFile; + std::string lockFile; for (int i = 0; i < argc; i++) { - if (string(argv[i]).compare("--lock-file") == 0) { + const std::string option(argv[i]); + if (option.find("--lock-file") != std::string::npos) { lockFile = argv[i + 1]; } } @@ -66,21 +65,18 @@ int main(int argc, char **argv) { unlock(lockFile); } - // gtest seems to randomly finish with error codes (e.g. -1, -1073741819) - // even when no tests have failed. not sure what causes this, but it - // happens on all platforms and keeps leading to false positives. - // according to the documentation, 1 is a failure, so we should be - // able to trust that code. - return (result == 1) ? 1 : 0; + // return code 1 means the test failed. + // any other non-zero code is probably a memory error. + return result; } -void lock(string lockFile) { +void lock(const std::string &lockFile) { double start = ARCH->time(); // keep checking until timeout is reached. while ((ARCH->time() - start) < LOCK_TIMEOUT) { - ifstream is(lockFile.c_str()); + std::ifstream is(lockFile.c_str()); bool noLock = !is; is.close(); @@ -93,8 +89,8 @@ void lock(string lockFile) { } // write empty lock file. - ofstream os(lockFile.c_str()); + std::ofstream os(lockFile.c_str()); os.close(); } -void unlock(string lockFile) { remove(lockFile.c_str()); } +void unlock(const std::string &lockFile) { remove(lockFile.c_str()); } diff --git a/src/test/integtests/net/NetworkTests.cpp b/src/test/integtests/net/NetworkTests.cpp index 8f5d39426..8acdcb204 100644 --- a/src/test/integtests/net/NetworkTests.cpp +++ b/src/test/integtests/net/NetworkTests.cpp @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -// TODO: fix, tests failing intermittently on mac. -#ifndef WINAPI_CARBON +// TODO: fix, tests failing intermittently and/or with segfault +#if 0 #define TEST_ENV @@ -56,7 +56,7 @@ using ::testing::Return; const size_t kMockDataSize = 1024 * 1024 * 10; // 10MB const UInt16 kMockDataChunkIncrement = 1024; // 1KB -const char *kMockFilename = "NetworkTests.mock"; +const char *kMockFilename = "tmp/test/NetworkTests.mock"; const size_t kMockFileSize = 1024 * 1024 * 10; // 10MB void getScreenShape(SInt32 &x, SInt32 &y, SInt32 &w, SInt32 &h); diff --git a/src/test/integtests/platform/MSWindowsKeyStateTests.cpp b/src/test/integtests/platform/MSWindowsKeyStateTests.cpp index 6e7f55dba..5ed97a72c 100644 --- a/src/test/integtests/platform/MSWindowsKeyStateTests.cpp +++ b/src/test/integtests/platform/MSWindowsKeyStateTests.cpp @@ -16,6 +16,9 @@ * along with this program. If not, see . */ +// TODO: fix Assertion failed: s_instance != nullptr +#if 0 + #define TEST_ENV #include "base/TMethodJob.h" @@ -142,3 +145,5 @@ TEST_F( delete desks; } + +#endif diff --git a/src/test/integtests/platform/OSXClipboardTests.cpp b/src/test/integtests/platform/OSXClipboardTests.cpp index aa20a2283..3de707af5 100644 --- a/src/test/integtests/platform/OSXClipboardTests.cpp +++ b/src/test/integtests/platform/OSXClipboardTests.cpp @@ -16,6 +16,9 @@ * along with this program. If not, see . */ +// TODO: fix failing tests (e.g. add_newValue_valueWasStored) +#if 0 + #include "platform/OSXClipboard.h" #include @@ -148,3 +151,5 @@ TEST(OSXClipboardTests, get_withFormatAdded_returnsExpected) { EXPECT_EQ("synergy rocks!", actual); } + +#endif \ No newline at end of file diff --git a/src/test/integtests/platform/XWindowsClipboardTests.cpp b/src/test/integtests/platform/XWindowsClipboardTests.cpp index 78963843a..52f1ccf63 100644 --- a/src/test/integtests/platform/XWindowsClipboardTests.cpp +++ b/src/test/integtests/platform/XWindowsClipboardTests.cpp @@ -23,6 +23,9 @@ #include #include +// TODO: fix segfault in release mode +#if 0 + class XWindowsClipboardTests : public ::testing::Test { protected: void SetUp() override { @@ -135,3 +138,5 @@ TEST_F(XWindowsClipboardTests, get_withFormatAdded_returnsExpected) { EXPECT_EQ("synergy rocks!", actual); } + +#endif diff --git a/src/test/integtests/platform/XWindowsKeyStateTests.cpp b/src/test/integtests/platform/XWindowsKeyStateTests.cpp index a51d0796d..8d36891cb 100644 --- a/src/test/integtests/platform/XWindowsKeyStateTests.cpp +++ b/src/test/integtests/platform/XWindowsKeyStateTests.cpp @@ -16,6 +16,9 @@ * along with this program. If not, see . */ +// TODO: fix Assertion `s_instance != nullptr' failed. +#if 0 + #define TEST_ENV #include "test/mock/synergy/MockEventQueue.h" @@ -213,3 +216,4 @@ TEST_F(XWindowsKeyStateTests, pollActiveGroup_xkb_areEqual) { SUCCEED() << "Xkb extension not installed"; #endif } +#endif \ No newline at end of file diff --git a/src/test/unittests/CMakeLists.txt b/src/test/unittests/CMakeLists.txt index 45df145f1..b0885b049 100644 --- a/src/test/unittests/CMakeLists.txt +++ b/src/test/unittests/CMakeLists.txt @@ -15,6 +15,6 @@ # along with this program. If not, see . config_test() -set(target unittests) +set(target ${UNIT_TESTS_BIN}) add_executable(${target} ${sources}) target_link_libraries(${target} ${test_libs}) diff --git a/src/test/unittests/main.cpp b/src/test/unittests/main.cpp index 64c88cbb3..86b4ad7d9 100644 --- a/src/test/unittests/main.cpp +++ b/src/test/unittests/main.cpp @@ -41,10 +41,7 @@ int main(int argc, char **argv) { ::testing::GTEST_FLAG(throw_on_failure) = true; testing::InitGoogleTest(&argc, argv); - // gtest seems to randomly finish with error codes (e.g. -1, -1073741819) - // even when no tests have failed. not sure what causes this, but it - // happens on all platforms and keeps leading to false positives. - // according to the documentation, 1 is a failure, so we should be - // able to trust that code. - return (RUN_ALL_TESTS() == 1) ? 1 : 0; + // return code 1 means the test failed. + // any other non-zero code is probably a memory error. + return RUN_ALL_TESTS(); }