|
1 # |
|
2 # Copyright 2005-2006 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 dtn-cp |
|
18 net::num_nodes 3 |
|
19 |
|
20 manifest::file apps/dtncp/dtncp dtncp |
|
21 manifest::file apps/dtncpd/dtncpd dtncpd |
|
22 |
|
23 dtn::config |
|
24 |
|
25 dtn::config_interface tcp |
|
26 dtn::config_linear_topology ALWAYSON tcp true |
|
27 |
|
28 proc wait_for_file {id path {timeout 30}} { |
|
29 do_until "in wait for file $path at node $id" $timeout { |
|
30 if {[tell_dtnd $id file exists $path]} { |
|
31 return |
|
32 } |
|
33 |
|
34 after 500 |
|
35 } |
|
36 } |
|
37 |
|
38 test::script { |
|
39 testlog "Running dtnds" |
|
40 dtn::run_dtnd * |
|
41 |
|
42 testlog "Waiting for dtnds to start up" |
|
43 dtn::wait_for_dtnd * |
|
44 |
|
45 set N [net::num_nodes] |
|
46 set last_node [expr $N - 1] |
|
47 set dest dtn://host-0/ |
|
48 |
|
49 testlog "Running dtncpd..." |
|
50 tell_dtnd $last_node file mkdir incoming |
|
51 set dtncpd_pid [dtn::run_app $last_node dtncpd incoming] |
|
52 |
|
53 testlog "Creating and copying an empty file" |
|
54 tell_dtnd 0 file mkdir test |
|
55 tell_dtnd 0 {set fd [open test/empty w]; close $fd} |
|
56 dtn::check expr [tell_dtnd 0 file size test/empty] == 0 |
|
57 dtn::run_app_and_wait 0 dtncp "test/empty dtn://host-2" |
|
58 wait_for_file $last_node incoming/host-0/empty |
|
59 dtn::check expr [tell_dtnd $last_node file size incoming/host-0/empty] == 0 |
|
60 |
|
61 set dtnd_size [tell_dtnd 0 file size dtnd] |
|
62 |
|
63 testlog "Copying the dtnd executable into dtnd.new ($dtnd_size bytes)" |
|
64 dtn::run_app_and_wait 0 dtncp "dtnd dtn://host-2 dtnd.new" |
|
65 |
|
66 testlog "Waiting for the file to be delivered" |
|
67 wait_for_file $last_node incoming/host-0/dtnd.new |
|
68 |
|
69 testlog "Checking that size and md5sum matches" |
|
70 dtn::check expr [tell_dtnd $last_node file size \ |
|
71 incoming/host-0/dtnd.new] == $dtnd_size |
|
72 set cksum1 [lindex [tell_dtnd 0 exec md5sum dtnd] 0] |
|
73 set cksum2 [lindex [tell_dtnd $last_node exec md5sum incoming/host-0/dtnd.new] 0] |
|
74 if {$cksum1 != $cksum2} { |
|
75 error "md5sum mismatch: $cksum1 != $cksum2" |
|
76 } |
|
77 |
|
78 testlog "Test success!" |
|
79 } |
|
80 |
|
81 test::exit_script { |
|
82 testlog "Stopping dtncpd" |
|
83 run::kill_pid $last_node $dtncpd_pid TERM |
|
84 |
|
85 testlog "Stopping all dtnds" |
|
86 dtn::stop_dtnd * |
|
87 } |