mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
ccan: forgotten test files after last update.
Also add ccan/config.h to .gitignore. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
33748bf119
commit
91209d4d66
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ gen_*
|
||||
daemon/lightning-cli
|
||||
check-bolt
|
||||
coverage
|
||||
ccan/config.h
|
||||
|
93
ccan/ccan/io/test/run-21-io_close_taken_fd.c
Normal file
93
ccan/ccan/io/test/run-21-io_close_taken_fd.c
Normal file
@ -0,0 +1,93 @@
|
||||
#include <ccan/io/io.h>
|
||||
/* Include the C files directly. */
|
||||
#include <ccan/io/poll.c>
|
||||
#include <ccan/io/io.c>
|
||||
#include <ccan/tap/tap.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define PORT "65021"
|
||||
|
||||
static struct io_listener *l;
|
||||
|
||||
static struct io_plan *steal_fd(struct io_conn *conn, int *fd)
|
||||
{
|
||||
io_close_listener(l);
|
||||
*fd = io_conn_fd(conn);
|
||||
return io_close_taken_fd(conn);
|
||||
}
|
||||
|
||||
static int make_listen_fd(const char *port, struct addrinfo **info)
|
||||
{
|
||||
int fd, on = 1;
|
||||
struct addrinfo *addrinfo, hints;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
|
||||
return -1;
|
||||
|
||||
fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
|
||||
addrinfo->ai_protocol);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
||||
if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if (listen(fd, 1) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
*info = addrinfo;
|
||||
return fd;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct addrinfo *addrinfo = NULL;
|
||||
int i, fd, in_fd, status;
|
||||
char buf[strlen("hellothere")];
|
||||
|
||||
/* This is how many tests you plan to run */
|
||||
plan_tests(15);
|
||||
fd = make_listen_fd(PORT, &addrinfo);
|
||||
l = io_new_listener(NULL, fd, steal_fd, &in_fd);
|
||||
fflush(stdout);
|
||||
if (!fork()) {
|
||||
io_close_listener(l);
|
||||
fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
|
||||
addrinfo->ai_protocol);
|
||||
if (fd < 0)
|
||||
exit(1);
|
||||
if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
|
||||
exit(2);
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
for (i = 0; i < strlen("hellothere"); i++) {
|
||||
if (write(fd, "hellothere" + i, 1) != 1)
|
||||
break;
|
||||
}
|
||||
close(fd);
|
||||
freeaddrinfo(addrinfo);
|
||||
exit(0);
|
||||
}
|
||||
freeaddrinfo(addrinfo);
|
||||
ok1(io_loop(NULL, NULL) == NULL);
|
||||
|
||||
for (i = 0; i < strlen("hellothere"); i++)
|
||||
ok1(read(in_fd, buf + i, 1) == 1);
|
||||
|
||||
ok1(memcmp(buf, "hellothere", sizeof(buf)) == 0);
|
||||
ok1(wait(&status));
|
||||
ok1(WIFEXITED(status));
|
||||
ok1(WEXITSTATUS(status) == 0);
|
||||
|
||||
/* This exits depending on whether all tests passed */
|
||||
return exit_status();
|
||||
}
|
61
ccan/ccan/io/test/run-22-POLLHUP-on-listening-socket.c
Normal file
61
ccan/ccan/io/test/run-22-POLLHUP-on-listening-socket.c
Normal file
@ -0,0 +1,61 @@
|
||||
#include <ccan/io/io.h>
|
||||
/* Include the C files directly. */
|
||||
#include <ccan/io/poll.c>
|
||||
#include <ccan/io/io.c>
|
||||
#include <ccan/tap/tap.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define PORT "65022"
|
||||
|
||||
static int make_listen_fd(const char *port, struct addrinfo **info)
|
||||
{
|
||||
int fd, on = 1;
|
||||
struct addrinfo *addrinfo, hints;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
if (getaddrinfo(NULL, port, &hints, &addrinfo) != 0)
|
||||
return -1;
|
||||
|
||||
fd = socket(addrinfo->ai_family, addrinfo->ai_socktype,
|
||||
addrinfo->ai_protocol);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
||||
if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
if (listen(fd, 1) != 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
*info = addrinfo;
|
||||
return fd;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct addrinfo *addrinfo = NULL;
|
||||
int fd;
|
||||
|
||||
/* This is how many tests you plan to run */
|
||||
plan_tests(1);
|
||||
fd = make_listen_fd(PORT, &addrinfo);
|
||||
freeaddrinfo(addrinfo);
|
||||
io_new_listener(NULL, fd, io_never, NULL);
|
||||
|
||||
/* Anyone could do this; a child doing it will cause poll to return
|
||||
* POLLHUP only! */
|
||||
shutdown(fd, SHUT_RDWR);
|
||||
ok1(io_loop(NULL, NULL) == NULL);
|
||||
|
||||
/* This exits depending on whether all tests passed */
|
||||
return exit_status();
|
||||
}
|
8
ccan/ccan/str/test/compile_ok-STR_MAX_CHARS-static.c
Normal file
8
ccan/ccan/str/test/compile_ok-STR_MAX_CHARS-static.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <ccan/str/str.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static char str[STR_MAX_CHARS(int)];
|
||||
|
||||
return str[0] ? 0 : 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user