test_15_tracing.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. from testenv import Env
  30. from testenv import CurlClient
  31. log = logging.getLogger(__name__)
  32. class TestTracing:
  33. # default verbose output
  34. def test_15_01_trace_defaults(self, env: Env, httpd):
  35. curl = CurlClient(env=env)
  36. url = f'http://{env.domain1}:{env.http_port}/data.json'
  37. r = curl.http_get(url=url, def_tracing=False, extra_args=[
  38. '-v'
  39. ])
  40. r.check_response(http_status=200)
  41. trace = r.trace_lines
  42. assert len(trace) > 0
  43. # trace ids
  44. def test_15_02_trace_ids(self, env: Env, httpd):
  45. curl = CurlClient(env=env)
  46. url = f'http://{env.domain1}:{env.http_port}/data.json'
  47. r = curl.http_get(url=url, def_tracing=False, extra_args=[
  48. '-v', '--trace-config', 'ids'
  49. ])
  50. r.check_response(http_status=200)
  51. for line in r.trace_lines:
  52. m = re.match(r'^\[0-[0x]] .+', line)
  53. if m is None:
  54. assert False, f'no match: {line}'
  55. # trace ids+time
  56. def test_15_03_trace_ids_time(self, env: Env, httpd):
  57. curl = CurlClient(env=env)
  58. url = f'http://{env.domain1}:{env.http_port}/data.json'
  59. r = curl.http_get(url=url, def_tracing=False, extra_args=[
  60. '-v', '--trace-config', 'ids,time'
  61. ])
  62. r.check_response(http_status=200)
  63. for line in r.trace_lines:
  64. m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)
  65. if m is None:
  66. assert False, f'no match: {line}'
  67. # trace all
  68. def test_15_04_trace_all(self, env: Env, httpd):
  69. curl = CurlClient(env=env)
  70. url = f'http://{env.domain1}:{env.http_port}/data.json'
  71. r = curl.http_get(url=url, def_tracing=False, extra_args=[
  72. '-v', '--trace-config', 'all'
  73. ])
  74. r.check_response(http_status=200)
  75. found_tcp = False
  76. for line in r.trace_lines:
  77. m = re.match(r'^([0-9:.]+) \[0-[0x]] .+', line)
  78. if m is None:
  79. assert False, f'no match: {line}'
  80. m = re.match(r'^([0-9:.]+) \[0-[0x]] . \[TCP].+', line)
  81. if m is not None:
  82. found_tcp = True
  83. if not found_tcp:
  84. assert False, f'TCP filter does not appear in trace "all": {r.stderr}'
  85. # trace all, no TCP, no time
  86. def test_15_05_trace_all(self, env: Env, httpd):
  87. curl = CurlClient(env=env)
  88. url = f'http://{env.domain1}:{env.http_port}/data.json'
  89. r = curl.http_get(url=url, def_tracing=False, extra_args=[
  90. '-v', '--trace-config', 'all,-tcp,-time'
  91. ])
  92. r.check_response(http_status=200)
  93. found_tcp = False
  94. for line in r.trace_lines:
  95. m = re.match(r'^\[0-[0x]] .+', line)
  96. if m is None:
  97. assert False, f'no match: {line}'
  98. m = re.match(r'^\[0-[0x]] . \[TCP].+', line)
  99. if m is not None:
  100. found_tcp = True
  101. if found_tcp:
  102. assert False, f'TCP filter appears in trace "all,-tcp": {r.stderr}'