From: Darafei Praliaskouski Date: Thu, 7 May 2026 20:08:46 +0000 (+0400) Subject: test: cover TTL option validation X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=4614c3e9ecf3dfaa0cb1b8a2dfe832655f3b4fa7;p=thirdparty%2Fmtr.git test: cover TTL option validation --- diff --git a/test/cmdparse.py b/test/cmdparse.py index ad6d23c..b3b8e81 100755 --- a/test/cmdparse.py +++ b/test/cmdparse.py @@ -17,15 +17,62 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -'''Test mtr-packet's command parsing.''' +'''Test mtr and mtr-packet command parsing.''' +import os +import subprocess import time import unittest import mtrpacket +PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +MTR = os.path.join(PROJECT_ROOT, 'mtr') + + +class TestMtrCommandParse(unittest.TestCase): + '''Test cases with malformed mtr command-line arguments.''' + + def run_mtr(self, *args): + return subprocess.run( + [MTR] + list(args), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) + + def test_first_ttl_cannot_exceed_max_ttl(self): + 'Test that conflicting first/max TTL options fail fast.' + + reply = self.run_mtr('--first-ttl', '91', '--max-ttl', '90') + + self.assertNotEqual(reply.returncode, 0) + self.assertIn( + 'firstTTL(91) cannot be larger than maxTTL(90)', + reply.stderr, + ) + + def test_first_ttl_can_equal_max_ttl(self): + 'Test that a single requested TTL depth remains valid.' + + reply = self.run_mtr( + '--report', + '--report-cycles', + '1', + '--no-dns', + '--first-ttl', + '91', + '--max-ttl', + '91', + '127.0.0.1', + ) + + self.assertEqual(reply.returncode, 0) + self.assertEqual(reply.stderr, '') + + class TestCommandParse(mtrpacket.MtrPacketTest): '''Test cases with malformed commands and version checks'''