Skip to content

Commit b35c0a2

Browse files
author
Michael Dickey
committed
PION-1306: updates for pion source bundle and automated builds
1 parent 6afe96c commit b35c0a2

File tree

11 files changed

+480
-9
lines changed

11 files changed

+480
-9
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ Release_*/
3131
*.user
3232
*.suo
3333
*.ncb
34-
_ReSharper.*/
34+
_ReSharper.*/
35+
tests/test_log.xml
36+
tests/test_results.xml
37+
pion-*.tar.gz
38+
pion-*.tar.bz2
39+
pion-*.tar.zip

Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ SUBDIRS = include src services utils @PION_TESTS_MAKEDIRS@
99
pkgconfigdir = $(libdir)/pkgconfig
1010
pkgconfig_DATA = pion.pc
1111

12-
EXTRA_DIST = autogen.sh *.sln *.xcodeproj doc build/*.vsprops *.vcproj
12+
EXTRA_DIST = README.md index.html autogen.sh *.sln *.xcodeproj *.vcxproj doc \
13+
build/*.props build/*.sh build/*.pl build/*.bat build/*.dll \
14+
build/pion.ico build/common.inc
1315

1416
include $(top_srcdir)/build/doxygen.inc
1517

include/pion/test/unit_test.hpp

Lines changed: 140 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
#include <iostream>
1414
#include <fstream>
15+
#include <boost/thread/mutex.hpp>
16+
#include <boost/thread/condition.hpp>
1517
#include <boost/test/unit_test.hpp>
18+
#include <boost/test/unit_test_log.hpp>
19+
#include <boost/test/output/xml_log_formatter.hpp>
1620
#include <boost/test/test_case_template.hpp>
1721
#include <pion/logger.hpp>
1822

@@ -31,7 +35,127 @@
3135

3236
namespace pion { // begin namespace pion
3337
namespace test { // begin namespace test
34-
38+
39+
/// thread-safe wrapper for Boost.Tests's XML log formatter
40+
class safe_xml_log_formatter
41+
: public boost::unit_test::output::xml_log_formatter
42+
{
43+
public:
44+
45+
/// default constructor
46+
safe_xml_log_formatter()
47+
: m_entry_in_progress(false)
48+
{}
49+
50+
/// virtual destructor
51+
virtual ~safe_xml_log_formatter() {}
52+
53+
/// wrapper to flush output for xml_log_formatter::log_start
54+
virtual void log_start(std::ostream& ostr,
55+
boost::unit_test::counter_t test_cases_amount )
56+
{
57+
xml_log_formatter::log_start(ostr, test_cases_amount);
58+
ostr << std::endl;
59+
}
60+
61+
/// wrapper to flush output for xml_log_formatter::log_finish
62+
virtual void log_finish(std::ostream& ostr)
63+
{
64+
xml_log_formatter::log_finish(ostr);
65+
ostr << std::endl;
66+
}
67+
68+
/// wrapper to flush output for xml_log_formatter::log_build_info
69+
virtual void log_build_info(std::ostream& ostr)
70+
{
71+
xml_log_formatter::log_build_info(ostr);
72+
ostr << std::endl;
73+
}
74+
75+
/// wrapper to flush output for xml_log_formatter::test_unit_start
76+
virtual void test_unit_start(std::ostream& ostr,
77+
boost::unit_test::test_unit const& tu )
78+
{
79+
xml_log_formatter::test_unit_start(ostr, tu);
80+
ostr << std::endl;
81+
}
82+
83+
/// wrapper to flush output for xml_log_formatter::test_unit_finish
84+
virtual void test_unit_finish(std::ostream& ostr,
85+
boost::unit_test::test_unit const& tu,
86+
unsigned long elapsed )
87+
{
88+
xml_log_formatter::test_unit_finish(ostr, tu, elapsed);
89+
ostr << std::endl;
90+
}
91+
92+
/// wrapper to flush output for xml_log_formatter::test_unit_skipped
93+
virtual void test_unit_skipped(std::ostream& ostr,
94+
boost::unit_test::test_unit const& tu )
95+
{
96+
xml_log_formatter::test_unit_skipped(ostr, tu);
97+
ostr << std::endl;
98+
}
99+
100+
/// wrapper to flush output for xml_log_formatter::log_exception
101+
virtual void log_exception(std::ostream& ostr,
102+
boost::unit_test::log_checkpoint_data const& d,
103+
boost::execution_exception const& ex )
104+
{
105+
xml_log_formatter::log_exception(ostr, d, ex);
106+
ostr << std::endl;
107+
}
108+
109+
/// thread-safe wrapper for xml_log_formatter::log_entry_start
110+
virtual void log_entry_start( std::ostream& ostr,
111+
boost::unit_test::log_entry_data const& entry_data,
112+
log_entry_types let )
113+
{
114+
boost::mutex::scoped_lock entry_lock(m_mutex);
115+
while (m_entry_in_progress) {
116+
m_entry_complete.wait(entry_lock);
117+
}
118+
m_entry_in_progress = true;
119+
xml_log_formatter::log_entry_start(ostr, entry_data, let);
120+
ostr.flush();
121+
}
122+
123+
/// thread-safe wrapper for xml_log_formatter::log_entry_value
124+
/// ensures that an entry is in progress
125+
virtual void log_entry_value( std::ostream& ostr, boost::unit_test::const_string value )
126+
{
127+
boost::mutex::scoped_lock entry_lock(m_mutex);
128+
if (m_entry_in_progress) {
129+
xml_log_formatter::log_entry_value(ostr, value);
130+
ostr.flush();
131+
}
132+
}
133+
134+
/// thread-safe wrapper for xml_log_formatter::log_entry_finish
135+
/// assumes the current thread has control via call to log_entry_start()
136+
virtual void log_entry_finish( std::ostream& ostr )
137+
{
138+
boost::mutex::scoped_lock entry_lock(m_mutex);
139+
if (m_entry_in_progress) {
140+
xml_log_formatter::log_entry_finish(ostr);
141+
ostr << std::endl;
142+
m_entry_in_progress = false;
143+
m_entry_complete.notify_one();
144+
}
145+
}
146+
147+
private:
148+
149+
/// true if a log entry is in progress
150+
volatile bool m_entry_in_progress;
151+
152+
/// condition used to signal the completion of a log entry
153+
boost::condition m_entry_complete;
154+
155+
/// mutex used to prevent multiple threads from interleaving entries
156+
boost::mutex m_mutex;
157+
};
158+
35159

36160
/// config is intended for use as a global fixture. By including the
37161
/// following line in one source code file of a unit test project, the constructor will
@@ -45,24 +169,38 @@ namespace test { // begin namespace test
45169
// argc and argv do not include parameters handled by the boost unit test framework, such as --log_level.
46170
int argc = boost::unit_test::framework::master_test_suite().argc;
47171
char** argv = boost::unit_test::framework::master_test_suite().argv;
48-
49172
bool verbose = false;
173+
50174
if (argc > 1) {
51175
if (argv[1][0] == '-' && argv[1][1] == 'v') {
52176
verbose = true;
177+
} else if (strlen(argv[1]) > 13 && strncmp(argv[1], "--log_output=", 13) == 0) {
178+
const char * const test_log_filename = argv[1] + 13;
179+
m_test_log_file.open(test_log_filename);
180+
if (m_test_log_file.is_open()) {
181+
boost::unit_test::unit_test_log.set_stream(m_test_log_file);
182+
boost::unit_test::unit_test_log.set_formatter(new safe_xml_log_formatter);
183+
} else {
184+
std::cerr << "unable to open " << test_log_filename << std::endl;
185+
}
53186
}
54187
}
188+
55189
if (verbose) {
56190
PION_LOG_CONFIG_BASIC;
57191
} else {
58192
std::cout << "Use '-v' to enable logging of errors and warnings from pion.\n";
59193
}
194+
60195
pion::logger log_ptr = PION_GET_LOGGER("pion");
61196
PION_LOG_SETLEVEL_WARN(log_ptr);
62197
}
63198
virtual ~config() {
64199
std::cout << "global teardown for all pion unit tests\n";
65200
}
201+
202+
/// xml log results output stream (needs to be global)
203+
static std::ofstream m_test_log_file;
66204
};
67205

68206

services/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ AllowNothingService_la_LDFLAGS = -no-undefined -module -avoid-version
4545
AllowNothingService_la_LIBADD = ../src/libpion.la @PION_EXTERNAL_LIBS@
4646
AllowNothingService_la_DEPENDENCIES = ../src/libpion.la
4747

48-
EXTRA_DIST = *.vcproj
48+
EXTRA_DIST = *.vcxproj *.vcxproj.filters

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ libpion_la_SOURCES = \
1717
libpion_la_LDFLAGS = -no-undefined -release $(PION_LIBRARY_VERSION)
1818
libpion_la_LIBADD = @PION_EXTERNAL_LIBS@
1919

20-
EXTRA_DIST = *.vcproj
20+
EXTRA_DIST = *.vcxproj *.vcxproj.filters

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ piontests_DEPENDENCIES = ../src/libpion.la \
1919
plugins/hasCreateAndDestroy.la plugins/hasCreateButNoDestroy.la \
2020
plugins/hasNoCreate.la
2121

22-
EXTRA_DIST = *.vcproj http_parser_tests_data.inc
22+
EXTRA_DIST = *.vcxproj *.vcxproj.filters boost*.xsd boost*.xsl config doc \
23+
http_parser_tests_data.inc spdy_parser_tests_data.inc

0 commit comments

Comments
 (0)