Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
enprofilertests.c
Go to the documentation of this file.
2 {
4  bool m_bWasProfilerEnabled;
5 
6  //---------------------------------------------------------------------------
7  // Ctor - Decides the tests to run
8  //---------------------------------------------------------------------------
9  void EnProfilerTests()
10  {
11  m_bWasProfilerEnabled = EnProfiler.IsEnabledC();
12 
13  AddInitTest("TestToggling");
14  AddInitTest("TestTogglingImmediate");
15  AddInitTest("TestSetFlags");
16  AddInitTest("TestClearFlags");
17  AddInitTest("TestAddFlags");
18  AddInitTest("TestModule");
19  AddInitTest("TestClassTimeData");
20  AddInitTest("TestClassCountData");
21  AddInitTest("TestFuncTimeData");
22  AddInitTest("TestFuncCountData");
23  }
24 
25  //---------------------------------------------------------------------------
26  // Dtor
27  //---------------------------------------------------------------------------
28  void ~EnProfilerTests()
29  {
30  EnProfiler.Enable(m_bWasProfilerEnabled, true);
31  }
32 
33  //---------------------------------------------------------------------------
34  // Tests
35  //---------------------------------------------------------------------------
36  // Test toggling state
37  TFResult TestToggling()
38  {
39  bool currentlyEnabled = EnProfiler.IsEnabledP();
40  EnProfiler.Enable(!currentlyEnabled);
41  if (Assert(currentlyEnabled != EnProfiler.IsEnabledP()))
42  {
43  EnProfiler.Enable(currentlyEnabled);
44  return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledP()));
45  }
46 
47  return NTFR(TFR.FAIL);
48  }
49 
50  //---------------------------------------------------------------------------
51  // Test toggling immediate state
52  TFResult TestTogglingImmediate()
53  {
54  bool currentlyEnabled = EnProfiler.IsEnabledC();
55  EnProfiler.Enable(!currentlyEnabled, true);
56  if (Assert(currentlyEnabled != EnProfiler.IsEnabledC()))
57  {
58  EnProfiler.Enable(currentlyEnabled, true);
59  return BTFR(Assert(currentlyEnabled == EnProfiler.IsEnabledC()));
60  }
61 
62  return NTFR(TFR.FAIL);
63  }
64 
65  //---------------------------------------------------------------------------
66  // Test SetFlags/GetFlags
67  TFResult TestSetFlags()
68  {
69  int currentFlags = EnProfiler.GetFlags();
70 
71  for (int i = 0; i < EnumTools.GetEnumSize(EnProfilerFlags); ++i)
72  {
73  int flags = EnumTools.GetEnumValue(EnProfilerFlags, i);
74  EnProfiler.SetFlags(flags);
75 
76  if (!Assert(EnProfiler.GetFlags() == flags))
77  {
78  EnProfiler.SetFlags(currentFlags);
79  return NTFR(TFR.FAIL);
80  }
81 
82  for (int j = 0; j < EnumTools.GetEnumSize(EnProfilerFlags); ++j)
83  {
84  flags |= EnumTools.GetEnumValue(EnProfilerFlags, j);
85  EnProfiler.SetFlags(flags);
86 
87  if (!Assert(EnProfiler.GetFlags() == flags))
88  {
89  EnProfiler.SetFlags(currentFlags);
90  return NTFR(TFR.FAIL);
91  }
92  }
93  }
94 
95  // Let's test some bogus
96  EnProfiler.SetFlags(-333);
97  int bogusFlags = EnProfiler.GetFlags();
98  bogusFlags &= ~EnProfilerFlags.ALL;
99  if (!Assert(bogusFlags == 0))
100  {
101  EnProfiler.SetFlags(currentFlags);
102  return NTFR(TFR.FAIL);
103  }
104 
105  bogusFlags = EnProfiler.SetFlags(6003);
106  bogusFlags &= ~EnProfilerFlags.ALL;
107  if (!Assert(bogusFlags == 0))
108  {
109  EnProfiler.SetFlags(currentFlags);
110  return NTFR(TFR.FAIL);
111  }
112 
113  // Reset
114  EnProfiler.SetFlags(currentFlags);
115  return NTFR(TFR.SUCCESS);
116  }
117 
118  //---------------------------------------------------------------------------
119  // Test removing of flags
120  TFResult TestClearFlags()
121  {
122  int currentFlags = EnProfiler.GetFlags();
123 
124  EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE);
125 
126  if (!Assert(EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE) == EnProfilerFlags.NONE))
127  {
128  EnProfiler.SetFlags(currentFlags);
129  return NTFR(TFR.FAIL);
130  }
131 
132  EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
133  EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
134 
135  if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
136  {
137  EnProfiler.SetFlags(currentFlags);
138  return NTFR(TFR.FAIL);
139  }
140 
141  EnProfiler.SetFlags(EnProfilerFlags.RECURSIVE | EnProfilerFlags.RESET);
142  EnProfiler.ClearFlags();
143 
144  if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.NONE))
145  {
146  EnProfiler.SetFlags(currentFlags);
147  return NTFR(TFR.FAIL);
148  }
149 
150  // Reset
151  EnProfiler.SetFlags(currentFlags);
152  return NTFR(TFR.SUCCESS);
153  }
154 
155  //---------------------------------------------------------------------------
156  // Test adding of flags
157  TFResult TestAddFlags()
158  {
159  int currentFlags = EnProfiler.GetFlags();
160 
161  EnProfiler.ClearFlags();
162 
163  // Return should match resulting flags
164  if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RESET) == EnProfiler.GetFlags()))
165  {
166  EnProfiler.SetFlags(currentFlags);
167  return NTFR(TFR.FAIL);
168  }
169 
170  if (!Assert(EnProfiler.GetFlags() == EnProfilerFlags.RESET))
171  {
172  EnProfiler.SetFlags(currentFlags);
173  return NTFR(TFR.FAIL);
174  }
175 
176  if (!Assert(EnProfiler.AddFlags(EnProfilerFlags.RECURSIVE) == (EnProfilerFlags.RESET | EnProfilerFlags.RECURSIVE)))
177  {
178  EnProfiler.SetFlags(currentFlags);
179  return NTFR(TFR.FAIL);
180  }
181 
182  // Reset
183  EnProfiler.SetFlags(currentFlags);
184  return NTFR(TFR.SUCCESS);
185  }
186 
187  //---------------------------------------------------------------------------
188  // Test module
189  TFResult TestModule()
190  {
191  // File lives in Game, use it while testing
192  const EnProfilerModule eptModule = EnProfilerModule.GAME;
193 
194  // This was added at the same time as this API, so check if it works as well
195  string nameOfCurrentModule = Type().GetModule();
196  if (!Assert(nameOfCurrentModule != ""))
197  {
198  return NTFR(TFR.FAIL);
199  }
200 
201  // We know we are in Game, so use it as a test
202  EnProfilerModule currentModule;
203  if (!Assert(EnProfiler.NameToModule(nameOfCurrentModule, currentModule)))
204  {
205  return NTFR(TFR.FAIL);
206  }
207 
208  if (!Assert(currentModule == eptModule))
209  {
210  return NTFR(TFR.FAIL);
211  }
212 
213  // Test if setting and getting works
214  EnProfilerModule currentlyProfiledModule = EnProfiler.GetModule();
215  EnProfiler.SetModule(eptModule);
216 
217  if (!Assert(EnProfiler.GetModule() == eptModule))
218  {
219  EnProfiler.SetModule(currentlyProfiledModule);
220  return NTFR(TFR.FAIL);
221  }
222 
223  // Data to restore
224  int currentFlags = EnProfiler.GetFlags();
225  bool wasEnabled = EnProfiler.RequestImmediateData();
226 
227  // Make sure we are only profiling Game and that the data is clean
228  // Only valid for the Get...Per... methods, as they need to be sorted
229  EnProfiler.RemoveFlags(EnProfilerFlags.RECURSIVE);
230 
231  // GetTickTime() returns in seconds, so gather the results in seconds too
232  int resolution = EnProfiler.GetTimeResolution();
233  EnProfiler.SetTimeResolution(1);
234 
235  // Time to sleeb
236  float previousTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
237  float timeSlept = Sleep(0.3);
238  float postTime = EnProfiler.GetTimeOfFunc("Sleep", Type(), true);
239  float diff = postTime - previousTime - timeSlept;
240 
241  // Restore
242  EnProfiler.SetTimeResolution(resolution);
243 
244  // We called the function, so it must have some time
245  if (!Assert(postTime > 0))
246  {
247  EnProfiler.SetFlags(currentFlags);
248 
249  if (!wasEnabled)
250  EnProfiler.Enable(false, true);
251 
252  EnProfiler.SetModule(currentlyProfiledModule);
253 
254  return NTFR(TFR.FAIL);
255  }
256 
257  if (!Assert(diff < 0.00001))
258  {
259  EnProfiler.SetFlags(currentFlags);
260 
261  if (!wasEnabled)
262  EnProfiler.Enable(false, true);
263 
264  EnProfiler.SetModule(currentlyProfiledModule);
265 
266  return NTFR(TFR.FAIL);
267  }
268 
269  // Clean the session
270  EnProfiler.ResetSession(true);
271 
272  // Something from a different module should not get sorted, so just fire something from a different module
273  for (int i = 0; i < 1000; ++i)
274  {
275  EnumTools.StringToEnum(EnProfilerModule, "MISSION_CUSTOM");
276  }
277 
278  // Sort and gather the data and validate if it is correct
279  EnProfiler.SortData();
280  array<ref EnProfilerTimeFuncPair> timePerFunc = {};
281  EnProfiler.GetTimePerFunc(timePerFunc);
282 
283  Debug.TFLog("Game fncs:", this, "TestModule");
284 
285  int funcCount = timePerFunc.Count();
286  for (int j = 0; j < funcCount; ++j)
287  {
288  EnProfilerTimeFuncPair tfp = timePerFunc[j];
289  Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfp.param1, tfp.param2), this, "TestModule");
290  // We are currently profiling Game, so this Core function shouldn't be present
291  if (!Assert(tfp.param2 != "EnumTools::StringToEnum"))
292  {
293  EnProfiler.SetFlags(currentFlags);
294 
295  if (!wasEnabled)
296  EnProfiler.Enable(false, true);
297 
298  EnProfiler.SetModule(currentlyProfiledModule);
299 
300  return NTFR(TFR.FAIL);
301  }
302  }
303 
304  array<ref EnProfilerTimeClassPair> timePerClass = {};
305  EnProfiler.GetTimePerClass(timePerClass);
306 
307  int classCount = timePerClass.Count();
308  for (int k = 0; k < classCount; ++k)
309  {
310  typename type = timePerClass[k].param2;
311  EnProfilerModule classModule;
312  if (!Assert(EnProfiler.NameToModule(type.GetModule(), classModule)))
313  {
314  EnProfiler.SetFlags(currentFlags);
315 
316  if (!wasEnabled)
317  EnProfiler.Enable(false, true);
318 
319  EnProfiler.SetModule(currentlyProfiledModule);
320 
321  return NTFR(TFR.FAIL);
322  }
323 
324  // Only classes from Game should be present
325  if (!Assert(classModule == eptModule))
326  {
327  EnProfiler.SetFlags(currentFlags);
328 
329  if (!wasEnabled)
330  EnProfiler.Enable(false, true);
331 
332  EnProfiler.SetModule(currentlyProfiledModule);
333 
334  return NTFR(TFR.FAIL);
335  }
336  }
337 
338  // Now let's check if we can gather the data of what we called earlier by switching the profiled module without resetting the session
339  EnProfiler.SetModule(EnProfilerModule.CORE, false);
340  EnProfiler.SortData();
341  timePerFunc.Clear(); // Let's reuse the array, but the Get...Per... methods only appends to the array, clearing is our responsibility
342  EnProfiler.GetTimePerFunc(timePerFunc);
343 
344  bool found = false;
345 
346  Debug.TFLog("Core fncs:", this, "TestModule");
347 
348  funcCount = timePerFunc.Count();
349  for (int l = 0; l < funcCount; ++l)
350  {
351  EnProfilerTimeFuncPair tfpc = timePerFunc[l];
352  Debug.TFLog(string.Format(" time: %1 | fnc: %2", tfpc.param1, tfpc.param2), this, "TestModule");
353  // We are currently profiling Core, so this Core function should be present
354  if (tfpc.param2 == "EnumTools::StringToEnum")
355  {
356  found = true;
357  break;
358  }
359  }
360 
361  Assert(found);
362 
363  // Test some bogus
364  EnProfilerModule mod = EnProfiler.GetModule();
365  EnProfiler.SetModule(-333);
366  bool success = Assert(EnProfiler.GetModule() == mod);
367  EnProfiler.SetModule(6003);
368  success &= Assert(EnProfiler.GetModule() == mod);
369 
370  EnProfiler.SetFlags(currentFlags);
371  EnProfiler.SetModule(currentlyProfiledModule);
372 
373  if (!wasEnabled)
374  EnProfiler.Enable(false, true);
375 
376  return BTFR(success && found);
377  }
378 
379  //---------------------------------------------------------------------------
380  // Test to see if class time data is correct
381  TFResult TestClassTimeData()
382  {
383  // We should restore this when done
384  int resolution = EnProfiler.GetTimeResolution();
385  bool wasEnabled = EnProfiler.RequestImmediateData();
386 
387  // GetTickTime() returns in seconds, so gather the results in seconds too
388  EnProfiler.SetTimeResolution(1);
389 
390  // Create the classes
391  EPTHelperClass clss = new EPTHelperClass();
392 
393  // Time to stress
394  float previousTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
395  float timeStressed = clss.DoEverything();
396  float postTime = EnProfiler.GetTimeOfClass(clss.Type(), true);
397  float postTimeStatic = EnProfiler.GetTimeOfClass(StaticGetType(EPTHelperClass), true);
398  float timeProfiled = postTime - previousTime;
399  float diff = Math.AbsFloat(timeProfiled - timeStressed);
400 
401  Debug.TFLog(string.Format("Profiling result: stressed: %1 | profiled: %2 | diff: %3", timeStressed, timeProfiled, diff), this, "TestClassTimeData");
402 
403  // Restore
404  EnProfiler.SetTimeResolution(resolution);
405  if (!wasEnabled)
406  EnProfiler.Enable(false, true);
407 
408  // We called the function, so it must have some time
409  if (!Assert(postTime > 0))
410  {
411  return NTFR(TFR.FAIL);
412  }
413 
414  if (!Assert(postTime == postTimeStatic))
415  {
416  return NTFR(TFR.FAIL);
417  }
418 
419  if (!Assert(diff < 0.001))
420  {
421  return NTFR(TFR.FAIL);
422  }
423 
424  return NTFR(TFR.SUCCESS);
425  }
426 
427  //---------------------------------------------------------------------------
428  // Test to see if class count data is correct
429  TFResult TestClassCountData()
430  {
431  const int allocAmount = 9;
432  const int releaseAmount = 6;
433  int remainingAmount = allocAmount - releaseAmount;
434 
435  // We should restore this when done
436  bool wasEnabled = EnProfiler.RequestImmediateData();
437 
438  // Time to test
439  int previousAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
440  int previousInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
441 
442  array<ref EPTHelperClass> instanceArr = {};
443  for (int i = 0; i < allocAmount; ++i)
444  {
445  instanceArr.Insert(new EPTHelperClass());
446  }
447 
448  for (int j = 0; j < releaseAmount; ++j)
449  {
450  delete instanceArr[j];
451  }
452 
453  int postAlloc = EnProfiler.GetAllocationsOfClass(StaticGetType(EPTHelperClass), true);
454  int postInstances = EnProfiler.GetInstancesOfClass(StaticGetType(EPTHelperClass), true);
455 
456  int alloced = postAlloc - previousAlloc;
457  int instances = postInstances - previousInstances;
458 
459  Debug.TFLog(string.Format("Profiling result: alloc: %1 | instances: %2", alloced, instances), this, "TestClassCountData");
460 
461  // Restore
462  if (!wasEnabled)
463  EnProfiler.Enable(false, true);
464 
465  // Time to check
466  if (!Assert(alloced == allocAmount))
467  {
468  return NTFR(TFR.FAIL);
469  }
470 
471  if (!Assert(instances == remainingAmount))
472  {
473  return NTFR(TFR.FAIL);
474  }
475 
476  return NTFR(TFR.SUCCESS);
477  }
478 
479  //---------------------------------------------------------------------------
480  // Test to see if func time data is correct
481  TFResult TestFuncTimeData()
482  {
483  // We should restore this when done
484  int resolution = EnProfiler.GetTimeResolution();
485  bool wasEnabled = EnProfiler.RequestImmediateData();
486 
487  // GetTickTime() returns in seconds, so gather the results in seconds too
488  EnProfiler.SetTimeResolution(1);
489 
490  // Time to stress
491  float previousTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
492  float timeStressed = StringFormat();
493  float postTime = EnProfiler.GetTimeOfFunc("StringFormat", Type(), true);
494  float timeProfiled = postTime - previousTime;
495  float diff = Math.AbsFloat(timeProfiled - timeStressed);
496 
497  float previousTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
498  float timeStressed2 = StringConcat();
499  float postTime2 = EnProfiler.GetTimeOfFunc("StringConcat", Type(), true);
500  float timeProfiled2 = postTime2 - previousTime2;
501  float diff2 = Math.AbsFloat(timeProfiled2 - timeStressed2);
502 
503  Debug.TFLog(string.Format("Profiling result: StringFormat: %1 | StringConcat: %2", timeProfiled, timeProfiled2), this, "TestFuncTimeData");
504 
505  // Restore
506  EnProfiler.SetTimeResolution(resolution);
507  if (!wasEnabled)
508  {
509  EnProfiler.Enable(false, true);
510  }
511 
512  // We called the function, so it must have some time
513  if (!Assert(postTime > 0))
514  {
515  return NTFR(TFR.FAIL);
516  }
517 
518  if (!Assert(diff < 0.001))
519  {
520  return NTFR(TFR.FAIL);
521  }
522 
523  if (!Assert(postTime2 > 0))
524  {
525  return NTFR(TFR.FAIL);
526  }
527 
528  if (!Assert(diff2 < 0.001))
529  {
530  return NTFR(TFR.FAIL);
531  }
532 
533  // I know that string.Format is faster than additive concatenation
534  if (!Assert(timeProfiled < timeProfiled2))
535  {
536  return NTFR(TFR.FAIL);
537  }
538 
539  return NTFR(TFR.SUCCESS);
540  }
541 
542  //---------------------------------------------------------------------------
543  // Test to see if func count data is correct
544  TFResult TestFuncCountData()
545  {
546  // We should restore this when done
547  bool wasEnabled = EnProfiler.RequestImmediateData();
548 
549  // Time to count
550 
551  // - CallFunction
552  int previousCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
553  GetGame().GameScript.CallFunction(this, "TestFuncCountDataHelper", null, 0);
554  int postCountCF = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
555 
556  int callCountCF = postCountCF - previousCountCF;
557 
558  // - CallFunctionParams
559  int previousCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
560  GetGame().GameScript.CallFunctionParams(this, "TestFuncCountDataHelper", null, null);
561  int postCountCFP = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
562 
563  int callCountCFP = postCountCFP - previousCountCFP;
564 
565  // - Regular call
566  int previousCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
567  TestFuncCountDataHelper();
568  int postCountRG = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
569 
570  int callCountRG = postCountRG - previousCountRG;
571 
572  // - Call
573  int previousCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
574  GetGame().GameScript.Call(this, "TestFuncCountDataHelper", 0);
575  int postCountC = EnProfiler.GetCountOfFunc("TestFuncCountDataHelper", Type(), true);
576 
577  int callCountC = postCountC - previousCountC;
578 
579  // - Garbage
580  int callCountNon = EnProfiler.GetCountOfFunc("Non Existing Method", Type(), true);
581 
582  // - Static
583  int previousCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
584  TestFuncCountDataHelperStatic();
585  int postCountS = EnProfiler.GetCountOfFunc("TestFuncCountDataHelperStatic", Type(), true);
586 
587  int callCountS = postCountS - previousCountS;
588 
589  // - Global
590  int previousCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
591  GetDayZGame();
592  int postCountG = EnProfiler.GetCountOfFuncG("GetDayZGame", true);
593 
594  int callCountG = postCountG - previousCountG;
595 
596  // - Global proto
597  // Not tracked, so don't need to compare before and after, should always be 0
598  ErrorEx("Testing global proto call", ErrorExSeverity.INFO);
599  int callCountGP = EnProfiler.GetCountOfFuncG("ErrorEx", true);
600 
601  // - Static proto
602  // Not tracked, so don't need to compare before and after, should always be 0
603  int callCountSP = EnProfiler.GetCountOfFunc("GetCountOfFunc", StaticGetType(EnProfiler), true);
604 
605  // - proto
606  // Not tracked, so don't need to compare before and after, should always be 0
607  GetGame().GetHostName();
608  int callCountP = EnProfiler.GetCountOfFunc("GetHostName", GetGame().Type(), true);
609 
610  // - proto native
611  // Not tracked, so don't need to compare before and after, should always be 0
612  GetGame().IsServer();
613  int callCountPN = EnProfiler.GetCountOfFunc("IsServer", GetGame().Type(), true);
614 
615  // - static proto native
616  // Not tracked, so don't need to compare before and after, should always be 0
617  ErrorModuleHandler.GetInstance();
618  int callCountSPN = EnProfiler.GetCountOfFunc("GetInstance", StaticGetType(ErrorModuleHandler), true);
619 
620  // Restore
621  if (!wasEnabled)
622  {
623  EnProfiler.Enable(false, true);
624  }
625 
626  // Do the checks
627 
628  // - CallFunction
629  if (!Assert(callCountCF == 1))
630  {
631  return NTFR(TFR.FAIL);
632  }
633 
634  // - CallFunctionParams
635  if (!Assert(callCountCFP == 1))
636  {
637  return NTFR(TFR.FAIL);
638  }
639 
640  // - Regular call
641  if (!Assert(callCountRG == 1))
642  {
643  return NTFR(TFR.FAIL);
644  }
645 
646  // - Call
647  if (!Assert(callCountC == 1))
648  {
649  return NTFR(TFR.FAIL);
650  }
651 
652  // - Garbage
653  if (!Assert(callCountNon == -1))
654  {
655  return NTFR(TFR.FAIL);
656  }
657 
658  // - Static
659  if (!Assert(callCountS == 1))
660  {
661  return NTFR(TFR.FAIL);
662  }
663 
664  // - Global
665  if (!Assert(callCountG == 1))
666  {
667  return NTFR(TFR.FAIL);
668  }
669 
670  // - Global proto
671  if (!Assert(callCountGP == 0))
672  {
673  return NTFR(TFR.FAIL);
674  }
675 
676  // - Static proto
677  if (!Assert(callCountSP == 0))
678  {
679  return NTFR(TFR.FAIL);
680  }
681 
682  // - proto
683  if (!Assert(callCountP == 0))
684  {
685  return NTFR(TFR.FAIL);
686  }
687 
688  // - proto native
689  if (!Assert(callCountPN == 0))
690  {
691  return NTFR(TFR.FAIL);
692  }
693 
694  // - static proto native
695  if (!Assert(callCountSPN == 0))
696  {
697  return NTFR(TFR.FAIL);
698  }
699 
700  return NTFR(TFR.SUCCESS);
701  }
702 
703  //---------------------------------------------------------------------------
704  // Helpers
705  //---------------------------------------------------------------------------
706  // Snore
707  float Sleep(float timeS)
708  {
709  float startTime = GetGame().GetTickTime();
710  while (GetGame().GetTickTime() - startTime < timeS)
711  {
712  // Zzz
713  }
714 
715  return GetGame().GetTickTime() - startTime;
716  }
717 
718  //---------------------------------------------------------------------------
719  // Example stress method
720  float StringFormat()
721  {
722  float startTime = GetGame().GetTickTime();
723 
724  for (int i = 0; i < 1000; ++i)
725  {
726  string example = string.Format("This %1 is %2 just %3 an %4 example %5", i, Type(), this, startTime, "lorem ipsum 1 2 3");
727  }
728 
729  return GetGame().GetTickTime() - startTime;
730  }
731 
732  //---------------------------------------------------------------------------
733  // Example stress method 2
734  float StringConcat()
735  {
736  float startTime = GetGame().GetTickTime();
737 
738  for (int i = 0; i < 1000; ++i)
739  {
740  string example = "This " + i + " is " + Type() + " just " + this + " an " + startTime + " example " + "lorem ipsum 1 2 3";
741  }
742 
743  return GetGame().GetTickTime() - startTime;
744  }
745 
746  //---------------------------------------------------------------------------
747  // To make sure it is only ever called in that test
748  void TestFuncCountDataHelper()
749  {
750  int dummy = 3;
751  }
752 
753  //---------------------------------------------------------------------------
754  // To make sure it is only ever called in that test
755  static void TestFuncCountDataHelperStatic()
756  {
757  int dummy = 3;
758  }
759 }
760 
761 class EPTHelperClass
762 {
763  float Sleep2(float timeS)
764  {
765  float startTime = GetGame().GetTickTime();
766  while (GetGame().GetTickTime() - startTime < timeS)
767  {
768  // Zzz
769  }
770 
771  return GetGame().GetTickTime() - startTime;
772  }
773  float SleepAgain(float timeS)
774  {
775  float startTime = GetGame().GetTickTime();
776  while (GetGame().GetTickTime() - startTime < timeS)
777  {
778  // Zzz
779  }
780 
781  return GetGame().GetTickTime() - startTime;
782  }
783 
784  float DoEverything()
785  {
786  float startTime = GetGame().GetTickTime();
787 
788  Sleep2(3);
789  SleepAgain(3);
790 
791  return GetGame().GetTickTime() - startTime;
792  }
793 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
NTFR
TFResult NTFR(TFR result)
Definition: testframework.c:273
Sleep2
EnProfilerTests TestFramework Sleep2(float timeS)
Definition: enprofilertests.c:763
EnProfilerModule
EnProfilerModule
Current base scripted modules.
Definition: enprofiler.c:21
SleepAgain
float SleepAgain(float timeS)
Definition: enprofilertests.c:773
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
TFResult
void TFResult(TFR result)
Definition: testframework.c:12
TestFramework
void TestFramework()
Definition: testframework.c:217
EnProfilerFlags
EnProfilerFlags
Flags that influences the behaviour of the EnProfiler API, applied through ...Flags functions.
Definition: enprofiler.c:8
ErrorEx
enum ShapeType ErrorEx
EnumTools
Definition: enconvert.c:589
DoEverything
float DoEverything()
Definition: enprofilertests.c:784
ErrorExSeverity
ErrorExSeverity
Definition: endebug.c:61
Assert
protected bool Assert(bool condition)
Definition: testframework.c:262
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
EnProfiler
Set of methods for accessing script profiling data.
Definition: enprofiler.c:72
AddInitTest
protected void AddInitTest(string test)
Definition: testframework.c:249
Debug
Definition: debug.c:13
TFR
TFR
Definition: testframework.c:1
Type
string Type
Definition: jsondatacontaminatedarea.c:11
BTFR
TFResult BTFR(bool result)
Definition: testframework.c:278
m_bWasProfilerEnabled
bool m_bWasProfilerEnabled
Remember this, so we can restore the previous state before the test!
Definition: enprofilertests.c:3
Math
Definition: enmath.c:6
EnProfilerTests
Definition: enprofilertests.c:1
ErrorModuleHandler
The error handler itself, for managing and distributing errors to modules Manages the ErrorHandlerMod...
Definition: errormodulehandler.c:28