The capture thread index must start at zero.
[dabba.git] / dabba / test / t1100-capture.sh
blob0c06bf7ef3d6b7aabc5ee6bdb8f705b87da8b336
1 #!/bin/sh
3 # Copyright (C) 2009-2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or (at
8 # your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
20 test_description='Test dabba capture command'
21 ring_size=$((16*1024*1024))
23 . ./dabba-test-lib.sh
25 check_capture_thread_nr()
27 local expected_thread_nr="$1"
28 local result_file="$2"
29 local result_thread_nr=$(python -c "import yaml; y = yaml.load(open('$result_file')); print len(y['captures']);")
30 return $(test "$expected_thread_nr" = "$result_thread_nr")
33 check_capture_thread_id()
35 local thread_nr="$1"
36 local result_file="$2"
37 local result_thread_id=$(python -c "import yaml; y = yaml.load(open('$result_file')); print y['captures'][$thread_nr]['id'];")
38 return $(echo "$result_thread_id" | grep -w -q -E "^[0-9]+")
41 check_capture_thread_interface()
43 local thread_nr="$1"
44 local expected_interface="$2"
45 local result_file="$3"
46 local result_interface=$(python -c "import yaml; y = yaml.load(open('$result_file')); print y['captures'][$thread_nr]['interface'];")
47 return $(test "$expected_interface" = "$result_interface")
50 check_capture_thread_pcap()
52 local thread_nr="$1"
53 local expected_pcap="$2"
54 local result_file="$3"
55 local result_pcap=$(python -c "import yaml; y = yaml.load(open('$result_file')); print y['captures'][$thread_nr]['pcap'];")
56 return $(test "$expected_pcap" = "$result_pcap")
59 check_capture_thread_packet_mmap_size()
61 local thread_nr="$1"
62 local expected_packet_mmap_size="$2"
63 local result_file="$3"
64 local result_packet_mmap_size=$(python -c "import yaml; y = yaml.load(open('$result_file')); print y['captures'][$thread_nr]['packet mmap size'];")
65 return $(test "$expected_packet_mmap_size" = "$result_packet_mmap_size")
68 test_expect_success "Setup: Start dabbad" "
69 $DABBAD_PATH/dabbad --daemonize
72 for i in `seq 0 9`
74 test_expect_success "Start a capture thread #$(($i+1)) on loopback" "
75 $DABBA_PATH/dabba capture start --device lo --pcap test$i.pcap --size $ring_size &&
76 $DABBA_PATH/dabba capture list > result &&
77 check_capture_thread_nr $i result &&
78 check_capture_thread_id $i result &&
79 check_capture_thread_interface $i lo result &&
80 check_capture_thread_pcap $i \"$PWD/test$i.pcap\" result &&
81 check_capture_thread_packet_mmap_size $i $ring_size result
83 done
85 test_expect_success "Cleanup: Stop dabbad" "
86 killall dabbad
89 test_done
91 # vim: ft=sh:tabstop=4:et