Review Board 1.7.16


clang compiler warning: fixes for tests to be compiled using clang

Review Request #4555 - Created March 29, 2015 and submitted

Diederik de Groot
13
ASTERISK-24917
Reviewers
asterisk-dev
Asterisk
clang's static analyzer will throw quite a number warnings / errors during compilation, some of which can be very helpfull in finding corner-case bugs. 

fixes for tests to be compiled using clang
executing the tests one-by-one works fine (completes to end) (skipping /main/stdtime) -> 
test show results failed:


=================== /main/message/ ====== 
FAIL   test_message_queue_handler_nom /main/message/             31036ms
[test_message.c:int handler_wait_for_message(struct ast_test *):244]: Test timed out while waiting for handler to get message

Not sure if this is actually a fail or just a timeout. WIP


=================== /main/strings/ ====== 
FAIL   escape_semicolons              /main/strings/             1ms     
[Mar 29 20:13:43] ERROR[2521]: utils.c:493 char *ast_escape_semicolons(const char *, char *, int): FRACK!, Failed assertion string != NULL && outbuf != NULL (0)
-> explainable by the change made to the source. ast_alloca(0) is not being executed -> test2 = NULL: need to resolv the open question how to handle ast_alloca(0) before making any further changes.

(With revision 5 of this code, this test now passes without a problem, had to fix both the test and the function being tested though)


=================== /main/stdtime ====== 
"test execute all" fails, caused by the /main/stdtime/ test. 
START  /main/stdtime/ - timezone_watch 
[test_time.c:enum ast_test_result_state test_timezone_watch(struct ast_test_info *, enum ast_test_command, struct ast_test *):84]: Executing deletion test...
j62747*CLI> 
CLI becomes unresponsive / no further command completion for example.
Guess this will need a little further investigation. Maybe the source changes made to main/stdtime/ where not completely correct.

Seems to be caused by inotify_daemon, at least there is where the segfault happens. WIP
<?xml version="1.0" encoding="UTF-8"?>
<testsuite errors="0" time="181.742" tests="444" n
<properties>
<property name="version" value="SV

Diff revision 9 (Latest)

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

  1. /branches/13/tests/test_acl.c: Loading...
  2. /branches/13/tests/test_sched.c: Loading...
  3. /branches/13/tests/test_stringfields.c: Loading...
  4. /branches/13/tests/test_strings.c: Loading...
/branches/13/tests/test_acl.c
Revision 433444 New Change
1
/*
1
/*
2
 * Asterisk -- An open source telephony toolkit.
2
 * Asterisk -- An open source telephony toolkit.
3
 *
3
 *
4
 * Copyright (C) 2010, Digium, Inc.
4
 * Copyright (C) 2010, Digium, Inc.
5
 *
5
 *
6
 * Mark Michelson <mmichelson@digium.com>
6
 * Mark Michelson <mmichelson@digium.com>
7
 *
7
 *
8
 * See http://www.asterisk.org for more information about
8
 * See http://www.asterisk.org for more information about
9
 * the Asterisk project. Please do not directly contact
9
 * the Asterisk project. Please do not directly contact
10
 * any of the maintainers of this project for assistance;
10
 * any of the maintainers of this project for assistance;
11
 * the project provides a web site, mailing lists and IRC
11
 * the project provides a web site, mailing lists and IRC
12
 * channels for your use.
12
 * channels for your use.
13
 *
13
 *
14
 * This program is free software, distributed under the terms of
14
 * This program is free software, distributed under the terms of
15
 * the GNU General Public License Version 2. See the LICENSE file
15
 * the GNU General Public License Version 2. See the LICENSE file
16
 * at the top of the source tree.
16
 * at the top of the source tree.
17
 */
17
 */
18

    
   
18

   
19
/*!
19
/*!
20
 * \file
20
 * \file
21
 * \brief ACL unit tests
21
 * \brief ACL unit tests
22
 *
22
 *
23
 * \author Mark Michelson <mmichelson@digium.com>
23
 * \author Mark Michelson <mmichelson@digium.com>
24
 *
24
 *
25
 */
25
 */
26

    
   
26

   
27
/*** MODULEINFO
27
/*** MODULEINFO
28
	<depend>TEST_FRAMEWORK</depend>
28
	<depend>TEST_FRAMEWORK</depend>
29
	<support_level>core</support_level>
29
	<support_level>core</support_level>
30
 ***/
30
 ***/
31

    
   
31

   
32
#include "asterisk.h"
32
#include "asterisk.h"
33

    
   
33

   
34
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
34
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
35

    
   
35

   
36
#include "asterisk/test.h"
36
#include "asterisk/test.h"
37
#include "asterisk/acl.h"
37
#include "asterisk/acl.h"
38
#include "asterisk/module.h"
38
#include "asterisk/module.h"
39
#include "asterisk/netsock2.h"
39
#include "asterisk/netsock2.h"
40
#include "asterisk/config.h"
40
#include "asterisk/config.h"
41

    
   
41

   
42
AST_TEST_DEFINE(invalid_acl)
42
AST_TEST_DEFINE(invalid_acl)
43
{
43
{
44
	const char * invalid_acls[] = {
44
	const char * invalid_acls[] = {
45
		/* Negative netmask */
45
		/* Negative netmask */
46
		"1.3.3.7/-1",
46
		"1.3.3.7/-1",
47
		/* Netmask too large */
47
		/* Netmask too large */
48
		"1.3.3.7/33",
48
		"1.3.3.7/33",
49
		/* Netmask waaaay too large */
49
		/* Netmask waaaay too large */
50
		"1.3.3.7/92342348927389492307420",
50
		"1.3.3.7/92342348927389492307420",
51
		/* Netmask non-numeric */
51
		/* Netmask non-numeric */
52
		"1.3.3.7/California",
52
		"1.3.3.7/California",
53
		/* Too many octets in Netmask */
53
		/* Too many octets in Netmask */
54
		"1.3.3.7/255.255.255.255.255",
54
		"1.3.3.7/255.255.255.255.255",
55
		/* Octets in IP address exceed 255 */
55
		/* Octets in IP address exceed 255 */
56
		"57.60.278.900/31",
56
		"57.60.278.900/31",
57
		/* Octets in IP address exceed 255 and are negative */
57
		/* Octets in IP address exceed 255 and are negative */
58
		"400.32.201029.-6/24",
58
		"400.32.201029.-6/24",
59
		/* Invalidly formatted IP address */
59
		/* Invalidly formatted IP address */
60
		"EGGSOFDEATH/4000",
60
		"EGGSOFDEATH/4000",
61
		/* Too many octets in IP address */
61
		/* Too many octets in IP address */
62
		"33.4.7.8.3/300030",
62
		"33.4.7.8.3/300030",
63
		/* Too many octets in Netmask */
63
		/* Too many octets in Netmask */
64
		"1.2.3.4/6.7.8.9.0",
64
		"1.2.3.4/6.7.8.9.0",
65
		/* Too many octets in IP address */
65
		/* Too many octets in IP address */
66
		"3.1.4.1.5.9/3",
66
		"3.1.4.1.5.9/3",
67
		/* IPv6 address has multiple double colons */
67
		/* IPv6 address has multiple double colons */
68
		"ff::ff::ff/3",
68
		"ff::ff::ff/3",
69
		/* IPv6 address is too long */
69
		/* IPv6 address is too long */
70
		"1234:5678:90ab:cdef:1234:5678:90ab:cdef:1234/56",
70
		"1234:5678:90ab:cdef:1234:5678:90ab:cdef:1234/56",
71
		/* IPv6 netmask is too large */
71
		/* IPv6 netmask is too large */
72
		"::ffff/129",
72
		"::ffff/129",
73
		/* IPv4-mapped IPv6 address has too few octets */
73
		/* IPv4-mapped IPv6 address has too few octets */
74
		"::ffff:255.255.255/128",
74
		"::ffff:255.255.255/128",
75
		/* Leading and trailing colons for IPv6 address */
75
		/* Leading and trailing colons for IPv6 address */
76
		":1234:/15",
76
		":1234:/15",
77
		/* IPv6 address and IPv4 netmask */
77
		/* IPv6 address and IPv4 netmask */
78
		"fe80::1234/255.255.255.0",
78
		"fe80::1234/255.255.255.0",
79
	};
79
	};
80

    
   
80

   
81
	enum ast_test_result_state res = AST_TEST_PASS;
81
	enum ast_test_result_state res = AST_TEST_PASS;
82
	struct ast_ha *ha = NULL;
82
	struct ast_ha *ha = NULL;
83
	int i;
83
	int i;
84

    
   
84

   
85
	switch (cmd) {
85
	switch (cmd) {
86
	case TEST_INIT:
86
	case TEST_INIT:
87
		info->name = "invalid_acl";
87
		info->name = "invalid_acl";
88
		info->category = "/main/acl/";
88
		info->category = "/main/acl/";
89
		info->summary = "Invalid ACL unit test";
89
		info->summary = "Invalid ACL unit test";
90
		info->description =
90
		info->description =
91
			"Ensures that garbage ACL values are not accepted";
91
			"Ensures that garbage ACL values are not accepted";
92
		return AST_TEST_NOT_RUN;
92
		return AST_TEST_NOT_RUN;
93
	case TEST_EXECUTE:
93
	case TEST_EXECUTE:
94
		break;
94
		break;
95
	}
95
	}
96

    
   
96

   
97
	for (i = 0; i < ARRAY_LEN(invalid_acls); ++i) {
97
	for (i = 0; i < ARRAY_LEN(invalid_acls); ++i) {
98
		int err = 0;
98
		int err = 0;
99
		ha = ast_append_ha("permit", invalid_acls[i], ha, &err);
99
		ha = ast_append_ha("permit", invalid_acls[i], ha, &err);
100
		if (ha || !err) {
100
		if (ha || !err) {
101
			ast_test_status_update(test, "ACL %s accepted even though it is total garbage.\n",
101
			ast_test_status_update(test, "ACL %s accepted even though it is total garbage.\n",
102
					invalid_acls[i]);
102
					invalid_acls[i]);
103
			if (ha) {
103
			if (ha) {
104
				ast_free_ha(ha);
104
				ast_free_ha(ha);
105
			}
105
			}
106
			res = AST_TEST_FAIL;
106
			res = AST_TEST_FAIL;
107
		}
107
		}
108
	}
108
	}
109

    
   
109

   
110
	return res;
110
	return res;
111
}
111
}
112

    
   
112

   
113
struct acl {
113
struct acl {
114
	const char *host;
114
	const char *host;
115
	const char *access;
115
	const char *access;
116
};
116
};
117

    
   
117

   
118
/* These constants are defined for the sole purpose of being shorter
118
/* These constants are defined for the sole purpose of being shorter
119
 * than their real names. It makes lines in this test quite a bit shorter
119
 * than their real names. It makes lines in this test quite a bit shorter
120
 */
120
 */
121

    
   
121

   
122
#define TACL_A AST_SENSE_ALLOW
122
#define TACL_A AST_SENSE_ALLOW
123
#define TACL_D AST_SENSE_DENY
123
#define TACL_D AST_SENSE_DENY
124

    
   
124

   

    
   
125
static int build_ha(const struct acl *acl, size_t len, struct ast_ha **ha, const char *acl_name, int *err, struct ast_test *test, enum ast_test_result_state *res) 

    
   
126
{

    
   
127
	size_t i;

    
   
128

   

    
   
129
	for (i = 0; i < len; ++i) {

    
   
130
		if (!(*ha = ast_append_ha(acl[i].access, acl[i].host, *ha, err))) {
Moved from 220

    
   
131
			ast_test_status_update(test, "Failed to add rule %s with access %s to %s\n",
Moved from 221

    
   
132
					       acl[i].host, acl[i].access, acl_name);

    
   
133
			*res = AST_TEST_FAIL;
Moved from 223

    
   
134
			return -1;
Moved from 224

    
   
135
		}
Moved from 225

    
   
136
	}

    
   
137

   
Moved from 227

    
   
138
	return 0;
Moved from 228

    
   
139
}

    
   
140

   
125
AST_TEST_DEFINE(acl)
141
AST_TEST_DEFINE(acl)
126
{
142
{
127
	struct acl permitallv4 = { "0.0.0.0/0", "permit" };
143
	struct acl permitallv4 = { "0.0.0.0/0", "permit" };
128
	struct acl denyallv4 = { "0.0.0.0/0", "deny" };
144
	struct acl denyallv4 = { "0.0.0.0/0", "deny" };
129
	struct acl permitallv6 = { "::/0", "permit" };
145
	struct acl permitallv6 = { "::/0", "permit" };
130
	struct acl denyallv6 = { "::/0", "deny" };
146
	struct acl denyallv6 = { "::/0", "deny" };
131

    
   
147

   
132
	struct acl acl1[] = {
148
	struct acl acl1[] = {
133
		{ "0.0.0.0/0.0.0.0", "deny" },
149
		{ "0.0.0.0/0.0.0.0", "deny" },
134
		{ "10.0.0.0/255.0.0.0", "permit" },
150
		{ "10.0.0.0/255.0.0.0", "permit" },
135
		{ "192.168.0.0/255.255.255.0", "permit" },
151
		{ "192.168.0.0/255.255.255.0", "permit" },
136
	};
152
	};
137

    
   
153

   
138
	struct acl acl2[] = {
154
	struct acl acl2[] = {
139
		{ "10.0.0.0/8", "deny" },
155
		{ "10.0.0.0/8", "deny" },
140
		{ "10.0.0.0/8", "permit" },
156
		{ "10.0.0.0/8", "permit" },
141
		{ "10.0.0.0/16", "deny" },
157
		{ "10.0.0.0/16", "deny" },
142
		{ "10.0.0.0/24", "permit" },
158
		{ "10.0.0.0/24", "permit" },
143
	};
159
	};
144

    
   
160

   
145
	struct acl acl3[] = {
161
	struct acl acl3[] = {
146
		{ "::/0", "deny" },
162
		{ "::/0", "deny" },
147
		{ "fe80::/64", "permit" },
163
		{ "fe80::/64", "permit" },
148
	};
164
	};
149

    
   
165

   
150
	struct acl acl4[] = {
166
	struct acl acl4[] = {
151
		{ "::/0", "deny" },
167
		{ "::/0", "deny" },
152
		{ "fe80::/64", "permit" },
168
		{ "fe80::/64", "permit" },
153
		{ "fe80::ffff:0:0:0/80", "deny" },
169
		{ "fe80::ffff:0:0:0/80", "deny" },
154
		{ "fe80::ffff:0:ffff:0/112", "permit" },
170
		{ "fe80::ffff:0:ffff:0/112", "permit" },
155
	};
171
	};
156

    
   
172

   
157
	struct acl acl5[] = {
173
	struct acl acl5[] = {
158
		{ "0.0.0.0/0.0.0.0", "deny" },
174
		{ "0.0.0.0/0.0.0.0", "deny" },
159
		{ "10.0.0.0/255.0.0.0,192.168.0.0/255.255.255.0", "permit" },
175
		{ "10.0.0.0/255.0.0.0,192.168.0.0/255.255.255.0", "permit" },
160
	};
176
	};
161

    
   
177

   
162
	struct acl acl6[] = {
178
	struct acl acl6[] = {
163
		{ "10.0.0.0/8", "deny" },
179
		{ "10.0.0.0/8", "deny" },
164
		{ "10.0.0.0/8", "permit" },
180
		{ "10.0.0.0/8", "permit" },
165
		{ "10.0.0.0/16,!10.0.0.0/24", "deny" },
181
		{ "10.0.0.0/16,!10.0.0.0/24", "deny" },
166
	};
182
	};
167

    
   
183

   
168
	struct acl acl7[] = {
184
	struct acl acl7[] = {
169
		{ "::/0,!fe80::/64", "deny" },
185
		{ "::/0,!fe80::/64", "deny" },
170
		{ "fe80::ffff:0:0:0/80", "deny" },
186
		{ "fe80::ffff:0:0:0/80", "deny" },
171
		{ "fe80::ffff:0:ffff:0/112", "permit" },
187
		{ "fe80::ffff:0:ffff:0/112", "permit" },
172
	};
188
	};
173

    
   
189

   
174
	struct {
190
	struct {
175
		const char *test_address;
191
		const char *test_address;
176
		int v4_permitall_result;
192
		int v4_permitall_result;
177
		int v4_denyall_result;
193
		int v4_denyall_result;
178
		int v6_permitall_result;
194
		int v6_permitall_result;
179
		int v6_denyall_result;
195
		int v6_denyall_result;
180
		int acl1_result;
196
		int acl1_result;
181
		int acl2_result;
197
		int acl2_result;
182
		int acl3_result;
198
		int acl3_result;
183
		int acl4_result;
199
		int acl4_result;
184
		int acl5_result;
200
		int acl5_result;
185
		int acl6_result;
201
		int acl6_result;
186
		int acl7_result;
202
		int acl7_result;
187
	} acl_tests[] = {
203
	} acl_tests[] = {
188
		{ "10.1.1.5",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
204
		{ "10.1.1.5",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
189
		{ "192.168.0.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
205
		{ "192.168.0.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
190
		{ "192.168.1.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
206
		{ "192.168.1.5",               TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
191
		{ "10.0.0.1",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
207
		{ "10.0.0.1",                  TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
192
		{ "10.0.10.10",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A },
208
		{ "10.0.10.10",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A },
193
		{ "172.16.0.1",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
209
		{ "172.16.0.1",                TACL_A, TACL_D, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A },
194
		{ "fe80::1234",                TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
210
		{ "fe80::1234",                TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
195
		{ "fe80::ffff:1213:dead:beef", TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_D },
211
		{ "fe80::ffff:1213:dead:beef", TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_D },
196
		{ "fe80::ffff:0:ffff:ABCD",    TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
212
		{ "fe80::ffff:0:ffff:ABCD",    TACL_A, TACL_A, TACL_A, TACL_D, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A, TACL_A },
197
	};
213
	};
198

    
   
214

   
199
	struct ast_ha *permit_hav4 = NULL;
215
	struct ast_ha *permit_hav4 = NULL;
200
	struct ast_ha *deny_hav4 = NULL;
216
	struct ast_ha *deny_hav4 = NULL;
201
	struct ast_ha *permit_hav6 = NULL;
217
	struct ast_ha *permit_hav6 = NULL;
202
	struct ast_ha *deny_hav6 = NULL;
218
	struct ast_ha *deny_hav6 = NULL;
203
	struct ast_ha *ha1 = NULL;
219
	struct ast_ha *ha1 = NULL;
204
	struct ast_ha *ha2 = NULL;
220
	struct ast_ha *ha2 = NULL;
205
	struct ast_ha *ha3 = NULL;
221
	struct ast_ha *ha3 = NULL;
206
	struct ast_ha *ha4 = NULL;
222
	struct ast_ha *ha4 = NULL;
207
	struct ast_ha *ha5 = NULL;
223
	struct ast_ha *ha5 = NULL;
208
	struct ast_ha *ha6 = NULL;
224
	struct ast_ha *ha6 = NULL;
209
	struct ast_ha *ha7 = NULL;
225
	struct ast_ha *ha7 = NULL;
210
	enum ast_test_result_state res = AST_TEST_PASS;
226
	enum ast_test_result_state res = AST_TEST_PASS;
211
	int err = 0;
227
	int err = 0;
212
	int i;
228
	int i;
213

    
   
229

   
214
	auto int build_ha(const struct acl *acl, size_t len, struct ast_ha **ha, const char *acl_name);

   
215
	auto int build_ha(const struct acl *acl, size_t len, struct ast_ha **ha, const char *acl_name) {

   
216
		size_t i;

   
217

    
   

   
218
		for (i = 0; i < len; ++i) {

   
219
			if (!(*ha = ast_append_ha(acl[i].access, acl[i].host, *ha, &err))) {

   
220
				ast_test_status_update(test, "Failed to add rule %s with access %s to %s\n",
Moved to 131

   
221
						       acl[i].host, acl[i].access, acl_name);
Moved to 132

   
222
				res = AST_TEST_FAIL;

   
223
				return -1;
Moved to 134

   
224
			}
Moved to 135

   
225
		}
Moved to 136

   
226

    
   

   
227
		return 0;
Moved to 138

   
228
	}
Moved to 139

   
229

    
   
230

   
230
	switch (cmd) {
231
	switch (cmd) {
231
	case TEST_INIT:
232
	case TEST_INIT:
232
		info->name = "acl";
233
		info->name = "acl";
233
		info->category = "/main/acl/";
234
		info->category = "/main/acl/";
234
		info->summary = "ACL unit test";
235
		info->summary = "ACL unit test";
235
		info->description =
236
		info->description =
236
			"Tests that hosts are properly permitted or denied";
237
			"Tests that hosts are properly permitted or denied";
237
		return AST_TEST_NOT_RUN;
238
		return AST_TEST_NOT_RUN;
238
	case TEST_EXECUTE:
239
	case TEST_EXECUTE:
239
		break;
240
		break;
240
	}
241
	}
241

    
   
242

   
242
	if (!(permit_hav4 = ast_append_ha(permitallv4.access, permitallv4.host, permit_hav4, &err))) {
243
	if (!(permit_hav4 = ast_append_ha(permitallv4.access, permitallv4.host, permit_hav4, &err))) {
243
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
244
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
244
		res = AST_TEST_FAIL;
245
		res = AST_TEST_FAIL;
245
		goto acl_cleanup;
246
		goto acl_cleanup;
246
	}
247
	}
247

    
   
248

   
248
	if (!(deny_hav4 = ast_append_ha(denyallv4.access, denyallv4.host, deny_hav4, &err))) {
249
	if (!(deny_hav4 = ast_append_ha(denyallv4.access, denyallv4.host, deny_hav4, &err))) {
249
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
250
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
250
		res = AST_TEST_FAIL;
251
		res = AST_TEST_FAIL;
251
		goto acl_cleanup;
252
		goto acl_cleanup;
252
	}
253
	}
253

    
   
254

   
254
	if (!(permit_hav6 = ast_append_ha(permitallv6.access, permitallv6.host, permit_hav6, &err))) {
255
	if (!(permit_hav6 = ast_append_ha(permitallv6.access, permitallv6.host, permit_hav6, &err))) {
255
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
256
		ast_test_status_update(test, "Failed to create permit_all ACL\n");
256
		res = AST_TEST_FAIL;
257
		res = AST_TEST_FAIL;
257
		goto acl_cleanup;
258
		goto acl_cleanup;
258
	}
259
	}
259

    
   
260

   
260
	if (!(deny_hav6 = ast_append_ha(denyallv6.access, denyallv6.host, deny_hav6, &err))) {
261
	if (!(deny_hav6 = ast_append_ha(denyallv6.access, denyallv6.host, deny_hav6, &err))) {
261
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
262
		ast_test_status_update(test, "Failed to create deny_all ACL\n");
262
		res = AST_TEST_FAIL;
263
		res = AST_TEST_FAIL;
263
		goto acl_cleanup;
264
		goto acl_cleanup;
264
	}
265
	}
265

    
   
266

   
266
	if (build_ha(acl1, ARRAY_LEN(acl1), &ha1, "ha1") != 0) {
267
	if (build_ha(acl1, ARRAY_LEN(acl1), &ha1, "ha1", &err, test, &res) != 0) {
267
		goto acl_cleanup;
268
		goto acl_cleanup;
268
	}
269
	}
269

    
   
270

   
270
	if (build_ha(acl2, ARRAY_LEN(acl2), &ha2, "ha2") != 0) {
271
	if (build_ha(acl2, ARRAY_LEN(acl2), &ha2, "ha2", &err, test, &res) != 0) {
271
		goto acl_cleanup;
272
		goto acl_cleanup;
272
	}
273
	}
273

    
   
274

   
274
	if (build_ha(acl3, ARRAY_LEN(acl3), &ha3, "ha3") != 0) {
275
	if (build_ha(acl3, ARRAY_LEN(acl3), &ha3, "ha3", &err, test, &res) != 0) {
275
		goto acl_cleanup;
276
		goto acl_cleanup;
276
	}
277
	}
277

    
   
278

   
278
	if (build_ha(acl4, ARRAY_LEN(acl4), &ha4, "ha4") != 0) {
279
	if (build_ha(acl4, ARRAY_LEN(acl4), &ha4, "ha4", &err, test, &res) != 0) {
279
		goto acl_cleanup;
280
		goto acl_cleanup;
280
	}
281
	}
281

    
   
282

   
282
	if (build_ha(acl5, ARRAY_LEN(acl5), &ha5, "ha5") != 0) {
283
	if (build_ha(acl5, ARRAY_LEN(acl5), &ha5, "ha5", &err, test, &res) != 0) {
283
		goto acl_cleanup;
284
		goto acl_cleanup;
284
	}
285
	}
285

    
   
286

   
286
	if (build_ha(acl6, ARRAY_LEN(acl6), &ha6, "ha6") != 0) {
287
	if (build_ha(acl6, ARRAY_LEN(acl6), &ha6, "ha6", &err, test, &res) != 0) {
287
		goto acl_cleanup;
288
		goto acl_cleanup;
288
	}
289
	}
289

    
   
290

   
290
	if (build_ha(acl7, ARRAY_LEN(acl7), &ha7, "ha7") != 0) {
291
	if (build_ha(acl7, ARRAY_LEN(acl7), &ha7, "ha7", &err, test, &res) != 0) {
291
		goto acl_cleanup;
292
		goto acl_cleanup;
292
	}
293
	}
293

    
   
294

   
294
	for (i = 0; i < ARRAY_LEN(acl_tests); ++i) {
295
	for (i = 0; i < ARRAY_LEN(acl_tests); ++i) {
295
		struct ast_sockaddr addr;
296
		struct ast_sockaddr addr;
296
		int permit_resv4;
297
		int permit_resv4;
297
		int permit_resv6;
298
		int permit_resv6;
298
		int deny_resv4;
299
		int deny_resv4;
299
		int deny_resv6;
300
		int deny_resv6;
300
		int acl1_res;
301
		int acl1_res;
301
		int acl2_res;
302
		int acl2_res;
302
		int acl3_res;
303
		int acl3_res;
303
		int acl4_res;
304
		int acl4_res;
304
		int acl5_res;
305
		int acl5_res;
305
		int acl6_res;
306
		int acl6_res;
306
		int acl7_res;
307
		int acl7_res;
307

    
   
308

   
308
		ast_sockaddr_parse(&addr, acl_tests[i].test_address, PARSE_PORT_FORBID);
309
		ast_sockaddr_parse(&addr, acl_tests[i].test_address, PARSE_PORT_FORBID);
309

    
   
310

   
310
		permit_resv4 = ast_apply_ha(permit_hav4, &addr);
311
		permit_resv4 = ast_apply_ha(permit_hav4, &addr);
311
		deny_resv4 = ast_apply_ha(deny_hav4, &addr);
312
		deny_resv4 = ast_apply_ha(deny_hav4, &addr);
312
		permit_resv6 = ast_apply_ha(permit_hav6, &addr);
313
		permit_resv6 = ast_apply_ha(permit_hav6, &addr);
313
		deny_resv6 = ast_apply_ha(deny_hav6, &addr);
314
		deny_resv6 = ast_apply_ha(deny_hav6, &addr);
314
		acl1_res = ast_apply_ha(ha1, &addr);
315
		acl1_res = ast_apply_ha(ha1, &addr);
315
		acl2_res = ast_apply_ha(ha2, &addr);
316
		acl2_res = ast_apply_ha(ha2, &addr);
316
		acl3_res = ast_apply_ha(ha3, &addr);
317
		acl3_res = ast_apply_ha(ha3, &addr);
317
		acl4_res = ast_apply_ha(ha4, &addr);
318
		acl4_res = ast_apply_ha(ha4, &addr);
318
		acl5_res = ast_apply_ha(ha5, &addr);
319
		acl5_res = ast_apply_ha(ha5, &addr);
319
		acl6_res = ast_apply_ha(ha6, &addr);
320
		acl6_res = ast_apply_ha(ha6, &addr);
320
		acl7_res = ast_apply_ha(ha7, &addr);
321
		acl7_res = ast_apply_ha(ha7, &addr);
321

    
   
322

   
322
		if (permit_resv4 != acl_tests[i].v4_permitall_result) {
323
		if (permit_resv4 != acl_tests[i].v4_permitall_result) {
323
			ast_test_status_update(test, "Access not as expected to %s on permitallv4. Expected %d but "
324
			ast_test_status_update(test, "Access not as expected to %s on permitallv4. Expected %d but "
324
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_permitall_result, permit_resv4);
325
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_permitall_result, permit_resv4);
325
			res = AST_TEST_FAIL;
326
			res = AST_TEST_FAIL;
326
			goto acl_cleanup;
327
			goto acl_cleanup;
327
		}
328
		}
328

    
   
329

   
329
		if (deny_resv4 != acl_tests[i].v4_denyall_result) {
330
		if (deny_resv4 != acl_tests[i].v4_denyall_result) {
330
			ast_test_status_update(test, "Access not as expected to %s on denyallv4. Expected %d but "
331
			ast_test_status_update(test, "Access not as expected to %s on denyallv4. Expected %d but "
331
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_denyall_result, deny_resv4);
332
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v4_denyall_result, deny_resv4);
332
			res = AST_TEST_FAIL;
333
			res = AST_TEST_FAIL;
333
			goto acl_cleanup;
334
			goto acl_cleanup;
334
		}
335
		}
335

    
   
336

   
336
		if (permit_resv6 != acl_tests[i].v6_permitall_result) {
337
		if (permit_resv6 != acl_tests[i].v6_permitall_result) {
337
			ast_test_status_update(test, "Access not as expected to %s on permitallv6. Expected %d but "
338
			ast_test_status_update(test, "Access not as expected to %s on permitallv6. Expected %d but "
338
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_permitall_result, permit_resv6);
339
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_permitall_result, permit_resv6);
339
			res = AST_TEST_FAIL;
340
			res = AST_TEST_FAIL;
340
			goto acl_cleanup;
341
			goto acl_cleanup;
341
		}
342
		}
342

    
   
343

   
343
		if (deny_resv6 != acl_tests[i].v6_denyall_result) {
344
		if (deny_resv6 != acl_tests[i].v6_denyall_result) {
344
			ast_test_status_update(test, "Access not as expected to %s on denyallv6. Expected %d but "
345
			ast_test_status_update(test, "Access not as expected to %s on denyallv6. Expected %d but "
345
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_denyall_result, deny_resv6);
346
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].v6_denyall_result, deny_resv6);
346
			res = AST_TEST_FAIL;
347
			res = AST_TEST_FAIL;
347
			goto acl_cleanup;
348
			goto acl_cleanup;
348
		}
349
		}
349

    
   
350

   
350
		if (acl1_res != acl_tests[i].acl1_result) {
351
		if (acl1_res != acl_tests[i].acl1_result) {
351
			ast_test_status_update(test, "Access not as expected to %s on acl1. Expected %d but "
352
			ast_test_status_update(test, "Access not as expected to %s on acl1. Expected %d but "
352
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl1_result, acl1_res);
353
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl1_result, acl1_res);
353
			res = AST_TEST_FAIL;
354
			res = AST_TEST_FAIL;
354
			goto acl_cleanup;
355
			goto acl_cleanup;
355
		}
356
		}
356

    
   
357

   
357
		if (acl2_res != acl_tests[i].acl2_result) {
358
		if (acl2_res != acl_tests[i].acl2_result) {
358
			ast_test_status_update(test, "Access not as expected to %s on acl2. Expected %d but "
359
			ast_test_status_update(test, "Access not as expected to %s on acl2. Expected %d but "
359
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl2_result, acl2_res);
360
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl2_result, acl2_res);
360
			res = AST_TEST_FAIL;
361
			res = AST_TEST_FAIL;
361
			goto acl_cleanup;
362
			goto acl_cleanup;
362
		}
363
		}
363

    
   
364

   
364
		if (acl3_res != acl_tests[i].acl3_result) {
365
		if (acl3_res != acl_tests[i].acl3_result) {
365
			ast_test_status_update(test, "Access not as expected to %s on acl3. Expected %d but "
366
			ast_test_status_update(test, "Access not as expected to %s on acl3. Expected %d but "
366
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl3_result, acl3_res);
367
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl3_result, acl3_res);
367
			res = AST_TEST_FAIL;
368
			res = AST_TEST_FAIL;
368
			goto acl_cleanup;
369
			goto acl_cleanup;
369
		}
370
		}
370

    
   
371

   
371
		if (acl4_res != acl_tests[i].acl4_result) {
372
		if (acl4_res != acl_tests[i].acl4_result) {
372
			ast_test_status_update(test, "Access not as expected to %s on acl4. Expected %d but "
373
			ast_test_status_update(test, "Access not as expected to %s on acl4. Expected %d but "
373
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl4_result, acl4_res);
374
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl4_result, acl4_res);
374
			res = AST_TEST_FAIL;
375
			res = AST_TEST_FAIL;
375
			goto acl_cleanup;
376
			goto acl_cleanup;
376
		}
377
		}
377

    
   
378

   
378
		if (acl5_res != acl_tests[i].acl5_result) {
379
		if (acl5_res != acl_tests[i].acl5_result) {
379
			ast_test_status_update(test, "Access not as expected to %s on acl5. Expected %d but "
380
			ast_test_status_update(test, "Access not as expected to %s on acl5. Expected %d but "
380
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl5_result, acl5_res);
381
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl5_result, acl5_res);
381
			res = AST_TEST_FAIL;
382
			res = AST_TEST_FAIL;
382
			goto acl_cleanup;
383
			goto acl_cleanup;
383
		}
384
		}
384

    
   
385

   
385
		if (acl6_res != acl_tests[i].acl6_result) {
386
		if (acl6_res != acl_tests[i].acl6_result) {
386
			ast_test_status_update(test, "Access not as expected to %s on acl6. Expected %d but "
387
			ast_test_status_update(test, "Access not as expected to %s on acl6. Expected %d but "
387
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl6_result, acl6_res);
388
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl6_result, acl6_res);
388
			res = AST_TEST_FAIL;
389
			res = AST_TEST_FAIL;
389
			goto acl_cleanup;
390
			goto acl_cleanup;
390
		}
391
		}
391

    
   
392

   
392
		if (acl7_res != acl_tests[i].acl7_result) {
393
		if (acl7_res != acl_tests[i].acl7_result) {
393
			ast_test_status_update(test, "Access not as expected to %s on acl7. Expected %d but "
394
			ast_test_status_update(test, "Access not as expected to %s on acl7. Expected %d but "
394
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl7_result, acl7_res);
395
					"got %d instead\n", acl_tests[i].test_address, acl_tests[i].acl7_result, acl7_res);
395
			res = AST_TEST_FAIL;
396
			res = AST_TEST_FAIL;
396
			goto acl_cleanup;
397
			goto acl_cleanup;
397
		}
398
		}
398
	}
399
	}
399

    
   
400

   
400
acl_cleanup:
401
acl_cleanup:
401
	if (permit_hav4) {
402
	if (permit_hav4) {
402
		ast_free_ha(permit_hav4);
403
		ast_free_ha(permit_hav4);
403
	}
404
	}
404
	if (deny_hav4) {
405
	if (deny_hav4) {
405
		ast_free_ha(deny_hav4);
406
		ast_free_ha(deny_hav4);
406
	}
407
	}
407
	if (permit_hav6) {
408
	if (permit_hav6) {
408
		ast_free_ha(permit_hav6);
409
		ast_free_ha(permit_hav6);
409
	}
410
	}
410
	if (deny_hav6) {
411
	if (deny_hav6) {
411
		ast_free_ha(deny_hav6);
412
		ast_free_ha(deny_hav6);
412
	}
413
	}
413
	if (ha1) {
414
	if (ha1) {
414
		ast_free_ha(ha1);
415
		ast_free_ha(ha1);
415
	}
416
	}
416
	if (ha2) {
417
	if (ha2) {
417
		ast_free_ha(ha2);
418
		ast_free_ha(ha2);
418
	}
419
	}
419
	if (ha3) {
420
	if (ha3) {
420
		ast_free_ha(ha3);
421
		ast_free_ha(ha3);
421
	}
422
	}
422
	if (ha4) {
423
	if (ha4) {
423
		ast_free_ha(ha4);
424
		ast_free_ha(ha4);
424
	}
425
	}
425
	if (ha5) {
426
	if (ha5) {
426
		ast_free_ha(ha5);
427
		ast_free_ha(ha5);
427
	}
428
	}
428
	if (ha6) {
429
	if (ha6) {
429
		ast_free_ha(ha6);
430
		ast_free_ha(ha6);
430
	}
431
	}
431
	if (ha7) {
432
	if (ha7) {
432
		ast_free_ha(ha7);
433
		ast_free_ha(ha7);
433
	}
434
	}
434
	return res;
435
	return res;
435
}
436
}
436

    
   
437

   
437
static int unload_module(void)
438
static int unload_module(void)
438
{
439
{
439
	AST_TEST_UNREGISTER(invalid_acl);
440
	AST_TEST_UNREGISTER(invalid_acl);
440
	AST_TEST_UNREGISTER(acl);
441
	AST_TEST_UNREGISTER(acl);
441
	return 0;
442
	return 0;
442
}
443
}
443

    
   
444

   
444
static int load_module(void)
445
static int load_module(void)
445
{
446
{
446
	AST_TEST_REGISTER(invalid_acl);
447
	AST_TEST_REGISTER(invalid_acl);
447
	AST_TEST_REGISTER(acl);
448
	AST_TEST_REGISTER(acl);
448
	return AST_MODULE_LOAD_SUCCESS;
449
	return AST_MODULE_LOAD_SUCCESS;
449
}
450
}
450

    
   
451

   
451
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ACL test module");
452
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ACL test module");
/branches/13/tests/test_sched.c
Revision 433444 New Change
 
/branches/13/tests/test_stringfields.c
Revision 433444 New Change
 
/branches/13/tests/test_strings.c
Revision 433444 New Change
 
  1. /branches/13/tests/test_acl.c: Loading...
  2. /branches/13/tests/test_sched.c: Loading...
  3. /branches/13/tests/test_stringfields.c: Loading...
  4. /branches/13/tests/test_strings.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.