Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_AutotestPrinter.c
Go to the documentation of this file.
1
6
class
SCR_AutotestPrinter
7
{
8
static
const
string
LOG_PATH =
"$logs:autotest.log"
;
9
static
const
int
LOG_ONCE_THRESHOLD = 10000;
10
11
protected
bool
m_bLogVerbose
;
12
protected
ref
FileHandle
m_LogFile
;
13
14
protected
ref
map<typename, ref array<string>
>
m_mLogBuffer
=
new
map<typename, ref array<string>
>();
15
16
protected
string
m_sLogOnceLastMsg
;
17
protected
int
m_iLogOnceLastMsgCount
;
18
19
//------------------------------------------------------------------------------------------------
20
void
PrintTestSuitePrelude
(
TestSuite
suite)
21
{
22
Log
(
""
);
23
Log
(
"############################################/"
);
24
Log
(
string
.Format(
"TestSuite #%1 started"
, suite.ClassName()));
25
}
26
27
//------------------------------------------------------------------------------------------------
28
void
PrintTestSuiteEpilogue
(
TestSuite
suite)
29
{
30
Log
(
"/############################################"
);
31
Log
(
""
);
32
}
33
34
//------------------------------------------------------------------------------------------------
36
void
Log
(
string
msg,
LogLevel
level =
LogLevel
.NORMAL,
bool
forceFileWrite =
false
,
bool
consoleLog =
true
)
37
{
38
// dump info how many "LogOnce"s preceeded this message
39
if
(
m_iLogOnceLastMsgCount
> 0)
40
{
41
string
logOnceMsg =
string
.Format(
"(x%2) %1"
,
m_sLogOnceLastMsg
,
m_iLogOnceLastMsgCount
);
42
m_iLogOnceLastMsgCount
= 0;
43
m_sLogOnceLastMsg
=
""
;
44
Log
(logOnceMsg);
45
}
46
47
if
(consoleLog)
48
{
49
Print
(
""
+ msg, level);
50
}
51
52
string
msgFile =
string
.Format(
"%3 %1%2"
, GetLogPrefix(level), msg, GetTimeLocal());
53
54
TestBase
activeTest =
SCR_AutotestHarness
.ActiveTestCase();
55
if
(activeTest && !forceFileWrite)
56
{
57
typename
activeTestType = activeTest.Type();
58
if
(!
m_mLogBuffer
.Contains(activeTestType))
59
{
60
m_mLogBuffer
.Insert(activeTestType, {});
61
}
62
63
array<string> buffer =
m_mLogBuffer
.Get(activeTestType);
64
buffer.Insert(msgFile);
65
}
66
else
67
{
68
m_LogFile
.WriteLine(msgFile);
69
}
70
}
71
72
//------------------------------------------------------------------------------------------------
74
void
LogOnce
(
string
msg,
LogLevel
level =
LogLevel
.NORMAL)
75
{
76
if
(msg ==
m_sLogOnceLastMsg
&&
m_iLogOnceLastMsgCount
< LOG_ONCE_THRESHOLD)
77
{
78
m_iLogOnceLastMsgCount
++;
79
return
;
80
}
81
82
if
(msg ==
m_sLogOnceLastMsg
&&
m_iLogOnceLastMsgCount
>= LOG_ONCE_THRESHOLD)
83
{
84
int
count =
m_iLogOnceLastMsgCount
;
85
m_iLogOnceLastMsgCount
= 0;
86
Log
(
string
.Format(
"(x%2) %1"
,
m_sLogOnceLastMsg
, count), level);
87
88
return
;
89
}
90
91
m_sLogOnceLastMsg
= msg;
92
m_iLogOnceLastMsgCount
= 0;
93
Log
(msg, level);
94
}
95
96
//------------------------------------------------------------------------------------------------
99
void
LogTestCaseResult
(
TestBase
test)
100
{
101
TestResultBase
result = test.GetResult();
102
if
(!result)
103
{
104
Log
(
string
.Format(
"\t⚠️ %1: NO_RESULT"
, test.GetName()), forceFileWrite:
true
);
105
return
;
106
}
107
108
if
(
TestResultTimeout
.Cast(result))
109
{
110
Log
(
string
.Format(
"\t⌚ %1: FAILURE"
, test.GetName()), forceFileWrite:
true
);
111
Log
(
string
.Format(
"\t\tFailure reason: %1"
,
"timeout"
), forceFileWrite:
true
);
112
DumpTestBuffer(test.Type());
113
return
;
114
}
115
116
if
(result.Failure())
117
{
118
Log
(
string
.Format(
"\t⛔ %1: FAILURE"
, test.GetName()), forceFileWrite:
true
);
119
120
string
failureReason = result.FailureText();
121
SCR_AutotestResult
autotestResult =
SCR_AutotestResult
.Cast(result);
122
if
(autotestResult)
123
failureReason = autotestResult.
GetFailureReason
();
124
125
Log
(
string
.Format(
"\t\tFailure reason: %1"
, failureReason), forceFileWrite:
true
);
126
127
DumpTestBuffer(test.Type());
128
}
129
else
130
{
131
Log
(
string
.Format(
"\t✅ %1: SUCCESS"
, test.GetName()), forceFileWrite:
true
);
132
if
(
m_bLogVerbose
)
133
{
134
DumpTestBuffer(test.Type());
135
}
136
}
137
}
138
139
//------------------------------------------------------------------------------------------------
141
private
void
DumpTestBuffer(
typename
testType)
142
{
143
array<string> buffer =
m_mLogBuffer
.Get(testType);
144
if
(!buffer)
145
{
146
Log
(
"\t Output: <none>"
, forceFileWrite:
true
, consoleLog:
false
);
147
return
;
148
}
149
150
Log
(
"\t Output:"
, forceFileWrite:
true
, consoleLog:
false
);
151
foreach
(
string
msgFile : buffer)
152
{
153
m_LogFile
.WriteLine(
"\t"
+ msgFile);
154
}
155
156
m_mLogBuffer
.Remove(testType);
157
}
158
159
//------------------------------------------------------------------------------------------------
160
private
string
GetLogPrefix(
LogLevel
level)
161
{
162
if
(level <=
LogLevel
.NORMAL)
163
return
""
;
164
165
return
string
.Format(
"(%1): "
,
typename
.EnumToString(
LogLevel
, level));
166
}
167
168
//------------------------------------------------------------------------------------------------
170
private
string
GetTimeLocal()
171
{
172
int
hour, minute, second;
173
System.GetHourMinuteSecond(hour, minute, second);
174
175
return
string
.Format(
"%1:%2:%3"
, hour.ToString(2), minute.ToString(2), second.ToString(2));
176
}
177
178
//------------------------------------------------------------------------------------------------
179
void
SCR_AutotestPrinter(
bool
verbose)
180
{
181
m_bLogVerbose
= verbose;
182
m_LogFile
= FileIO.OpenFile(LOG_PATH,
FileMode
.WRITE);
183
}
184
185
//------------------------------------------------------------------------------------------------
186
void
~SCR_AutotestPrinter()
187
{
188
m_LogFile
.Close();
189
}
190
}
Log
override void Log()
Definition
SCR_VotingBase.c:117
FileHandle
Definition
FileHandle.c:69
SCR_AutotestHarness
Definition
SCR_AutotestHarness.c:24
SCR_AutotestPrinter::LogOnce
void LogOnce(string msg, LogLevel level=LogLevel.NORMAL)
Prevents duplicate printing of the same message. Intended to be used with messages printed many times...
Definition
SCR_AutotestPrinter.c:74
SCR_AutotestPrinter::PrintTestSuiteEpilogue
void PrintTestSuiteEpilogue(TestSuite suite)
Definition
SCR_AutotestPrinter.c:28
SCR_AutotestPrinter::m_sLogOnceLastMsg
string m_sLogOnceLastMsg
Definition
SCR_AutotestPrinter.c:16
SCR_AutotestPrinter::m_mLogBuffer
ref map< typename, ref array< string > > m_mLogBuffer
Definition
SCR_AutotestPrinter.c:14
SCR_AutotestPrinter::Log
void Log(string msg, LogLevel level=LogLevel.NORMAL, bool forceFileWrite=false, bool consoleLog=true)
Should be used in tests instead of global Print. Forwards test output to separate file.
Definition
SCR_AutotestPrinter.c:36
SCR_AutotestPrinter::m_bLogVerbose
bool m_bLogVerbose
Definition
SCR_AutotestPrinter.c:11
SCR_AutotestPrinter::m_iLogOnceLastMsgCount
int m_iLogOnceLastMsgCount
Definition
SCR_AutotestPrinter.c:17
SCR_AutotestPrinter::PrintTestSuitePrelude
void PrintTestSuitePrelude(TestSuite suite)
Definition
SCR_AutotestPrinter.c:20
SCR_AutotestPrinter::m_LogFile
ref FileHandle m_LogFile
Definition
SCR_AutotestPrinter.c:12
SCR_AutotestPrinter::LogTestCaseResult
void LogTestCaseResult(TestBase test)
Definition
SCR_AutotestPrinter.c:99
SCR_AutotestResult
Definition
SCR_AutotestResult.c:5
SCR_AutotestResult::GetFailureReason
string GetFailureReason()
Plain failure text.
Definition
SCR_AutotestResult.c:33
TestBase
Test base class.
Definition
TestBase.c:14
TestResultBase
Definition
TestResultBase.c:17
TestResultTimeout
Definition
TestResultTimeout.c:13
TestSuite
Collection of tests. Provides API for environment preparation.
Definition
TestSuite.c:14
map
Definition
Types.c:486
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
FileMode
FileMode
Mode for opening file. See FileSystem::Open.
Definition
FileMode.c:14
scripts
Autotest
Game
TestFramework
SCR_AutotestPrinter.c
Generated by
1.17.0