test_15_tracing.py (4114B)
1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 #*************************************************************************** 4 # _ _ ____ _ 5 # Project ___| | | | _ \| | 6 # / __| | | | |_) | | 7 # | (__| |_| | _ <| |___ 8 # \___|\___/|_| \_\_____| 9 # 10 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 11 # 12 # This software is licensed as described in the file COPYING, which 13 # you should have received as part of this distribution. The terms 14 # are also available at https://curl.se/docs/copyright.html. 15 # 16 # You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 # copies of the Software, and permit persons to whom the Software is 18 # furnished to do so, under the terms of the COPYING file. 19 # 20 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 # KIND, either express or implied. 22 # 23 # SPDX-License-Identifier: curl 24 # 25 ########################################################################### 26 # 27 import logging 28 import re 29 30 from testenv import Env 31 from testenv import CurlClient 32 33 34 log = logging.getLogger(__name__) 35 36 37 class TestTracing: 38 39 # default verbose output 40 def test_15_01_trace_defaults(self, env: Env, httpd): 41 curl = CurlClient(env=env) 42 url = f'http://{env.domain1}:{env.http_port}/data.json' 43 r = curl.http_get(url=url, def_tracing=False, extra_args=[ 44 '-v' 45 ]) 46 r.check_response(http_status=200) 47 trace = r.trace_lines 48 assert len(trace) > 0 49 50 # trace ids 51 def test_15_02_trace_ids(self, env: Env, httpd): 52 curl = CurlClient(env=env) 53 url = f'http://{env.domain1}:{env.http_port}/data.json' 54 r = curl.http_get(url=url, def_tracing=False, extra_args=[ 55 '-v', '--trace-config', 'ids' 56 ]) 57 r.check_response(http_status=200) 58 for line in r.trace_lines: 59 m = re.match(r'^\[0-[0x]] .+', line) 60 if m is None: 61 assert False, f'no match: {line}' 62 63 # trace ids+time 64 def test_15_03_trace_ids_time(self, env: Env, httpd): 65 curl = CurlClient(env=env) 66 url = f'http://{env.domain1}:{env.http_port}/data.json' 67 r = curl.http_get(url=url, def_tracing=False, extra_args=[ 68 '-v', '--trace-config', 'ids,time' 69 ]) 70 r.check_response(http_status=200) 71 for line in r.trace_lines: 72 m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line) 73 if m is None: 74 assert False, f'no match: {line}' 75 76 # trace all 77 def test_15_04_trace_all(self, env: Env, httpd): 78 curl = CurlClient(env=env) 79 url = f'http://{env.domain1}:{env.http_port}/data.json' 80 r = curl.http_get(url=url, def_tracing=False, extra_args=[ 81 '-v', '--trace-config', 'all' 82 ]) 83 r.check_response(http_status=200) 84 found_tcp = False 85 for line in r.trace_lines: 86 m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line) 87 if m is None: 88 assert False, f'no match: {line}' 89 m = re.match(r'^([0-9:.]+) \[0-[0x]] .+ \[TCP].+', line) 90 if m is not None: 91 found_tcp = True 92 assert found_tcp, f'TCP filter does not appear in trace "all": {r.stderr}' 93 94 # trace all, no TCP, no time 95 def test_15_05_trace_all(self, env: Env, httpd): 96 curl = CurlClient(env=env) 97 url = f'http://{env.domain1}:{env.http_port}/data.json' 98 r = curl.http_get(url=url, def_tracing=False, extra_args=[ 99 '-v', '--trace-config', 'all,-tcp,-time' 100 ]) 101 r.check_response(http_status=200) 102 found_tcp = False 103 for line in r.trace_lines: 104 m = re.match(r'^\[0-[0x]] .+', line) 105 if m is None: 106 assert False, f'no match: {line}' 107 m = re.match(r'^\[0-[0x]] . \[TCP].+', line) 108 if m is not None: 109 found_tcp = True 110 if found_tcp: 111 assert False, f'TCP filter appears in trace "all,-tcp": {r.stderr}'