using dasynq::pipe2;
using ::fcntl;
+using ::open;
using ::close;
using ::kill;
using ::getpgid;
#include <sys/types.h>
#include <unistd.h>
+#include "baseproc-sys.h"
+
// Complete read - read the specified size until end-of-file or error; continue read if
// interrupted by signal.
inline ssize_t complete_read(int fd, void * buf, size_t n)
char * cbuf = static_cast<char *>(buf);
ssize_t r = 0;
while ((size_t)r < n) {
- ssize_t res = read(fd, cbuf + r, n - r);
+ ssize_t res = bp_sys::read(fd, cbuf + r, n - r);
if (res == 0) {
return r;
}
// map of fd to the handler for writes to that fd
std::map<int, std::unique_ptr<bp_sys::write_handler>> write_hndlr_map;
+// map of path to file content
+std::map<std::string, std::vector<char>> file_content_map;
+
} // anon namespace
namespace bp_sys {
data = std::move(dwhndlr->data);
}
+// Supply a file content
+void supply_file_content(const std::string &path, std::vector<char> &data)
+{
+ file_content_map[path] = data;
+}
+
+void supply_file_content(const std::string &path, std::vector<char> &&data)
+{
+ file_content_map[path] = std::move(data);
+}
// Mock implementations of system calls:
+int open(const char *pathname, int flags)
+{
+ auto i = file_content_map.find(pathname);
+ if (i == file_content_map.end()) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ int nfd = allocfd();
+ supply_read_data(nfd, i->second);
+ return nfd;
+}
+
int pipe2(int fds[2], int flags)
{
fds[0] = allocfd();
void supply_read_data(int fd, std::vector<char> &&data);
void set_blocking(int fd);
void extract_written_data(int fd, std::vector<char> &data);
+void supply_file_content(const std::string &path, const std::vector<char> &data);
+void supply_file_content(const std::string &path, std::vector<char> &&data);
// Mock system calls:
// implementations elsewhere:
+int open(const char *pathname, int flags);
int pipe2(int pipefd[2], int flags);
int close(int fd);
int kill(pid_t pid, int sig);
inline pid_t waitpid(pid_t p, exit_status *statusp, int flags)
{
- throw std::string("not implemented");
+ // throw std::string("not implemented");
+ return 0; // TODO complete mock
}
ssize_t read(int fd, void *buf, size_t count);