#summary Test Framework
@@[Home] -> [TestFramework]
http://usvn.ahuman.org/svn/ahwiki/images/wiki/test/mindtest.jpg
----
== Test Strategy ==
In the early stages testing is not the important area as proof-of-the-concept is more critical. In the same time to force aHuman working even somehow requires running quite complex set of functions in multi-thread environment. So debugging is quite tricky.
To reduce overhead from bugfixing, below approaches are applied in aHuman project, specifically for the testing purposes:
* Logging
* Automated Testing
* Thread Dumps
== Logging ==
Logging is implemented based on log4j ideas:
* each class derived from Object, has protected member "logger"
* each logger has name, by default equal to class name for simple objects, otherwise it could be equal to "class instance" name or to "service"
* there are log levels: DEBUG/INFO/ERROR - with usual meaning
* there are log controls, defined in main.xml:
{{{
}}}
* "syncMode" feature defines whether logging is produces by async thread or in the same thread as caller; async thread is started after server startup sequence
== Automated Testing ==
Until project is mature, test codebase alignments looks to me not efficient. That's why all the test code is collected in the only test module, with below coding approach:
* partly implementation is inspired by JUnit
* test code consists of test service and test units
* test unit has pre-defined interface and implements set of test cases, where each test case is identified and can be run independently from others
* test units are part of aiengine running process and can be called externally by pre-defined interface using xml function call like:
{{{
}}}
* call can be done by tools.exe utility:
{{{
start tools.exe console -s localhost:20001 -i %1 -o %1.out
}}}
* after the call, test case can either form response xml, or throw any exception; the last will be combined within pre-defined standard xml response
{{{
INFO: ---------------------------
INFO: AI console
INFO: connected to localhost:20001
REQUEST:
RESPONSE:
C++ Exception: assertion failed (false) (file=nnfinderfactory.cpp,
line=62)
...skipped...
NNFinderFactory::create (aiengine, 0x41f017)
AIExpertDebug::testCreateBySamples (aiengine,0x414363)
AIExpertDebug::onMessage (aiengine, 0x414141)
Channel::subscribeEvent (aiengine, 0x4080ff)
Channel::publish (aiengine, 0x40789f)
PublisherImpl::publish (aiengine, 0x40b3ab)
SocketConnection::processMessage (aiengine, 0x411790)
SocketConnection::processData (aiengine, 0x41148f)
SocketConnection::performRead (aiengine, 0x41129b)
SocketConnection::readMessages (aiengine, 0x410fde)
SocketConnection::startConnection (aiengine, 0x410f39)
::__beginthreadex (aiengine, 0x49b973)
:: (unknown, 0x7c80b683)
Exception: C++ Exception: assertion failed (false) (file=nnfinderfactory.cpp, line=62)
...skipped...
NNFinderFactory::create (aiengine, 0x41f017)
AIExpertDebug::testCreateBySamples (aiengine, 0x414363)
AIExpertDebug::onMessage (aiengine, 0x414141)
Channel::subscribeEvent (aiengine, 0x4080ff)
Channel::publish (aiengine, 0x40789f)
PublisherImpl::publish (aiengine, 0x40b3ab)
SocketConnection::processMessage (aiengine, 0x411790)
SocketConnection::processData (aiengine, 0x41148f)
SocketConnection::performRead (aiengine, 0x41129b)
SocketConnection::readMessages (aiengine, 0x410fde)
SocketConnection::startConnection (aiengine, 0x410f39)
::__beginthreadex (aiengine, 0x49b973)
:: (unknown, 0x7c80b683)
INFO: disconnected
}}}
== Thread Dumps ==
Multi-thread application is hard to debug without understanding what happens in different threads in the same time. Framework contains special functions to print threads and their stack trace.
Also test unit created to allow calling these functions from outside of engine process. Threads are suspended for the time of capturing stack trace.
* each thread has unique name, if started via AIEngine call; framework-based threads are started with well-defined names
{{{
virtual RFC_HND runThread( String name , Object *object , ObjectThreadFunction function , void *p_arg ) = 0;
}}}
* threads and stack trace are logged to main log after calls to AIEngine methods:
{{{
virtual void threadDumpAll( bool showStackTrace ) = 0;
virtual void threadDumpByName( String name , bool showStackTrace ) = 0;
}}}
* test unit call to show all thread, optionally printing stack trace for each:
{{{
results in output:
------------
thread index=0, name=SensesTracker, threadId=0x17fc
thread index=1, name=chat.in, threadId=0x161c
thread index=2, name=chat.out, threadId=0x1798
thread index=3, name=debug, threadId=0xb90
thread index=4, name=debug.1, threadId=0xfbc
thread index=5, name=debug.commands.in, threadId=0x874
thread index=6, name=debug.commands.out, threadId=0xc60
thread index=7, name=imagekbcmd, threadId=0xcc8
thread index=8, name=imagekbrsp, threadId=0x11c4
thread index=9, name=main, threadId=0x14ac
thread index=10, name=sensordata, threadId=0x107c
------------
}}}
* test unit call to show specific thread by its name, optionally with printing its stack trace:
{{{
results in log output:
00:00:29,593 [INFO, 0x1660] - THREAD DUMP: thread name=main, threadId=0x1634: [.]
00:00:41,401 [INFO, 0x1660] - CALL STACK:
::_rfc_hnd_waitevent (aiengine.vc, 0x5aeaec)
AIEngineImpl::waitExitSignal (aiengine.vc, 0x4aaed6)
AIEngineImpl::runInternal (aiengine.vc, 0x4a8491)
AIEngine::run (aiengine.vc, 0x4a78a4)
::_main (aiengine.vc, 0x56999f)
...skipped...
}}}