#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "manager.h"
void test_request_stdio(void);
void test_request_tty(void);
static void
test_nop()
{
}
static void
test_inet()
{
int fd = socket(AF_INET, SOCK_STREAM, 0);
int saved_errno = errno;
close(fd);
errno = saved_errno ? saved_errno : errno;
}
static void
test_kill()
{
kill(0, SIGINT);
}
static void
test_pledge()
{
if (pledge("stdio rpath", NULL) != 0)
_exit(errno);
}
static void
test_rpath()
{
int fd;
char data[512];
if ((fd = open("/dev/zero", O_RDONLY)) == -1)
_exit(errno);
if (read(fd, data, sizeof(data)) == -1)
_exit(errno);
close(fd);
}
static void
test_wpath()
{
int fd;
char data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
if ((fd = open("/dev/null", O_WRONLY)) == -1)
_exit(errno);
if (write(fd, data, sizeof(data)) == -1)
_exit(errno);
close(fd);
}
static void
test_cpath()
{
const char filename[] = "/tmp/generic-test-cpath";
if (mkdir(filename, S_IRWXU) == -1)
_exit(errno);
if (rmdir(filename) == -1)
_exit(errno);
}
int
main(int argc, char *argv[])
{
int ret = EXIT_SUCCESS;
if (argc != 1)
errx(1, "usage: %s", argv[0]);
start_test(&ret, "", test_nop);
start_test(&ret, "", test_inet);
start_test(&ret, "abort", test_inet);
start_test(&ret, "stdio", test_inet);
start_test(&ret, "inet", test_inet);
start_test(&ret, "stdio inet", test_inet);
start_test(&ret, "fattr", test_kill);
start_test(&ret, "stdio", test_kill);
start_test(&ret, "stdio rpath", test_rpath);
start_test(&ret, "stdio wpath", test_wpath);
start_test(&ret, "cpath", test_cpath);
start_test(&ret, "stdio rpath", test_pledge);
start_test(&ret, "stdio rpath wpath", test_pledge);
start_test(&ret, "stdio", test_pledge);
start_test(&ret, "stdio unix", test_pledge);
start_test(&ret, NULL, test_request_stdio);
start_test(&ret, NULL, test_request_tty);
return (ret);
}