xref: /curl/tests/http/test_15_tracing.py (revision ce3dce90)
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#
27import logging
28import re
29
30from testenv import Env
31from testenv import CurlClient
32
33
34log = logging.getLogger(__name__)
35
36
37class 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        if not found_tcp:
93            assert False, f'TCP filter does not appear in trace "all": {r.stderr}'
94
95    # trace all, no TCP, no time
96    def test_15_05_trace_all(self, env: Env, httpd):
97        curl = CurlClient(env=env)
98        url = f'http://{env.domain1}:{env.http_port}/data.json'
99        r = curl.http_get(url=url, def_tracing=False, extra_args=[
100            '-v', '--trace-config', 'all,-tcp,-time'
101        ])
102        r.check_response(http_status=200)
103        found_tcp = False
104        for line in  r.trace_lines:
105            m = re.match(r'^\[0-[0x]] .+', line)
106            if m is None:
107                assert False, f'no match: {line}'
108            m = re.match(r'^\[0-[0x]] . \[TCP].+', line)
109            if m is not None:
110                found_tcp = True
111        if found_tcp:
112            assert False, f'TCP filter appears in trace "all,-tcp": {r.stderr}'
113