1 #include <gtest/gtest.h>
4 #include "common/Clock.h"
5 #include "common/PrebufferedStreambuf.h"
6 #include "include/coredumpctl.h"
7 #include "SubsystemMap.h"
9 using namespace ceph::logging;
14 subs.add(0, "none", 10, 10);
15 subs.add(1, "foosys", 20, 1);
16 subs.add(2, "bar", 20, 2);
17 subs.add(3, "baz", 10, 3);
22 log.set_log_file("/tmp/foo");
23 log.reopen_log_file();
25 log.set_stderr_level(5, -1);
28 for (int i=0; i<100; i++) {
31 if (subs.should_gather(sys, l)) {
32 Entry *e = new Entry(ceph_clock_now(),
50 TEST(Log, ManyNoGather)
53 subs.add(1, "foo", 1, 1);
56 log.set_log_file("/tmp/big");
57 log.reopen_log_file();
58 for (int i=0; i<many; i++) {
60 if (subs.should_gather(1, l))
61 log.submit_entry(new Entry(ceph_clock_now(), pthread_self(), l, 1));
68 TEST(Log, ManyGatherLog)
71 subs.add(1, "foo", 20, 10);
74 log.set_log_file("/tmp/big");
75 log.reopen_log_file();
76 for (int i=0; i<many; i++) {
78 if (subs.should_gather(1, l))
79 log.submit_entry(new Entry(ceph_clock_now(), pthread_self(), l, 1,
80 "this is a long string asdf asdf asdf asdf asdf asdf asd fasd fasdf "));
86 TEST(Log, ManyGatherLogStringAssign)
89 subs.add(1, "foo", 20, 10);
92 log.set_log_file("/tmp/big");
93 log.reopen_log_file();
94 for (int i=0; i<many; i++) {
96 if (subs.should_gather(1, l)) {
97 Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
99 oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd";
100 e->set_str(oss.str());
107 TEST(Log, ManyGatherLogStringAssignWithReserve)
110 subs.add(1, "foo", 20, 10);
113 log.set_log_file("/tmp/big");
114 log.reopen_log_file();
115 for (int i=0; i<many; i++) {
117 if (subs.should_gather(1, l)) {
118 Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
120 oss.str().reserve(80);
121 oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd";
122 e->set_str(oss.str());
130 TEST(Log, ManyGatherLogPrebuf)
133 subs.add(1, "foo", 20, 10);
136 log.set_log_file("/tmp/big");
137 log.reopen_log_file();
138 for (int i=0; i<many; i++) {
140 if (subs.should_gather(1, l)) {
141 Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
142 PrebufferedStreambuf psb(e->m_static_buf, sizeof(e->m_static_buf));
144 oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd";
145 //e->m_str = oss.str();
153 TEST(Log, ManyGatherLogPrebufOverflow)
156 subs.add(1, "foo", 20, 10);
159 log.set_log_file("/tmp/big");
160 log.reopen_log_file();
161 for (int i=0; i<many; i++) {
163 if (subs.should_gather(1, l)) {
164 Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
165 PrebufferedStreambuf psb(e->m_static_buf, sizeof(e->m_static_buf));
167 oss << "this i a long stream asdf asdf asdf asdf asdf asdf asdf asdf asdf as fd"
168 << std::string(sizeof(e->m_static_buf) * 2, '-') ;
169 //e->m_str = oss.str();
177 TEST(Log, ManyGather)
180 subs.add(1, "foo", 20, 1);
183 log.set_log_file("/tmp/big");
184 log.reopen_log_file();
185 for (int i=0; i<many; i++) {
187 if (subs.should_gather(1, l))
188 log.submit_entry(new Entry(ceph_clock_now(), pthread_self(), l, 1));
197 subs.add(1, "foo", 20, 1);
200 log.set_log_file("/tmp/big");
201 log.reopen_log_file();
204 Entry *e = new Entry(ceph_clock_now(), pthread_self(), 10, 1);
206 PrCtl unset_dumpable;
207 log.submit_entry(e); // this should segv
214 TEST(Log, InternalSegv)
216 ASSERT_DEATH(do_segv(), ".*");
222 subs.add(1, "foo", 20, 10);
225 log.set_log_file("/tmp/big");
226 log.reopen_log_file();
228 Entry *e = new Entry(ceph_clock_now(), pthread_self(), l, 1);
230 std::string msg(10000000, 0);