Library/Application: switch DiagnosticContext_test
This commit is contained in:
parent
ff052ec5a2
commit
80f09cb33b
2 changed files with 73 additions and 55 deletions
|
|
@ -28,11 +28,16 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
|
||||
#include "vault/thread-wrapper.hpp"
|
||||
#include "lib/diagnostic-context.hpp"
|
||||
#include "lib/thread.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <array>
|
||||
|
||||
using std::this_thread::sleep_for;
|
||||
using std::chrono_literals::operator ""us;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -47,20 +52,15 @@ namespace test{
|
|||
const uint NUM_THREADS = 75;
|
||||
const uint MAX_RAND = 100*1000;
|
||||
|
||||
inline bool
|
||||
isOdd (uint val)
|
||||
{
|
||||
return bool (val % 2);
|
||||
}
|
||||
auto isOdd = [](auto val) { return bool (val % 2); };
|
||||
|
||||
} // (End) test setup....
|
||||
|
||||
using vault::ThreadJoinable;
|
||||
using error::LERR_(LOGIC);
|
||||
using lib::ThreadJoinable;
|
||||
using std::rand;
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Subject of this test:
|
||||
* a thread-local stack of int values
|
||||
*/
|
||||
|
|
@ -77,13 +77,11 @@ namespace test{
|
|||
* DiagnosticContext frames are placed into automatic storage (as local
|
||||
* variable within some function scope). Based on thread-local storage,
|
||||
* the next reachable frame can be accessed from anywhere within
|
||||
* the callstack. This feature is useful for collecting
|
||||
* the callstack. This feature is useful for collecting
|
||||
* information regarding features cross-cutting
|
||||
* the usual dependency hierarchy.
|
||||
*
|
||||
* @see lib::DiagnosticContext
|
||||
* @see lib::ThreadLocal
|
||||
* @see vault::Thread
|
||||
* @see lib::ThreadJoinable
|
||||
*/
|
||||
class DiagnosticContext_test : public Test
|
||||
{
|
||||
|
|
@ -112,7 +110,7 @@ namespace test{
|
|||
CHECK (0 == zero);
|
||||
CHECK (0 == Marker::access());
|
||||
|
||||
{ // nested scope
|
||||
{ // nested scope
|
||||
CHECK (0 == Marker::access());
|
||||
|
||||
Marker one(1);
|
||||
|
|
@ -157,43 +155,48 @@ namespace test{
|
|||
* we frequently got aborts even with 40 threads.
|
||||
* This is surprising, since all of the lists
|
||||
* generated in the individual threads are
|
||||
* of size below 20 elements.
|
||||
* of size below 20 elements.
|
||||
*/
|
||||
void
|
||||
verify_heavilyParallelUsage()
|
||||
{
|
||||
TestThread testcase[NUM_THREADS] SIDEEFFECT;
|
||||
auto verifyResult = [](VecI sequence)
|
||||
{
|
||||
uint prev = 0;
|
||||
for (uint val : sequence)
|
||||
{
|
||||
CHECK (isOdd(val) and val > prev);
|
||||
prev = val;
|
||||
}
|
||||
};
|
||||
|
||||
std::array<TestThread, NUM_THREADS> testcase;
|
||||
|
||||
for (uint i=0; i < NUM_THREADS; ++i)
|
||||
testcase[i].join();
|
||||
// CHECK (testcase[i].join().isValid() ); ////////////////////////////////////////////OOO need a way to pass the verification-Result. Maybe a Future?
|
||||
verifyResult (testcase[i].join());
|
||||
}
|
||||
|
||||
|
||||
/** build a call stack within separate thread and capture diagnostics */
|
||||
struct TestThread
|
||||
: ThreadJoinable
|
||||
: ThreadJoinable<VecI>
|
||||
{
|
||||
TestThread()
|
||||
: ThreadJoinable("test diagnostic context stack"
|
||||
,verifyDiagnosticStack)
|
||||
: ThreadJoinable("test context stack"
|
||||
,&verifyDiagnosticStack)
|
||||
{ }
|
||||
};
|
||||
|
||||
|
||||
/** the actual test operation running in a separate thread */
|
||||
static void
|
||||
|
||||
/** the actual test operation running in a separate thread
|
||||
* produces a descending number sequence, and only odd values
|
||||
* will be captured into the diagnostic stack
|
||||
*/
|
||||
static VecI
|
||||
verifyDiagnosticStack()
|
||||
{
|
||||
uint seed (1 + rand() % MAX_RAND);
|
||||
|
||||
VecI sequence = descend (seed);
|
||||
|
||||
uint prev = 0;
|
||||
for (uint val : sequence)
|
||||
if (not (isOdd(val) and seed >= val and val > prev ))
|
||||
throw error::Fatal ("thread-local diagnostic stack");
|
||||
else
|
||||
prev = val;
|
||||
return descend (seed);
|
||||
}
|
||||
|
||||
static VecI
|
||||
|
|
@ -202,7 +205,8 @@ namespace test{
|
|||
if (current < 2)
|
||||
return Marker::extractStack();
|
||||
|
||||
usleep (500);
|
||||
sleep_for (500us);
|
||||
|
||||
if (isOdd(current))
|
||||
{
|
||||
Marker remember(current);
|
||||
|
|
|
|||
|
|
@ -80522,35 +80522,45 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695679685747" ID="ID_1841477437" MODIFIED="1695681430475" TEXT="DiagnosticContext_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1695681285804" ID="ID_478666570" MODIFIED="1695681455264" TEXT="Problem: Fehlerübergabe">
|
||||
<node COLOR="#338800" CREATED="1695679685747" ID="ID_1841477437" MODIFIED="1696368998612" TEXT="DiagnosticContext_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#435e98" CREATED="1695681285804" ID="ID_478666570" MODIFIED="1696369059125" TEXT="Problem: Fehlerübergabe">
|
||||
<linktarget COLOR="#b65b7a" DESTINATION="ID_478666570" ENDARROW="Default" ENDINCLINATION="41;-72;" ID="Arrow_ID_1595086726" SOURCE="ID_1998022902" STARTARROW="None" STARTINCLINATION="-427;24;"/>
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
<node CREATED="1695681308242" ID="ID_1949309520" MODIFIED="1695681321659" TEXT="die eigentliche Verifikation muß im Einzelthread erfolgen"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695681322500" ID="ID_428007765" MODIFIED="1695681342909" TEXT="Check-Ergebnis dann wohl per Flag übergeben">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#5b280f" CREATED="1695681322500" ID="ID_428007765" MODIFIED="1696369052812" TEXT="Check-Ergebnis dann wohl per Flag übergeben">
|
||||
<icon BUILTIN="button_cancel"/>
|
||||
</node>
|
||||
<node COLOR="#435e98" CREATED="1696369004667" ID="ID_1560013621" MODIFIED="1696369056348" TEXT="nein viel besser ⟹ kann jetzt das ganze Ergebnis per join() übergeben">
|
||||
<icon BUILTIN="idea"/>
|
||||
</node>
|
||||
<node CREATED="1696369040716" ID="ID_964371967" MODIFIED="1696369049832" TEXT="dann passiert die Prüfung im Haupt-Thread"/>
|
||||
</node>
|
||||
<node CREATED="1695681283396" ID="ID_1116798044" MODIFIED="1695681285000" TEXT="verify_heavilyParallelUsage"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695679805882" ID="ID_62892662" MODIFIED="1695681430475" TEXT="SessionCommandFunction_test">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node CREATED="1695680321963" ID="ID_1398377573" MODIFIED="1695680331789" TEXT="insgesamt ehr unglücklich damit...">
|
||||
<node COLOR="#338800" CREATED="1695679805882" FOLDED="true" ID="ID_62892662" MODIFIED="1696180242543" TEXT="SessionCommandFunction_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#5b280f" CREATED="1695681374017" ID="ID_767210660" MODIFIED="1696369156711" TEXT="man könnte/sollte Fehler explizit fangen — als Konsitenzcheck">
|
||||
<icon BUILTIN="button_cancel"/>
|
||||
<node CREATED="1696369157990" ID="ID_1718564394" MODIFIED="1696369162654" TEXT="besser: maybeThrow()"/>
|
||||
<node CREATED="1696369163205" ID="ID_231695782" MODIFIED="1696369195434" TEXT="mehr ist dann doch nicht notwendig">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...denn die Fehler sind nicht Teil des Tests, sondern »könnten« nur auftregen (wenn irgendwo in der Applikation was faul ist)
|
||||
</p>
|
||||
</body>
|
||||
</html></richcontent>
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1695680321963" ID="ID_1398377573" MODIFIED="1696369087313" TEXT="insgesamt ehr unglücklich damit...">
|
||||
<font ITALIC="true" NAME="SansSerif" SIZE="12"/>
|
||||
<icon BUILTIN="smily_bad"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1695681374017" ID="ID_767210660" MODIFIED="1695681418164" TEXT="man könnte/sollte Fehler explizit fangen — als Konsitenzcheck">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1695394237210" ID="ID_11553358" MODIFIED="1696029630733" TEXT="Applikation umstellen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1696029414385" ID="ID_140265798" MODIFIED="1696029417676" TEXT="weitere Tests...">
|
||||
<node COLOR="#338800" CREATED="1696029465122" FOLDED="true" ID="ID_1060376805" MODIFIED="1696180242543" TEXT="SessionCommandFunction_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1696036153400" ID="ID_1572079642" MODIFIED="1696036156883" TEXT="Umstellung">
|
||||
<node CREATED="1696036158076" ID="ID_429764463" MODIFIED="1696036170175" TEXT="puh... der Test ist komplex">
|
||||
<icon BUILTIN="smiley-oh"/>
|
||||
|
|
@ -80877,6 +80887,11 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1695394237210" ID="ID_11553358" MODIFIED="1696029630733" TEXT="Applikation umstellen">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1696029414385" ID="ID_140265798" MODIFIED="1696029417676" TEXT="weitere Tests...">
|
||||
<node COLOR="#338800" CREATED="1696029465122" ID="ID_1515483274" MODIFIED="1696357491529" TEXT="SubsystemRunner_test">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
|
|
@ -80888,7 +80903,6 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node CREATED="1696029465120" ID="ID_1782746519" MODIFIED="1696029465120" TEXT="bus-term-test.cpp (/zLumi/tests/stage)"/>
|
||||
</node>
|
||||
<node CREATED="1696029465119" ID="ID_820648476" MODIFIED="1696029572456" TEXT="eigentliche Verwendungen">
|
||||
<node CREATED="1696029465121" ID="ID_1756135675" MODIFIED="1696029465121" TEXT="diagnostic-context-test.cpp (/zLumi/tests/basics)"/>
|
||||
<node CREATED="1696029465121" ID="ID_484763089" MODIFIED="1696029589510" TEXT="dummy-tick.hpp">
|
||||
<node CREATED="1696029465123" ID="ID_944980561" MODIFIED="1696029607971" TEXT="tick-service.hpp">
|
||||
<node CREATED="1696029465123" ID="ID_221141346" MODIFIED="1696029617413" TEXT="dummy-player-service.cpp"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue