2020-08-05 11:03:11 +02:00
extends Node
2020-11-06 16:57:49 +01:00
const screen_size = Vector2 ( 1024 , 600 )
2022-01-06 08:36:36 +01:00
var start_time : int
var last_time : int
2020-11-06 16:57:49 +01:00
2022-01-06 08:36:36 +01:00
const PRINT_TIME_EVERY_MILISECONDS : int = 5000
var time_to_print_next_time : int = PRINT_TIME_EVERY_MILISECONDS
2020-08-05 11:03:11 +02:00
2022-01-06 08:36:36 +01:00
var time_to_show : int = 25 * 1000 # How long test works in miliseconds
2020-08-05 11:03:11 +02:00
2022-01-06 08:36:36 +01:00
var time_for_each_step : int = - 1
2020-11-17 20:10:21 +01:00
2022-01-06 08:36:36 +01:00
var can_be_closed : bool = true
2021-04-15 19:13:17 +02:00
2020-11-17 20:10:21 +01:00
# Each scene runs alone
2022-01-06 08:36:36 +01:00
const alone_steps : Array = [
2021-09-18 21:01:07 +02:00
" res://CreatingAllThings/CreatingAllThings.tscn " ,
2021-04-04 12:52:42 +02:00
" res://Nodes/Nodes.tscn " ,
2022-01-06 08:36:36 +01:00
" res://Physics/2D/Physics2D.tscn " ,
" res://Physics/3D/Physics3D.tscn " ,
# "res://ReparentingDeleting/ReparentingDeleting.tscn", Not always reproducible
" res://AutomaticBugs/FunctionExecutor.tscn " , # Only need to run once
2020-11-17 20:10:21 +01:00
]
2022-01-06 08:36:36 +01:00
var time_object : Object
func _init ( ) :
# Workaround for Time/OS breaking change - https://github.com/godotengine/godot/pull/54056
if ClassDB . class_exists ( " _Time " ) :
time_object = ClassDB . instantiate ( " _Time " )
elif ClassDB . class_exists ( " Time " ) :
time_object = ClassDB . instantiate ( " Time " )
2021-04-23 21:50:57 +02:00
else :
2022-01-06 08:36:36 +01:00
time_object = ClassDB . instantiate ( " _OS " )
start_time = time_object . get_ticks_msec ( )
2021-04-04 12:52:42 +02:00
# In case when user doesn't provide time
time_for_each_step = time_to_show / ( alone_steps . size ( ) )
2022-01-06 08:36:36 +01:00
for argument in OS . get_cmdline_args ( ) :
if argument . is_valid_float ( ) : # Ignore all non numeric arguments
2021-01-11 19:20:11 +01:00
time_to_show = int ( argument . to_float ( ) * 1000 )
2021-03-27 15:53:32 +01:00
time_for_each_step = time_to_show / ( alone_steps . size ( ) )
2022-01-06 08:36:36 +01:00
print ( " Time set to: " + str ( time_to_show / 1000.0 ) + " seconds with " + str ( alone_steps . size ( ) ) + " steps, each step will take " + str ( time_for_each_step / 1000.0 ) + " seconds. " )
break # We only need to take first numeric argument
2020-08-05 11:03:11 +02:00
2020-11-06 16:57:49 +01:00
func _process ( delta : float ) - > void :
2022-01-06 08:36:36 +01:00
var current_run_time : int = time_object . get_ticks_msec ( ) - start_time
# While loop instead simple if, because will allow to properly flush results under heavy operations(e.g. Thread sanitizer)
while current_run_time > time_to_print_next_time :
2020-12-13 19:26:04 +01:00
print ( " Test is running now " + str ( int ( time_to_print_next_time / 1000 ) ) + " seconds " )
time_to_print_next_time += PRINT_TIME_EVERY_MILISECONDS
2022-01-06 08:36:36 +01:00
if current_run_time > time_to_show && can_be_closed :
2020-12-29 08:29:25 +01:00
print ( " ######################## Ending test ######################## " )
2020-08-05 11:03:11 +02:00
get_tree ( ) . quit ( )
2021-04-23 21:50:57 +02:00
2021-06-18 18:38:38 +02:00
2022-01-06 08:36:36 +01:00
func _exit_tree ( ) - > void :
time_object . free ( )