| | 1 | | #pragma rtGlobals=3 |
| | 2 | | #pragma TextEncoding="UTF-8" |
| | 3 | | #pragma rtFunctionErrors=1 |
| | 4 | | #pragma version=1.10 |
| | 5 | | #pragma ModuleName=IUTF_Hooks |
| | 6 | |
|
| | 7 | | ///@cond HIDDEN_SYMBOL |
| | 8 | |
|
| | 9 | | /// @name Hook execution level |
| | 10 | | /// @{ |
| | 11 | | static Constant HOOK_LEVEL_TEST_RUN = 0 |
| | 12 | | static Constant HOOK_LEVEL_TEST_SUITE = 1 |
| | 13 | | static Constant HOOK_LEVEL_TEST_CASE = 2 |
| | 14 | | /// @} |
| | 15 | |
|
| | 16 | | /// Groups all hooks which are executed at test case/suite begin/end |
| | 17 | | Structure IUTF_TestHooks |
| | 18 | | string testBegin |
| | 19 | | string testEnd |
| | 20 | | string testSuiteBegin |
| | 21 | | string testSuiteEnd |
| | 22 | | string testCaseBegin |
| | 23 | | string testCaseEnd |
| | 24 | | EndStructure |
| | 25 | |
|
| | 26 | | /// @brief initialize all strings in TestHook structure to be non <null> |
| 20 | 27 | | static Function InitHooks(s) |
| | 28 | | STRUCT IUTF_TestHooks &s |
| | 29 | |
|
| 20 | 30 | | s.testBegin = "" |
| 20 | 31 | | s.testEnd = "" |
| 20 | 32 | | s.testSuiteBegin = "" |
| 20 | 33 | | s.testSuiteEnd = "" |
| 20 | 34 | | s.testCaseBegin = "" |
| 20 | 35 | | s.testCaseEnd = "" |
| 20 | 36 | | End |
| | 37 | |
|
| | 38 | | /// @brief Execute the provided user hook and catches all runtime errors. If the name of the hook |
| | 39 | | /// function doesn't end in "_OVERRIDE" this hook will be considered as prototype and won't be |
| | 40 | | /// executed. The return is still 0 as if no error happened. |
| | 41 | | /// |
| | 42 | | /// @param name name of the test run/suite/case |
| | 43 | | /// @param userHook the function reference to the user hook |
| | 44 | | /// @param procWIn name of the procedure window |
| 224 | 45 | | static Function ExecuteUserHook(name, userHook, procWin, level) |
| | 46 | | FUNCREF USER_HOOK_PROTO userHook |
| | 47 | | string name, procWin |
| | 48 | | variable level |
| | 49 | |
|
| 224 | 50 | | variable err |
| 224 | 51 | | string errorMessage, endTime |
| 224 | 52 | | string hookName = StringByKey("Name", FuncRefInfo(userHook)) |
| | 53 | |
|
| 224 | 54 | | if(!StringMatch(hookName, "*_OVERRIDE")) |
| 218 | 55 | | return NaN |
| 6 | 56 | | endif |
| | 57 | |
|
| 6 | 58 | | switch(level) |
| 6 | 59 | | case HOOK_LEVEL_TEST_RUN: |
| 6 | 60 | | IUTF_Reporting_Control#TestSuiteBegin("@HOOK_SUITE") |
| 6 | 61 | | IUTF_Reporting_Control#TestCaseBegin(hookName, 0) |
| 6 | 62 | | break; |
| 0 | 63 | | case HOOK_LEVEL_TEST_SUITE: |
| 0 | 64 | | IUTF_Reporting_Control#TestCaseBegin(hookName, 0) |
| 0 | 65 | | break; |
| 0 | 66 | | case HOOK_LEVEL_TEST_CASE: |
| 0 | 67 | | IUTF_Reporting_Control#TestCaseBegin(hookName, 0) |
| 0 | 68 | | break; |
| 0 | 69 | | default: |
| 0 | 70 | | sprintf errorMessage, "Unknown hook level: %d", level |
| 0 | 71 | | IUTF_Reporting#ReportErrorAndAbort(errorMessage) |
| 0 | 72 | | return NaN |
| 6 | 73 | | endswitch |
| | 74 | |
|
| 6 | 75 | | StartWaveTracking(name) |
| | 76 | |
|
| 6 | 77 | | try |
| 6 | 78 | | IUTF_Basics#ClearRTError() |
| 6 | 79 | | userHook(name); AbortOnRTE |
| 5 | 80 | | catch |
| 0 | 81 | | errorMessage = GetRTErrMessage() |
| 0 | 82 | | err = GetRTError(1) |
| 0 | 83 | | IUTF_Basics#EvaluateRTE(err, errorMessage, V_AbortCode, hookName, IUTF_USER_HOOK_TYPE, procWin) |
| | 84 | |
|
| 0 | 85 | | IUTF_Basics#setAbortFlag() |
| 0 | 86 | | endtry |
| | 87 | |
|
| 5 | 88 | | endTime = IUTF_Reporting#GetTimeString() |
| | 89 | |
|
| 5 | 90 | | FinishWaveTracking(name) |
| | 91 | |
|
| 5 | 92 | | switch(level) |
| 5 | 93 | | case HOOK_LEVEL_TEST_RUN: |
| 5 | 94 | | IUTF_Reporting_Control#TestCaseEnd(endTime) |
| 5 | 95 | | IUTF_Reporting_Control#TestSuiteEnd() |
| 5 | 96 | | break |
| 0 | 97 | | case HOOK_LEVEL_TEST_SUITE: |
| 0 | 98 | | IUTF_Reporting_Control#TestCaseEnd(endTime) |
| 0 | 99 | | break |
| 0 | 100 | | case HOOK_LEVEL_TEST_CASE: |
| 0 | 101 | | IUTF_Reporting_Control#TestCaseEnd(endTime) |
| 0 | 102 | | break |
| 0 | 103 | | default: |
| 0 | 104 | | sprintf errorMessage, "Unknown hook level: %d", level |
| 0 | 105 | | IUTF_Reporting#ReportErrorAndAbort(errorMessage) |
| 0 | 106 | | return NaN |
| 5 | 107 | | endswitch |
| 224 | 108 | | End |
| | 109 | |
|
| | 110 | | /// @brief Execute the builtin and user hooks |
| | 111 | | /// |
| | 112 | | /// @param hookType One of @ref HookTypes |
| | 113 | | /// @param hooks hooks structure |
| | 114 | | /// @param enableTAP set this to a value other than 0 to enable TAP output |
| | 115 | | /// @param enableJU set this to a value other than 0 to enable JUnit output |
| | 116 | | /// @param name name of the test run/suite/case |
| | 117 | | /// @param procWin name of the procedure window |
| | 118 | | /// @param tcIndex current index of TestRunData |
| | 119 | | /// @param param parameter for the builtin hooks |
| | 120 | | /// |
| | 121 | | /// Catches runtime errors in the user hooks as well. |
| | 122 | | /// Takes care of correct bracketing of user and builtin functions as well. For |
| | 123 | | /// `begin` functions the order is builtin/user and for `end` functions user/builtin. |
| 224 | 124 | | static Function ExecuteHooks(hookType, hooks, enableTAP, enableJU, name, procWin, tcIndex, [param]) |
| | 125 | | variable hookType |
| | 126 | | STRUCT IUTF_TestHooks &hooks |
| | 127 | | variable enableTAP, enableJU |
| | 128 | | string name, procWin |
| | 129 | | variable tcIndex |
| | 130 | | variable param |
| | 131 | |
|
| 224 | 132 | | variable err, skip, tcOutIndex |
| 224 | 133 | | string errorMessage, hookName, endTime |
| | 134 | |
|
| 224 | 135 | | WAVE/T testRunData = IUTF_Basics#GetTestRunData() |
| 224 | 136 | | skip = str2num(testRunData[tcIndex][%SKIP]) |
| | 137 | |
|
| 224 | 138 | | switch(hookType) |
| 6 | 139 | | case IUTF_TEST_BEGIN_CONST: |
| 6 | 140 | | AbortOnValue ParamIsDefault(param), 1 |
| | 141 | |
|
| 6 | 142 | | FUNCREF USER_HOOK_PROTO userHook = $hooks.testBegin |
| | 143 | |
|
| 6 | 144 | | TestBegin(name, param) |
| 6 | 145 | | ExecuteUserHook(name, userHook, procWin, HOOK_LEVEL_TEST_RUN) |
| 6 | 146 | | break |
| 27 | 147 | | case IUTF_TEST_SUITE_BEGIN_CONST: |
| 27 | 148 | | AbortOnValue !ParamIsDefault(param), 1 |
| | 149 | |
|
| 27 | 150 | | FUNCREF USER_HOOK_PROTO userHook = $hooks.testSuiteBegin |
| | 151 | |
|
| 27 | 152 | | TestSuiteBegin(name) |
| 27 | 153 | | ExecuteUserHook(name, userHook, procWin, HOOK_LEVEL_TEST_SUITE) |
| 27 | 154 | | break |
| 79 | 155 | | case IUTF_TEST_CASE_BEGIN_CONST: |
| 79 | 156 | | AbortOnValue !ParamIsDefault(param), 1 |
| | 157 | |
|
| 79 | 158 | | FUNCREF USER_HOOK_PROTO userHook = $hooks.testCaseBegin |
| | 159 | |
|
| 79 | 160 | | if(!skip) |
| 79 | 161 | | TestCaseBegin(name) |
| 79 | 162 | | ExecuteUserHook(name, userHook, procWin, HOOK_LEVEL_TEST_CASE) |
| 79 | 163 | | endif |
| 79 | 164 | | BeforeTestCase(name, skip) |
| 79 | 165 | | break |
| 79 | 166 | | case IUTF_TEST_CASE_END_CONST: |
| 79 | 167 | | AbortOnValue ParamIsDefault(param), 1 |
| | 168 | |
|
| 79 | 169 | | // get the end time of the test case as fast as possible |
| 79 | 170 | | endTime = IUTF_Reporting#GetTimeString() |
| 79 | 171 | | // cache the current index in the results wave as a hook can change it |
| 79 | 172 | | WAVE/T wvTestCase = IUTF_Reporting#GetTestCaseWave() |
| 79 | 173 | | tcOutIndex = FindDimLabel(wvTestCase, UTF_ROW, "CURRENT") |
| | 174 | |
|
| 79 | 175 | | AfterTestCase(name, skip) |
| | 176 | |
|
| 79 | 177 | | if(!skip) |
| 79 | 178 | | FUNCREF USER_HOOK_PROTO userHook = $hooks.testCaseEnd |
| 79 | 179 | | ExecuteUserHook(name, userHook, procWin, HOOK_LEVEL_TEST_CASE) |
| 79 | 180 | | endif |
| 79 | 181 | | AfterTestCaseUserHook(name, param) |
| | 182 | |
|
| 79 | 183 | | if(!skip) |
| 79 | 184 | | // finalize the normal test case at tcOutIndex and reset the test case index to the |
| 79 | 185 | | // one after the hook |
| 79 | 186 | | TestCaseEnd(name, tcOutIndex, endTime) |
| 79 | 187 | | endif |
| 79 | 188 | | break |
| 27 | 189 | | case IUTF_TEST_SUITE_END_CONST: |
| 27 | 190 | | AbortOnValue !ParamIsDefault(param), 1 |
| | 191 | |
|
| 27 | 192 | | FUNCREF USER_HOOK_PROTO userHook = $hooks.testSuiteEnd |
| | 193 | |
|
| 27 | 194 | | ExecuteUserHook(name, userHook, procWin, HOOK_LEVEL_TEST_SUITE) |
| 27 | 195 | | TestSuiteEnd(name) |
| 27 | 196 | | break |
| 6 | 197 | | case IUTF_TEST_END_CONST: |
| 6 | 198 | | AbortOnValue ParamIsDefault(param), 1 |
| | 199 | |
|
| 6 | 200 | | FUNCREF USER_HOOK_PROTO userHook = $hooks.testEnd |
| | 201 | |
|
| 6 | 202 | | ExecuteUserHook(name, userHook, procWin, HOOK_LEVEL_TEST_RUN) |
| 5 | 203 | | TestEnd(name, param) |
| 5 | 204 | | if(enableJU) |
| 5 | 205 | | IUTF_JUnit#JU_WriteOutput() |
| 5 | 206 | | endif |
| 5 | 207 | | if(enableTAP) |
| 0 | 208 | | IUTF_TAP#TAP_Write() |
| 5 | 209 | | endif |
| 5 | 210 | | break |
| 0 | 211 | | default: |
| 0 | 212 | | IUTF_Reporting#ReportErrorAndAbort("Unknown hookType") |
| 0 | 213 | | break |
| 223 | 214 | | endswitch |
| 224 | 215 | | End |
| | 216 | |
|
| | 217 | | /// Internal Setup for Testrun |
| | 218 | | /// @param name name of the test suite group |
| 6 | 219 | | static Function TestBegin(name, debugMode) |
| | 220 | | string name |
| | 221 | | variable debugMode |
| | 222 | |
|
| 6 | 223 | | string msg |
| | 224 | |
|
| 6 | 225 | | IUTF_Reporting_Control#TestBegin() |
| 6 | 226 | | IUTF_Basics#InitAbortFlag() |
| 6 | 227 | | IUTF_Debug#SetDebugger(debugMode) |
| | 228 | |
|
| 6 | 229 | | WAVE/T wvFailed = IUTF_Reporting#GetFailedProcWave() |
| 6 | 230 | | IUTF_Utils_Vector#SetLength(wvFailed, 0) |
| | 231 | |
|
| 6 | 232 | | ClearBaseFilename() |
| | 233 | |
|
| 6 | 234 | | sprintf msg, "Start of test \"%s\"", name |
| 6 | 235 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 6 | 236 | | End |
| | 237 | |
|
| | 238 | | /// Internal Cleanup for Testrun |
| | 239 | | /// @param name name of the test suite group |
| 5 | 240 | | static Function TestEnd(name, debugMode) |
| | 241 | | string name |
| | 242 | | variable debugMode |
| | 243 | |
|
| 5 | 244 | | string msg |
| 5 | 245 | | variable i, index |
| 5 | 246 | | DFREF dfr = GetPackageFolder() |
| 5 | 247 | | WAVE/T wvFailed = IUTF_Reporting#GetFailedProcWave() |
| 5 | 248 | | WAVE/T wvTestRun = IUTF_Reporting#GetTestRunWave() |
| | 249 | |
|
| 5 | 250 | | if(str2num(wvTestRun[%CURRENT][%NUM_ASSERT_ERROR]) == 0) |
| 5 | 251 | | sprintf msg, "Test finished with no errors" |
| 0 | 252 | | else |
| 0 | 253 | | sprintf msg, "Test finished with %s errors", wvTestRun[%CURRENT][%NUM_ASSERT_ERROR] |
| 5 | 254 | | endif |
| | 255 | |
|
| 5 | 256 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| | 257 | |
|
| 5 | 258 | | index = IUTF_Utils_Vector#GetLength(wvFailed) |
| 5 | 259 | | for(i = 0; i < index; i += 1) |
| 5 | 260 | | msg = " " + TC_ASSERTION_LIST_INDICATOR + " " + wvFailed[i] |
| 5 | 261 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 5 | 262 | | endfor |
| | 263 | |
|
| 5 | 264 | | sprintf msg, "End of test \"%s\"", name |
| 5 | 265 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| | 266 | |
|
| 5 | 267 | | IUTF_Reporting_Control#TestEnd() |
| 5 | 268 | | IUTF_Debug#RestoreDebugger() |
| 5 | 269 | | End |
| | 270 | |
|
| | 271 | | /// Internal Setup for Test Suite |
| | 272 | | /// @param testSuite name of the test suite |
| 27 | 273 | | static Function TestSuiteBegin(testSuite) |
| | 274 | | string testSuite |
| | 275 | |
|
| 27 | 276 | | string msg |
| | 277 | |
|
| 27 | 278 | | IUTF_Reporting_Control#TestSuiteBegin(testSuite) |
| | 279 | |
|
| 27 | 280 | | sprintf msg, "Entering test suite \"%s\"", testSuite |
| 27 | 281 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 27 | 282 | | End |
| | 283 | |
|
| | 284 | | /// Internal Cleanup for Test Suite |
| | 285 | | /// @param testSuite name of the test suite |
| 27 | 286 | | static Function TestSuiteEnd(testSuite) |
| | 287 | | string testSuite |
| | 288 | |
|
| 27 | 289 | | string msg |
| | 290 | |
|
| 27 | 291 | | WAVE/T wvTestSuite = IUTF_Reporting#GetTestSuiteWave() |
| | 292 | |
|
| 27 | 293 | | if(str2num(wvTestSuite[%CURRENT][%NUM_ASSERT_ERROR]) == 0) |
| 27 | 294 | | sprintf msg, "Finished with no errors" |
| 0 | 295 | | else |
| 0 | 296 | | sprintf msg, "Failed with %s errors", wvTestSuite[%CURRENT][%NUM_ASSERT_ERROR] |
| 27 | 297 | | endif |
| | 298 | |
|
| 27 | 299 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| | 300 | |
|
| 27 | 301 | | IUTF_Reporting_Control#TestSuiteEnd() |
| | 302 | |
|
| 27 | 303 | | sprintf msg, "Leaving test suite \"%s\"", testSuite |
| 27 | 304 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 27 | 305 | | End |
| | 306 | |
|
| | 307 | | /// Internal Setup for Test Case |
| | 308 | | /// @param testCase name of the test case |
| 79 | 309 | | static Function TestCaseBegin(testCase) |
| | 310 | | string testCase |
| | 311 | |
|
| 79 | 312 | | string msg |
| | 313 | |
|
| 79 | 314 | | // create a new unique folder as working folder |
| 79 | 315 | | DFREF dfr = GetPackageFolder() |
| 79 | 316 | | string/G dfr:lastFolder = GetDataFolder(1) |
| 79 | 317 | | SetDataFolder root: |
| 79 | 318 | | string/G dfr:workFolder = "root:" + UniqueName("tempFolder", 11, 0) |
| 79 | 319 | | SVAR/SDFR=dfr workFolder |
| 79 | 320 | | NewDataFolder/O/S $workFolder |
| | 321 | |
|
| 79 | 322 | | sprintf msg, "Entering test case \"%s\"", testCase |
| 79 | 323 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 79 | 324 | | End |
| | 325 | |
|
| | 326 | | /// @brief Called after the test case begin user hook and before the test case function |
| 79 | 327 | | static Function BeforeTestCase(name, skip) |
| | 328 | | string name |
| | 329 | | variable skip |
| | 330 | |
|
| | 331 | | #if IgorVersion() >= 9.0 |
| 79 | 332 | | if(!skip) |
| 79 | 333 | | StartWaveTracking(name) |
| 79 | 334 | | endif |
| | 335 | | #endif |
| | 336 | |
|
| 79 | 337 | | IUTF_Reporting_Control#TestCaseBegin(name, skip) |
| | 338 | |
|
| 79 | 339 | | End |
| | 340 | |
|
| | 341 | | /// @brief Called after the test case and after the test case end user hook |
| 79 | 342 | | static Function AfterTestCaseUserHook(name, keepDataFolder) |
| | 343 | | string name |
| | 344 | | variable keepDataFolder |
| | 345 | |
|
| 79 | 346 | | string msg |
| | 347 | |
|
| 79 | 348 | | DFREF dfr = GetPackageFolder() |
| 79 | 349 | | SVAR/Z/SDFR=dfr lastFolder |
| 79 | 350 | | SVAR/Z/SDFR=dfr workFolder |
| | 351 | |
|
| 79 | 352 | | if(SVAR_Exists(lastFolder) && DataFolderExists(lastFolder)) |
| 79 | 353 | | SetDataFolder $lastFolder |
| 79 | 354 | | endif |
| 79 | 355 | | if(!keepDataFolder) |
| 79 | 356 | | if(SVAR_Exists(workFolder) && DataFolderExists(workFolder)) |
| 79 | 357 | | KillDataFolder/Z $workFolder |
| 79 | 358 | | endif |
| 79 | 359 | | endif |
| 79 | 360 | | End |
| | 361 | |
|
| | 362 | | /// Internal Cleanup for Test Case |
| | 363 | | /// @param testCase name of the test case |
| 79 | 364 | | static Function TestCaseEnd(testCase, tcIndex, endTime) |
| | 365 | | string testCase, endTime |
| | 366 | | variable tcIndex |
| | 367 | |
|
| 79 | 368 | | string msg |
| 79 | 369 | | variable oldIndex |
| | 370 | |
|
| 79 | 371 | | WAVE/T wvTestCase = IUTF_Reporting#GetTestCaseWave() |
| 79 | 372 | | oldIndex = IUTF_Utils_Waves#MoveDimLabel(wvTestCase, UTF_ROW, "CURRENT", tcIndex) |
| | 373 | |
|
| 79 | 374 | | IUTF_Reporting_Control#TestCaseEnd(endTime) |
| | 375 | |
|
| 79 | 376 | | IUTF_Utils_Waves#MoveDimLabel(wvTestCase, UTF_ROW, "CURRENT", oldIndex) |
| | 377 | |
|
| 79 | 378 | | sprintf msg, "Leaving test case \"%s\"", testCase |
| 79 | 379 | | IUTF_Reporting#IUTF_PrintStatusMessage(msg) |
| 79 | 380 | | End |
| | 381 | |
|
| | 382 | | /// @brief Called after the test case and before the test case end user hook |
| 79 | 383 | | static Function AfterTestCase(name, skip) |
| | 384 | | string name |
| | 385 | | variable skip |
| | 386 | |
|
| 79 | 387 | | string msg |
| | 388 | |
|
| 79 | 389 | | IUTF_Reporting#CleanupInfoMsg() |
| | 390 | |
|
| 79 | 391 | | WAVE/T wvTestCase = IUTF_Reporting#GetTestCaseWave() |
| | 392 | |
|
| 79 | 393 | | if(skip) |
| 0 | 394 | | return NaN |
| 79 | 395 | | endif |
| | 396 | |
|
| 79 | 397 | | FinishWaveTracking(name) |
| | 398 | |
|
| 79 | 399 | | if(IsExpectedFailure()) |
| 0 | 400 | | if(str2num(wvTestCase[%CURRENT][%NUM_ASSERT_ERROR]) == 0) |
| 0 | 401 | | sprintf msg, "Test case \"%s\" doesn't contain at least one assertion error", name |
| 0 | 402 | | IUTF_Reporting#TestCaseFail(msg, isFailure = 1) |
| 0 | 403 | | else |
| 0 | 404 | | // reset the assertion error counter as all previous errors are intended |
| 0 | 405 | | wvTestCase[%CURRENT][%NUM_ASSERT_ERROR] = "0" |
| 0 | 406 | | if(!CmpStr(wvTestCase[%CURRENT][%STATUS], IUTF_STATUS_FAIL)) |
| 0 | 407 | | wvTestCase[%CURRENT][%STATUS] = IUTF_STATUS_RUNNING |
| 0 | 408 | | endif |
| 0 | 409 | | endif |
| 79 | 410 | | else |
| 79 | 411 | | if(str2num(wvTestCase[%CURRENT][%NUM_ASSERT]) == 0) |
| 0 | 412 | | sprintf msg, "Test case \"%s\" doesn't contain at least one assertion", name |
| 0 | 413 | | IUTF_Reporting#TestCaseFail(msg) |
| 79 | 414 | | endif |
| 79 | 415 | | endif |
| 79 | 416 | | End |
| | 417 | |
|
| | 418 | | /// Sets the hooks to the builtin defaults |
| 6 | 419 | | static Function setDefaultHooks(hooks) |
| | 420 | | STRUCT IUTF_TestHooks &hooks |
| | 421 | |
|
| 6 | 422 | | hooks.testBegin = "TEST_BEGIN" |
| 6 | 423 | | hooks.testEnd = "TEST_END" |
| 6 | 424 | | hooks.testSuiteBegin = "TEST_SUITE_BEGIN" |
| 6 | 425 | | hooks.testSuiteEnd = "TEST_SUITE_END" |
| 6 | 426 | | hooks.testCaseBegin = "TEST_CASE_BEGIN" |
| 6 | 427 | | hooks.testCaseEnd = "TEST_CASE_END" |
| 6 | 428 | | End |
| | 429 | |
|
| | 430 | | /// Check that all hook functions, default and override, |
| | 431 | | /// have the expected signature and abort if not. |
| 106 | 432 | | static Function abortWithInvalidHooks(hooks) |
| | 433 | | STRUCT IUTF_TestHooks &hooks |
| | 434 | |
|
| 106 | 435 | | variable i, numEntries |
| 106 | 436 | | string msg |
| | 437 | |
|
| 106 | 438 | | Make/T/N=6/FREE wvInfo |
| | 439 | |
|
| 106 | 440 | | wvInfo[0] = FunctionInfo(hooks.testBegin) |
| 106 | 441 | | wvInfo[1] = FunctionInfo(hooks.testEnd) |
| 106 | 442 | | wvInfo[2] = FunctionInfo(hooks.testSuiteBegin) |
| 106 | 443 | | wvInfo[3] = FunctionInfo(hooks.testSuiteEnd) |
| 106 | 444 | | wvInfo[4] = FunctionInfo(hooks.testCaseBegin) |
| 106 | 445 | | wvInfo[5] = FunctionInfo(hooks.testCaseEnd) |
| | 446 | |
|
| 106 | 447 | | numEntries = DimSize(wvInfo, 0) |
| 106 | 448 | | for(i = 0; i < numEntries; i += 1) |
| 636 | 449 | | if(NumberByKey("N_PARAMS", wvInfo[i]) != 1 || NumberByKey("N_OPT_PARAMS", wvInfo[i]) != 0 || NumberByKey("PARAM_0_TY |
| 0 | 450 | | sprintf msg, "The override test hook \"%s\" must accept exactly one string parameter.", StringByKey("NAME", wvInfo |
| 0 | 451 | | IUTF_Reporting#ReportErrorAndAbort(msg) |
| 636 | 452 | | endif |
| | 453 | |
|
| 636 | 454 | | if(NumberByKey("RETURNTYPE", wvInfo[i]) != 0x4) |
| 0 | 455 | | sprintf msg, "The override test hook \"%s\" must return a numeric variable.", StringByKey("NAME", wvInfo[i]) |
| 0 | 456 | | IUTF_Reporting#ReportErrorAndAbort(msg) |
| 636 | 457 | | endif |
| 636 | 458 | | endfor |
| 106 | 459 | | End |
| | 460 | |
|
| | 461 | | /// Looks for global override hooks in the same indpendent module as the framework itself |
| | 462 | | /// is running in. |
| 6 | 463 | | static Function getGlobalHooks(hooks) |
| | 464 | | STRUCT IUTF_TestHooks &hooks |
| | 465 | |
|
| 6 | 466 | | string userHooks = FunctionList("*_OVERRIDE", ";", "KIND:2,WIN:[" + GetIndependentModuleName() + "]") |
| | 467 | |
|
| 6 | 468 | | variable i |
| 6 | 469 | | for(i = 0; i < ItemsInList(userHooks); i += 1) |
| 6 | 470 | | string userHook = StringFromList(i, userHooks) |
| 6 | 471 | | strswitch(userHook) |
| 0 | 472 | | case "TEST_BEGIN_OVERRIDE": |
| 0 | 473 | | hooks.testBegin = userHook |
| 0 | 474 | | break |
| 6 | 475 | | case "TEST_END_OVERRIDE": |
| 6 | 476 | | hooks.testEnd = userHook |
| 6 | 477 | | break |
| 0 | 478 | | case "TEST_SUITE_BEGIN_OVERRIDE": |
| 0 | 479 | | hooks.testSuiteBegin = userHook |
| 0 | 480 | | break |
| 0 | 481 | | case "TEST_SUITE_END_OVERRIDE": |
| 0 | 482 | | hooks.testSuiteEnd = userHook |
| 0 | 483 | | break |
| 0 | 484 | | case "TEST_CASE_BEGIN_OVERRIDE": |
| 0 | 485 | | hooks.testCaseBegin = userHook |
| 0 | 486 | | break |
| 0 | 487 | | case "TEST_CASE_END_OVERRIDE": |
| 0 | 488 | | hooks.testCaseEnd = userHook |
| 0 | 489 | | break |
| 0 | 490 | | default: |
| 0 | 491 | | // ignore unknown functions |
| 0 | 492 | | break |
| 6 | 493 | | endswitch |
| 6 | 494 | | endfor |
| | 495 | |
|
| 6 | 496 | | abortWithInvalidHooks(hooks) |
| 6 | 497 | | End |
| | 498 | |
|
| | 499 | | /// Looks for local override hooks in a specific procedure file |
| 100 | 500 | | static Function getLocalHooks(hooks, procName) |
| | 501 | | string procName |
| | 502 | | STRUCT IUTF_TestHooks &hooks |
| | 503 | |
|
| 100 | 504 | | variable err |
| 100 | 505 | | string userHooks = FunctionList("*_OVERRIDE", ";", "KIND:18,WIN:" + procName) |
| | 506 | |
|
| 100 | 507 | | variable i |
| 100 | 508 | | for(i = 0; i < ItemsInList(userHooks); i += 1) |
| 0 | 509 | | string userHook = StringFromList(i, userHooks) |
| | 510 | |
|
| 0 | 511 | | string fullFunctionName = IUTF_Basics#getFullFunctionName(err, userHook, procName) |
| 0 | 512 | | strswitch(userHook) |
| 0 | 513 | | case "TEST_SUITE_BEGIN_OVERRIDE": |
| 0 | 514 | | hooks.testSuiteBegin = fullFunctionName |
| 0 | 515 | | break |
| 0 | 516 | | case "TEST_SUITE_END_OVERRIDE": |
| 0 | 517 | | hooks.testSuiteEnd = fullFunctionName |
| 0 | 518 | | break |
| 0 | 519 | | case "TEST_CASE_BEGIN_OVERRIDE": |
| 0 | 520 | | hooks.testCaseBegin = fullFunctionName |
| 0 | 521 | | break |
| 0 | 522 | | case "TEST_CASE_END_OVERRIDE": |
| 0 | 523 | | hooks.testCaseEnd = fullFunctionName |
| 0 | 524 | | break |
| 0 | 525 | | default: |
| 0 | 526 | | // ignore unknown functions |
| 0 | 527 | | break |
| 0 | 528 | | endswitch |
| 0 | 529 | | endfor |
| | 530 | |
|
| 100 | 531 | | abortWithInvalidHooks(hooks) |
| 100 | 532 | | End |
| | 533 | |
|
| | 534 | | /// @brief Stores the state of TestHook structure to DF dfr with key as template |
| 10 | 535 | | static Function StoreHooks(dfr, s, key) |
| | 536 | | DFREF dfr |
| | 537 | | STRUCT IUTF_TestHooks &s |
| | 538 | | string key |
| | 539 | |
|
| 10 | 540 | | key = "S" + key |
| 10 | 541 | | string/G dfr:$(key + "testBegin") = s.testBegin |
| 10 | 542 | | string/G dfr:$(key + "testEnd") = s.testEnd |
| 10 | 543 | | string/G dfr:$(key + "testSuiteBegin") = s.testSuiteBegin |
| 10 | 544 | | string/G dfr:$(key + "testSuiteEnd") = s.testSuiteEnd |
| 10 | 545 | | string/G dfr:$(key + "testCaseBegin") = s.testCaseBegin |
| 10 | 546 | | string/G dfr:$(key + "testCaseEnd") = s.testCaseEnd |
| 10 | 547 | | End |
| | 548 | |
|
| | 549 | | /// @brief Restores the state of TestHook structure from DF dfr with key as template |
| 20 | 550 | | static Function RestoreHooks(dfr, s, key) |
| | 551 | | DFREF dfr |
| | 552 | | STRUCT IUTF_TestHooks &s |
| | 553 | | string key |
| | 554 | |
|
| 20 | 555 | | key = "S" + key |
| 20 | 556 | | SVAR testBegin = dfr:$(key + "testBegin") |
| 20 | 557 | | SVAR testEnd = dfr:$(key + "testEnd") |
| 20 | 558 | | SVAR testSuiteBegin = dfr:$(key + "testSuiteBegin") |
| 20 | 559 | | SVAR testSuiteEnd = dfr:$(key + "testSuiteEnd") |
| 20 | 560 | | SVAR testCaseBegin = dfr:$(key + "testCaseBegin") |
| 20 | 561 | | SVAR testCaseEnd = dfr:$(key + "testCaseEnd") |
| 20 | 562 | | s.testBegin = testBegin |
| 20 | 563 | | s.testEnd = testEnd |
| 20 | 564 | | s.testSuiteBegin = testSuiteBegin |
| 20 | 565 | | s.testSuiteEnd = testSuiteEnd |
| 20 | 566 | | s.testCaseBegin = testCaseBegin |
| 20 | 567 | | s.testCaseEnd = testCaseEnd |
| 20 | 568 | | End |
| | 569 | |
|
| 85 | 570 | | static Function StartWaveTracking(name) |
| | 571 | | string name |
| | 572 | |
|
| | 573 | | #if IgorVersion() >= 9.0 |
| 85 | 574 | | DFREF dfr = GetPackageFolder() |
| 85 | 575 | | NVAR/SDFR=dfr/Z waveTrackingMode |
| | 576 | |
|
| 85 | 577 | | if(NVAR_Exists(waveTrackingMode)) |
| 85 | 578 | | WaveTracking/LOCL stop |
| 85 | 579 | | WaveTracking/FREE stop |
| 85 | 580 | | if(!IUTF_FunctionTags#HasFunctionTag(name, UTF_FTAG_NO_WAVE_TRACKING)) |
| 85 | 581 | | if((waveTrackingMode & UTF_WAVE_TRACKING_FREE) == UTF_WAVE_TRACKING_FREE) |
| 5 | 582 | | WaveTracking/FREE counter |
| 85 | 583 | | endif |
| 85 | 584 | | if((waveTrackingMode & UTF_WAVE_TRACKING_LOCAL) == UTF_WAVE_TRACKING_LOCAL) |
| 5 | 585 | | WaveTracking/LOCL counter |
| 85 | 586 | | endif |
| 85 | 587 | | endif |
| 85 | 588 | | endif |
| | 589 | | #endif |
| 85 | 590 | | End |
| | 591 | |
|
| 84 | 592 | | static Function FinishWaveTracking(name) |
| | 593 | | string name |
| | 594 | |
|
| 84 | 595 | | string msg |
| | 596 | |
|
| | 597 | | #if IgorVersion() >= 9.0 |
| 84 | 598 | | DFREF dfr = GetPackageFolder() |
| 84 | 599 | | NVAR/SDFR=dfr waveTrackingMode |
| | 600 | |
|
| 84 | 601 | | if(NVAR_Exists(waveTrackingMode)) |
| 84 | 602 | | if((waveTrackingMode & UTF_WAVE_TRACKING_LOCAL) == UTF_WAVE_TRACKING_LOCAL) |
| 4 | 603 | | WaveTracking/LOCL count |
| 4 | 604 | | if(V_Flag == IUTF_WVTRACK_COUNT_MODE) |
| 4 | 605 | | if(V_numWaves) |
| 0 | 606 | | sprintf msg, "Local wave leak detected (leaked waves: %d) in \"%s\"", V_numWaves, name |
| 0 | 607 | | IUTF_Reporting#TestCaseFail(msg) |
| 4 | 608 | | endif |
| 4 | 609 | | WaveTracking/LOCL stop |
| 0 | 610 | | elseif(V_Flag != IUTF_WVTRACK_INACTIVE_MODE) |
| 0 | 611 | | // do nothing for IUTF_WVTRACK_INACTIVE_MODE. |
| 0 | 612 | | // Most likely the user has used a tag to opt out this test case for wave tracking. |
| 0 | 613 | | sprintf msg, "Test case \"%s\" modified WaveTracking mode to %d. IUTF can not track at the same time.", name, V_ |
| 0 | 614 | | IUTF_Reporting#TestCaseFail(msg) |
| 4 | 615 | | endif |
| 84 | 616 | | endif |
| | 617 | |
|
| 84 | 618 | | if((waveTrackingMode & UTF_WAVE_TRACKING_FREE) == UTF_WAVE_TRACKING_FREE) |
| 4 | 619 | | WaveTracking/FREE count |
| 4 | 620 | | if(V_Flag == IUTF_WVTRACK_COUNT_MODE) |
| 4 | 621 | | if(V_numWaves) |
| 0 | 622 | | sprintf msg, "Free wave leak detected (leaked waves: %d) in \"%s\"", V_numWaves, name |
| 0 | 623 | | IUTF_Reporting#TestCaseFail(msg) |
| 4 | 624 | | endif |
| 4 | 625 | | WaveTracking/FREE stop |
| 0 | 626 | | elseif(V_Flag != IUTF_WVTRACK_INACTIVE_MODE) |
| 0 | 627 | | // do nothing for IUTF_WVTRACK_INACTIVE_MODE. |
| 0 | 628 | | // Most likely the user has used a tag to opt out this test case for wave tracking. |
| 0 | 629 | | sprintf msg, "Test case \"%s\" modified WaveTracking mode to %d. IUTF can not track at the same time.", name, V_ |
| 0 | 630 | | IUTF_Reporting#TestCaseFail(msg) |
| 4 | 631 | | endif |
| 84 | 632 | | endif |
| 84 | 633 | | endif |
| | 634 | | #endif |
| 84 | 635 | | End |
| | 636 | |
|
| | 637 | | ///@endcond // HIDDEN_SYMBOL |