feat: establish simulation scaling baseline
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
extends SceneTree
|
||||
|
||||
const SimulationManagerScript := preload("res://simulation/SimulationManager.gd")
|
||||
const BenchmarkScript := preload("res://simulation/benchmark/SimulationScalingBenchmark.gd")
|
||||
|
||||
var failures: Array[String] = []
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
call_deferred("_run")
|
||||
|
||||
|
||||
func _run() -> void:
|
||||
var first := _run_case(9001)
|
||||
var repeated := _run_case(9001)
|
||||
var different_seed := _run_case(9002)
|
||||
_check(not first.is_empty(), "The benchmark fixture should produce one result")
|
||||
if first.is_empty():
|
||||
_finish()
|
||||
return
|
||||
_check(first["fixture_valid"], "The prepared benchmark state should pass schema validation")
|
||||
_check(
|
||||
(
|
||||
int(first["schema_version"]) == SimulationScalingBenchmark.SCHEMA_VERSION
|
||||
and StringName(first["workload_id"]) == SimulationScalingBenchmark.WORKLOAD_ID
|
||||
and int(first["population"]) == 12
|
||||
and int(first["history_seed_events"]) == 24
|
||||
and int(first["measured_ticks"]) == 8
|
||||
and int(first["npc_updates"]) == 96
|
||||
and is_equal_approx(float(first["tick_interval"]), 1.2)
|
||||
and int(first["end_tick"]) - int(first["start_tick"]) == 8
|
||||
),
|
||||
"The result should identify the exact workload and measured update count"
|
||||
)
|
||||
_check(
|
||||
(
|
||||
int(first["elapsed_usec"]) > 0
|
||||
and int(first["simulation_usec"]) > 0
|
||||
and int(first["arrival_usec"]) > 0
|
||||
and int(first["start_state_bytes"]) > 0
|
||||
and int(first["end_state_bytes"]) >= int(first["start_state_bytes"])
|
||||
and int(first["arrivals_processed"]) > 0
|
||||
and int(first["events_recorded"]) > 0
|
||||
and int(first["end_event_count"]) >= 24
|
||||
and String(first["final_checksum"]).length() == 64
|
||||
),
|
||||
"The benchmark should report timing, state growth, updates, history, and a checksum"
|
||||
)
|
||||
for deterministic_key in [
|
||||
"final_checksum",
|
||||
"start_state_bytes",
|
||||
"end_state_bytes",
|
||||
"state_growth_bytes",
|
||||
"start_event_count",
|
||||
"end_event_count",
|
||||
"events_recorded",
|
||||
"start_known_reference_count",
|
||||
"end_known_reference_count",
|
||||
"arrivals_processed",
|
||||
"warmup_arrivals",
|
||||
"tick_interval",
|
||||
]:
|
||||
_check(
|
||||
first[deterministic_key] == repeated[deterministic_key],
|
||||
"Repeated benchmark runs should preserve %s" % deterministic_key
|
||||
)
|
||||
_check(
|
||||
first["final_checksum"] != different_seed["final_checksum"],
|
||||
"A different fixture seed should produce a different deterministic checksum"
|
||||
)
|
||||
_finish()
|
||||
|
||||
|
||||
func _run_case(seed_value: int) -> Dictionary:
|
||||
var manager := SimulationManagerScript.new()
|
||||
manager.simulation_seed = seed_value
|
||||
manager.debug_logs = false
|
||||
manager.set_process(false)
|
||||
root.add_child(manager)
|
||||
var benchmark := BenchmarkScript.new()
|
||||
if not benchmark.prepare_manager(manager, 12, 24, seed_value):
|
||||
manager.free()
|
||||
return {}
|
||||
var fixture_valid := SimulationStateRecord.from_json(manager.serialize_state()) != null
|
||||
var result: Dictionary = benchmark.measure_manager(manager, 12, 24, 2, 8)
|
||||
result["fixture_valid"] = fixture_valid
|
||||
manager.free()
|
||||
return result
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
if not condition:
|
||||
failures.append(message)
|
||||
|
||||
|
||||
func _finish() -> void:
|
||||
if failures.is_empty():
|
||||
print("[TEST] Simulation scaling benchmark passed: valid fixture -> stable metrics")
|
||||
quit(0)
|
||||
return
|
||||
for failure in failures:
|
||||
push_error("[TEST] " + failure)
|
||||
quit(1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://sn24dfw1g3pd
|
||||
Reference in New Issue
Block a user