GDB (xrefs)
Loading...
Searching...
No Matches
ptid-selftests.c
Go to the documentation of this file.
1/* Self tests for ptid_t for GDB, the GNU debugger.
2
3 Copyright (C) 2017-2023 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/ptid.h"
22#include <type_traits>
23
24namespace selftests {
25namespace ptid {
26
27/* Check that the ptid_t class is POD.
28
29 This is a requirement for as long as we have ptids embedded in
30 structures allocated with malloc. */
31
32static_assert (gdb::And<std::is_standard_layout<ptid_t>,
33 std::is_trivial<ptid_t>>::value,
34 "ptid_t is POD");
35
36/* We want to avoid implicit conversion from int to ptid_t. */
37
38static_assert (!std::is_convertible<int, ptid_t>::value,
39 "constructor is explicit");
40
41/* Build some useful ptids. */
42
43static constexpr ptid_t pid = ptid_t (1);
44static constexpr ptid_t lwp = ptid_t (1, 2, 0);
45static constexpr ptid_t tid = ptid_t (1, 0, 2);
46static constexpr ptid_t both = ptid_t (1, 2, 2);
47
48/* Build some constexpr version of null_ptid and minus_one_ptid to use in
49 static_assert. Once the real ones are made constexpr, we can get rid of
50 these. */
51
52static constexpr ptid_t null = ptid_t::make_null ();
53static constexpr ptid_t minus_one = ptid_t::make_minus_one ();
54
55/* Verify pid. */
56
57static_assert (pid.pid () == 1, "pid's pid is right");
58static_assert (lwp.pid () == 1, "lwp's pid is right");
59static_assert (tid.pid () == 1, "tid's pid is right");
60static_assert (both.pid () == 1, "both's pid is right");
61
62/* Verify lwp_p. */
63
64static_assert (!pid.lwp_p (), "pid's lwp_p is right");
65static_assert (lwp.lwp_p (), "lwp's lwp_p is right");
66static_assert (!tid.lwp_p (), "tid's lwp_p is right");
67static_assert (both.lwp_p (), "both's lwp_p is right");
68
69/* Verify lwp. */
70
71static_assert (pid.lwp () == 0, "pid's lwp is right");
72static_assert (lwp.lwp () == 2, "lwp's lwp is right");
73static_assert (tid.lwp () == 0, "tid's lwp is right");
74static_assert (both.lwp () == 2, "both's lwp is right");
75
76/* Verify tid_p. */
77
78static_assert (!pid.tid_p (), "pid's tid_p is right");
79static_assert (!lwp.tid_p (), "lwp's tid_p is right");
80static_assert (tid.tid_p (), "tid's tid_p is right");
81static_assert (both.tid_p (), "both's tid_p is right");
82
83/* Verify tid. */
84
85static_assert (pid.tid () == 0, "pid's tid is right");
86static_assert (lwp.tid () == 0, "lwp's tid is right");
87static_assert (tid.tid () == 2, "tid's tid is right");
88static_assert (both.tid () == 2, "both's tid is right");
89
90/* Verify is_pid. */
91
92static_assert (pid.is_pid (), "pid is a pid");
93static_assert (!lwp.is_pid (), "lwp isn't a pid");
94static_assert (!tid.is_pid (), "tid isn't a pid");
95static_assert (!both.is_pid (), "both isn't a pid");
96static_assert (!null.is_pid (), "null ptid isn't a pid");
97static_assert (!minus_one.is_pid (), "minus one ptid isn't a pid");
98
99/* Verify operator ==. */
100
101static_assert (pid == ptid_t (1, 0, 0), "pid operator== is right");
102static_assert (lwp == ptid_t (1, 2, 0), "lwp operator== is right");
103static_assert (tid == ptid_t (1, 0, 2), "tid operator== is right");
104static_assert (both == ptid_t (1, 2, 2), "both operator== is right");
105
106/* Verify operator !=. */
107
108static_assert (pid != ptid_t (2, 0, 0), "pid isn't equal to a different pid");
109static_assert (pid != lwp, "pid isn't equal to one of its thread");
110static_assert (lwp != tid, "lwp isn't equal to tid");
111static_assert (both != lwp, "both isn't equal to lwp");
112static_assert (both != tid, "both isn't equal to tid");
113
114/* Verify matches against minus_one. */
115
116static_assert (pid.matches (minus_one), "pid matches minus one");
117static_assert (lwp.matches (minus_one), "lwp matches minus one");
118static_assert (tid.matches (minus_one), "tid matches minus one");
119static_assert (both.matches (minus_one), "both matches minus one");
120
121/* Verify matches against pid. */
122
123static_assert (pid.matches (pid), "pid matches pid");
124static_assert (lwp.matches (pid), "lwp matches pid");
125static_assert (tid.matches (pid), "tid matches pid");
126static_assert (both.matches (pid), "both matches pid");
127static_assert (!ptid_t (2, 0, 0).matches (pid), "other pid doesn't match pid");
128static_assert (!ptid_t (2, 2, 0).matches (pid), "other lwp doesn't match pid");
129static_assert (!ptid_t (2, 0, 2).matches (pid), "other tid doesn't match pid");
130static_assert (!ptid_t (2, 2, 2).matches (pid), "other both doesn't match pid");
131
132/* Verify matches against exact matches. */
133
134static_assert (!pid.matches (lwp), "pid doesn't match lwp");
135static_assert (lwp.matches (lwp), "lwp matches lwp");
136static_assert (!tid.matches (lwp), "tid doesn't match lwp");
137static_assert (!both.matches (lwp), "both doesn't match lwp");
138static_assert (!ptid_t (2, 2, 0).matches (lwp), "other lwp doesn't match lwp");
139
140static_assert (!pid.matches (tid), "pid doesn't match tid");
141static_assert (!lwp.matches (tid), "lwp doesn't match tid");
142static_assert (tid.matches (tid), "tid matches tid");
143static_assert (!both.matches (tid), "both doesn't match tid");
144static_assert (!ptid_t (2, 0, 2).matches (tid), "other tid doesn't match tid");
145
146static_assert (!pid.matches (both), "pid doesn't match both");
147static_assert (!lwp.matches (both), "lwp doesn't match both");
148static_assert (!tid.matches (both), "tid doesn't match both");
149static_assert (both.matches (both), "both matches both");
150static_assert (!ptid_t (2, 2, 2).matches (both),
151 "other both doesn't match both");
152
153
154} /* namespace ptid */
155} /* namespace selftests */
static constexpr ptid_t both
static constexpr ptid_t minus_one
static constexpr ptid_t tid
static constexpr ptid_t pid
static constexpr ptid_t lwp
static constexpr ptid_t null
int value
Definition py-param.c:79