tracepoint-selftests.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Self tests for tracepoint-related code for GDB, the GNU debugger.
  2. Copyright (C) 2018-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "gdbsupport/selftest.h"
  16. #include "tracepoint.h"
  17. namespace selftests {
  18. namespace tracepoint_tests {
  19. static void
  20. test_parse_static_tracepoint_marker_definition ()
  21. {
  22. static_tracepoint_marker marker;
  23. const char def[] = ("1234:6d61726b657231:6578747261207374756666,"
  24. "abba:6d61726b657232:,"
  25. "cafe:6d61726b657233:6d6f72657374756666");
  26. const char *start = def;
  27. const char *end;
  28. parse_static_tracepoint_marker_definition (start, &end, &marker);
  29. SELF_CHECK (marker.address == 0x1234);
  30. SELF_CHECK (marker.str_id == "marker1");
  31. SELF_CHECK (marker.extra == "extra stuff");
  32. SELF_CHECK (end == strchr (start, ','));
  33. start = end + 1;
  34. parse_static_tracepoint_marker_definition (start, &end, &marker);
  35. SELF_CHECK (marker.address == 0xabba);
  36. SELF_CHECK (marker.str_id == "marker2");
  37. SELF_CHECK (marker.extra == "");
  38. SELF_CHECK (end == strchr (start, ','));
  39. start = end + 1;
  40. parse_static_tracepoint_marker_definition (start, &end, &marker);
  41. SELF_CHECK (marker.address == 0xcafe);
  42. SELF_CHECK (marker.str_id == "marker3");
  43. SELF_CHECK (marker.extra == "morestuff");
  44. SELF_CHECK (end == def + strlen (def));
  45. }
  46. } /* namespace tracepoint_tests */
  47. } /* namespace selftests */
  48. void _initialize_tracepoint_selftests ();
  49. void
  50. _initialize_tracepoint_selftests ()
  51. {
  52. selftests::register_test
  53. ("parse_static_tracepoint_marker_definition",
  54. selftests::tracepoint_tests::test_parse_static_tracepoint_marker_definition);
  55. }