source: tests/check.c @ a181ec1

Last change on this file since a181ec1 was e7e6484, checked in by dx <dx@…>, at 2017-03-12T04:27:59Z

The protocol argument to socketpair was incorrect.

For some reason the protocol was being set to PF_UNIX which is
incorrect. According to the man pages and other sources (like Stevens
Unix Network Programming), the protocol should be '0' which will
use the default for the given domain. This appears to actually
work under Linux (which appears to allow 0 or 1 as the protocol without
error), but fails under Mac OSX (which only allows 0).

  • Property mode set to 100644
File size: 2.9 KB
Line 
1#include <stdlib.h>
2#include <glib.h>
3#include <gmodule.h>
4#include <check.h>
5#include <locale.h>
6#include <sys/time.h>
7#include "bitlbee.h"
8#include "testsuite.h"
9
10global_t global;        /* Against global namespace pollution */
11
12gboolean g_io_channel_pair(GIOChannel **ch1, GIOChannel **ch2)
13{
14        int sock[2];
15
16        if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) < 0) {
17                perror("socketpair");
18                return FALSE;
19        }
20
21        *ch1 = g_io_channel_unix_new(sock[0]);
22        *ch2 = g_io_channel_unix_new(sock[1]);
23        return TRUE;
24}
25
26irc_t *torture_irc(void)
27{
28        irc_t *irc;
29        GIOChannel *ch1, *ch2;
30
31        if (!g_io_channel_pair(&ch1, &ch2)) {
32                return NULL;
33        }
34        irc = irc_new(g_io_channel_unix_get_fd(ch1));
35        return irc;
36}
37
38double gettime()
39{
40        struct timeval time[1];
41
42        gettimeofday(time, 0);
43        return((double) time->tv_sec + (double) time->tv_usec / 1000000);
44}
45
46void sighandler_shutdown_setup()
47{
48        /* no-op. originally defined in unix.c, needed by bitlbee.c */
49}
50
51/* From check_util.c */
52Suite *util_suite(void);
53
54/* From check_nick.c */
55Suite *nick_suite(void);
56
57/* From check_md5.c */
58Suite *md5_suite(void);
59
60/* From check_arc.c */
61Suite *arc_suite(void);
62
63/* From check_irc.c */
64Suite *irc_suite(void);
65
66/* From check_help.c */
67Suite *help_suite(void);
68
69/* From check_user.c */
70Suite *user_suite(void);
71
72/* From check_set.c */
73Suite *set_suite(void);
74
75/* From check_jabber_sasl.c */
76Suite *jabber_sasl_suite(void);
77
78/* From check_jabber_sasl.c */
79Suite *jabber_util_suite(void);
80
81int main(int argc, char **argv)
82{
83        int nf;
84        SRunner *sr;
85        GOptionContext *pc;
86        gboolean no_fork = FALSE;
87        gboolean verbose = FALSE;
88        GOptionEntry options[] = {
89                { "no-fork", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork" },
90                { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
91                { NULL }
92        };
93
94        pc = g_option_context_new("");
95        g_option_context_add_main_entries(pc, options, NULL);
96
97        if (!g_option_context_parse(pc, &argc, &argv, NULL)) {
98                return 1;
99        }
100
101        g_option_context_free(pc);
102
103        log_init();
104        b_main_init();
105        setlocale(LC_CTYPE, "");
106
107        if (verbose) {
108                log_link(LOGLVL_ERROR, LOGOUTPUT_CONSOLE);
109#ifdef DEBUG
110                log_link(LOGLVL_DEBUG, LOGOUTPUT_CONSOLE);
111#endif
112                log_link(LOGLVL_INFO, LOGOUTPUT_CONSOLE);
113                log_link(LOGLVL_WARNING, LOGOUTPUT_CONSOLE);
114        }
115
116        global.conf = conf_load(0, NULL);
117        global.conf->runmode = RUNMODE_DAEMON;
118
119        sr = srunner_create(util_suite());
120        srunner_add_suite(sr, nick_suite());
121        srunner_add_suite(sr, md5_suite());
122        srunner_add_suite(sr, arc_suite());
123        srunner_add_suite(sr, irc_suite());
124        srunner_add_suite(sr, help_suite());
125        srunner_add_suite(sr, user_suite());
126        srunner_add_suite(sr, set_suite());
127        srunner_add_suite(sr, jabber_sasl_suite());
128        srunner_add_suite(sr, jabber_util_suite());
129        if (no_fork) {
130                srunner_set_fork_status(sr, CK_NOFORK);
131        }
132        srunner_run_all(sr, verbose ? CK_VERBOSE : CK_NORMAL);
133        nf = srunner_ntests_failed(sr);
134        srunner_free(sr);
135        return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
136}
Note: See TracBrowser for help on using the repository browser.