Annotation of embedaddon/mtr/test/param.py, revision 1.1.1.1
1.1 misho 1: #!/usr/bin/env python
2: #
3: # mtr -- a network diagnostic tool
4: # Copyright (C) 2016 Matt Kimball
5: #
6: # This program is free software; you can redistribute it and/or modify
7: # it under the terms of the GNU General Public License version 2 as
8: # published by the Free Software Foundation.
9: #
10: # This program is distributed in the hope that it will be useful,
11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: # GNU General Public License for more details.
14: #
15: # You should have received a copy of the GNU General Public License
16: # along with this program; if not, write to the Free Software
17: # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18: #
19:
20: '''Test probe customization parameters'''
21:
22: import sys
23: import unittest
24:
25: import mtrpacket
26:
27:
28: @unittest.skipIf(sys.platform == 'cygwin', 'No Cygwin test')
29: class TestParameters(mtrpacket.MtrPacketTest):
30: 'Use parameter arguments to mtr-packet and examine the resulting packet'
31:
32: def test_size(self):
33: 'Test probes sent with an explicit packet size'
34:
35: with mtrpacket.PacketListen('-4') as listen:
36: cmd = '20 send-probe ip-4 127.0.0.1 size 512'
37:
38: self.write_command(cmd)
39:
40: self.assertEqual(listen.attrib['size'], '512')
41:
42: def test_pattern(self):
43: 'Test probes are filled with the requested bit pattern'
44:
45: with mtrpacket.PacketListen('-4') as listen:
46: cmd = '20 send-probe ip-4 127.0.0.1 bit-pattern 44'
47:
48: self.write_command(cmd)
49:
50: self.assertEqual(listen.attrib['bitpattern'], '44')
51:
52: def test_tos(self):
53: 'Test setting the TOS field'
54:
55: with mtrpacket.PacketListen('-4') as listen:
56: cmd = '20 send-probe ip-4 127.0.0.1 tos 62'
57:
58: self.write_command(cmd)
59:
60: self.assertEqual(listen.attrib['tos'], '62')
61:
62:
63: @unittest.skipIf(sys.platform == 'cygwin', 'No Cygwin test')
64: class TestIPv6Parameters(mtrpacket.MtrPacketTest):
65: 'Test packet paramter customization for IPv6'
66:
67: @unittest.skipUnless(mtrpacket.HAVE_IPV6, 'No IPv6')
68: def test_param(self):
69: 'Test a variety of packet parameters'
70:
71: with mtrpacket.PacketListen('-6') as listen:
72: param = 'size 256 bit-pattern 51 tos 77'
73: cmd = '20 send-probe ip-6 ::1 ' + param
74:
75: self.write_command(cmd)
76:
77: self.assertEqual(listen.attrib['size'], '256')
78: self.assertEqual(listen.attrib['bitpattern'], '51')
79:
80:
81: if __name__ == '__main__':
82: mtrpacket.check_running_as_root()
83: unittest.main()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>