[go: up one dir, main page]

Menu

[ebf9b6]: / tests / src / case3002.py  Maximize  Restore  History

Download this file

402 lines (362 with data), 17.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#
# Copyright (c) 2013-2016, Christian Ferrari <tiian@users.sourceforge.net>
# All rights reserved.
#
# This file is part of FLoM.
#
# FLoM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# FLoM 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 FLoM. If not, see <http://www.gnu.org/licenses/>.
#
import sys
sys.path.append('../../../src/python')
from flom import *
#
# Happy path usage
#
def happy_path() :
#
# Non default values used for tests
#
nd_socket_name = "/tmp/flom_socket_name"
nd_trace_filename = "/tmp/flom.trc"
nd_resource_name = "red.green.blue"
nd_unicast_address = "127.0.0.1"
nd_multicast_address = "224.0.0.1"
nd_tls_certificate = "CA1/peer1_CA1_cert.pem"
nd_tls_private_key = "CA1/peer1_CA1_key.pem"
nd_tls_ca_certificate = "CA1/cacert.pem"
# handle allocation
my_handle = flom_handle_t()
ret_cod = FLOM_RC_OK
# handle initialization
ret_cod = flom_handle_init(my_handle)
if FLOM_RC_OK != ret_cod:
sys.stderr.write("flom_handle_init() returned " +
str(ret_cod) + " '" + flom_strerror(ret_cod) + "'\n")
sys.exit(1)
# get current AF_UNIX/PF_LOCAL socket_name
sys.stdout.write("flom_handle_get_socket_name() = '" +
flom_handle_get_socket_name(my_handle) + "'\n")
# set a new AF_UNIX/PF_LOCAL socket_name
ret_cod = flom_handle_set_socket_name(my_handle, nd_socket_name)
if FLOM_RC_OK != ret_cod:
sys.stderr.write("flom_handle_set_socket_name() returned " +
ret_cod + ", '" + flom_strerror(ret_cod) + "'\n")
sys.exit(1)
# get new AF_UNIX/PF_LOCAL socket_name
sys.stdout.write("flom_handle_get_socket_name() = '" +
flom_handle_get_socket_name(my_handle) + "'\n")
# check socket name
if nd_socket_name != flom_handle_get_socket_name(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_socket_name\n")
sys.exit(1)
# we don't get current trace filename because it can be altered by a
# global config file
# set a new trace filename
flom_handle_set_trace_filename(my_handle, nd_trace_filename)
# get new trace filename
sys.stdout.write("flom_handle_get_trace_filename() = '" +
flom_handle_get_trace_filename(my_handle) + "'\n")
# check trace filename
if nd_trace_filename != flom_handle_get_trace_filename(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_trace_filename\n")
sys.exit(1)
# get current resource name
sys.stdout.write("flom_handle_get_resource_name() = '" +
flom_handle_get_resource_name(my_handle) + "'\n")
# set a new resource name
ret_cod = flom_handle_set_resource_name(my_handle, nd_resource_name)
if FLOM_RC_OK != ret_cod:
sys.stderr.write("flom_handle_set_resource_name() returned " +
str(ret_cod) + ", '" + flom_strerror(ret_cod) +
"'\n")
sys.exit(1)
# get new resource name
sys.stdout.write("flom_handle_get_resource_name() = '" +
flom_handle_get_resource_name(my_handle) + "'\n")
# get current value for resource create property
sys.stdout.write("flom_handle_get_resource_create() = " +
str(flom_handle_get_resource_create(my_handle)) + "\n")
# set a new value for resource create property
flom_handle_set_resource_create(my_handle, FALSE)
# get new value for resource create property
sys.stdout.write("flom_handle_get_resource_create() = " +
str(flom_handle_get_resource_create(my_handle)) + "\n")
# check resource create 1/2
if flom_handle_get_resource_create(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_resource_create\n")
sys.exit(1)
# set a new value for resource create property
flom_handle_set_resource_create(my_handle, TRUE)
# get new value for resource create property
sys.stdout.write("flom_handle_get_resource_create() = " +
str(flom_handle_get_resource_create(my_handle)) + "\n")
# check resource create 2/2
if not flom_handle_get_resource_create(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_resource_create\n")
sys.exit(1)
# get current value for resource timeout property
sys.stdout.write("flom_handle_get_resource_timeout() = " +
str(flom_handle_get_resource_timeout(my_handle)) + "\n")
# set a new value for resource timeout property
flom_handle_set_resource_timeout(my_handle, -1)
# get new value for resource timeout property
sys.stdout.write("flom_handle_get_resource_timeout() = " +
str(flom_handle_get_resource_timeout(my_handle)) + "\n")
# check resource timeout
ret_cod = flom_handle_get_resource_timeout(my_handle)
if -1 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_resource_timeout\n")
sys.exit(1)
# get current value for resource quantity property
sys.stdout.write("flom_handle_get_resource_quantity() = " +
str(flom_handle_get_resource_quantity(my_handle)) + "\n")
# set a new value for resource quantity property
flom_handle_set_resource_quantity(my_handle, 3)
# get new value for resource quantity property
sys.stdout.write("flom_handle_get_resource_quantity() = " +
str(flom_handle_get_resource_quantity(my_handle)) + "\n")
# check resource quantity
ret_cod = flom_handle_get_resource_quantity(my_handle)
if 3 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_resource_quantity\n")
sys.exit(1)
# get current value for resource lock mode property
sys.stdout.write("flom_handle_get_lock_mode() = " +
str(flom_handle_get_lock_mode(my_handle)) + "\n")
# set a new value for resource lock mode property
flom_handle_set_lock_mode(my_handle, FLOM_LOCK_MODE_PW)
# get new value for resource lock mode property
sys.stdout.write("flom_handle_get_lock_mode() = " +
str(flom_handle_get_lock_mode(my_handle)) + "\n")
# check resource lock mode
ret_cod = flom_handle_get_lock_mode(my_handle)
if FLOM_LOCK_MODE_PW != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set" +
"/get_lock_mode\n")
sys.exit(1)
# get current value for resource idle lifespan
sys.stdout.write("flom_handle_get_resource_idle_lifespan() = " +
str(flom_handle_get_resource_idle_lifespan(my_handle)) +
"\n")
# set a new value for resource idle lifespan
flom_handle_set_resource_idle_lifespan(my_handle, 10000)
# get new value for resource idle lifespan
sys.stdout.write("flom_handle_get_resource_idle_lifespan() = " +
str(flom_handle_get_resource_idle_lifespan(my_handle)) +
"\n")
# check resource idle lifespan
ret_cod = flom_handle_get_resource_idle_lifespan(my_handle)
if 10000 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_resource_idle_lifespan\n")
sys.exit(1)
# get current unicast address
sys.stdout.write("flom_handle_get_unicast_address() = '" +
str(flom_handle_get_unicast_address(my_handle)) + "'\n")
# set a new unicast_address
flom_handle_set_unicast_address(my_handle, nd_unicast_address)
# get new unicast address
sys.stdout.write("flom_handle_get_unicast_address() = '" +
str(flom_handle_get_unicast_address(my_handle)) + "'\n")
# check unicast address
if nd_unicast_address != flom_handle_get_unicast_address(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_unicast_address\n")
sys.exit(1)
# get current multicast address */
sys.stdout.write("flom_handle_get_multicast_address() = '" +
str(flom_handle_get_multicast_address(my_handle)) + "'\n")
# set a new multicast_address
flom_handle_set_multicast_address(my_handle, nd_multicast_address)
# get new multicast address
sys.stdout.write("flom_handle_get_multicast_address() = '" +
str(flom_handle_get_multicast_address(my_handle)) + "'\n")
# check multicast address
if nd_multicast_address != flom_handle_get_multicast_address(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_multicast_address\n")
sys.exit(1)
# set AF_UNIX/PF_LOCAL socket_name again
ret_cod = flom_handle_set_socket_name(my_handle, nd_socket_name)
if FLOM_RC_OK != ret_cod:
sys.stderr.write("flom_handle_set_socket_name() returned " +
str(ret_cod) + ", '" + flom_strerror(ret_cod) +
"'\n")
sys.exit(1)
# get current value for unicast port
sys.stdout.write("flom_handle_get_unicast_port() = " +
str(flom_handle_get_unicast_port(my_handle)) + "\n")
# set a new value for unicast_port
flom_handle_set_unicast_port(my_handle, 7777)
# get new value for unicast port
sys.stdout.write("flom_handle_get_unicast_port() = " +
str(flom_handle_get_unicast_port(my_handle)) + "\n")
# check unicast port
ret_cod = flom_handle_get_unicast_port(my_handle)
if 7777 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_unicast_port\n")
sys.exit(1)
# get current value for multicast port
sys.stdout.write("flom_handle_get_multicast_port() = " +
str(flom_handle_get_multicast_port(my_handle)) + "\n")
# set a new value for multicast_port
flom_handle_set_multicast_port(my_handle, 8888)
# get new value for multicast port
sys.stdout.write("flom_handle_get_multicast_port() = " +
str(flom_handle_get_multicast_port(my_handle)) + "\n")
# check multicast port
ret_cod = flom_handle_get_multicast_port(my_handle)
if 8888 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_multicast_port\n")
sys.exit(1)
# get current value for discovery attempts property
sys.stdout.write("flom_handle_get_discovery_attempts() = " +
str(flom_handle_get_discovery_attempts(my_handle)) + "\n")
# set a new value for discovery attempts property
flom_handle_set_discovery_attempts(my_handle, 5)
# get new value for discovery attempts
sys.stdout.write("flom_handle_get_discovery_attempts() = " +
str(flom_handle_get_discovery_attempts(my_handle)) + "\n")
# check discovery attempts
ret_cod = flom_handle_get_discovery_attempts(my_handle)
if 5 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_discovery_attempts\n")
sys.exit(1)
# get current value for discovery timeout property
sys.stdout.write("flom_handle_get_discovery_timeout() = " +
str(flom_handle_get_discovery_timeout(my_handle)) + "\n")
# set a new value for discovery timeout property
flom_handle_set_discovery_timeout(my_handle, 750)
# get new value for discovery timeout
sys.stdout.write("flom_handle_get_discovery_timeout() = " +
str(flom_handle_get_discovery_timeout(my_handle)) + "\n")
# check discovery timeout
ret_cod = flom_handle_get_discovery_timeout(my_handle)
if 750 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_discovery_timeout\n")
sys.exit(1)
# get current value for discovery ttl property
sys.stdout.write("flom_handle_get_discovery_ttl() = " +
str(flom_handle_get_discovery_ttl(my_handle)) + "\n")
# set a new value for discovery ttl property
flom_handle_set_discovery_ttl(my_handle, 2)
# get new value for discovery ttl
sys.stdout.write("flom_handle_get_discovery_ttl() = " +
str(flom_handle_get_discovery_ttl(my_handle)) + "\n")
# check discovery ttl
ret_cod = flom_handle_get_discovery_ttl(my_handle)
if 2 != ret_cod:
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_discovery_ttl\n")
sys.exit(1)
# get current value for TLS certificate
sys.stderr.write("flom_handle_get_tls_certificate() = '" +
str(flom_handle_get_tls_certificate(my_handle)) + "'\n");
# set a new TLS certificate
ret_cod = flom_handle_set_tls_certificate(my_handle, nd_tls_certificate)
if FLOM_RC_OK != ret_cod:
sys.stderr.write(
"flom_handle_set_tls_certificate() returned " + str(ret_cod) +
", '" + str(flom_strerror(ret_cod)) + "'\n")
sys.exit(1);
# get new TLS certificate
sys.stderr.write("flom_handle_get_tls_certificate() = '" +
str(flom_handle_get_tls_certificate(my_handle)) + "'\n")
# get current value for TLS private key
sys.stderr.write("flom_handle_get_tls_private_key() = '" +
str(flom_handle_get_tls_private_key(my_handle)) + "'\n")
# set a new TLS private key
ret_cod = flom_handle_set_tls_private_key(my_handle, nd_tls_private_key)
if FLOM_RC_OK != ret_cod:
sys.stderr.write(
"flom_handle_set_tls_private_key() returned " + str(ret_cod) +
", '" + str(flom_strerror(ret_cod)) + "'\n")
sys.exit(1);
# get new TLS private key */
sys.stderr.write("flom_handle_get_tls_private_key() = '" +
str(flom_handle_get_tls_private_key(my_handle)) + "'\n")
# get current value for TLS CA certificate */
sys.stderr.write("flom_handle_get_tls_ca_certificate() = '" +
str(flom_handle_get_tls_ca_certificate(my_handle)) +
"'\n")
# set a new TLS CA certificate
ret_cod = flom_handle_set_tls_ca_certificate(
my_handle, nd_tls_ca_certificate)
if FLOM_RC_OK != ret_cod:
sys.stderr.write(
"flom_handle_set_tls_ca_certificate() returned "+ str(ret_cod) +
", '" + str(flom_strerror(ret_cod)) + "'\n")
sys.exit(1);
# get new TLS CA certificate
sys.stderr.write("flom_handle_get_tls_ca_certificate() = '" +
str(flom_handle_get_tls_ca_certificate(my_handle)) +
"'\n")
# get current value for TLS check peer ID property
sys.stdout.write("flom_handle_get_tls_check_peer_id() = " +
str(flom_handle_get_tls_check_peer_id(my_handle)) + "\n")
# set a new value for TLS check peer ID property
flom_handle_set_tls_check_peer_id(my_handle, FALSE)
# get new value for TLS check peer ID property
sys.stdout.write("flom_handle_get_tls_check_peer_id() = " +
str(flom_handle_get_tls_check_peer_id(my_handle)) + "\n")
# check TLS check peer ID 1/2
if flom_handle_get_tls_check_peer_id(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_tls_check_peer_id\n")
sys.exit(1)
# set a new value for TLS check peer ID property
flom_handle_set_tls_check_peer_id(my_handle, TRUE)
# get new value for TLS check peer ID property
sys.stdout.write("flom_handle_get_tls_check_peer_id() = " +
str(flom_handle_get_tls_check_peer_id(my_handle)) + "\n")
# check TLS check peer ID 2/2
if not flom_handle_get_tls_check_peer_id(my_handle):
sys.stderr.write("Unexpected result from flom_handle_set/" +
"get_tls_check_peer_id\n")
sys.exit(1)
# lock acquisition
ret_cod = flom_handle_lock(my_handle)
if FLOM_RC_OK != ret_cod:
sys.stderr.write("happy_path/flom_handle_lock() returned " +
str(ret_cod) + " '" + flom_strerror(ret_cod) +
"'\n")
sys.exit(1)
# retrieve locked element
sys.stdout.write("happy_path locked element is '" +
flom_handle_get_locked_element(my_handle) + "'\n")
# lock release
ret_cod = flom_handle_unlock(my_handle)
if FLOM_RC_OK != ret_cod:
sys.stderr.write("happy_path/flom_handle_unlock() returned " +
str(ret_cod) + " '" + flom_strerror(ret_cod) +
"'\n")
sys.exit(1)
# handle clean-up (memory release)
ret_cod = flom_handle_clean(my_handle)
if FLOM_RC_OK != ret_cod:
sys.stderr.write("happy_path/flom_handle_clean() returned " +
str(ret_cod) + " '" + flom_strerror(ret_cod) + "'\n")
sys.exit(1)
# handle deallocation
del my_handle
happy_path()