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