Skip to content

Commit fc68b8a

Browse files
committed
Added testing
1 parent 24704d7 commit fc68b8a

File tree

6 files changed

+212
-31
lines changed

6 files changed

+212
-31
lines changed

TheForceEngine/TFE_Input/replay.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,16 @@ namespace TFE_Input
965965
{
966966
char replayPath[TFE_MAX_PATH];
967967
sprintf(replayPath, "%s", sourceReplayPath);
968-
968+
969969
FileUtil::fixupPath(replayPath);
970970

971+
if (!FileUtil::exists(replayPath))
972+
{
973+
TFE_System::logWrite(LOG_MSG, "Replay", "Replay file does not exist: %s . Exiting...", replayPath);
974+
TFE_FrontEndUI::setState(APP_STATE_QUIT);
975+
return;
976+
}
977+
971978
TFE_SaveSystem::SaveHeader header;
972979
loadReplayHeader(replayPath, &header);
973980

@@ -979,7 +986,7 @@ namespace TFE_Input
979986
// This is a replay wrapper that handles agents and replay configuration
980987
void loadReplayWrapper(string replayFile, string modName, string levelId)
981988
{
982-
TFE_System::logWrite(LOG_MSG, "Replay", "modname = %s levelid = %s", modName.c_str(), levelId.c_str());
989+
TFE_System::logWrite(LOG_MSG, "Replay", "Loading Replay File = %s Modname = %s Levelid = %s", replayFile.c_str(), modName.c_str(), levelId.c_str());
983990

984991
// If you are replaying a demo, you should not be recording.
985992

TheForceEngine/Tests/Replays/base_replay_log.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
[MemoryRegion] Allocated new memory block in region 'game' - new size is 3 blocks, total size is '25165824'
12
[Player] Setting up level 'SECBASE'
23
[Error : Dark Forces Game Script] LevelScript.fs (0, 0) : Failed to open script file 'LevelScript.fs'
4+
[MemoryRegion] Allocated new memory block in region 'level' - new size is 2 blocks, total size is '16777216'
35
[Warning : level_loadGeometry] Could not open 'ZWIMP10L.BM', using 'default.bm' instead.
46
[Warning : level_loadGeometry] Could not open 'ZWIMP11.BM', using 'default.bm' instead.
57
[Warning : level_loadINF] Hit the end of INF 'SECBASE' before parsing all items: 58/60
8+
[MemoryRegion] Allocated new memory block in region 'game' - new size is 1 blocks, total size is '8388608'
69
[Replay] Update 61: X:16140206 Y:2293760 Z:24754258, yaw: 8025, pitch: 0, keysDown: , keysPressed: , mouse: 0,1,1186,268
710
[Replay] Update 62: X:16140206 Y:2289558 Z:24754258, yaw: 8025, pitch: -7, keysDown: , keysPressed: , mouse: 0,0,1186,268
811
[Replay] Update 63: X:16140206 Y:2256850 Z:24754258, yaw: 8025, pitch: -7, keysDown: , keysPressed: , mouse: 0,0,1186,268

TheForceEngine/Tests/runTests.bat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
if exist runTests.ps1 (
3+
start powershell -ExecutionPolicy bypass -File runTests.ps1
4+
exit
5+
) else (
6+
echo.
7+
echo.
8+
echo Cannot find runTests.ps1 in this directory. Make sure you put BOTH files in the same folder!
9+
echo.
10+
echo.
11+
)

TheForceEngine/Tests/runTests.ps1

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
# Setup TheForceEngine directory. Place the executable here to run your test
3+
4+
# If you do not, then it will guess where the executable is.
5+
$root_path = ""
6+
7+
# Fidn the specific build. Assume path is two layers above the script and in x64\DEBUG or x64\Release
8+
$build="RELEASE"
9+
10+
# Enable strict mode for better error handling
11+
Set-StrictMode -Version Latest
12+
$ErrorActionPreference = "Stop"
13+
14+
# Function to get the full path of the script directory
15+
function Get-ScriptDirectory {
16+
return Split-Path -Parent $PSCommandPath
17+
}
18+
19+
# If unset, try to copy from x64 release/debug folder during build and copy it to a standard place.
20+
if (-not $root_path -or -not (Test-Path "$root_path/TheForceEngine.exe")) {
21+
$root_path = Join-Path (Get-ScriptDirectory) "..\..\x64\$build\"
22+
Write-Host $root_path
23+
if (Test-Path "$root_path\TheForceEngine.exe") {
24+
$destPath = Join-Path (Get-ScriptDirectory) "..\"
25+
Copy-Item -Path "$root_path\TheForceEngine.exe" -Destination $destPath
26+
Write-Host "Found TheForceEngine.exe in path $root_path - copied to $destPath"
27+
$root_path = $destPath
28+
} else {
29+
Write-Host "ERROR: Cannot find TheForceEngine.exe. Please set it in the script"
30+
exit 1
31+
}
32+
}
33+
34+
# Directory where TFE logs are kept
35+
$user_doc_path = ""
36+
37+
if (-not $user_doc_path -or -not (Test-Path $user_doc_path -PathType Container)) {
38+
$user_doc_path = "$env:USERPROFILE\Documents\TheForceEngine"
39+
if (Test-Path $user_doc_path -PathType Container) {
40+
Write-Host "Found the user directory in $user_doc_path"
41+
} else {
42+
Write-Host "WARNING: Cannot find the user TFE directory $user_doc_path. Hopefully, it will be created by the executable."
43+
}
44+
}
45+
46+
# Path to the demo file
47+
$demo_path = ""
48+
49+
if (-not $demo_path -or -not (Test-Path $demo_path)) {
50+
$demo_path = Join-Path (Get-ScriptDirectory) "Replays\base_test.demo"
51+
if (Test-Path $demo_path) {
52+
Write-Host "Found the demo at $demo_path"
53+
} else {
54+
Write-Host "ERROR: Cannot find the demo file $demo_path. It should be in the TheForceEngine\Tests\Replays folder"
55+
exit 1
56+
}
57+
}
58+
59+
# Path to the demo log file
60+
$demo_log_path = ""
61+
62+
if (-not $demo_log_path -or -not (Test-Path $demo_log_path)) {
63+
$demo_log_path = Join-Path (Get-ScriptDirectory) "Replays\base_replay_log.txt"
64+
if (Test-Path $demo_log_path) {
65+
Write-Host "Found the demo log at $demo_log_path"
66+
} else {
67+
Write-Host "ERROR: Cannot find the demo log file $demo_log_path. It should be in the TheForceEngine\Tests\Replays folder"
68+
exit 1
69+
}
70+
}
71+
72+
# Run the demo and generate a new log file
73+
Push-Location $root_path
74+
Write-Host "Running The Force Engine..."
75+
Write-Host "Executing Command $root_path\TheForceEngine.exe -gDark -r$demo_path --demo_logging --exit_after_replay ..."
76+
77+
$proc = Start-Process -FilePath "$root_path\TheForceEngine.exe" -ArgumentList "-gDark -r`"$demo_path`" --demo_logging --exit_after_replay" -NoNewWindow -Wait -PassThru
78+
$exitCode = $($proc.ExitCode)
79+
Write-Host "Done running The Force Engine. Result is $exitCode"
80+
81+
if ($exitCode -ne 0) {
82+
Write-Host "ERROR: TFE failed to run. Please look at the logs hopefully generated in $user_doc_path"
83+
exit 1
84+
}
85+
86+
# Diff Log Results of the test replay.log and the base one.
87+
$replayLog = Join-Path $user_doc_path "replay.log"
88+
89+
if (-not (Test-Path $replayLog)) {
90+
Write-Host "ERROR: Missing $replayLog - No log generated?"
91+
exit 1
92+
}
93+
94+
if (-not (Test-Path $demo_log_path)) {
95+
Write-Host "ERROR: Missing $demo_log_path - did you not checkout the latest code?"
96+
exit 1
97+
}
98+
99+
# Compare last lines of both log files
100+
$lastLine1 = Get-Content -Path $replayLog | Select-Object -Last 1
101+
$lastLine2 = Get-Content -Path $demo_log_path | Select-Object -Last 1
102+
103+
if ($lastLine1 -eq $lastLine2) {
104+
Write-Host "TEST SUCCEEDED RESULTS MATCH!"
105+
exit 0
106+
} else {
107+
Write-Host "ERROR: RESULTS DO NOT MATCH!"
108+
Write-Host "Expected: $lastLine2"
109+
Write-Host "Got: $lastLine1"
110+
exit 1
111+
}

TheForceEngine/Tests/runTests.sh

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,95 @@
1-
# Setup the root path
2-
root_path="$1"
1+
# Setup theforceengine binary directory
2+
root_path=""
33

4-
# TFE does not like tildes in paths
5-
user_path=~
4+
# If unset try to look in a common folder
5+
if [[ ! -s "$root_path" || ! -f "$root_path/theforceengine" ]]; then
6+
root_path="$(dirname "$(realpath "$0")")"/../../
7+
if [ -f $root_path/theforceengine ]; then
8+
echo "Found theforceengine in path $root_path"
9+
else
10+
echo "WARNING: Cannot find theforceengine binary. Will try one folder up"
11+
root_path="$(dirname "$(realpath "$0")")"/../../../
12+
if [ -f $root_path/theforceengine ]; then
13+
echo "Found theforceengine in path $root_path"
14+
else
15+
echo "ERROR: Cannot find theforceengine binary. Please set it in the script"
16+
exit 1
17+
fi
18+
fi
19+
fi
620

7-
ls -tral $root_path
21+
# Directory where your TFE logs are kept - needed for logs
22+
user_doc_path=""
823

9-
ls -tral $root_path/TheForceEngine/
24+
if [[ ! -s "$user_doc_path" || ! -d "$user_doc_path" ]]; then
25+
# TFE does not like tildes in paths
26+
user_root=$(realpath ~)
27+
user_doc_path=$user_root/.local/share/TheForceEngine
28+
if [ -d $user_doc_path ]; then
29+
echo "Found the user directory in $user_doc_path"
30+
else
31+
echo "WARNING: Cannot find the user tfe directory $user_doc_path. Hopefully it will be created by the executable"
32+
fi
33+
fi
1034

11-
ls -tral $root_path/TheForceEngine/Tests/Replays/
35+
# Path to the demo file
36+
demo_path=""
1237

13-
ldd $root_path/TheForceEngine/theforceengine
38+
if [[ ! -s "$demo_path" || ! -f "$demo_path" ]]; then
39+
demo_path="$(dirname "$(realpath "$0")")"/Replays/base_test.demo
40+
if [ -f $demo_path ]; then
41+
echo "Found the demo at $demo_path"
42+
else
43+
echo "ERROR: Cannot find the demo file $demo_path. It should be in the TheForceEngine/Tests/Replays folder"
44+
exit 1
45+
fi
46+
fi
1447

15-
# Run the demo and generate new log file
16-
echo "running tfe"
17-
$root_path/TheForceEngine/theforceengine -gDark -r$root_path/Tests/Replays/base_test.demo --demo_logging --exit_after_replay
18-
echo "Result is "$?
19-
echo "Done running tfe"
48+
# Path to the demo log file
49+
demo_log_path=""
2050

21-
if [ -f $root_path/TheForceEngine/theforceengine ]; then
22-
echo "dump exists"
23-
else
24-
echo "no dump exists"
25-
fi
51+
if [[ ! -s "$demo_log_path" || ! -f "$demo_log_path" ]]; then
52+
demo_log_path="$(dirname "$(realpath "$0")")"/Replays/base_replay_log.txt
53+
if [ -f $demo_log_path ]; then
54+
echo "Found the demo log at $demo_log_path"
55+
else
56+
echo "ERROR: Cannot find the demo log file $demo_log_path. It should be in the TheForceEngine/Tests/Replays folder"
57+
exit 1
58+
fi
59+
fi
2660

27-
echo "running tfe2"
28-
$root_path/theforceengine -gDark -r$root_path/Tests/Replays/base_test.demo --demo_logging --exit_after_replay
29-
echo "Result is "$?
30-
echo "Done running tfe"
61+
# Run the demo and generate new log file
62+
pushd $root_path
63+
echo "Running TFE test..."
64+
echo "Executing Command $root_path/theforceengine -gDark -r$demo_path --demo_logging --exit_after_replay ....."
65+
$root_path/theforceengine -gDark -r$demo_path --demo_logging --exit_after_replay
66+
result=$?
67+
echo "Done running test. Result is $result"
3168

69+
if [ $result != "0" ]; then
70+
echo "ERROR: TFE failed to run. Please look at the logs hopefully generated in $user_doc_path"
71+
exit 1
72+
fi
73+
74+
# Diff Log Results of the test replay.log and the base one.
3275

33-
#find / -type d -iname the_force_engine_log.txt 2>/dev/null | xargs cat
76+
if [ ! -f $user_doc_path/replay.log ]; then
77+
echo "ERROR: Missing $user_doc_path/replay.log - No log generated?"
78+
exit 1
79+
fi
3480

35-
top -b -n 1 | head -n 20
81+
if [ ! -f $demo_log_path ]; then
82+
echo "ERROR: Missing $demo_log_path - did you not checkout the latest code?"
83+
exit 1
84+
fi
3685

37-
# Diff Results of the rest
38-
result=`diff <(tail -n 1 $user_path/.local/share/TheForceEngine/replay.log) <(tail -n 1 $root_path/TheForceEngine/Tests/Replays/base_replay_log.txt)`
86+
result=`diff <(tail -n 1 $user_doc_path/replay.log) <(tail -n 1 $demo_log_path)`
3987

4088
if $result > /dev/null; then
41-
echo "RESULTS MATCH!"
89+
echo "TEST SUCCEEDED RESULTS MATCH!"
4290
exit 0
4391
else
44-
echo "RESULTS DO NOT MATCH!"
92+
echo "ERROR: RESULTS DO NOT MATCH!"
4593
echo $result
4694
exit 1
4795
fi
48-

TheForceEngine/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ void parseCommandLine(s32 argc, char* argv[])
405405
const char* opt = argv[i];
406406
const size_t len = strlen(opt);
407407

408+
TFE_System::logWrite(LOG_MSG, "Main", "Parsing parameter %s", opt);
409+
408410
// Is this an option name or value?
409411
const char* optValue = nullptr;
410412
if (len && opt[0] == '-')

0 commit comments

Comments
 (0)