-include ../../mconfig
-objects = tests.o test-dinit.o proctests.o test-run-child-proc.o
+objects = tests.o test-dinit.o proctests.o test-run-child-proc.o test-bpsys.o
parent_objs = service.o proc-service.o dinit-log.o load_service.o baseproc-service.o
check: build-tests
cd includes; ln -sf ../../includes/*.h .
cd includes; ln -sf ../test-includes/*.h .
-tests: prepare-incdir $(parent_objs) tests.o test-dinit.o
- $(CXX) $(SANITIZEOPTS) -o tests $(parent_objs) tests.o test-dinit.o $(EXTRA_LIBS)
+tests: prepare-incdir $(parent_objs) tests.o test-dinit.o test-bpsys.o
+ $(CXX) $(SANITIZEOPTS) -o tests $(parent_objs) tests.o test-dinit.o test-bpsys.o $(EXTRA_LIBS)
-proctests: prepare-incdir $(parent_objs) proctests.o test-dinit.o
- $(CXX) $(SANITIZEOPTS) -o proctests $(parent_objs) proctests.o test-dinit.o $(EXTRA_LIBS)
+proctests: prepare-incdir $(parent_objs) proctests.o test-dinit.o test-bpsys.o
+ $(CXX) $(SANITIZEOPTS) -o proctests $(parent_objs) proctests.o test-dinit.o test-bpsys.o $(EXTRA_LIBS)
$(objects): %.o: %.cc
$(CXX) $(CXXOPTS) $(SANITIZEOPTS) -Iincludes -I../dasynq -c $< -o $@
process_service p = process_service(&sset, "testproc", std::move(command), command_offsets, depends);
p.start(true);
+ sset.process_queues();
+
+ assert(p.get_state() == service_state_t::STARTING);
base_process_service_test::exec_succeeded(&p);
+ sset.process_queues();
assert(p.get_state() == service_state_t::STARTED);
}
--- /dev/null
+#include <vector>
+#include <utility>
+#include <algorithm>
+
+#include "baseproc-sys.h"
+
+std::vector<bool> usedfds = {true, true, true};
+
+// Allocate a file descriptor
+static int allocfd()
+{
+ auto f = std::find(usedfds.begin(), usedfds.end(), false);
+ if (f == usedfds.end()) {
+ int r = usedfds.size();
+ usedfds.push_back(true);
+ return r;
+ }
+
+ *f = true;
+ return f - usedfds.begin();
+}
+
+namespace bp_sys {
+
+int pipe2(int fds[2], int flags)
+{
+ fds[0] = allocfd();
+ fds[1] = allocfd();
+ return 0;
+}
+
+int close(int fd)
+{
+ if (fd >= usedfds.size()) abort();
+
+ usedfds[fd] = false;
+ return 0;
+}
+
+}
#include <sys/types.h>
+#include <iostream>
// Mock system functions for testing.
namespace bp_sys {
-inline int pipe2(int pipefd[2], int flags)
-{
- abort();
- return 0;
-}
+int pipe2(int pipefd[2], int flags);
+int close(int fd);
inline int fcntl(int fd, int cmd, ...)
{
return 0;
}
-inline int close(int fd)
-{
- abort();
- return 0;
-}
-
inline int kill(pid_t pid, int sig)
{
+ // No proper mock implemented yet:
+ std::cout << "(kill; aborting)" << std::endl;
abort();
return 0;
}
public:
pid_t fork(eventloop_t &loop, bool reserved_child_watcher, int priority = dasynq::DEFAULT_PRIORITY)
{
- return -1;
+ return 2; // doesn't matter much what we return here, but it should be a potentially valid pid
}
void add_reserved(eventloop_t &eloop, pid_t child, int prio = dasynq::DEFAULT_PRIORITY) noexcept