Skip to content

Commit 53d3f9c

Browse files
authored
Improve Operating System Testing demo (#1124)
- Display more return values of Engine/OS methods such as system fonts, memory information and security information. - Add headless support (the generated report is also printed to stdout). - Improve theming in the generated report. - Hide video adapter type if this information can't be queried in the current rendering method. - Update C# script for Godot 4.x platform names.
1 parent edccce8 commit 53d3f9c

File tree

5 files changed

+77
-29
lines changed

5 files changed

+77
-29
lines changed

misc/os_test/CSharpTest.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,16 @@ public string OperatingSystem()
66
{
77
#if GODOT_WINDOWS
88
return "Windows";
9-
#elif GODOT_LINUXBSD || GODOT_X11
10-
return "Linux (or BSD)";
11-
#elif GODOT_SERVER
12-
return "Server (Linux or BSD)";
13-
#elif GODOT_MACOS || GODOT_OSX
9+
#elif GODOT_LINUXBSD
10+
return "Linux/*BSD";
11+
#elif GODOT_MACOS
1412
return "macOS";
1513
#elif GODOT_ANDROID
1614
return "Android";
1715
#elif GODOT_IOS
1816
return "iOS";
19-
#elif GODOT_HTML5
20-
return "HTML5";
21-
#elif GODOT_HAIKU
22-
return "Haiku";
23-
#elif GODOT_UWP
24-
return "UWP (Windows 10)";
17+
#elif GODOT_WEB
18+
return "Web";
2519
#elif GODOT
2620
return "Other";
2721
#else

misc/os_test/actions.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func _on_open_shell_folder_pressed() -> void:
1414
# MacOS-specific.
1515
path = "file://" + path
1616

17-
OS.shell_open(path)
17+
OS.shell_show_in_file_manager(path)
1818

1919

2020
func _on_change_window_title_pressed() -> void:

misc/os_test/os_test.gd

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ extends Node
33
@onready var rtl: RichTextLabel = $HBoxContainer/Features
44
@onready var csharp_test: Node = $CSharpTest
55

6+
# Line number for alternate line coloring. Incremented by 1 each time a line is added
7+
# (ignoring headers).
8+
var line_count := 0
9+
610
# Returns a human-readable string from a date and time, date, or time dictionary.
711
func datetime_to_string(date: Dictionary) -> void:
812
if (
@@ -38,27 +42,48 @@ func datetime_to_string(date: Dictionary) -> void:
3842
})
3943

4044

41-
func scan_midi_devices() -> String:
45+
func scan_midi_inputs() -> String:
46+
if DisplayServer.get_name() == "headless":
47+
# Workaround for <https://github.com/godotengine/godot/issues/52821>.
48+
return ""
49+
4250
OS.open_midi_inputs()
4351
var devices := ", ".join(OS.get_connected_midi_inputs())
4452
OS.close_midi_inputs()
4553
return devices
4654

4755

4856
func add_header(header: String) -> void:
49-
rtl.append_text("\n[font_size=24][color=#6df]{header}[/color][/font_size]\n\n".format({
57+
rtl.append_text("\n[font_size=24][color=#5cf]{header}[/color][/font_size]\n[font_size=1]\n[/font_size]".format({
5058
header = header,
5159
}))
5260

61+
# Also print to the terminal for easy copy-pasting and headless usage.
62+
print_rich("\n[b][u][color=blue]{header}[/color][/u][/b]\n".format({
63+
header = header,
64+
}))
5365

5466
func add_line(key: String, value: Variant) -> void:
55-
if typeof(value) == TYPE_BOOL:
67+
line_count += 1
68+
var original_value: Variant = value
69+
if typeof(original_value) == TYPE_BOOL:
5670
# Colorize boolean values.
57-
value = "[color=8f8]true[/color]" if value else "[color=#f88]false[/color]"
71+
value = "[color=6f7]true[/color]" if original_value else "[color=#f76]false[/color]"
5872

59-
rtl.append_text("[color=#adf]{key}:[/color] {value}\n".format({
73+
rtl.append_text("{bgcolor}[color=#9df]{key}:[/color] {value}{bgcolor_end}\n".format({
6074
key = key,
6175
value = value if str(value) != "" else "[color=#fff8](empty)[/color]",
76+
bgcolor = "[bgcolor=#8883]" if line_count % 2 == 0 else "",
77+
bgcolor_end = "[/bgcolor]" if line_count % 2 == 0 else "",
78+
}))
79+
if typeof(original_value) == TYPE_BOOL:
80+
# Colorize boolean values (`print_rich()`-friendly version, using basic colors only).
81+
value = "[color=green]true[/color]" if original_value else "[color=red]false[/color]"
82+
83+
# Also print to the terminal for easy copy-pasting and headless usage.
84+
print_rich("[b][color=cyan]{key}:[/color][/b] {value}".format({
85+
key = key,
86+
value = value if str(value) != "" else "[code](empty)[/code]",
6287
}))
6388

6489

@@ -71,8 +96,9 @@ func _ready() -> void:
7196
add_line("Output latency", "%f ms" % (AudioServer.get_output_latency() * 1000))
7297
add_line("Output device list", ", ".join(AudioServer.get_output_device_list()))
7398
add_line("Capture device list", ", ".join(AudioServer.get_input_device_list()))
99+
add_line("Connected MIDI inputs", scan_midi_inputs())
74100

75-
add_header("Date")
101+
add_header("Date and time")
76102
add_line("Date and time (local)", Time.get_datetime_string_from_system(false, true))
77103
add_line("Date and time (UTC)", Time.get_datetime_string_from_system(true, true))
78104
add_line("Date (local)", Time.get_date_string_from_system(false))
@@ -103,14 +129,22 @@ func _ready() -> void:
103129

104130
add_header("Engine")
105131
add_line("Version", Engine.get_version_info()["string"])
132+
add_line("Compiled for architecture", Engine.get_architecture_name())
106133
add_line("Command-line arguments", str(OS.get_cmdline_args()))
107134
add_line("Is debug build", OS.is_debug_build())
108135
add_line("Executable path", OS.get_executable_path())
109136
add_line("User data directory", OS.get_user_data_dir())
110137
add_line("Filesystem is persistent", OS.is_userfs_persistent())
138+
add_line("Process ID (PID)", OS.get_process_id())
139+
add_line("Main thread ID", OS.get_main_thread_id())
140+
add_line("Thread caller ID", OS.get_thread_caller_id())
141+
add_line("Memory information", OS.get_memory_info())
142+
add_line("Static memory usage", OS.get_static_memory_usage())
143+
add_line("Static memory peak usage", OS.get_static_memory_peak_usage())
111144

112145
add_header("Environment")
113146
add_line("Value of `PATH`", OS.get_environment("PATH"))
147+
# Check for case-sensitivity behavior across platforms.
114148
add_line("Value of `path`", OS.get_environment("path"))
115149

116150
add_header("Hardware")
@@ -128,6 +162,7 @@ func _ready() -> void:
128162

129163
add_header("Localization")
130164
add_line("Locale", OS.get_locale())
165+
add_line("Language", OS.get_locale_language())
131166

132167
add_header("Mobile")
133168
add_line("Granted permissions", OS.get_granted_permissions())
@@ -137,15 +172,31 @@ func _ready() -> void:
137172
add_line("Mono module enabled", "Yes" if csharp_enabled else "No")
138173
if csharp_enabled:
139174
csharp_test.set_script(load("res://CSharpTest.cs"))
140-
add_line("Operating System", csharp_test.OperatingSystem())
141-
add_line("Platform Type", csharp_test.PlatformType())
175+
add_line("Operating system", csharp_test.OperatingSystem())
176+
add_line("Platform type", csharp_test.PlatformType())
142177

143178
add_header("Software")
144179
add_line("OS name", OS.get_name())
145-
add_line("Process ID", OS.get_process_id())
180+
add_line("OS version", OS.get_version())
181+
add_line("Distribution name", OS.get_distribution_name())
146182
add_line("System dark mode supported", DisplayServer.is_dark_mode_supported())
147183
add_line("System dark mode enabled", DisplayServer.is_dark_mode())
148184
add_line("System accent color", "#%s" % DisplayServer.get_accent_color().to_html())
185+
add_line("System fonts", "%d fonts available" % OS.get_system_fonts().size())
186+
add_line("System font path (\"sans-serif\")", OS.get_system_font_path("sans-serif"))
187+
add_line("System font path (\"sans-serif\") for English text", ", ".join(OS.get_system_font_path_for_text("sans-serif", "Hello")))
188+
add_line("System font path (\"sans-serif\") for Chinese text", ", ".join(OS.get_system_font_path_for_text("sans-serif", "你好")))
189+
add_line("System font path (\"sans-serif\") for Japanese text", ", ".join(OS.get_system_font_path_for_text("sans-serif", "こんにちは")))
190+
191+
add_header("Security")
192+
add_line("Is sandboxed", OS.is_sandboxed())
193+
add_line("Entropy (8 random bytes)", OS.get_entropy(8))
194+
add_line("System CA certificates", ("Available (%d bytes)" % OS.get_system_ca_certificates().length()) if not OS.get_system_ca_certificates().is_empty() else "Not available")
195+
196+
add_header("Engine directories")
197+
add_line("User data", OS.get_data_dir())
198+
add_line("Configuration", OS.get_config_dir())
199+
add_line("Cache", OS.get_cache_dir())
149200

150201
add_header("System directories")
151202
add_line("Desktop", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP))
@@ -160,13 +211,15 @@ func _ready() -> void:
160211
add_header("Video")
161212
add_line("Adapter name", RenderingServer.get_video_adapter_name())
162213
add_line("Adapter vendor", RenderingServer.get_video_adapter_vendor())
163-
add_line("Adapter type", [
164-
"Other (Unknown)",
165-
"Integrated",
166-
"Discrete",
167-
"Virtual",
168-
"CPU",
169-
][RenderingServer.get_video_adapter_type()])
214+
if ProjectSettings.get_setting_with_override("rendering/renderer/rendering_method") != "gl_compatibility":
215+
# Querying the adapter type isn't supported in Compatibility.
216+
add_line("Adapter type", [
217+
"Other (Unknown)",
218+
"Integrated",
219+
"Discrete",
220+
"Virtual",
221+
"CPU",
222+
][RenderingServer.get_video_adapter_type()])
170223
add_line("Adapter graphics API version", RenderingServer.get_video_adapter_api_version())
171224

172225
var video_adapter_driver_info := OS.get_video_adapter_driver_info()

misc/os_test/os_test.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ layout_mode = 2
3131
size_flags_horizontal = 3
3232
size_flags_vertical = 3
3333
focus_mode = 2
34+
theme_override_constants/line_separation = 6
3435
theme_override_styles/focus = SubResource("StyleBoxEmpty_dl4cr")
3536
bbcode_enabled = true
3637

misc/os_test/project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ In a nutshell, this demo shows how you can get information from the
1919
operating system, or interact with the operating system."
2020
config/tags=PackedStringArray("demo", "official", "porting")
2121
run/main_scene="res://os_test.tscn"
22-
config/features=PackedStringArray("4.2")
22+
config/features=PackedStringArray("4.3")
2323
run/low_processor_mode=true
2424
config/icon="res://icon.webp"
2525

0 commit comments

Comments
 (0)