< Summary - Igor Pro Universal Testing Framework

Information
Class: procedures.igortest-test-md-gen
Assembly: procedures
File(s): /builds/mirror/igortest/procedures/igortest-test-md-gen.ipf
Tag: 74147b3
Line coverage
7%
Covered lines: 21
Uncovered lines: 242
Coverable lines: 263
Total lines: 385
Line coverage: 7.9%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/builds/mirror/igortest/procedures/igortest-test-md-gen.ipf

#LineLine coverage
 1#pragma rtGlobals=3
 2#pragma TextEncoding="UTF-8"
 3#pragma rtFunctionErrors=1
 4#pragma version=1.10
 5#pragma ModuleName=IUTF_Test_MD_Gen
 6
 7///@cond HIDDEN_SYMBOL
 8
 9/// @brief Returns a global wave that stores the results of the DataGenerators of this testrun
 2210static Function/WAVE GetDataGeneratorWaves()
 11
 2212  string name = "DataGeneratorWaves"
 13
 2214  DFREF       dfr = GetPackageFolder()
 2215  WAVE/Z/WAVE wv  = dfr:$name
 2216  if(WaveExists(wv))
 1117    return wv
 1118  endif
 19
 1120  Make/WAVE/N=(IUTF_WAVECHUNK_SIZE) dfr:$name/WAVE=wv
 1121  IUTF_Utils_Vector#SetLength(wv, 0)
 22
 1123  return wv
 2224End
 25
 26/// @brief Returns a global wave that stores the references for DataGeneratorWaves.
 527static Function/WAVE GetDataGeneratorRefs()
 28
 529  string name = "DataGeneratorRefs"
 30
 531  DFREF    dfr = GetPackageFolder()
 532  WAVE/Z/T wv  = dfr:$name
 533  if(WaveExists(wv))
 034    return wv
 535  endif
 36
 537  Make/T/N=(IUTF_WAVECHUNK_SIZE) dfr:$name/WAVE=wv
 538  IUTF_Utils_Vector#SetLength(wv, 0)
 39
 540  return wv
 541End
 42
 43/// @brief Find the current index in the global data generator wave reference wave.
 44///
 45/// @param fullFuncName  the full function name
 46///
 47/// @returns The index inside the data generate wave reference wave. -1 if not found.
 048static Function GetDataGeneratorRef(fullFuncName)
 49  string fullFuncName
 50
 051  WAVE/T dgRefs = GetDataGeneratorRefs()
 52
 053  return IUTF_Utils_Vector#FindText(dgRefs, fullFuncName)
 054End
 55
 56/// Returns the functionName of the specified DataGenerator. The priority is first local then ProcGlobal.
 57/// If funcName is specified with Module then in all procedures is looked. No ProcGlobal function is returned in that ca
 058static Function/S GetDataGeneratorFunctionName(err, funcName, procName)
 59  variable &err
 60  string funcName, procName
 61
 062  string infoStr, modName, pName, errMsg
 63
 064  err = 0
 065  if(ItemsInList(funcName, "#") > 2)
 066    sprintf errMsg, "Data Generator Function %s is specified with Independent Module, this is not supported.", funcName
 067    err = 1
 068    return errMsg
 069  endif
 070  // if funcName is specified without Module then FunctionInfo looks in procedure procName only.
 071  // if funcName is specified with Module then FunctionInfo looks in all procedures of current compile unit, independent
 072  infoStr = FunctionInfo(funcName, procName)
 073  if(!IUTF_Utils#IsEmpty(infoStr))
 074    modName = StringByKey("MODULE", infoStr)
 075    pName   = StringByKey("NAME", infoStr)
 076    if(!CmpStr(StringByKey("SPECIAL", infoStr), "static") && IUTF_Utils#IsEmpty(modName))
 077      sprintf errMsg, "Data Generator Function %s is declared static but the procedure file %s is missing a \"#pragma Mo
 078      err = 1
 079      return errMsg
 080    endif
 081    if(IUTF_Utils#IsEmpty(modName))
 082      return pName
 083    endif
 084    return modName + "#" + pName
 085  else
 086    // look in ProcGlobal of current compile unit
 087    infoStr = FunctionInfo(funcName)
 088    if(!IUTF_Utils#IsEmpty(infoStr))
 089      pName = StringByKey("NAME", infoStr)
 090      return pName
 091    endif
 092  endif
 093  infoStr = GetIndependentModuleName()
 094  if(!CmpStr(infoStr, "ProcGlobal"))
 095    sprintf errMsg, "Data Generator Function %s not found in %s or ProcGlobal.", funcName, procName
 096  else
 097    sprintf errMsg, "In Independent Module %s, data Generator Function %s not found in %s or globally in IM.", infoStr, 
 098  endif
 099  err = 1
 100
 0101  return errMsg
 0102End
 103
 104///@endcond // HIDDEN_SYMBOL
 105
 0106static Function/S GetDataGenFullFunctionName(procWin, fullTestCase)
 107  string fullTestCase
 108  string procWin
 109
 0110  variable err
 0111  string dgen, msg
 112
 0113  dgen = IUTF_FunctionTags#GetFunctionTagValue(fullTestCase, UTF_FTAG_TD_GENERATOR, err)
 0114  if(err)
 0115    sprintf msg, "Could not find data generator specification for multi data test case %s. %s", fullTestCase, dgen
 0116    IUTF_Reporting#ReportErrorAndAbort(msg)
 0117  endif
 118
 0119  dgen = GetDataGeneratorFunctionName(err, dgen, procWin)
 0120  if(err)
 0121    sprintf msg, "Could not get full function name of data generator: %s", dgen
 0122    IUTF_Reporting#ReportErrorAndAbort(msg)
 0123  endif
 124
 0125  return dgen
 0126End
 127
 0128static Function/S GetDataGeneratorForMMD(procWin, fullFuncName)
 129  string procWin, fullFuncName
 130
 0131  variable i, j, numTypes
 0132  string msg, dgen
 0133  string dgenList = ""
 134
 0135  WAVE/T templates = IUTF_Test_MD_MMD#GetMMDVarTemplates()
 0136  Make/FREE/D wType0 = {0xff %^ IUTF_WAVETYPE0_CMPL %^ IUTF_WAVETYPE0_INT64, NaN, NaN, NaN, IUTF_WAVETYPE0_CMPL, IUTF_WA
 0137  Make/FREE/D wType1 = {IUTF_WAVETYPE1_NUM, IUTF_WAVETYPE1_TEXT, IUTF_WAVETYPE1_DFR, IUTF_WAVETYPE1_WREF, IUTF_WAVETYPE1
 138
 0139  numTypes = DimSize(templates, UTF_ROW)
 0140  for(i = 0; i < numTypes; i += 1)
 0141    for(j = 0; j < IUTF_DGEN_NUM_VARS; j += 1)
 0142      dgen = GetSingleDataGeneratorForMMD(procWin, fullFuncName, templates[i], j)
 0143      if(!IUTF_Utils#IsEmpty(dgen))
 0144        dgenList = AddListItem(dgen, dgenList, ";", Inf)
 0145      endif
 0146    endfor
 0147  endfor
 148
 0149  if(IUTF_Utils#IsEmpty(dgenList))
 0150    sprintf msg, "No data generator functions specified for test case %s in test suite %s.", fullFuncName, procWin
 0151    IUTF_Reporting#ReportErrorAndAbort(msg)
 0152  endif
 153
 0154  return dgenList
 0155End
 156
 0157static Function CheckFunctionSignatureMDgen(procWin, fullFuncName, markSkip)
 158  string procWin, fullFuncName
 159  variable &markSkip
 160
 0161  variable i, j, numTypes
 162
 0163  WAVE/T templates = IUTF_Test_MD_MMD#GetMMDVarTemplates()
 0164  Make/FREE/D wType0 = {0xff %^ IUTF_WAVETYPE0_CMPL %^ IUTF_WAVETYPE0_INT64, NaN, NaN, NaN, IUTF_WAVETYPE0_CMPL, IUTF_WA
 0165  Make/FREE/D wType1 = {IUTF_WAVETYPE1_NUM, IUTF_WAVETYPE1_TEXT, IUTF_WAVETYPE1_DFR, IUTF_WAVETYPE1_WREF, IUTF_WAVETYPE1
 166
 0167  numTypes = DimSize(templates, UTF_ROW)
 0168  for(i = 0; i < numTypes; i += 1)
 0169    for(j = 0; j < IUTF_DGEN_NUM_VARS; j += 1)
 0170      markSkip = markSkip | CheckMDgenOutput(procWin, fullFuncName, templates[i], j, wType0[i], wType1[i])
 0171    endfor
 0172  endfor
 0173End
 174
 175/// Get a single data generator for a MMD test case. This returns an empty string if no data
 176/// generator could be found.
 0177static Function/S GetSingleDataGeneratorForMMD(procWin, fullFuncName, varTemplate, index)
 178  string procWin, fullFuncName, varTemplate
 179  variable index
 180
 0181  string varName, tagName, dgen, msg
 0182  variable err
 183
 0184  varName = varTemplate + num2istr(index)
 0185  tagName = UTF_FTAG_TD_GENERATOR + " " + varName
 0186  dgen    = IUTF_FunctionTags#GetFunctionTagValue(fullFuncName, tagName, err)
 0187  if(err == UTF_TAG_NOT_FOUND)
 0188    return ""
 0189  endif
 0190  dgen = GetDataGeneratorFunctionName(err, dgen, procWin)
 0191  if(err)
 0192    sprintf msg, "Could not get full function name of data generator: %s", dgen
 0193    IUTF_Reporting#ReportErrorAndAbort(msg)
 0194  endif
 195
 0196  EvaluateDgenTagResult(err, fullFuncName, varName)
 197
 0198  return dgen
 0199End
 200
 201/// Check Multi-Multi Data Generator output
 202/// return 1 if one data generator has a zero sized wave, 0 otherwise
 0203static Function CheckMDgenOutput(procWin, fullFuncName, varTemplate, index, wType0, wType1)
 204  string procWin, fullFuncName, varTemplate
 205  variable index, wType0, wType1
 206
 0207  string varName, tagName, dgen, msg
 0208  variable err
 209
 0210  varName = varTemplate + num2istr(index)
 0211  tagName = UTF_FTAG_TD_GENERATOR + " " + varName
 0212  dgen    = IUTF_FunctionTags#GetFunctionTagValue(fullFuncName, tagName, err)
 0213  if(err == UTF_TAG_NOT_FOUND)
 0214    return 0
 0215  endif
 0216  dgen = GetDataGeneratorFunctionName(err, dgen, procWin)
 0217  if(err)
 0218    sprintf msg, "Could not get full function name of data generator: %s", dgen
 0219    IUTF_Reporting#ReportErrorAndAbort(msg)
 0220  endif
 221
 0222  EvaluateDgenTagResult(err, fullFuncName, varName)
 223
 0224  WAVE wGenerator = CheckDGenOutput(fullFuncName, dgen, wType0, wType1, NaN)
 225
 0226  IUTF_Test_MD_MMD#AddMMDTestCaseData(fullFuncName, dgen, varName, DimSize(wGenerator, UTF_ROW))
 227
 0228  return CheckDataGenZeroSize(wGenerator, fullFuncName, dgen)
 0229End
 230
 0231static Function CheckDataGenZeroSize(wGenerator, fullFuncName, dgen)
 232  WAVE wGenerator
 233  string fullFuncName, dgen
 234
 0235  string msg
 236
 0237  if(!DimSize(wGenerator, UTF_ROW))
 0238    sprintf msg, "Note: In test case %s data generator function \"%s\" returns a zero sized wave. Test case marked SKIP.
 0239    IUTF_Reporting#ReportError(msg, incrGlobalErrorCounter = 0)
 0240    return 1
 0241  endif
 242
 0243  return 0
 0244End
 245
 0246static Function EvaluateDgenTagResult(err, fullFuncName, varName)
 247  variable err
 248  string fullFuncName, varName
 249
 0250  string msg
 251
 0252  if(err == UTF_TAG_EMPTY)
 0253    sprintf msg, "No data generator function specified for function \"%s\" data generator variable \"%s\".", fullFuncNam
 0254    IUTF_Reporting#ReportErrorAndAbort(msg)
 0255  endif
 0256  if(err != UTF_TAG_OK)
 0257    sprintf msg, "Problem determining data generator function specified for function \"%s\" data generator variable \"%s
 0258    IUTF_Reporting#ReportErrorAndAbort(msg)
 0259  endif
 0260End
 261
 0262static Function/WAVE GetGeneratorWave(dgen)
 263  string dgen
 264
 0265  variable dimPos
 266
 0267  WAVE/WAVE wDgen = GetDataGeneratorWaves()
 0268  dimPos = GetDataGeneratorRef(dgen)
 0269  if(dimPos == -1)
 0270    return $""
 0271  endif
 0272  WAVE wGenerator = wDgen[dimPos]
 273
 0274  return wGenerator
 0275End
 276
 0277static Function/WAVE CheckDGenOutput(fullFuncName, dgen, wType0, wType1, wRefSubType)
 278  string fullFuncName, dgen
 279  variable wType0, wType1, wRefSubType
 280
 0281  string msg
 282
 0283  WAVE/Z wGenerator = GetGeneratorWave(dgen)
 0284  if(!WaveExists(wGenerator))
 0285    // wave is not stored
 0286    sprintf msg, "Data Generator function \"%s\" has no suitable data for test case \"%s\".", dgen, fullFuncName
 0287    IUTF_Reporting#ReportErrorAndAbort(msg)
 0288  elseif(!((wType1 == IUTF_WAVETYPE1_NUM && WaveType(wGenerator, 1) == wType1 && WaveType(wGenerator) & wType0) || (wTyp
 0289    sprintf msg, "Data Generator \"%s\" functions returned wave format does not fit to expected test case parameter. It 
 0290    IUTF_Reporting#ReportErrorAndAbort(msg)
 0291  elseif(!IUTF_Utils#IsNaN(wRefSubType) && wType1 == IUTF_WAVETYPE1_WREF && !IUTF_Utils#HasConstantWaveTypes(wGenerator,
 0292    sprintf msg, "Test case \"%s\" expects specific wave type1 %u from the Data Generator \"%s\". The wave type from the
 0293    IUTF_Reporting#ReportErrorAndAbort(msg)
 0294  endif
 295
 0296  return wGenerator
 0297End
 298
 0299static Function ExecuteAllDataGenerators(debugMode)
 300  variable debugMode
 301
 0302  variable i, j, size, length, dimPos, err
 0303  string dgenList, dgen, fullFuncName, endTime, msg, procWin
 0304  variable DGENLIST_Index
 305
 0306  WAVE/T testRunData = IUTF_Basics#GetTestRunData()
 0307  size           = DimSize(testRunData, UTF_ROW)
 0308  DGENLIST_Index = FindDimLabel(testRunData, UTF_COLUMN, "DGENLIST")
 309
 0310  if(!size)
 0311    return NaN
 0312  endif
 313
 0314  WAVE/WAVE wDgen = GetDataGeneratorWaves()
 315
 0316  IUTF_Debug#SetDebugger(debugMode)
 0317  IUTF_Reporting_Control#TestSuiteBegin("@DGEN_SUITE")
 318
 0319  for(i = 0; i < size; i += 1)
 0320    dgenList = testRunData[i][DGENLIST_Index]
 0321    WAVE/T dgenWave = ListToTextWave(dgenList, ";")
 0322    length = DimSize(dgenWave, UTF_ROW)
 323
 0324    for(j = 0; j < length; j += 1)
 0325      dgen   = dgenWave[j]
 0326      dimPos = GetDataGeneratorRef(dgen)
 0327      if(dimPos != -1)
 0328        continue
 0329      endif
 0330      procWin = StringByKey("PROCWIN", FunctionInfo(dgen))
 331
 0332      FUNCREF TEST_CASE_PROTO_DGEN fDgen = $dgen
 0333      if(!IUTF_FuncRefIsAssigned(FuncRefInfo(fDgen)))
 0334        fullFuncName = testRunData[i][%FULLFUNCNAME]
 0335        sprintf msg, "Data Generator function \"%s\" has wrong format. It is referenced by test case \"%s\".", dgen, ful
 0336        IUTF_Reporting#ReportErrorAndAbort(msg)
 0337      endif
 338
 0339      IUTF_Reporting_Control#TestCaseBegin(dgen, 0)
 0340      try
 0341        IUTF_Basics#ClearRTError()
 0342        WAVE/Z wGenerator = fDgen(); AbortOnRTE
 0343      catch
 0344        msg = GetRTErrMessage()
 0345        err = GetRTError(1)
 0346        IUTF_Basics#EvaluateRTE(err, msg, V_AbortCode, dgen, IUTF_DATA_GEN_TYPE, procWin)
 347
 0348        sprintf msg, "Invalid Data Generator \"%s\"", dgen
 0349        IUTF_Reporting#ReportErrorAndAbort(msg)
 0350      endtry
 0351      endTime = IUTF_Reporting#GetTimeString()
 352
 0353      if(!WaveExists(wGenerator))
 0354        sprintf msg, "Data Generator function \"%s\" (%s) returns a null wave.", dgen, procWin
 0355        IUTF_Reporting#ReportErrorAndAbort(msg)
 0356      elseif(DimSize(wGenerator, UTF_COLUMN) > 0)
 0357        sprintf msg, "Data Generator function \"%s\" (%s) returns not a 1D wave.", dgen, procWin
 0358        IUTF_Reporting#ReportErrorAndAbort(msg)
 0359      endif
 360
 0361      IUTF_Reporting_Control#TestCaseEnd(endTime)
 362
 0363      AddDataGeneratorWave(dgen, wGenerator)
 0364    endfor
 0365  endfor
 366
 0367  IUTF_Reporting_Control#TestSuiteEnd() // of @DGEN_SUITE
 0368  IUTF_Debug#RestoreDebugger()
 0369End
 370
 0371static Function AddDataGeneratorWave(name, generator)
 372  string name
 373  WAVE   generator
 374
 0375  variable index
 376
 0377  WAVE/WAVE wv     = GetDataGeneratorWaves()
 0378  WAVE/T    wvRefs = GetDataGeneratorRefs()
 379
 0380  index     = IUTF_Utils_Vector#AddRow(wv)
 0381  wv[index] = generator
 0382  IUTF_Utils_Vector#EnsureCapacity(wvRefs, index)
 0383  wvRefs[index] = name
 0384  IUTF_Utils_Vector#SetLength(wvRefs, IUTF_Utils_Vector#GetLength(wv))
 0385End