|
1 # |
|
2 # Copyright 2007 Intel Corporation |
|
3 # |
|
4 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 # you may not use this file except in compliance with the License. |
|
6 # You may obtain a copy of the License at |
|
7 # |
|
8 # http://www.apache.org/licenses/LICENSE-2.0 |
|
9 # |
|
10 # Unless required by applicable law or agreed to in writing, software |
|
11 # distributed under the License is distributed on an "AS IS" BASIS, |
|
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 # See the License for the specific language governing permissions and |
|
14 # limitations under the License. |
|
15 # |
|
16 |
|
17 test::name api-poll |
|
18 net::num_nodes 1 |
|
19 |
|
20 manifest::file apps/dtntest/dtntest dtntest |
|
21 |
|
22 dtn::config |
|
23 dtn::config_topology_common false |
|
24 |
|
25 test::script { |
|
26 testlog "Running dtnd and dtntest" |
|
27 dtn::run_dtnd 0 |
|
28 dtn::run_dtntest 0 |
|
29 |
|
30 testlog "Waiting for dtnd and dtntest to start up" |
|
31 dtn::wait_for_dtnd 0 |
|
32 dtn::wait_for_dtntest 0 |
|
33 |
|
34 testlog "Creating two handles" |
|
35 set h1 [dtn::tell_dtntest 0 dtn_open] |
|
36 set h2 [dtn::tell_dtntest 0 dtn_open] |
|
37 |
|
38 testlog "Creating registrations for source and dest" |
|
39 set regid0 [dtn::tell_dtntest 0 dtn_register $h1 endpoint=dtn://host-0/src expiration=30] |
|
40 set regid1 [dtn::tell_dtntest 0 dtn_register $h2 endpoint=dtn://host-0/dst expiration=30] |
|
41 |
|
42 testlog "Setting up a callback handler" |
|
43 set chan [dtn::tell_dtntest 0 dtn_poll_channel $h2] |
|
44 dtn::tell_dtntest 0 { proc arrived {h} { global bundles; \ |
|
45 lappend bundles [dtn_recv $h payload_mem=true timeout=0]; } } |
|
46 |
|
47 proc send_recv {dest {do_poll 1}} { |
|
48 global chan h1 h2 |
|
49 |
|
50 if {$do_poll} { |
|
51 dtn::tell_dtntest 0 dtn_begin_poll $h2 10000 |
|
52 dtn::tell_dtntest 0 fileevent $chan readable [list arrived $h2] |
|
53 } |
|
54 |
|
55 dtn::tell_dtntest 0 "dtn_send $h1 source=dtn://host-0/src $dest\ |
|
56 expiration=10 payload_data=test_payload" |
|
57 |
|
58 # when polling, we first wait for delivery and then check the |
|
59 # bundles var, otherwise we need to call recv to get the |
|
60 # contents, then it will be delivered |
|
61 if {$do_poll} { |
|
62 dtn::wait_for_bundle_stat 0 1 delivered |
|
63 puts [dtn::tell_dtntest 0 set bundles] |
|
64 dtn::tell_dtntest 0 set bundles {} |
|
65 dtn::tell_dtntest 0 fileevent $chan readable "" |
|
66 } else { |
|
67 puts [dtn::tell_dtntest 0 dtn_recv $h2 payload_mem=true timeout=10000] |
|
68 dtn::wait_for_bundle_stat 0 1 delivered |
|
69 } |
|
70 |
|
71 dtn::wait_for_bundle_stat 0 0 pending |
|
72 dtn::tell_dtnd 0 bundle reset_stats |
|
73 } |
|
74 |
|
75 testlog "Sending and polling for a couple bundles" |
|
76 for {set i 0} {$i < 5} {incr i} { |
|
77 send_recv dest=dtn://host-0/dst |
|
78 after 1000 |
|
79 } |
|
80 |
|
81 testlog "Testing poll timeout" |
|
82 dtn::tell_dtntest 0 "dtn_begin_poll $h2 1000" |
|
83 after 2000 |
|
84 catch {dtn::tell_dtntest 0 dtn_recv $h2 payload_mem=true timeout=0} err |
|
85 if {$err != "error: error in dtn_recv: operation timed out"} { |
|
86 error "unexpected error from dtn_recv: $err" |
|
87 } |
|
88 |
|
89 testlog "Testing a normal delivery" |
|
90 send_recv dest=dtn://host-0/dst 0 |
|
91 |
|
92 testlog "Testing a poll delivery" |
|
93 send_recv dest=dtn://host-0/dst |
|
94 |
|
95 testlog "Testing poll cancel" |
|
96 dtn::tell_dtntest 0 "dtn_begin_poll $h2 10000" |
|
97 dtn::tell_dtntest 0 fileevent $chan readable \ |
|
98 "error: unexpected notification on idle channel" |
|
99 after 2000 |
|
100 dtn::tell_dtntest 0 fileevent $chan readable "" |
|
101 dtn::tell_dtntest 0 "dtn_cancel_poll $h2" |
|
102 |
|
103 testlog "Testing a normal delivery" |
|
104 send_recv dest=dtn://host-0/dst 0 |
|
105 |
|
106 testlog "Testing a poll delivery" |
|
107 send_recv dest=dtn://host-0/dst |
|
108 |
|
109 testlog "Test success!" |
|
110 } |
|
111 |
|
112 test::exit_script { |
|
113 testlog "Stopping dtnd and dtntest" |
|
114 dtn::tell_dtntest 0 dtn_close $h1 |
|
115 dtn::tell_dtntest 0 dtn_close $h2 |
|
116 dtn::stop_dtntest 0 |
|
117 dtn::stop_dtnd 0 |
|
118 } |