From af978fb8ddfb1bab37c52fd7e0bd4ebf5e8b18f4 Mon Sep 17 00:00:00 2001 From: James Lindsay Date: Tue, 6 Aug 2024 10:37:00 +0100 Subject: [PATCH] Maze runner tests --- .buildkite/block.full.yml | 1 + .buildkite/pipeline.linux.full.yml | 197 ++++++++++++++++++ .buildkite/pipeline_trigger.sh | 1 + TESTING.md | 27 ++- features/csharp/csharp_config.feature | 4 +- features/csharp/csharp_persistence.feature | 2 +- features/csharp/csharp_sessions.feature | 6 + .../maze_runner/Assets/Editor/Builder.cs | 15 ++ features/scripts/build_maze_runner.sh | 10 +- features/steps/unity_steps.rb | 13 ++ features/support/env.rb | 10 + scripts/ci-build-linux-fixture.sh | 29 +++ scripts/ci-run-linux-tests.sh | 26 +++ src/BugsnagUnity/Native/Linux/NativeClient.cs | 17 +- 14 files changed, 348 insertions(+), 10 deletions(-) create mode 100644 .buildkite/pipeline.linux.full.yml create mode 100755 scripts/ci-build-linux-fixture.sh create mode 100755 scripts/ci-run-linux-tests.sh diff --git a/.buildkite/block.full.yml b/.buildkite/block.full.yml index 88c22efae..4c2dddb06 100644 --- a/.buildkite/block.full.yml +++ b/.buildkite/block.full.yml @@ -9,4 +9,5 @@ steps: buildkite-agent pipeline upload .buildkite/pipeline.ios.full.yml && buildkite-agent pipeline upload .buildkite/pipeline.windows.full.yml && buildkite-agent pipeline upload .buildkite/pipeline.macos.full.yml && + buildkite-agent pipeline upload .buildkite/pipeline.linux.full.yml && buildkite-agent pipeline upload .buildkite/pipeline.webgl.full.yml diff --git a/.buildkite/pipeline.linux.full.yml b/.buildkite/pipeline.linux.full.yml new file mode 100644 index 000000000..990f517ff --- /dev/null +++ b/.buildkite/pipeline.linux.full.yml @@ -0,0 +1,197 @@ +aliases: + - &2020 "2020.3.48f1" + - &2021 "2021.3.36f1" + - &2022 "2022.3.22f1" + - &2023 "2023.2.19f1" + +agents: + queue: macos-14 + +steps: + # + # Build Linux test fixtures + # + - label: Build Unity 2020 Linux test fixture + timeout_in_minutes: 30 + key: "linux-2020-fixture" + depends_on: "build-artifacts" + env: + UNITY_VERSION: *2020 + plugins: + artifacts#v1.9.0: + download: + - Bugsnag.unitypackage + upload: + - unity.log + - features/fixtures/maze_runner/build/linux-release-2020.zip + commands: + - scripts/ci-build-linux-fixture.sh release + retry: + automatic: + - exit_status: "*" + limit: 1 + + - label: Build Unity 2021 linux test fixture + timeout_in_minutes: 30 + key: "linux-2021-fixture" + depends_on: "build-artifacts" + env: + UNITY_VERSION: *2021 + commands: + - scripts/ci-build-linux-fixture.sh release + plugins: + artifacts#v1.9.0: + download: + - Bugsnag.unitypackage + upload: + - unity.log + - unity_import.log + - c/linux-release-2021.zip + retry: + automatic: + - exit_status: "*" + limit: 1 + + - label: Build Unity 2021 linux DEV test fixture + timeout_in_minutes: 30 + key: "linux-2021-dev-fixture" + depends_on: "build-artifacts" + env: + UNITY_VERSION: *2021 + commands: + - scripts/ci-build-linux-fixture.sh dev + plugins: + artifacts#v1.9.0: + download: + - Bugsnag.unitypackage + upload: + - unity.log + - unity_import.log + - features/fixtures/maze_runner/build/linux-dev-2021.zip + retry: + automatic: + - exit_status: "*" + limit: 1 + + - label: Build Unity 2022 linux test fixture + timeout_in_minutes: 30 + key: "linux-2022-fixture" + depends_on: "build-artifacts" + env: + UNITY_VERSION: *2022 + commands: + - scripts/ci-build-linux-fixture.sh release + plugins: + artifacts#v1.9.0: + download: + - Bugsnag.unitypackage + upload: + - unity.log + - unity_import.log + - features/fixtures/maze_runner/build/linux-release-2022.zip + retry: + automatic: + - exit_status: "*" + limit: 1 + + - label: Build Unity 2023 linux test fixture + skip: Pending PLAT-12072 + timeout_in_minutes: 30 + key: "linux-2023-fixture" + depends_on: "build-artifacts" + env: + UNITY_VERSION: *2023 + commands: + - scripts/ci-build-linux-fixture.sh release + plugins: + artifacts#v1.9.0: + download: + - Bugsnag.unitypackage + upload: + - unity.log + - unity_import.log + - features/fixtures/maze_runner/build/linux-release-2023.zip + retry: + automatic: + - exit_status: "*" + limit: 1 + + # + # Run linux e2e tests + # + - label: Run linux e2e tests for Unity 2020 + timeout_in_minutes: 30 + depends_on: "linux-2020-fixture" + env: + UNITY_VERSION: *2020 + plugins: + artifacts#v1.9.0: + download: + - features/fixtures/maze_runner/build/linux-release-2020.zip + upload: + - maze_output/**/* + - maze_output/metrics.csv + + command: + - scripts/ci-run-linux-tests.sh release + + - label: Run linux e2e tests for Unity 2021 + timeout_in_minutes: 30 + depends_on: "linux-2021-fixture" + env: + UNITY_VERSION: *2021 + plugins: + artifacts#v1.9.0: + download: + - features/fixtures/maze_runner/build/linux-release-2021.zip + upload: + - maze_output/**/* + - maze_output/metrics.csv + commands: + - scripts/ci-run-linux-tests.sh release + + - label: Run linux e2e DEV tests for Unity 2021 + timeout_in_minutes: 30 + depends_on: "linux-2021-dev-fixture" + env: + UNITY_VERSION: *2021 + plugins: + artifacts#v1.9.0: + download: + - features/fixtures/maze_runner/build/linux-dev-2021.zip + upload: + - maze_output/**/* + - maze_output/metrics.csv + commands: + - scripts/ci-run-linux-tests.sh dev + + - label: Run linux e2e tests for Unity 2022 + timeout_in_minutes: 30 + depends_on: "linux-2022-fixture" + env: + UNITY_VERSION: *2022 + plugins: + artifacts#v1.9.0: + download: + - features/fixtures/maze_runner/build/linux-release-2022.zip + upload: + - maze_output/**/* + - maze_output/metrics.csv + commands: + - scripts/ci-run-linux-tests.sh release + + - label: Run linux e2e tests for Unity 2023 + skip: Pending PLAT-12072 + timeout_in_minutes: 30 + depends_on: "linux-2023-fixture" + env: + UNITY_VERSION: *2023 + plugins: + artifacts#v1.9.0: + download: + - features/fixtures/maze_runner/build/linux-release-2023.zip + upload: + - maze_output/**/* + - maze_output/metrics.csv + commands: + - scripts/ci-run-linux-tests.sh release diff --git a/.buildkite/pipeline_trigger.sh b/.buildkite/pipeline_trigger.sh index 8be39d688..d5c032b6f 100755 --- a/.buildkite/pipeline_trigger.sh +++ b/.buildkite/pipeline_trigger.sh @@ -10,6 +10,7 @@ if [[ "$BUILDKITE_MESSAGE" == *"[full ci]"* || buildkite-agent pipeline upload .buildkite/pipeline.ios.full.yml buildkite-agent pipeline upload .buildkite/pipeline.windows.full.yml buildkite-agent pipeline upload .buildkite/pipeline.macos.full.yml + buildkite-agent pipeline upload .buildkite/pipeline.linux.full.yml buildkite-agent pipeline upload .buildkite/pipeline.webgl.full.yml else # Basic build, but allow a full build to be triggered diff --git a/TESTING.md b/TESTING.md index 3ff5bfbc6..29910fc3e 100644 --- a/TESTING.md +++ b/TESTING.md @@ -102,7 +102,7 @@ This will generate the following file: #### MacOS -1. `UNITY_VERSION=2018.4.36f1 ./features/scripts/build_maze_runner.sh macos` +1. `UNITY_VERSION=2018.4.36f1 ./features/scripts/build_maze_runner.sh release macos` Where `UNITY_VERSION` corresponds to the Unity installation path, e.g: ``` @@ -119,7 +119,7 @@ This will generate the test fixture app: Building the test fixture on Windows requires a Git bash terminal. In a Git bash terminal: -1. `UNITY_VERSION=2018.4.36f1 ./features/scripts/build_maze_runner.sh windows` +1. `UNITY_VERSION=2018.4.36f1 ./features/scripts/build_maze_runner.sh release windows` Where `UNITY_VERSION` corresponds to the Unity installation path, e.g: ``` @@ -132,6 +132,20 @@ dependencies: ./features/fixtures/maze_runner/build/Windows ``` +#### Linux + +1. `UNITY_VERSION=2021.3.40f1 ./features/scripts/build_maze_runner.sh release linux` + +Where `UNITY_VERSION` corresponds to the Unity installation path, e.g: +``` +$HOME/Unity/Hub/Editor/$UNITY_VERSION/Editor/Unity +``` +This will generate a build folder containing the test fixture executable, together with the UnityPlayer.so and other +dependencies: +``` +./features/fixtures/maze_runner/build/linux +``` + ### Running an end-to-end test #### MacOS @@ -155,6 +169,15 @@ In the Ubuntu terminal: bundle exec maze-runner --app=features/fixtures/maze_runner/build/Windows/Mazerunner.exe --os=windows ``` +#### Linux + +1. Check the contents of `Gemfile` to select the version of `maze-runner` to use +1. Run `bundle install` if you haven't run end-to-end tests before +1. To run the tests: + ```shell script + bundle exec maze-runner --app=features/fixtures/maze_runner/build/linux/Mazerunner --os=linux + ``` + #### WebGL The WebGL e2e tests depend on Chrome and `chromedriver` (available from Homebrew). diff --git a/features/csharp/csharp_config.feature b/features/csharp/csharp_config.feature index 5954f26d0..b592eb346 100644 --- a/features/csharp/csharp_config.feature +++ b/features/csharp/csharp_config.feature @@ -27,7 +27,7 @@ Feature: csharp events And the exception "message" equals "Error 2" And the event "app.isLaunching" is false - @skip_cocoa @skip_windows @skip_webgl # PLAT-9061 + @skip_cocoa @skip_windows @skip_linux @skip_webgl # PLAT-9061 Scenario: Set long launch time When I run the game in the "LongLaunchTime" state And I wait to receive 2 errors @@ -39,7 +39,7 @@ Feature: csharp events And the exception "message" equals "Error 2" And the event "app.isLaunching" is false - @skip_cocoa @skip_windows @skip_webgl # PLAT-9061 + @skip_cocoa @skip_windows @skip_linux @skip_webgl # PLAT-9061 Scenario: Set short launch time When I run the game in the "ShortLaunchTime" state And I wait to receive 2 errors diff --git a/features/csharp/csharp_persistence.feature b/features/csharp/csharp_persistence.feature index c56f2e2ad..8cf1b7acb 100644 --- a/features/csharp/csharp_persistence.feature +++ b/features/csharp/csharp_persistence.feature @@ -3,7 +3,7 @@ Feature: Unity Persistence Background: Given I clear the Bugsnag cache - @skip_windows @skip_webgl @skip_cocoa @skip_android #pending PLAT-8632 + @skip_windows @skip_linux @skip_webgl @skip_cocoa @skip_android #pending PLAT-8632 Scenario: Receive a persisted session When I set the HTTP status code for the next request to 408 And I run the game in the "PersistSession" state diff --git a/features/csharp/csharp_sessions.feature b/features/csharp/csharp_sessions.feature index ac5e29d9c..a9fac573b 100644 --- a/features/csharp/csharp_sessions.feature +++ b/features/csharp/csharp_sessions.feature @@ -37,6 +37,7 @@ Feature: Session Tracking And the session payload field "app.type" equals the platform-dependent string: | macos | MacOS | | windows | Windows | + | linux | Linux | | switch | nintendo-switch | | browser | WebGL | | android | android | @@ -45,6 +46,7 @@ Feature: Session Tracking And the session payload field "device.osName" equals the platform-dependent string: | macos | Mac OS | | windows | Microsoft Windows NT | + | linux | Unix | | switch | Nintendo Switch | | browser | Unix | | android | android | @@ -53,6 +55,7 @@ Feature: Session Tracking And the session payload field "device.manufacturer" equals the platform-dependent string: | macos | Apple | | windows | PC | + | linux | @skip | | switch | Nintendo | | browser | @skip | | android | @skip | @@ -72,6 +75,7 @@ Feature: Session Tracking And the session payload field "app.type" equals the platform-dependent string: | macos | MacOS | | windows | Windows | + | linux | Linux | | switch | nintendo-switch | | browser | WebGL | | android | android | @@ -80,6 +84,7 @@ Feature: Session Tracking And the session payload field "device.osName" equals the platform-dependent string: | macos | Mac OS | | windows | Microsoft Windows NT | + | linux | Unix | | switch | Nintendo Switch | | browser | Unix | | android | android | @@ -88,6 +93,7 @@ Feature: Session Tracking And the session payload field "device.manufacturer" equals the platform-dependent string: | macos | Apple | | windows | PC | + | linux | @skip | | switch | Nintendo | | browser | @skip | | android | @skip | diff --git a/features/fixtures/maze_runner/Assets/Editor/Builder.cs b/features/fixtures/maze_runner/Assets/Editor/Builder.cs index 59eea7505..147ca731f 100644 --- a/features/fixtures/maze_runner/Assets/Editor/Builder.cs +++ b/features/fixtures/maze_runner/Assets/Editor/Builder.cs @@ -31,6 +31,11 @@ public static void Win64Release() Win64(false); } + public static void Linux64Release() + { + Linux64(false); + } + public static void WebGLRelease() { WebGL(false); @@ -46,6 +51,11 @@ public static void Win64Dev() Win64(true); } + public static void Linux64Dev() + { + Linux64(true); + } + public static void WebGLDev() { WebGL(true); @@ -61,6 +71,11 @@ static void Win64(bool dev) BuildStandalone(dev ? "build/Windows/Mazerunner_dev.exe" : "build/Windows/Mazerunner.exe", BuildTarget.StandaloneWindows64, dev); } + static void Linux64(bool dev) + { + BuildStandalone(dev ? "build/linux/Mazerunner_dev" : "build/linux/Mazerunner", BuildTarget.StandaloneLinux64, dev); + } + static void WebGL(bool dev) { BuildStandalone("build/WebGL/Mazerunner" + (dev ? "_dev" : ""), BuildTarget.WebGL, dev); diff --git a/features/scripts/build_maze_runner.sh b/features/scripts/build_maze_runner.sh index 6bcce3ac4..52193b39c 100755 --- a/features/scripts/build_maze_runner.sh +++ b/features/scripts/build_maze_runner.sh @@ -6,7 +6,7 @@ if [ -z "$UNITY_VERSION" ]; then fi if [[ $# != 2 ]]; then - echo "Build type (release/dev) and platform (macos/webgl/windows/wsl) must be passed as parameters" + echo "Build type (release/dev) and platform (macos/webgl/windows/wsl/linux) must be passed as parameters" exit 2 fi @@ -36,6 +36,14 @@ elif [ "$PLATFORM_TYPE" == "wsl" ]; then fi set -m UNITY_PATH="/mnt/c/Program Files/Unity/Hub/Editor/$UNITY_VERSION/Editor/Unity.exe" +elif [ "$PLATFORM_TYPE" == "linux" ]; then + if [ "$BUILD_TYPE" == "release" ]; then + PLATFORM="Linux64Release" + else + PLATFORM="Linux64Dev" + fi + set -m + UNITY_PATH="$HOME/Unity/Hub/Editor/$UNITY_VERSION/Editor/Unity" elif [ "$PLATFORM_TYPE" == "webgl" ]; then if [ "$BUILD_TYPE" == "release" ]; then PLATFORM="WebGLRelease" diff --git a/features/steps/unity_steps.rb b/features/steps/unity_steps.rb index aaf3c9ce2..33454bb21 100644 --- a/features/steps/unity_steps.rb +++ b/features/steps/unity_steps.rb @@ -34,6 +34,12 @@ def execute_command(action, scenario_name = '') Maze::Runner.run_command(command, blocking: false) execute_command('clear_cache') + when 'linux' + log = File.join(Dir.pwd, 'mazerunner.log') + command = "#{Maze.config.app} --args -logfile #{log} > /dev/null" + Maze::Runner.run_command(command, blocking: false) + execute_command('clear_cache') + when 'android', 'ios' execute_command('clear_cache') when 'browser' @@ -80,6 +86,13 @@ def execute_command(action, scenario_name = '') execute_command('run_scenario', state) + when 'linux' + log = File.join(Dir.pwd, "#{state}-mazerunner.log") + command = "#{Maze.config.app} --args -logfile #{log} > /dev/null" + Maze::Runner.run_command(command, blocking: false) + + execute_command('run_scenario', state) + when 'android', 'ios' execute_command('run_scenario', state) diff --git a/features/support/env.rb b/features/support/env.rb index f3d75ae48..0a58cc211 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -48,6 +48,13 @@ skip_this_scenario("Skipping scenario") if Maze.config.os == 'windows' end +Before('@linux_only') do |_scenario| + skip_this_scenario('Skipping scenario') unless Maze.config.os == 'linux' +end +Before('@skip_linux') do |_scenario| + skip_this_scenario("Skipping scenario") if Maze.config.os == 'linux' +end + Before('@switch_only') do |_scenario| skip_this_scenario('Skipping scenario') unless Maze.config.os == 'switch' @@ -71,6 +78,7 @@ elsif Maze.config.os&.downcase == 'windows' # Allow the necessary environment variables to be passed from Ubuntu (under WSL) to the Windows test fixture ENV['WSLENV'] = 'BUGSNAG_SCENARIO:BUGSNAG_APIKEY:MAZE_ENDPOINT' + elsif Maze.config.os&.downcase == 'linux' elsif Maze.config.browser != nil # WebGL release_path = 'features/fixtures/maze_runner/build/WebGL/Mazerunner' @@ -138,6 +146,8 @@ case Maze::Helper.get_current_platform when 'macos' `killall Mazerunner` + when 'linux' + `killall Mazerunner` when 'webgl','windows' execute_command('close_application') when 'switch' diff --git a/scripts/ci-build-linux-fixture.sh b/scripts/ci-build-linux-fixture.sh new file mode 100755 index 000000000..6649b327f --- /dev/null +++ b/scripts/ci-build-linux-fixture.sh @@ -0,0 +1,29 @@ +#!/bin/bash -e + +if [ -z "$UNITY_VERSION" ]; then + echo "UNITY_VERSION must be set, to e.g. 2018.4.36f1" + exit 1 +fi + +if [[ $# != 1 ]]; then + echo "Build type (release/dev) must be passed as a parameter" + exit 2 +fi + +BUILD_TYPE=$1 + +# Build the Linux fixture +./features/scripts/build_maze_runner.sh $BUILD_TYPE linux + +pushd features/fixtures/maze_runner/build + zip -r linux-${UNITY_VERSION:0:4}.zip linux +popd + + +pushd features/fixtures/maze_runner/build + if [ "$BUILD_TYPE" == "release" ]; then + zip -r linux-release-${UNITY_VERSION:0:4}.zip linux + else + zip -r linux-dev-${UNITY_VERSION:0:4}.zip linux + fi +popd diff --git a/scripts/ci-run-linux-tests.sh b/scripts/ci-run-linux-tests.sh new file mode 100755 index 000000000..ee35d719b --- /dev/null +++ b/scripts/ci-run-linux-tests.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +if [ -z "$UNITY_VERSION" ]; then + echo "UNITY_VERSION must be set, to e.g. 2018.4.36f1" + exit 1 +fi + +if [[ $# != 1 ]]; then + echo "Build type (release/dev) must be passed as a parameter" + exit 2 +fi + +BUILD_TYPE=$1 + +pushd features/fixtures/maze_runner/build + if [ "$BUILD_TYPE" == "release" ]; then + unzip linux-release-${UNITY_VERSION:0:4}.zip + APP_PATH="features/fixtures/maze_runner/build/linux/Mazerunner" + else + unzip linux-dev-${UNITY_VERSION:0:4}.zip + APP_PATH="features/fixtures/maze_runner/build/linux/Mazerunner_dev" + fi +popd + +bundle install +bundle exec maze-runner --app=$APP_PATH --os=linux features/csharp diff --git a/src/BugsnagUnity/Native/Linux/NativeClient.cs b/src/BugsnagUnity/Native/Linux/NativeClient.cs index a6518c675..e2aee56e9 100644 --- a/src/BugsnagUnity/Native/Linux/NativeClient.cs +++ b/src/BugsnagUnity/Native/Linux/NativeClient.cs @@ -70,9 +70,18 @@ private class StatvfsBuffer public ulong f_bsize; public ulong f_frsize; - public long f_blocks; - public long f_bfree; - public long f_bavailable; + public ulong f_blocks; + public ulong f_bfree; + public ulong f_bavailable; + + public ulong f_files; + public ulong f_ffree; + public ulong f_favail; + + public ulong f_fsid; + public ulong f_flag; + public ulong f_namemax; + } [return: MarshalAs(UnmanagedType.SysInt)] @@ -107,7 +116,7 @@ public void PopulateDeviceWithState(DeviceWithState device) // See https://man7.org/linux/man-pages/man3/statvfs.3.html StatvfsBuffer buffer = new StatvfsBuffer(); if (statvfs(Environment.CurrentDirectory, buffer) == 0) { - device.FreeDisk = buffer.f_bavailable * (long)buffer.f_bsize; + device.FreeDisk = (long)buffer.f_bavailable * (long)buffer.f_bsize; } }