]> jfr.im git - solanum.git/blame - tests/ircd_util.c
tests: add sendto_* test framework
[solanum.git] / tests / ircd_util.c
CommitLineData
d2b5f411
SA
1/*
2 * ircd_util.c: Utility functions for making test ircds
3 * Copyright 2017 Simon Arlott
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 * USA
19 */
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23#include <unistd.h>
24#include "tap/basic.h"
25
26#include "stdinc.h"
27#include "ircd_defs.h"
28#include "defaults.h"
29#include "client.h"
30#include "ircd_util.h"
31
32#define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
33
34extern int charybdis_main(int argc, const char *argv[]);
35
36static char argv0[BUFSIZE];
37static char configfile[BUFSIZE];
38static char logfile[BUFSIZE];
39static char pidfile[BUFSIZE];
40
41static const char *argv[] = {
42 argv0,
43 "-configfile", configfile,
44 "-logfile", logfile,
45 "-pidfile", pidfile,
46 "-conftest",
47 NULL,
48};
49
50void ircd_util_init(const char *name)
51{
52 rb_strlcpy(argv0, name, sizeof(argv0));
53 snprintf(configfile, sizeof(configfile), "%sonf", name);
54 snprintf(logfile, sizeof(logfile), "%s.log", name);
55 snprintf(pidfile, sizeof(pidfile), "%s.pid", name);
56 unlink(logfile);
57 unlink(pidfile);
58
59 rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
60 rb_linebuf_init(LINEBUF_HEAP_SIZE);
61
62 char buf[BUFSIZE];
63 ircd_paths[IRCD_PATH_IRCD_EXEC] = argv0;
64 ircd_paths[IRCD_PATH_PREFIX] = ".";
65
66 snprintf(buf, sizeof(buf), "runtime%cmodules", RB_PATH_SEPARATOR);
67 ircd_paths[IRCD_PATH_MODULES] = rb_strdup(buf);
68
69 snprintf(buf, sizeof(buf), "runtime%1$cmodules%1$cautoload", RB_PATH_SEPARATOR);
70 ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(buf);
71
72 ircd_paths[IRCD_PATH_ETC] = "runtime";
73 ircd_paths[IRCD_PATH_LOG] = "runtime";
74
75 snprintf(buf, sizeof(buf), "runtime%1$chelp%1$cusers", RB_PATH_SEPARATOR);
76 ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(buf);
77
78 snprintf(buf, sizeof(buf), "runtime%1$chelp%1$copers", RB_PATH_SEPARATOR);
79 ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(buf);
80
81 snprintf(buf, sizeof(buf), "runtime%cmotd", RB_PATH_SEPARATOR);
82 ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(buf);
83 ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(buf);
84
85 snprintf(buf, sizeof(buf), "%s.ban.db", name);
86 ircd_paths[IRCD_PATH_BANDB] = rb_strdup(buf);
87 snprintf(buf, sizeof(buf), "%s.ban.db-journal", name);
88 unlink(buf);
89
90 ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(pidfile);
91 ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(logfile);
92
93 snprintf(buf, sizeof(buf), "runtime%cbin", RB_PATH_SEPARATOR);
94 ircd_paths[IRCD_PATH_BIN] = rb_strdup(buf);
95 ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(buf);
96
97 is_int(0, charybdis_main(ARRAY_SIZE(argv) - 1, argv), MSG);
98}
99
100void ircd_util_free(void)
101{
102}