#!/usr/bin/env python1# -*- coding: utf-8 -*-23import sys45if len(sys.argv) < 2:6print("ERROR: You must run program with file name as argument.")7sys.exit(50)89fname = sys.argv[1]1011with open(fname.strip(), "r", encoding="utf-8") as fileread:12file_contents = fileread.read()1314# If find "ERROR: AddressSanitizer:", then happens invalid read or write15# This is critical bug, so we need to fix this as fast as possible1617if file_contents.find("ERROR: AddressSanitizer:") != -1:18print("FATAL ERROR: An incorrectly used memory was found.")19sys.exit(51)2021# There is also possible, that program crashed with or without backtrace.2223if (24file_contents.find("Program crashed with signal") != -125or file_contents.find("Dumping the backtrace") != -126or file_contents.find("Segmentation fault (core dumped)") != -127or file_contents.find("Aborted (core dumped)") != -128or file_contents.find("terminate called without an active exception") != -129):30print("FATAL ERROR: Godot has been crashed.")31sys.exit(52)3233# Finding memory leaks in Godot is quite difficult, because we need to take into34# account leaks also in external libraries. They are usually provided without35# debugging symbols, so the leak report from it usually has only 2/3 lines,36# so searching for 5 element - "#4 0x" - should correctly detect the vast37# majority of memory leaks3839if file_contents.find("ERROR: LeakSanitizer:") != -1:40if file_contents.find("#4 0x") != -1:41print("ERROR: Memory leak was found")42sys.exit(53)4344# It may happen that Godot detects leaking nodes/resources and removes them, so45# this possibility should also be handled as a potential error, even if46# LeakSanitizer doesn't report anything4748if file_contents.find("ObjectDB instances leaked at exit") != -1:49print("ERROR: Memory leak was found")50sys.exit(54)5152# In test project may be put several assert functions which will control if53# project is executed with right parameters etc. which normally will not stop54# execution of project5556if file_contents.find("Assertion failed") != -1:57print("ERROR: Assertion failed in project, check execution log for more info")58sys.exit(55)5960# For now Godot leaks a lot of rendering stuff so for now we just show info61# about it and this needs to be re-enabled after fixing this memory leaks.6263if file_contents.find("were leaked") != -1 or file_contents.find("were never freed") != -1:64print("WARNING: Memory leak was found")6566sys.exit(0)676869