extern pid_t last_forked_pid;
}
+// This is a mock for a Dasynq-based event loop
class eventloop_t
{
time_val current_time {0, 0};
}
}
+ void send_fd_event(int fd, int events)
+ {
+ auto i = regd_fd_watchers.find(fd);
+ if (i != regd_fd_watchers.end()) {
+ i->second->fd_event(*this, fd, events);
+ }
+ }
+
class child_proc_watcher
{
public:
#include "service.h"
#include "test_service.h"
+#include "baseproc-sys.h"
constexpr static auto REG = dependency_type::REGULAR;
constexpr static auto WAITS = dependency_type::WAITS_FOR;
assert(! tl.got_started);
}
+static void flush_log(int fd)
+{
+ while (! is_log_flushed()) {
+ event_loop.send_fd_event(fd, dasynq::OUT_EVENTS);
+ event_loop.send_fd_event(STDOUT_FILENO, dasynq::OUT_EVENTS);
+ }
+
+ std::vector<char> wdata;
+ bp_sys::extract_written_data(fd, wdata);
+ bp_sys::extract_written_data(0, wdata);
+}
+
+void test_log1()
+{
+ service_set sset;
+ init_log(&sset, true /* syslog format */);
+
+ int logfd = bp_sys::allocfd();
+ setup_main_log(logfd);
+
+ flush_log(logfd);
+
+ log(loglevel_t::ERROR, "test one");
+
+ // flush
+ //event_loop.
+ event_loop.send_fd_event(logfd, dasynq::OUT_EVENTS);
+
+ std::vector<char> wdata;
+ bp_sys::extract_written_data(logfd, wdata);
+
+ std::string wstr {wdata.begin(), wdata.end()};
+
+ assert(wstr == "<27>dinit: test one\n");
+}
#define RUN_TEST(name, spacing) \
std::cout << #name "..." spacing << std::flush; \
RUN_TEST(test13, " ");
RUN_TEST(test14, " ");
RUN_TEST(test15, " ");
+ RUN_TEST(test_log1, " ");
}