Path: blob/main/external/curl/tests/http/test_15_tracing.py
2066 views
#!/usr/bin/env python31# -*- coding: utf-8 -*-2#***************************************************************************3# _ _ ____ _4# Project ___| | | | _ \| |5# / __| | | | |_) | |6# | (__| |_| | _ <| |___7# \___|\___/|_| \_\_____|8#9# Copyright (C) Daniel Stenberg, <[email protected]>, et al.10#11# This software is licensed as described in the file COPYING, which12# you should have received as part of this distribution. The terms13# are also available at https://curl.se/docs/copyright.html.14#15# You may opt to use, copy, modify, merge, publish, distribute and/or sell16# copies of the Software, and permit persons to whom the Software is17# furnished to do so, under the terms of the COPYING file.18#19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY20# KIND, either express or implied.21#22# SPDX-License-Identifier: curl23#24###########################################################################25#26import logging27import re2829from testenv import Env30from testenv import CurlClient313233log = logging.getLogger(__name__)343536class TestTracing:3738# default verbose output39def test_15_01_trace_defaults(self, env: Env, httpd):40curl = CurlClient(env=env)41url = f'http://{env.domain1}:{env.http_port}/data.json'42r = curl.http_get(url=url, def_tracing=False, extra_args=[43'-v'44])45r.check_response(http_status=200)46trace = r.trace_lines47assert len(trace) > 04849# trace ids50def test_15_02_trace_ids(self, env: Env, httpd):51curl = CurlClient(env=env)52url = f'http://{env.domain1}:{env.http_port}/data.json'53r = curl.http_get(url=url, def_tracing=False, extra_args=[54'-v', '--trace-config', 'ids'55])56r.check_response(http_status=200)57for line in r.trace_lines:58m = re.match(r'^\[0-[0x]] .+', line)59if m is None:60assert False, f'no match: {line}'6162# trace ids+time63def test_15_03_trace_ids_time(self, env: Env, httpd):64curl = CurlClient(env=env)65url = f'http://{env.domain1}:{env.http_port}/data.json'66r = curl.http_get(url=url, def_tracing=False, extra_args=[67'-v', '--trace-config', 'ids,time'68])69r.check_response(http_status=200)70for line in r.trace_lines:71m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)72if m is None:73assert False, f'no match: {line}'7475# trace all76def test_15_04_trace_all(self, env: Env, httpd):77curl = CurlClient(env=env)78url = f'http://{env.domain1}:{env.http_port}/data.json'79r = curl.http_get(url=url, def_tracing=False, extra_args=[80'-v', '--trace-config', 'all'81])82r.check_response(http_status=200)83found_tcp = False84for line in r.trace_lines:85m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)86if m is None:87assert False, f'no match: {line}'88m = re.match(r'^([0-9:.]+) \[0-[0x]] .+ \[TCP].+', line)89if m is not None:90found_tcp = True91assert found_tcp, f'TCP filter does not appear in trace "all": {r.stderr}'9293# trace all, no TCP, no time94def test_15_05_trace_all(self, env: Env, httpd):95curl = CurlClient(env=env)96url = f'http://{env.domain1}:{env.http_port}/data.json'97r = curl.http_get(url=url, def_tracing=False, extra_args=[98'-v', '--trace-config', 'all,-tcp,-time'99])100r.check_response(http_status=200)101found_tcp = False102for line in r.trace_lines:103m = re.match(r'^\[0-[0x]] .+', line)104if m is None:105assert False, f'no match: {line}'106m = re.match(r'^\[0-[0x]] . \[TCP].+', line)107if m is not None:108found_tcp = True109if found_tcp:110assert False, f'TCP filter appears in trace "all,-tcp": {r.stderr}'111112113