Skip to content

Commit

Permalink
Add crash testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlinx committed Jun 8, 2023
1 parent 0066e05 commit 78e2346
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 2 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ jobs:
- name: Update Submodules
run: git submodule update --init

- name: Install Python Dependencies
run: |
apt-get update
apt-get -y install python3
apt-get -y install python3-pip
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
- name: Install Dependencies
run: |
nuget restore
Expand All @@ -29,9 +37,12 @@ jobs:
- name: Reimport Assets
run: timeout $IMPORT_TIME godot --editor || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi

- name: Run
- name: Run Unit Tests
run: godot addons/WAT/cli.tscn run=all

- name: Run Solution Crash Test
run: python3 solution_crash_tester.py 0 msbuild

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
Expand Down
10 changes: 10 additions & 0 deletions CrashTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

using Godot;

public class CrashTest
{
public void TestTwo()
{
GD.Print("TestTwo");
}
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
colorama
112 changes: 112 additions & 0 deletions solution_crash_tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import subprocess
import sys
import time

from colorama import Fore
from colorama import init as colorama_init

colorama_init()

class Content:
ONE = """
using Godot;
public class CrashTest
{
public void Test()
{
GD.Print("Test");
}
}
"""
TWO = """
using Godot;
public class CrashTest
{
public void TestTwo()
{
GD.Print("TestTwo");
}
}
"""

DIVIDER = f"{Fore.LIGHTBLACK_EX}---------------------------------{Fore.RESET}"

begin_test_delay = 20;
delay = 0;
build_type = "dotnet"
if len(sys.argv) > 1 and sys.argv[1]:
delay = int(sys.argv[1])

if len(sys.argv) > 2 and sys.argv[2]:
build_type = sys.argv[2]

godot_process = subprocess.Popen(['godot', '--editor', '.'], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
required_success_count = 50;
success_count = 0

print(f"{Fore.LIGHTGREEN_EX}Solution Crash Tester(Delay: {delay} ms, Required Successes: {required_success_count}):{Fore.RESET}, Build CLI {build_type}")
print(f"{Fore.LIGHTGREEN_EX} Press Ctrl+C to exit{Fore.RESET}")
print(DIVIDER)

time.sleep(begin_test_delay);
success = False

try:
while True:
content = ""
try:
with open("CrashTest.cs", "r+") as file:
content = file.read()
file.close()
except OSError:
print(f"{Fore.BLUE} CrashTest.cs doesn't exist, creating new file{Fore.RESET}")
with open("CrashTest.cs", "w+") as file:
if content == Content.ONE:
print(f"{Fore.BLUE} Changing Content to TWO{Fore.RESET}")
file.write(Content.TWO)
else:
print(f"{Fore.BLUE} Changing Content to ONE{Fore.RESET}")
file.write(Content.ONE)
file.close()
time.sleep(delay/1000)
print(f"{Fore.LIGHTBLUE_EX} Running Build:{Fore.RESET}")
start = time.time()
build_command = ["dotnet", "build"]
if build_type == "msbuild":
build_command = ["msbuild"]
result = subprocess.run(build_command, stdout=subprocess.PIPE)
end = time.time()
if (result.returncode == 0):
print(f"{Fore.BLUE} Success (%.2f s){Fore.RESET}" % (end - start))
else:
print(f"{Fore.RED} Build Failed:")
print(f"{Fore.LIGHTBLACK_EX}{result.stdout.decode('utf-8')}{Fore.RESET}");
break

if godot_process.poll() != None:
print(f"{Fore.RED}FAIL: Godot crashed. A marshalling bug exists in the project{Fore.RESET}");
success = False
break
else:
success_count += 1
print(f"{Fore.BLUE} Survived ({success_count}/{required_success_count}) rebuilds.{Fore.RESET}");

if success_count >= required_success_count:
print(f"{Fore.LIGHTGREEN_EX}SUCCESS: Godot survived the rebuilds.")
success = True
break
print(DIVIDER)
except KeyboardInterrupt:
pass

if godot_process.poll() == None:
godot_process.kill()

print(f"{Fore.LIGHTGREEN_EX}Exited...{Fore.RESET}");

if success:
sys.exit()
else:
sys.exit(1)

0 comments on commit 78e2346

Please sign in to comment.