#!/usr/bin/env python312import sys34if len(sys.argv) < 2:5print("ERROR: You must run program with file name as argument.")6sys.exit(50)78fname = sys.argv[1]910with open(fname.strip(), "r", encoding="utf-8") as fileread:11file_contents = fileread.read()1213# If find "ERROR: AddressSanitizer:", then happens invalid read or write14# This is critical bug, so we need to fix this as fast as possible1516if file_contents.find("ERROR: AddressSanitizer:") != -1:17print("FATAL ERROR: An incorrectly used memory was found.")18sys.exit(51)1920# There is also possible, that program crashed with or without backtrace.2122if (23file_contents.find("Program crashed with signal") != -124or file_contents.find("Dumping the backtrace") != -125or file_contents.find("Segmentation fault (core dumped)") != -126or file_contents.find("Aborted (core dumped)") != -127or file_contents.find("terminate called without an active exception") != -128):29print("FATAL ERROR: Godot has been crashed.")30sys.exit(52)3132# Finding memory leaks in Godot is quite difficult, because we need to take into33# account leaks also in external libraries. They are usually provided without34# debugging symbols, so the leak report from it usually has only 2/3 lines,35# so searching for 5 element - "#4 0x" - should correctly detect the vast36# majority of memory leaks3738if file_contents.find("ERROR: LeakSanitizer:") != -1:39if file_contents.find("#4 0x") != -1:40print("ERROR: Memory leak was found")41sys.exit(53)4243# It may happen that Godot detects leaking nodes/resources and removes them, so44# this possibility should also be handled as a potential error, even if45# LeakSanitizer doesn't report anything4647if file_contents.find("ObjectDB instances leaked at exit") != -1:48print("ERROR: Memory leak was found")49sys.exit(54)5051# In test project may be put several assert functions which will control if52# project is executed with right parameters etc. which normally will not stop53# execution of project5455if file_contents.find("Assertion failed") != -1:56print("ERROR: Assertion failed in project, check execution log for more info")57sys.exit(55)5859# For now Godot leaks a lot of rendering stuff so for now we just show info60# about it and this needs to be re-enabled after fixing this memory leaks.6162if file_contents.find("were leaked") != -1 or file_contents.find("were never freed") != -1:63print("WARNING: Memory leak was found")6465sys.exit(0)666768