1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/* Helpers to create and connect Unix or TCP sockets. */
#ifndef TEST_ENDPOINT_H
#define TEST_ENDPOINT_H
#include <arpa/inet.h>
#include <sys/un.h>
#include "munit.h"
/* A few tests depend on knowing that certain reads and writes will not be short
* and will happen immediately. */
#define TEST_SOCKET_MIN_BUF_SIZE 4096
/* Munit parameter defining the socket type to use in test_endpoint_setup.
*
* If set to "unix" a pair of unix abstract sockets will be created. If set to
* "tcp" a pair of TCP sockets using the loopback interface will be created. */
#define TEST_ENDPOINT_FAMILY "endpoint-family"
/* Null-terminated list of legal values for TEST_ENDPOINT_FAMILY. Currently
* "unix" and "tcp". */
extern char *test_endpoint_family_values[];
/* Listening socket endpoint. */
struct test_endpoint
{
char address[256]; /* Rendered address string. */
sa_family_t family; /* Address family (either AF_INET or AF_UNIX) */
int fd; /* Listening socket. */
union { /* Server address (either a TCP or Unix) */
struct sockaddr_in in_address;
struct sockaddr_un un_address;
};
};
/* Create a listening endpoint.
*
* This will bind a random address and start listening to it. */
void test_endpoint_setup(struct test_endpoint *e,
const MunitParameter params[]);
/* Tear down a listening endpoint. */
void test_endpoint_tear_down(struct test_endpoint *e);
/* Establish a new client connection. */
int test_endpoint_connect(struct test_endpoint *e);
/* Accept a new client connection. */
int test_endpoint_accept(struct test_endpoint *e);
/* Connect and accept a connection, returning the pair of connected sockets. */
void test_endpoint_pair(struct test_endpoint *e, int *server, int *client);
/* Return the endpoint address. */
const char *test_endpoint_address(struct test_endpoint *e);
#endif /* TEST_ENDPOINT_H */
|