Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2008-01-31 14:30:43


Author: jtorjo
Date: 2008-01-31 14:30:43 EST (Thu, 31 Jan 2008)
New Revision: 43036
URL: http://svn.boost.org/trac/boost/changeset/43036

Log:
[logging]
v0.21.10, 31 jan 2008
- added test_on_dedicated_thread
Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3
   sandbox/logging/lib/logging/tests/test_on_ded_thread/test.cpp | 104 +++++++++++++++++++++++++++++++++++++++
   sandbox/logging/lib/logging/tests/test_on_ded_thread/test_on_ded_thread.vcproj | 2
   3 files changed, 105 insertions(+), 4 deletions(-)

Modified: sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp 2008-01-31 14:30:43 EST (Thu, 31 Jan 2008)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.21.9, 31 jan 2008
+@section changelog_cur_ver Current Version: v0.21.10, 31 jan 2008
+- added test_on_dedicated_thread
 - updated Jamfile.v2 files for examples and test, for them to compile all files tests/examples
 - updated Jamfile.v2 to actually build the tests + the tests to use BOOST_CHECK
 - updated docs : about caching/destruction

Modified: sandbox/logging/lib/logging/tests/test_on_ded_thread/test.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_on_ded_thread/test.cpp (original)
+++ sandbox/logging/lib/logging/tests/test_on_ded_thread/test.cpp 2008-01-31 14:30:43 EST (Thu, 31 Jan 2008)
@@ -2,7 +2,107 @@
     Tests on_dedicated_thread
 */
 
-#include <boost/logging/logging.hpp>
 
-int main() {
+#include <boost/test/minimal.hpp>
+
+
+#include <boost/logging/format_fwd.hpp>
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
+
+#include <boost/logging/format_ts.hpp>
+#include <boost/logging/format/formatter/thread_id.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/xtime.hpp>
+
+using namespace boost::logging;
+
+typedef logger_format_write< default_, default_, writer::threading::on_dedicated_thread > logger_type;
+
+BOOST_DECLARE_LOG_FILTER(g_log_filter, filter::no_ts )
+BOOST_DECLARE_LOG(g_l, logger_type)
+
+#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l(), g_log_filter()->is_enabled() )
+
+BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
+BOOST_DEFINE_LOG(g_l, logger_type)
+
+void do_sleep(int ms) {
+ using namespace boost;
+ xtime next;
+ xtime_get( &next, TIME_UTC);
+ next.nsec += (ms % 1000) * 1000000;
+
+ int nano_per_sec = 1000000000;
+ next.sec += next.nsec / nano_per_sec;
+ next.sec += ms / 1000;
+ next.nsec %= nano_per_sec;
+ thread::sleep( next);
+}
+
+int MESSAGES_PER_THREAD = 200;
+int THREAD_COUNT = 5;
+void use_log_thread() {
+ for ( int i = 0; i < MESSAGES_PER_THREAD; ++i) {
+ L_ << detail::get_thread_id() << " message " << (i+1) ;
+ do_sleep(1);
+ }
+}
+
+std::ostringstream g_out;
+
+void test_logged_messages() {
+ typedef std::map<detail::thread_id_type, int> coll;
+ coll messages;
+ std::istringstream in( g_out.str());
+ std::string line;
+ while ( std::getline( in, line ) ) {
+ // each logged message has this syntax:
+ // thread_id message idx
+ detail::thread_id_type thread_id;
+ std::string word;
+ int idx = 0;
+ std::istringstream line_in(line);
+ line_in >> thread_id >> word >> idx;
+ BOOST_CHECK(word == "message");
+
+ // for each thread - we should be reading an increasing index 1, 2, 3, ...
+ BOOST_CHECK( messages[thread_id] + 1 == idx);
+ messages[thread_id] = idx;
+ // we only have THREAD_COUNT threads logging!
+ BOOST_CHECK( (int)messages.size() <= THREAD_COUNT);
+ }
+
+ // at this point, each thread should have written all MESSAGES_PER_THREAD messages
+ BOOST_CHECK( (int)messages.size() == THREAD_COUNT);
+ for ( coll::const_iterator b = messages.begin(), e = messages.end() ; b != e; ++b)
+ BOOST_CHECK( b->second == MESSAGES_PER_THREAD);
+}
+
+
+void test_on_dedicated_thread() {
+ g_l()->writer().add_formatter( formatter::append_newline() );
+ g_l()->writer().add_destination( destination::stream(g_out) );
+ g_l()->writer().add_destination( destination::dbg_window() );
+ g_l()->mark_as_initialized();
+
+ for ( int i = 0 ; i < THREAD_COUNT; ++i)
+ boost::thread t( &use_log_thread);
+
+ // allow for all threads to finish
+ int sleep_ms = MESSAGES_PER_THREAD * THREAD_COUNT * 2 ;
+ std::cout << "sleeping for " << sleep_ms << " milliseconds" << std::endl;
+ do_sleep( MESSAGES_PER_THREAD * THREAD_COUNT * 2 /* just in case*/);
+ test_logged_messages();
 }
+
+
+
+
+int test_main(int, char *[]) {
+ test_on_dedicated_thread();
+ return 0;
+}
+
+
+// End of file
+

Modified: sandbox/logging/lib/logging/tests/test_on_ded_thread/test_on_ded_thread.vcproj
==============================================================================
--- sandbox/logging/lib/logging/tests/test_on_ded_thread/test_on_ded_thread.vcproj (original)
+++ sandbox/logging/lib/logging/tests/test_on_ded_thread/test_on_ded_thread.vcproj 2008-01-31 14:30:43 EST (Thu, 31 Jan 2008)
@@ -62,7 +62,7 @@
                         <Tool
                                 Name="VCLinkerTool"
                                 LinkIncremental="2"
- AdditionalLibraryDirectories="D:\boosts\boost_1_33_1\bin\boost\libs\thread\build\libboost_thread.lib\vc-8_0\debug\threading-multi"
+ AdditionalLibraryDirectories="D:\boosts\boost_1_34_1\bin.v2\libs\thread\build\msvc-8.0\debug\link-static\threading-multi\"
                                 GenerateDebugInformation="true"
                                 SubSystem="1"
                                 TargetMachine="1"


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk