serval-dna/tests/rhizomeprotocol

187 lines
5.1 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# Tests for Serval rhizome protocol.
#
# Copyright 2012 Paul Gardner-Stephen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
source "${0%/*}/../testdefs_rhizome.sh"
shopt -s extglob
teardown() {
stop_all_servald_servers
kill_all_servald_processes
assert_no_servald_processes
}
setup_rhizome() {
set_instance +A
create_rhizome_identities 1
set_instance +B
create_rhizome_identities 1
}
# Called by start_servald_instances for each instance.
configure_servald_server() {
executeOk_servald config set log.show_pid on
executeOk_servald config set log.show_time on
executeOk_servald config set debug.rhizome on
executeOk_servald config set debug.rhizometx on
executeOk_servald config set debug.rhizomerx on
executeOk_servald config set server.respawn_on_signal off
executeOk_servald config set mdp.wifi.tick_ms 100
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
executeOk_servald config set rhizome.fetch_interval_ms 100
}
# Predicate function:
# - return true if the file bundle identified by $BID and $VERSION has been
# received by all the given instances
# - does this by examining the server log files of the respective instances
# for tell-tale INFO messages
bundle_received_by() {
local I
for I; do
logvar="LOG${I#+}"
grep "RHIZOME ADD MANIFEST service=file bid=$BID version=$VERSION" "${!logvar}" || return 1
done
return 0
}
setup_common() {
setup_servald
setup_rhizome
assert_no_servald_processes
}
extract_manifest_vars() {
local manifest="${1?}"
extract_manifest_id BID "$manifest"
extract_manifest_version VERSION "$manifest"
extract_manifest_filesize FILESIZE "$manifest"
FILEHASH=
if [ "$FILESIZE" != '0' ]; then
extract_manifest_filehash FILEHASH "$manifest"
fi
}
add_file() {
local name="$1"
[ -e "$name" ] || echo 'File $name' >"$name"
local sidvar="SID$instance_name"
executeOk_servald rhizome add file "${!sidvar}" '' "$name" "$name.manifest"
executeOk_servald rhizome list ''
assert_rhizome_list "$name"
extract_manifest_vars "$name.manifest"
}
update_file() {
local orig_name="$1"
local new_name="$2"
[ -e "$new_name" ] || echo 'File $new_name' >"$new_name"
local sidvar="SID$instance_name"
[ "$new_name" != "$orig_name" ] && cp "$orig_name.manifest" "$new_name.manifest"
sed -i -e '/^date=/d;/^filehash=/d;/^filesize=/d;/^version=/d;/^name=/d' "$new_name.manifest"
executeOk_servald rhizome add file "${!sidvar}" '' "$new_name" "$new_name.manifest"
executeOk_servald rhizome list ''
assert_rhizome_list "$new_name"
extract_manifest_vars "$new_name.manifest"
}
doc_FileTransfer="New bundle and update transfer to one node"
setup_FileTransfer() {
setup_common
set_instance +A
add_file file1
start_servald_instances +A +B
}
test_FileTransfer() {
wait_until bundle_received_by +B
set_instance +B
assert_received file1
set_instance +A
update_file file1 file2
set_instance +B
wait_until bundle_received_by +B
assert_received file2
}
doc_FileTransferBig="Big new bundle transfers to one node"
setup_FileTransferBig() {
setup_common
set_instance +A
dd if=/dev/urandom of=file1 bs=1k count=1k 2>&1
echo x >>file1
ls -l file1
add_file file1
start_servald_instances +A +B
}
test_FileTransferBig() {
wait_until bundle_received_by +B
set_instance +B
assert_received file1
}
assert_received() {
local name="${1?}"
executeOk_servald rhizome list ''
assert_rhizome_list "$name!"
local _hash
if [ -s "$name" ]; then
extract_manifest_filehash _hash "$name.manifest"
executeOk_servald rhizome extract file "$_hash" extracted
assert cmp "$name" extracted
fi
}
doc_FileTransferMulti="New bundle transfers to four nodes"
setup_FileTransferMulti() {
setup_common
set_instance +A
add_file file1
start_servald_instances +A +B +C +D +E
}
test_FileTransferMulti() {
wait_until bundle_received_by +B +C +D +E
local I
for I in +B +C +D +E; do
set_instance $I
assert_received file1
done
}
doc_FileTransferDelete="Payload deletion transfers to one node"
setup_FileTransferDelete() {
setup_common
set_instance +A
add_file file1
start_servald_instances +A +B
wait_until bundle_received_by +B
set_instance +A
>file1_2
update_file file1 file1_2
}
test_FileTransferDelete() {
wait_until bundle_received_by +B
set_instance +B
assert_received file1_2
}
runTests "$@"