Path: blob/main/external/curl/tests/http/test_15_tracing.py
2654 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 re28import pytest2930from testenv import Env31from testenv import CurlClient323334log = logging.getLogger(__name__)353637@pytest.mark.skipif(condition=not Env.curl_is_debug(), reason="needs curl debug")38class TestTracing:3940# default verbose output41def test_15_01_trace_defaults(self, env: Env, httpd):42curl = CurlClient(env=env)43url = f'http://{env.domain1}:{env.http_port}/data.json'44r = curl.http_get(url=url, def_tracing=False, extra_args=[45'-v'46])47r.check_response(http_status=200)48trace = r.trace_lines49assert len(trace) > 05051# trace ids52def test_15_02_trace_ids(self, env: Env, httpd):53curl = CurlClient(env=env)54url = f'http://{env.domain1}:{env.http_port}/data.json'55r = curl.http_get(url=url, def_tracing=False, extra_args=[56'-v', '--trace-config', 'ids'57])58r.check_response(http_status=200)59for line in r.trace_lines:60m = re.match(r'^\[0-[0x]] .+', line)61if m is None:62assert False, f'no match: {line}'6364# trace ids+time65def test_15_03_trace_ids_time(self, env: Env, httpd):66curl = CurlClient(env=env)67url = f'http://{env.domain1}:{env.http_port}/data.json'68r = curl.http_get(url=url, def_tracing=False, extra_args=[69'-v', '--trace-config', 'ids,time'70])71r.check_response(http_status=200)72for line in r.trace_lines:73m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)74if m is None:75assert False, f'no match: {line}'7677# trace all78def test_15_04_trace_all(self, env: Env, httpd):79if not env.curl_is_verbose():80pytest.skip('only works for curl with verbose strings')81curl = CurlClient(env=env)82url = f'http://{env.domain1}:{env.http_port}/data.json'83r = curl.http_get(url=url, def_tracing=False, extra_args=[84'-v', '--trace-config', 'all'85])86r.check_response(http_status=200)87found_tcp = False88for line in r.trace_lines:89m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)90if m is None:91assert False, f'no match: {line}'92m = re.match(r'^([0-9:.]+) \[0-[0x]] .+ \[TCP].+', line)93if m is not None:94found_tcp = True95assert found_tcp, f'TCP filter does not appear in trace "all": {r.stderr}'9697# trace all, no TCP, no time98def test_15_05_trace_all(self, env: Env, httpd):99curl = CurlClient(env=env)100url = f'http://{env.domain1}:{env.http_port}/data.json'101r = curl.http_get(url=url, def_tracing=False, extra_args=[102'-v', '--trace-config', 'all,-tcp,-time'103])104r.check_response(http_status=200)105found_tcp = False106for line in r.trace_lines:107m = re.match(r'^\[0-[0x]] .+', line)108if m is None:109assert False, f'no match: {line}'110m = re.match(r'^\[0-[0x]] . \[TCP].+', line)111if m is not None:112found_tcp = True113if found_tcp:114assert False, f'TCP filter appears in trace "all,-tcp": {r.stderr}'115116117