tests: add sendto_* test framework

This commit is contained in:
Simon Arlott 2017-08-05 14:09:01 +01:00
parent 84a3275b7a
commit d2b5f4111b
No known key found for this signature in database
GPG key ID: C8975F2043CA5D24
16 changed files with 439 additions and 8 deletions

6
.gitignore vendored
View file

@ -56,13 +56,19 @@ ircd/version.c
ircd/version.c.last ircd/version.c.last
ssld/ssld ssld/ssld
wsockd/wsockd wsockd/wsockd
tests/core
tests/msgbuf_parse1 tests/msgbuf_parse1
tests/msgbuf_unparse1 tests/msgbuf_unparse1
tests/rb_linebuf_put1 tests/rb_linebuf_put1
tests/rb_snprintf_append1 tests/rb_snprintf_append1
tests/rb_snprintf_try_append1 tests/rb_snprintf_try_append1
tests/send1
tests/substitution1 tests/substitution1
tests/runtests tests/runtests
tests/*.c.ban.db
tests/*.c.ban.db-journal
tests/*.c.log
tests/*.c.pid
testsuite/ircd.pid.* testsuite/ircd.pid.*
tools/charybdis-mkpasswd tools/charybdis-mkpasswd
tools/charybdis-mkfingerprint tools/charybdis-mkfingerprint

View file

@ -823,13 +823,6 @@ charybdis_main(int argc, char * const argv[])
ircd_ssl_ok = true; ircd_ssl_ok = true;
} }
if (testing_conf)
{
fprintf(stderr, "\nConfig testing complete.\n");
fflush(stderr);
return 0; /* Why? We want the launcher to exit out. */
}
me.from = &me; me.from = &me;
me.servptr = &me; me.servptr = &me;
SetMe(&me); SetMe(&me);
@ -843,6 +836,13 @@ charybdis_main(int argc, char * const argv[])
construct_umodebuf(); construct_umodebuf();
if (testing_conf)
{
fprintf(stderr, "\nConfig testing complete.\n");
fflush(stderr);
return 0; /* Why? We want the launcher to exit out. */
}
check_class(); check_class();
write_pidfile(pidFileName); write_pidfile(pidFileName);
load_help(); load_help();

View file

@ -4,6 +4,7 @@ check_PROGRAMS = runtests \
rb_linebuf_put1 \ rb_linebuf_put1 \
rb_snprintf_append1 \ rb_snprintf_append1 \
rb_snprintf_try_append1 \ rb_snprintf_try_append1 \
send1 \
substitution1 substitution1
AM_CFLAGS=$(WARNFLAGS) AM_CFLAGS=$(WARNFLAGS)
AM_CPPFLAGS = $(DEFAULT_INCLUDES) -I../librb/include -I.. AM_CPPFLAGS = $(DEFAULT_INCLUDES) -I../librb/include -I..
@ -24,7 +25,16 @@ msgbuf_unparse1_SOURCES = msgbuf_unparse1.c
rb_linebuf_put1_SOURCES = rb_linebuf_put1.c rb_linebuf_put1_SOURCES = rb_linebuf_put1.c
rb_snprintf_append1_SOURCES = rb_snprintf_append1.c rb_snprintf_append1_SOURCES = rb_snprintf_append1.c
rb_snprintf_try_append1_SOURCES = rb_snprintf_try_append1.c rb_snprintf_try_append1_SOURCES = rb_snprintf_try_append1.c
send1_SOURCES = send1.c ircd_util.c client_util.c
substitution1_SOURCES = substitution1.c substitution1_SOURCES = substitution1.c
check-local: $(check_PROGRAMS) check-local: $(check_PROGRAMS) \
../authd/authd \
../bandb/bandb \
../ssld/ssld \
../wsockd/wsockd \
$(patsubst ../modules/%.c,../modules/.libs/%.so,$(wildcard ../modules/*.c)) \
$(patsubst ../modules/core/%.c,../modules/core/.libs/%.so,$(wildcard ../modules/core/*.c)) \
$(patsubst ../extensions/%.c,../extensions/.libs/%.so,$(wildcard ../extensions/*.c))
./runtests -l $(abs_top_srcdir)/tests/TESTS ./runtests -l $(abs_top_srcdir)/tests/TESTS

View file

@ -3,4 +3,5 @@ msgbuf_unparse1
rb_linebuf_put1 rb_linebuf_put1
rb_snprintf_append1 rb_snprintf_append1
rb_snprintf_try_append1 rb_snprintf_try_append1
send1
substitution1 substitution1

94
tests/client_util.c Normal file
View file

@ -0,0 +1,94 @@
/*
* client_util.c: Utility functions for making test clients
* Copyright 2017 Simon Arlott
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "tap/basic.h"
#include "stdinc.h"
#include "ircd_defs.h"
#include "client_util.h"
#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
struct Client *make_local_person(void)
{
return make_local_person_nick(TEST_NICK);
}
struct Client *make_local_person_nick(const char *nick)
{
return make_local_person_full(nick, TEST_USERNAME, TEST_HOSTNAME, TEST_IP, TEST_REALNAME);
}
struct Client *make_local_person_full(const char *nick, const char *username, const char *hostname, const char *ip, const char *realname)
{
struct Client *client;
client = make_client(NULL);
rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &lclient_list);
client->servptr = &me;
rb_dlinkAdd(client, &client->lnode, &client->servptr->serv->users);
SetClient(client);
make_user(client);
rb_inet_pton_sock(ip, (struct sockaddr *)&client->localClient->ip);
rb_strlcpy(client->name, nick, sizeof(client->name));
rb_strlcpy(client->username, username, sizeof(client->username));
rb_strlcpy(client->host, hostname, sizeof(client->host));
rb_inet_ntop_sock((struct sockaddr *)&client->localClient->ip, client->sockhost, sizeof(client->sockhost));
rb_strlcpy(client->info, realname, sizeof(client->info));
return client;
}
void remove_local_person(struct Client *client)
{
exit_client(NULL, client, &me, "Test client removed");
}
char *get_client_sendq(const struct Client *client)
{
static char buf[EXT_BUFSIZE + sizeof(CRLF)];
if (rb_linebuf_len(&client->localClient->buf_sendq)) {
int ret;
memset(buf, 0, sizeof(buf));
ret = rb_linebuf_get(&client->localClient->buf_sendq, buf, sizeof(buf), 0, 1);
if (is_bool(ret > 0, true, MSG)) {
return buf;
} else {
return "<get_client_sendq error>";
}
}
return "";
}
void client_util_init(void)
{
}
void client_util_free(void)
{
}

55
tests/client_util.h Normal file
View file

@ -0,0 +1,55 @@
/*
* client_util.c: Utility functions for making test clients
* Copyright 2017 Simon Arlott
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "stdinc.h"
#include "ircd_defs.h"
#include "msg.h"
#include "client.h"
#define TEST_NICK "test"
#define TEST_USERNAME "username"
#define TEST_HOSTNAME "example.test"
#define TEST_IP "2001:db8::1:5ee:bad:c0de"
#define TEST_REALNAME "Test user"
#define CRLF "\r\n"
void client_util_init(void);
void client_util_free(void);
struct Client *make_local_person(void);
struct Client *make_local_person_nick(const char *nick);
struct Client *make_local_person_full(const char *nick, const char *username, const char *hostname, const char *ip, const char *realname);
void remove_local_person(struct Client *client);
char *get_client_sendq(const struct Client *client);
#define is_client_sendq_empty(client, message, ...) do { \
is_string("", get_client_sendq(client), message, ##__VA_ARGS__); \
} while (0)
#define is_client_sendq(queue, client, message, ...) do { \
is_string(queue, get_client_sendq(client), message, ##__VA_ARGS__); \
is_client_sendq_empty(client, message, ##__VA_ARGS__); \
} while (0)

102
tests/ircd_util.c Normal file
View file

@ -0,0 +1,102 @@
/*
* ircd_util.c: Utility functions for making test ircds
* Copyright 2017 Simon Arlott
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "tap/basic.h"
#include "stdinc.h"
#include "ircd_defs.h"
#include "defaults.h"
#include "client.h"
#include "ircd_util.h"
#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
extern int charybdis_main(int argc, const char *argv[]);
static char argv0[BUFSIZE];
static char configfile[BUFSIZE];
static char logfile[BUFSIZE];
static char pidfile[BUFSIZE];
static const char *argv[] = {
argv0,
"-configfile", configfile,
"-logfile", logfile,
"-pidfile", pidfile,
"-conftest",
NULL,
};
void ircd_util_init(const char *name)
{
rb_strlcpy(argv0, name, sizeof(argv0));
snprintf(configfile, sizeof(configfile), "%sonf", name);
snprintf(logfile, sizeof(logfile), "%s.log", name);
snprintf(pidfile, sizeof(pidfile), "%s.pid", name);
unlink(logfile);
unlink(pidfile);
rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
rb_linebuf_init(LINEBUF_HEAP_SIZE);
char buf[BUFSIZE];
ircd_paths[IRCD_PATH_IRCD_EXEC] = argv0;
ircd_paths[IRCD_PATH_PREFIX] = ".";
snprintf(buf, sizeof(buf), "runtime%cmodules", RB_PATH_SEPARATOR);
ircd_paths[IRCD_PATH_MODULES] = rb_strdup(buf);
snprintf(buf, sizeof(buf), "runtime%1$cmodules%1$cautoload", RB_PATH_SEPARATOR);
ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(buf);
ircd_paths[IRCD_PATH_ETC] = "runtime";
ircd_paths[IRCD_PATH_LOG] = "runtime";
snprintf(buf, sizeof(buf), "runtime%1$chelp%1$cusers", RB_PATH_SEPARATOR);
ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(buf);
snprintf(buf, sizeof(buf), "runtime%1$chelp%1$copers", RB_PATH_SEPARATOR);
ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(buf);
snprintf(buf, sizeof(buf), "runtime%cmotd", RB_PATH_SEPARATOR);
ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(buf);
ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(buf);
snprintf(buf, sizeof(buf), "%s.ban.db", name);
ircd_paths[IRCD_PATH_BANDB] = rb_strdup(buf);
snprintf(buf, sizeof(buf), "%s.ban.db-journal", name);
unlink(buf);
ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(pidfile);
ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(logfile);
snprintf(buf, sizeof(buf), "runtime%cbin", RB_PATH_SEPARATOR);
ircd_paths[IRCD_PATH_BIN] = rb_strdup(buf);
ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(buf);
is_int(0, charybdis_main(ARRAY_SIZE(argv) - 1, argv), MSG);
}
void ircd_util_free(void)
{
}

31
tests/ircd_util.h Normal file
View file

@ -0,0 +1,31 @@
/*
* ircd_util.c: Utility functions for making test ircds
* Copyright 2017 Simon Arlott
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "stdinc.h"
#include "ircd_defs.h"
#define TEST_ME_NAME "me.test"
void ircd_util_init(const char *name);
void ircd_util_free(void);

1
tests/runtime/bin/authd Symbolic link
View file

@ -0,0 +1 @@
../../../authd/authd

1
tests/runtime/bin/bandb Symbolic link
View file

@ -0,0 +1 @@
../../../bandb/bandb

1
tests/runtime/bin/ssld Symbolic link
View file

@ -0,0 +1 @@
../../../ssld/ssld

1
tests/runtime/bin/wsockd Symbolic link
View file

@ -0,0 +1 @@
../../../wsockd/wsockd

1
tests/runtime/help Symbolic link
View file

@ -0,0 +1 @@
../../help

1
tests/runtime/motd Normal file
View file

@ -0,0 +1 @@
Hello World!

119
tests/send1.c Normal file
View file

@ -0,0 +1,119 @@
/*
* send1.c: Test sendto_* under various conditions
* Copyright 2017 Simon Arlott
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "tap/basic.h"
#include "ircd_util.h"
#include "client_util.h"
#include "send.h"
#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
static void sendto_one_numeric1(void)
{
struct Client *user = make_local_person();
sendto_one_numeric(user, 1, "Hello %s!", "World");
is_client_sendq(":" TEST_ME_NAME " 001 " TEST_NICK " Hello World!" CRLF, user, MSG);
remove_local_person(user);
}
static void sendto_wallops_flags1(void)
{
struct Client *user1 = make_local_person_nick("user1");
struct Client *user2 = make_local_person_nick("user2");
struct Client *oper1 = make_local_person_nick("oper1");
struct Client *oper2 = make_local_person_nick("oper2");
struct Client *oper3 = make_local_person_nick("oper3");
struct Client *oper4 = make_local_person_nick("oper4");
rb_dlinkAddAlloc(oper1, &local_oper_list);
rb_dlinkAddAlloc(oper1, &oper_list);
SetOper(oper1);
rb_dlinkAddAlloc(oper2, &local_oper_list);
rb_dlinkAddAlloc(oper2, &oper_list);
SetOper(oper2);
rb_dlinkAddAlloc(oper3, &local_oper_list);
rb_dlinkAddAlloc(oper3, &oper_list);
SetOper(oper3);
rb_dlinkAddAlloc(oper4, &local_oper_list);
rb_dlinkAddAlloc(oper4, &oper_list);
SetOper(oper4);
user1->umodes |= UMODE_WALLOP;
oper1->umodes |= UMODE_WALLOP | UMODE_OPERWALL;
oper2->umodes |= UMODE_WALLOP | UMODE_OPERWALL | UMODE_ADMIN;
oper3->umodes |= UMODE_WALLOP;
oper4->umodes |= UMODE_OPERWALL;
sendto_wallops_flags(UMODE_WALLOP, oper1, "Test to users");
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, user1, "User is +w; " MSG);
is_client_sendq_empty(user2, "User is -w; " MSG);
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper1, "User is +w; " MSG);
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper2, "User is +w; " MSG);
is_client_sendq(":oper1!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to users" CRLF, oper3, "User is +w; " MSG);
is_client_sendq_empty(oper4, "User is -w; " MSG);
sendto_wallops_flags(UMODE_OPERWALL, oper2, "Test to opers");
is_client_sendq_empty(user1, "Not an oper; " MSG);
is_client_sendq_empty(user2, "Not an oper; " MSG);
is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper1, "Oper is +z; " MSG);
is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper2, "Oper is +z; " MSG);
is_client_sendq_empty(oper3, "Oper is -z; " MSG);
is_client_sendq(":oper2!" TEST_USERNAME "@" TEST_HOSTNAME " WALLOPS :Test to opers" CRLF, oper4, "Oper is +z; " MSG);
sendto_wallops_flags(UMODE_ADMIN, &me, "Test to admins");
is_client_sendq_empty(user1, "Not an admin; " MSG);
is_client_sendq_empty(user2, "Not an admin; " MSG);
is_client_sendq_empty(oper1, "Not an admin; " MSG);
is_client_sendq(":" TEST_ME_NAME " WALLOPS :Test to admins" CRLF, oper2, MSG);
is_client_sendq_empty(oper3, "Not an admin; " MSG);
is_client_sendq_empty(oper4, "Not an admin; " MSG);
remove_local_person(user1);
remove_local_person(user2);
remove_local_person(oper1);
remove_local_person(oper2);
remove_local_person(oper3);
remove_local_person(oper4);
}
int main(int argc, char *argv[])
{
plan_lazy();
ircd_util_init(__FILE__);
client_util_init();
sendto_one_numeric1();
sendto_wallops_flags1();
client_util_free();
ircd_util_free();
return 0;
}

7
tests/send1.conf Normal file
View file

@ -0,0 +1,7 @@
serverinfo {
sid = "0AA";
name = "me.test";
description = "Test server";
network_name = "Test network";
};