]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/recursordist/testrunner.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #define BOOST_TEST_DYN_LINK
27 #include <boost/test/unit_test.hpp>
30 #include <dnsrecords.hh>
35 static std::string s_timestampFormat
= "%s";
37 static const char* toTimestampStringMilli(const struct timeval
& tv
, char* buf
, size_t sz
)
41 size_t len
= strftime(buf
, sz
, s_timestampFormat
.c_str(), localtime_r(&tv
.tv_sec
, &tm
));
43 len
= snprintf(buf
, sz
, "%lld", static_cast<long long>(tv
.tv_sec
));
46 snprintf(buf
+ len
, sz
- len
, ".%03ld", static_cast<long>(tv
.tv_usec
) / 1000);
50 static void loggerBackend(const Logging::Entry
& entry
)
52 static thread_local
std::stringstream buf
;
55 buf
<< "msg=" << std::quoted(entry
.message
);
57 buf
<< " oserror=" << std::quoted(entry
.error
.get());
61 buf
<< " subsystem=" << std::quoted(entry
.name
.get());
63 buf
<< " level=" << entry
.level
;
64 if (entry
.d_priority
) {
65 buf
<< " prio=" << static_cast<int>(entry
.d_priority
);
68 buf
<< " ts=" << std::quoted(toTimestampStringMilli(entry
.d_timestamp
, timebuf
, sizeof(timebuf
)));
69 for (auto const& v
: entry
.values
) {
71 buf
<< v
.first
<< "=" << std::quoted(v
.second
);
73 Logger::Urgency u
= entry
.d_priority
? Logger::Urgency(entry
.d_priority
) : Logger::Info
;
74 g_log
<< u
<< buf
.str() << endl
;
77 static bool init_unit_test()
79 g_slog
= Logging::Logger::create(loggerBackend
);
85 int main(int argc
, char* argv
[])
87 return boost::unit_test::unit_test_main(&init_unit_test
, argc
, argv
);