Debian Codegraph @

storage/perfschema/unittest/pfs_instr_class-t.cc

raw symbols SCIP
1 /* Copyright (c) 2008, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #include <string.h> // strncpy
25
26 #include "my_thread.h"
27 #include "storage/perfschema/pfs_global.h"
28 #include "storage/perfschema/pfs_instr.h"
29 #include "storage/perfschema/pfs_instr_class.h"
30 #include "storage/perfschema/unittest/stub_digest.h"
31 #include "storage/perfschema/unittest/stub_pfs_plugin_table.h"
32 #include "storage/perfschema/unittest/stub_pfs_tls_channel.h"
33 #include "storage/perfschema/unittest/stub_server_telemetry.h"
34 #include "unittest/mytap/tap.h"
35
36 static void test_no_registration() {
37 int rc;
38 PFS_sync_key key;
39 PFS_thread_key thread_key;
40 PFS_file_key file_key;
41 PFS_socket_key socket_key;
42 PFS_memory_key memory_key;
43 PFS_mutex_class *mutex;
44 PFS_rwlock_class *rwlock;
45 PFS_cond_class *cond;
46 PFS_thread_class *thread;
47 PFS_file_class *file;
48 PFS_socket_class *socket;
49 PFS_memory_class *memory;
50 /* PFS_table_share *table; */
51
52 rc = init_sync_class(0, 0, 0);
53 ok(rc == 0, "zero init (sync)");
54 rc = init_thread_class(0);
55 ok(rc == 0, "zero init (thread)");
56 rc = init_file_class(0);
57 ok(rc == 0, "zero init (file)");
58 rc = init_socket_class(0);
59 ok(rc == 0, "zero init (socket)");
60 rc = init_table_share(0);
61 ok(rc == 0, "zero init (table)");
62 rc = init_memory_class(0);
63 ok(rc == 0, "zero init (memory)");
64
65 PSI_mutex_info_v1 mutex_info;
66 memset(&mutex_info, 0, sizeof(mutex_info));
67
68 PSI_rwlock_info_v1 rwlock_info;
69 memset(&rwlock_info, 0, sizeof(rwlock_info));
70
71 PSI_cond_info_v1 cond_info;
72 memset(&cond_info, 0, sizeof(cond_info));
73
74 PSI_thread_info_v5 thread_info;
75 memset(&thread_info, 0, sizeof(thread_info));
76 thread_info.m_os_name = "OS_NAME";
77
78 PSI_file_info_v1 file_info;
79 memset(&file_info, 0, sizeof(file_info));
80
81 PSI_socket_info_v1 socket_info;
82 memset(&socket_info, 0, sizeof(socket_info));
83
84 PSI_memory_info_v1 memory_info;
85 memset(&memory_info, 0, sizeof(memory_info));
86
87 key = register_mutex_class("FOO", 3, &mutex_info);
88 ok(key == 0, "no mutex registered");
89 key = register_mutex_class("BAR", 3, &mutex_info);
90 ok(key == 0, "no mutex registered");
91 key = register_mutex_class("FOO", 3, &mutex_info);
92 ok(key == 0, "no mutex registered");
93
94 key = register_rwlock_class("FOO", 3, &rwlock_info);
95 ok(key == 0, "no rwlock registered");
96 key = register_rwlock_class("BAR", 3, &rwlock_info);
97 ok(key == 0, "no rwlock registered");
98 key = register_rwlock_class("FOO", 3, &rwlock_info);
99 ok(key == 0, "no rwlock registered");
100
101 key = register_cond_class("FOO", 3, &cond_info);
102 ok(key == 0, "no cond registered");
103 key = register_cond_class("BAR", 3, &cond_info);
104 ok(key == 0, "no cond registered");
105 key = register_cond_class("FOO", 3, &cond_info);
106 ok(key == 0, "no cond registered");
107
108 thread_key = register_thread_class("FOO", 3, &thread_info);
109 ok(thread_key == 0, "no thread registered");
110 thread_key = register_thread_class("BAR", 3, &thread_info);
111 ok(thread_key == 0, "no thread registered");
112 thread_key = register_thread_class("FOO", 3, &thread_info);
113 ok(thread_key == 0, "no thread registered");
114
115 file_key = register_file_class("FOO", 3, &file_info);
116 ok(file_key == 0, "no file registered");
117 file_key = register_file_class("BAR", 3, &file_info);
118 ok(file_key == 0, "no file registered");
119 file_key = register_file_class("FOO", 3, &file_info);
120 ok(file_key == 0, "no file registered");
121
122 socket_key = register_socket_class("FOO", 3, &socket_info);
123 ok(socket_key == 0, "no socket registered");
124 socket_key = register_socket_class("BAR", 3, &socket_info);
125 ok(socket_key == 0, "no socket registered");
126 socket_key = register_socket_class("FOO", 3, &socket_info);
127 ok(socket_key == 0, "no socket registered");
128
129 memory_key = register_memory_class("FOO", 3, &memory_info);
130 ok(memory_key == 0, "no memory registered");
131 memory_key = register_memory_class("BAR", 3, &memory_info);
132 ok(memory_key == 0, "no memory registered");
133 memory_key = register_memory_class("FOO", 3, &memory_info);
134 ok(memory_key == 0, "no memory registered");
135
136 #ifdef LATER
137 PFS_thread fake_thread;
138 fake_thread.m_table_share_hash_pins = NULL;
139
140 table = find_or_create_table_share(&fake_thread, false, "foo_db", 6,
141 "foo_table", 9);
142 ok(table == NULL, "not created");
143 table = find_or_create_table_share(&fake_thread, false, "bar_db", 6,
144 "bar_table", 9);
145 ok(table == NULL, "not created");
146 table = find_or_create_table_share(&fake_thread, false, "foo_db", 6,
147 "foo_table", 9);
148 ok(table == NULL, "not created");
149 #endif
150
151 mutex = find_mutex_class(0);
152 ok(mutex == nullptr, "no mutex key 0");
153 mutex = find_mutex_class(1);
154 ok(mutex == nullptr, "no mutex key 1");
155 mutex = find_mutex_class(9999);
156 ok(mutex == nullptr, "no mutex key 9999");
157
158 rwlock = find_rwlock_class(0);
159 ok(rwlock == nullptr, "no rwlock key 0");
160 rwlock = find_rwlock_class(1);
161 ok(rwlock == nullptr, "no rwlock key 1");
162 rwlock = find_rwlock_class(9999);
163 ok(rwlock == nullptr, "no rwlock key 9999");
164
165 cond = find_cond_class(0);
166 ok(cond == nullptr, "no cond key 0");
167 cond = find_cond_class(1);
168 ok(cond == nullptr, "no cond key 1");
169 cond = find_cond_class(9999);
170 ok(cond == nullptr, "no cond key 9999");
171
172 thread = find_thread_class(0);
173 ok(thread == nullptr, "no thread key 0");
174 thread = find_thread_class(1);
175 ok(thread == nullptr, "no thread key 1");
176 thread = find_thread_class(9999);
177 ok(thread == nullptr, "no thread key 9999");
178
179 file = find_file_class(0);
180 ok(file == nullptr, "no file key 0");
181 file = find_file_class(1);
182 ok(file == nullptr, "no file key 1");
183 file = find_file_class(9999);
184 ok(file == nullptr, "no file key 9999");
185
186 socket = find_socket_class(0);
187 ok(socket == nullptr, "no socket key 0");
188 socket = find_socket_class(1);
189 ok(socket == nullptr, "no socket key 1");
190 socket = find_socket_class(9999);
191 ok(socket == nullptr, "no socket key 9999");
192
193 memory = find_memory_class(0);
194 ok(memory == nullptr, "no memory key 0");
195 memory = find_memory_class(1);
196 ok(memory == nullptr, "no memory key 1");
197 memory = find_memory_class(9999);
198 ok(memory == nullptr, "no memory key 9999");
199
200 cleanup_sync_class();
201 cleanup_thread_class();
202 cleanup_file_class();
203 cleanup_socket_class();
204 cleanup_table_share();
205 cleanup_memory_class();
206 }
207
208 static void test_mutex_registration() {
209 int rc;
210 PFS_sync_key key;
211 PFS_mutex_class *mutex;
212 PSI_mutex_info_v1 mutex_info;
213 memset(&mutex_info, 0, sizeof(mutex_info));
214
215 rc = init_sync_class(5, 0, 0);
216 ok(rc == 0, "room for 5 mutex");
217
218 key = register_mutex_class("FOO", 3, &mutex_info);
219 ok(key == 1, "foo registered");
220 key = register_mutex_class("BAR", 3, &mutex_info);
221 ok(key == 2, "bar registered");
222 key = register_mutex_class("FOO", 3, &mutex_info);
223 ok(key == 1, "foo re registered");
224 key = register_mutex_class("M-3", 3, &mutex_info);
225 ok(key == 3, "M-3 registered");
226 key = register_mutex_class("M-4", 3, &mutex_info);
227 ok(key == 4, "M-4 registered");
228 key = register_mutex_class("M-5", 3, &mutex_info);
229 ok(key == 5, "M-5 registered");
230 ok(mutex_class_lost == 0, "lost nothing");
231 key = register_mutex_class("M-6", 3, &mutex_info);
232 ok(key == 0, "M-6 not registered");
233 ok(mutex_class_lost == 1, "lost 1 mutex");
234 key = register_mutex_class("M-7", 3, &mutex_info);
235 ok(key == 0, "M-7 not registered");
236 ok(mutex_class_lost == 2, "lost 2 mutex");
237 key = register_mutex_class("M-3", 3, &mutex_info);
238 ok(key == 3, "M-3 re registered");
239 ok(mutex_class_lost == 2, "lost 2 mutex");
240 key = register_mutex_class("M-5", 3, &mutex_info);
241 ok(key == 5, "M-5 re registered");
242 ok(mutex_class_lost == 2, "lost 2 mutex");
243
244 mutex = find_mutex_class(0);
245 ok(mutex == nullptr, "no key 0");
246 mutex = find_mutex_class(3);
247 ok(mutex != nullptr, "found key 3");
248 ok(strncmp(mutex->m_name.str(), "M-3", 3) == 0, "key 3 is M-3");
249 ok(mutex->m_name.length() == 3, "name length 3");
250 mutex = find_mutex_class(9999);
251 ok(mutex == nullptr, "no key 9999");
252
253 cleanup_sync_class();
254 }
255
256 static void test_rwlock_registration() {
257 int rc;
258 PFS_sync_key key;
259 PFS_rwlock_class *rwlock;
260 PSI_rwlock_info_v1 rwlock_info;
261 memset(&rwlock_info, 0, sizeof(rwlock_info));
262
263 rc = init_sync_class(0, 5, 0);
264 ok(rc == 0, "room for 5 rwlock");
265
266 key = register_rwlock_class("FOO", 3, &rwlock_info);
267 ok(key == 1, "foo registered");
268 key = register_rwlock_class("BAR", 3, &rwlock_info);
269 ok(key == 2, "bar registered");
270 key = register_rwlock_class("FOO", 3, &rwlock_info);
271 ok(key == 1, "foo re registered");
272 key = register_rwlock_class("RW-3", 4, &rwlock_info);
273 ok(key == 3, "RW-3 registered");
274 key = register_rwlock_class("RW-4", 4, &rwlock_info);
275 ok(key == 4, "RW-4 registered");
276 key = register_rwlock_class("RW-5", 4, &rwlock_info);
277 ok(key == 5, "RW-5 registered");
278 key = register_rwlock_class("RW-6", 4, &rwlock_info);
279 ok(key == 0, "RW-6 not registered");
280 key = register_rwlock_class("RW-7", 4, &rwlock_info);
281 ok(key == 0, "RW-7 not registered");
282 key = register_rwlock_class("RW-3", 4, &rwlock_info);
283 ok(key == 3, "RW-3 re registered");
284 key = register_rwlock_class("RW-5", 4, &rwlock_info);
285 ok(key == 5, "RW-5 re registered");
286
287 rwlock = find_rwlock_class(0);
288 ok(rwlock == nullptr, "no key 0");
289 rwlock = find_rwlock_class(3);
290 ok(rwlock != nullptr, "found key 3");
291 ok(strncmp(rwlock->m_name.str(), "RW-3", 4) == 0, "key 3 is RW-3");
292 ok(rwlock->m_name.length() == 4, "name length 4");
293 rwlock = find_rwlock_class(9999);
294 ok(rwlock == nullptr, "no key 9999");
295
296 cleanup_sync_class();
297 }
298
299 static void test_cond_registration() {
300 int rc;
301 PFS_sync_key key;
302 PFS_cond_class *cond;
303 PSI_cond_info_v1 cond_info;
304 memset(&cond_info, 0, sizeof(cond_info));
305
306 rc = init_sync_class(0, 0, 5);
307 ok(rc == 0, "room for 5 cond");
308
309 key = register_cond_class("FOO", 3, &cond_info);
310 ok(key == 1, "foo registered");
311 key = register_cond_class("BAR", 3, &cond_info);
312 ok(key == 2, "bar registered");
313 key = register_cond_class("FOO", 3, &cond_info);
314 ok(key == 1, "foo re registered");
315 key = register_cond_class("C-3", 3, &cond_info);
316 ok(key == 3, "C-3 registered");
317 key = register_cond_class("C-4", 3, &cond_info);
318 ok(key == 4, "C-4 registered");
319 key = register_cond_class("C-5", 3, &cond_info);
320 ok(key == 5, "C-5 registered");
321 key = register_cond_class("C-6", 3, &cond_info);
322 ok(key == 0, "C-6 not registered");
323 key = register_cond_class("C-7", 3, &cond_info);
324 ok(key == 0, "C-7 not registered");
325 key = register_cond_class("C-3", 3, &cond_info);
326 ok(key == 3, "C-3 re registered");
327 key = register_cond_class("C-5", 3, &cond_info);
328 ok(key == 5, "C-5 re registered");
329
330 cond = find_cond_class(0);
331 ok(cond == nullptr, "no key 0");
332 cond = find_cond_class(3);
333 ok(cond != nullptr, "found key 3");
334 ok(strncmp(cond->m_name.str(), "C-3", 3) == 0, "key 3 is C-3");
335 ok(cond->m_name.length() == 3, "name length 3");
336 cond = find_cond_class(9999);
337 ok(cond == nullptr, "no key 9999");
338
339 cleanup_sync_class();
340 }
341
342 static void test_thread_registration() {
343 int rc;
344 PFS_thread_key key;
345 PFS_thread_class *thread;
346 PSI_thread_info_v5 thread_info;
347 memset(&thread_info, 0, sizeof(thread_info));
348 thread_info.m_os_name = "OS_NAME";
349
350 rc = init_thread_class(5);
351 ok(rc == 0, "room for 5 thread");
352
353 key = register_thread_class("FOO", 3, &thread_info);
354 ok(key == 1, "foo registered");
355 key = register_thread_class("BAR", 3, &thread_info);
356 ok(key == 2, "bar registered");
357 key = register_thread_class("FOO", 3, &thread_info);
358 ok(key == 1, "foo re registered");
359 key = register_thread_class("Thread-3", 8, &thread_info);
360 ok(key == 3, "Thread-3 registered");
361 key = register_thread_class("Thread-4", 8, &thread_info);
362 ok(key == 4, "Thread-4 registered");
363 key = register_thread_class("Thread-5", 8, &thread_info);
364 ok(key == 5, "Thread-5 registered");
365 key = register_thread_class("Thread-6", 8, &thread_info);
366 ok(key == 0, "Thread-6 not registered");
367 key = register_thread_class("Thread-7", 8, &thread_info);
368 ok(key == 0, "Thread-7 not registered");
369 key = register_thread_class("Thread-3", 8, &thread_info);
370 ok(key == 3, "Thread-3 re registered");
371 key = register_thread_class("Thread-5", 8, &thread_info);
372 ok(key == 5, "Thread-5 re registered");
373
374 thread = find_thread_class(0);
375 ok(thread == nullptr, "no key 0");
376 thread = find_thread_class(3);
377 ok(thread != nullptr, "found key 3");
378 ok(strncmp(thread->m_name.str(), "Thread-3", 8) == 0, "key 3 is Thread-3");
379 ok(thread->m_name.length() == 8, "name length 8");
380 thread = find_thread_class(9999);
381 ok(thread == nullptr, "no key 9999");
382
383 cleanup_thread_class();
384 }
385
386 static void test_file_registration() {
387 int rc;
388 PFS_file_key key;
389 PFS_file_class *file;
390 PSI_file_info_v1 file_info;
391 memset(&file_info, 0, sizeof(file_info));
392
393 rc = init_file_class(5);
394 ok(rc == 0, "room for 5 file");
395
396 key = register_file_class("FOO", 3, &file_info);
397 ok(key == 1, "foo registered");
398 key = register_file_class("BAR", 3, &file_info);
399 ok(key == 2, "bar registered");
400 key = register_file_class("FOO", 3, &file_info);
401 ok(key == 1, "foo re registered");
402 key = register_file_class("File-3", 6, &file_info);
403 ok(key == 3, "File-3 registered");
404 key = register_file_class("File-4", 6, &file_info);
405 ok(key == 4, "File-4 registered");
406 key = register_file_class("File-5", 6, &file_info);
407 ok(key == 5, "File-5 registered");
408 key = register_file_class("File-6", 6, &file_info);
409 ok(key == 0, "File-6 not registered");
410 key = register_file_class("File-7", 6, &file_info);
411 ok(key == 0, "File-7 not registered");
412 key = register_file_class("File-3", 6, &file_info);
413 ok(key == 3, "File-3 re registered");
414 key = register_file_class("File-5", 6, &file_info);
415 ok(key == 5, "File-5 re registered");
416
417 file = find_file_class(0);
418 ok(file == nullptr, "no key 0");
419 file = find_file_class(3);
420 ok(file != nullptr, "found key 3");
421 ok(strncmp(file->m_name.str(), "File-3", 6) == 0, "key 3 is File-3");
422 ok(file->m_name.length() == 6, "name length 6");
423 file = find_file_class(9999);
424 ok(file == nullptr, "no key 9999");
425
426 cleanup_file_class();
427 }
428
429 static void test_socket_registration() {
430 int rc;
431 PFS_socket_key key;
432 PFS_socket_class *socket;
433 PSI_socket_info_v1 socket_info;
434 memset(&socket_info, 0, sizeof(socket_info));
435
436 rc = init_socket_class(5);
437 ok(rc == 0, "room for 5 socket");
438
439 key = register_socket_class("FOO", 3, &socket_info);
440 ok(key == 1, "foo registered");
441 key = register_socket_class("BAR", 3, &socket_info);
442 ok(key == 2, "bar registered");
443 key = register_socket_class("FOO", 3, &socket_info);
444 ok(key == 1, "foo re registered");
445 key = register_socket_class("Socket-3", 8, &socket_info);
446 ok(key == 3, "Socket-3 registered");
447 key = register_socket_class("Socket-4", 8, &socket_info);
448 ok(key == 4, "Socket-4 registered");
449 key = register_socket_class("Socket-5", 8, &socket_info);
450 ok(key == 5, "Socket-5 registered");
451 ok(socket_class_lost == 0, "lost nothing");
452 key = register_socket_class("Socket-6", 8, &socket_info);
453 ok(key == 0, "Socket-6 not registered");
454 ok(socket_class_lost == 1, "lost 1 socket");
455 key = register_socket_class("Socket-7", 8, &socket_info);
456 ok(key == 0, "Socket-7 not registered");
457 ok(socket_class_lost == 2, "lost 2 socket");
458 key = register_socket_class("Socket-3", 8, &socket_info);
459 ok(key == 3, "Socket-3 re registered");
460 ok(socket_class_lost == 2, "lost 2 socket");
461 key = register_socket_class("Socket-5", 8, &socket_info);
462 ok(key == 5, "Socket-5 re registered");
463 ok(socket_class_lost == 2, "lost 2 socket");
464
465 socket = find_socket_class(0);
466 ok(socket == nullptr, "no key 0");
467 socket = find_socket_class(3);
468 ok(socket != nullptr, "found key 3");
469 ok(strncmp(socket->m_name.str(), "Socket-3", 8) == 0, "key 3 is Socket-3");
470 ok(socket->m_name.length() == 8, "name length 3");
471 socket = find_socket_class(9999);
472 ok(socket == nullptr, "no key 9999");
473
474 cleanup_socket_class();
475 }
476
477 static void test_table_registration() {
478 #ifdef LATER
479 PFS_table_share *table_share;
480 PFS_table_share *table_share_2;
481
482 PFS_thread fake_thread;
483 fake_thread.m_table_share_hash_pins = NULL;
484
485 table_share_lost = 0;
486 table_share =
487 find_or_create_table_share(&fake_thread, false, "db1", 3, "t1", 2);
488 ok(table_share == NULL, "not created");
489 ok(table_share_lost == 1, "lost the table");
490
491 table_share_lost = 0;
492 init_table_share(5);
493 init_table_share_hash();
494
495 table_share =
496 find_or_create_table_share(&fake_thread, false, "db1", 3, "t1", 2);
497 ok(table_share != NULL, "created db1.t1");
498 ok(table_share_lost == 0, "not lost");
499
500 table_share_2 =
501 find_or_create_table_share(&fake_thread, false, "db1", 3, "t1", 2);
502 ok(table_share_2 != NULL, "found db1.t1");
503 ok(table_share_lost == 0, "not lost");
504 ok(table_share == table_share_2, "same table");
505
506 table_share_2 =
507 find_or_create_table_share(&fake_thread, false, "db1", 3, "t2", 2);
508 ok(table_share_2 != NULL, "created db1.t2");
509 ok(table_share_lost == 0, "not lost");
510
511 table_share_2 =
512 find_or_create_table_share(&fake_thread, false, "db2", 3, "t1", 2);
513 ok(table_share_2 != NULL, "created db2.t1");
514 ok(table_share_lost == 0, "not lost");
515
516 table_share_2 =
517 find_or_create_table_share(&fake_thread, false, "db2", 3, "t2", 2);
518 ok(table_share_2 != NULL, "created db2.t2");
519 ok(table_share_lost == 0, "not lost");
520
521 table_share_2 =
522 find_or_create_table_share(&fake_thread, false, "db3", 3, "t3", 2);
523 ok(table_share_2 != NULL, "created db3.t3");
524 ok(table_share_lost == 0, "not lost");
525
526 table_share_2 =
527 find_or_create_table_share(&fake_thread, false, "db4", 3, "t4", 2);
528 ok(table_share_2 == NULL, "lost db4.t4");
529 ok(table_share_lost == 1, "lost");
530
531 table_share_lost = 0;
532 table_share_2 =
533 find_or_create_table_share(&fake_thread, false, "db1", 3, "t2", 2);
534 ok(table_share_2 != NULL, "found db1.t2");
535 ok(table_share_lost == 0, "not lost");
536 ok(strncmp(table_share_2->m_schema_name, "db1", 3) == 0, "schema db1");
537 ok(table_share_2->m_schema_name_length == 3, "length 3");
538 ok(strncmp(table_share_2->m_table_name, "t2", 2) == 0, "table t2");
539 ok(table_share_2->m_table_name_length == 2, "length 2");
540
541 cleanup_table_share_hash();
542 cleanup_table_share();
543 #endif
544 }
545
546 static void test_memory_registration() {
547 int rc;
548 PFS_memory_key key;
549 PFS_memory_class *memory;
550 PSI_memory_info_v1 memory_info;
551 memset(&memory_info, 0, sizeof(memory_info));
552
553 rc = init_memory_class(5);
554 ok(rc == 0, "room for 5 memory");
555
556 key = register_memory_class("FOO", 3, &memory_info);
557 ok(key == 1, "foo registered");
558 key = register_memory_class("BAR", 3, &memory_info);
559 ok(key == 2, "bar registered");
560 key = register_memory_class("FOO", 3, &memory_info);
561 ok(key == 1, "foo re registered");
562 key = register_memory_class("Memory-3", 8, &memory_info);
563 ok(key == 3, "Memory-3 registered");
564 key = register_memory_class("Memory-4", 8, &memory_info);
565 ok(key == 4, "Memory-4 registered");
566 key = register_memory_class("Memory-5", 8, &memory_info);
567 ok(key == 5, "Memory-5 registered");
568 ok(memory_class_lost == 0, "lost nothing");
569 key = register_memory_class("Memory-6", 8, &memory_info);
570 ok(key == 0, "Memory-6 not registered");
571 ok(memory_class_lost == 1, "lost 1 memory");
572 key = register_memory_class("Memory-7", 8, &memory_info);
573 ok(key == 0, "Memory-7 not registered");
574 ok(memory_class_lost == 2, "lost 2 memory");
575 key = register_memory_class("Memory-3", 8, &memory_info);
576 ok(key == 3, "Memory-3 re registered");
577 ok(memory_class_lost == 2, "lost 2 memory");
578 key = register_memory_class("Memory-5", 8, &memory_info);
579 ok(key == 5, "Memory-5 re registered");
580 ok(memory_class_lost == 2, "lost 2 memory");
581
582 memory = find_memory_class(0);
583 ok(memory == nullptr, "no key 0");
584 memory = find_memory_class(3);
585 ok(memory != nullptr, "found key 3");
586 ok(strncmp(memory->m_name.str(), "Memory-3", 8) == 0, "key 3 is Memory-3");
587 ok(memory->m_name.length() == 8, "name length 3");
588 memory = find_memory_class(9999);
589 ok(memory == nullptr, "no key 9999");
590
591 cleanup_memory_class();
592 }
593
594 #ifdef LATER
595 void set_wait_stat(PFS_instr_class *klass) {
596 PFS_single_stat *stat;
597 stat = &global_instr_class_waits_array[klass->m_event_name_index];
598
599 stat->m_count = 12;
600 stat->m_min = 5;
601 stat->m_max = 120;
602 stat->m_sum = 999;
603 }
604
605 bool is_empty_stat(PFS_instr_class *klass) {
606 PFS_single_stat *stat;
607 stat = &global_instr_class_waits_array[klass->m_event_name_index];
608
609 if (stat->m_count != 0) return false;
610 if (stat->m_min != (ulonglong)-1) return false;
611 if (stat->m_max != 0) return false;
612 if (stat->m_sum != 0) return false;
613 return true;
614 }
615 #endif
616
617 static void test_instruments_reset() {
618 int rc;
619 PFS_sync_key key;
620 PFS_file_key file_key;
621 PFS_socket_key socket_key;
622 PFS_mutex_class *mutex_1;
623 PFS_mutex_class *mutex_2;
624 PFS_mutex_class *mutex_3;
625 PFS_rwlock_class *rwlock_1;
626 PFS_rwlock_class *rwlock_2;
627 PFS_rwlock_class *rwlock_3;
628 PFS_cond_class *cond_1;
629 PFS_cond_class *cond_2;
630 PFS_cond_class *cond_3;
631 PFS_file_class *file_1;
632 PFS_file_class *file_2;
633 PFS_file_class *file_3;
634 PFS_socket_class *socket_1;
635 PFS_socket_class *socket_2;
636 PFS_socket_class *socket_3;
637
638 rc = init_sync_class(3, 3, 3);
639 ok(rc == 0, "init (sync)");
640 rc = init_thread_class(3);
641 ok(rc == 0, "init (thread)");
642 rc = init_file_class(3);
643 ok(rc == 0, "init (file)");
644 rc = init_socket_class(3);
645 ok(rc == 0, "init (socket)");
646
647 PSI_mutex_info_v1 mutex_info;
648 memset(&mutex_info, 0, sizeof(mutex_info));
649
650 PSI_rwlock_info_v1 rwlock_info;
651 memset(&rwlock_info, 0, sizeof(rwlock_info));
652
653 PSI_cond_info_v1 cond_info;
654 memset(&cond_info, 0, sizeof(cond_info));
655
656 PSI_file_info_v1 file_info;
657 memset(&file_info, 0, sizeof(file_info));
658
659 PSI_socket_info_v1 socket_info;
660 memset(&socket_info, 0, sizeof(socket_info));
661
662 key = register_mutex_class("M-1", 3, &mutex_info);
663 ok(key == 1, "mutex registered");
664 key = register_mutex_class("M-2", 3, &mutex_info);
665 ok(key == 2, "mutex registered");
666 key = register_mutex_class("M-3", 3, &mutex_info);
667 ok(key == 3, "mutex registered");
668
669 key = register_rwlock_class("RW-1", 4, &rwlock_info);
670 ok(key == 1, "rwlock registered");
671 key = register_rwlock_class("RW-2", 4, &rwlock_info);
672 ok(key == 2, "rwlock registered");
673 key = register_rwlock_class("RW-3", 4, &rwlock_info);
674 ok(key == 3, "rwlock registered");
675
676 key = register_cond_class("C-1", 3, &cond_info);
677 ok(key == 1, "cond registered");
678 key = register_cond_class("C-2", 3, &cond_info);
679 ok(key == 2, "cond registered");
680 key = register_cond_class("C-3", 3, &cond_info);
681 ok(key == 3, "cond registered");
682
683 file_key = register_file_class("F-1", 3, &file_info);
684 ok(file_key == 1, "file registered");
685 file_key = register_file_class("F-2", 3, &file_info);
686 ok(file_key == 2, "file registered");
687 file_key = register_file_class("F-3", 3, &file_info);
688 ok(file_key == 3, "file registered");
689
690 socket_key = register_socket_class("S-1", 3, &socket_info);
691 ok(socket_key == 1, "socket registered");
692 socket_key = register_socket_class("S-2", 3, &socket_info);
693 ok(socket_key == 2, "socket registered");
694 socket_key = register_socket_class("S-3", 3, &socket_info);
695 ok(socket_key == 3, "socket registered");
696
697 mutex_1 = find_mutex_class(1);
698 ok(mutex_1 != nullptr, "mutex key 1");
699 mutex_2 = find_mutex_class(2);
700 ok(mutex_2 != nullptr, "mutex key 2");
701 mutex_3 = find_mutex_class(3);
702 ok(mutex_3 != nullptr, "mutex key 3");
703
704 rwlock_1 = find_rwlock_class(1);
705 ok(rwlock_1 != nullptr, "rwlock key 1");
706 rwlock_2 = find_rwlock_class(2);
707 ok(rwlock_2 != nullptr, "rwlock key 2");
708 rwlock_3 = find_rwlock_class(3);
709 ok(rwlock_3 != nullptr, "rwlock key 3");
710
711 cond_1 = find_cond_class(1);
712 ok(cond_1 != nullptr, "cond key 1");
713 cond_2 = find_cond_class(2);
714 ok(cond_2 != nullptr, "cond key 2");
715 cond_3 = find_cond_class(3);
716 ok(cond_3 != nullptr, "cond key 3");
717
718 file_1 = find_file_class(1);
719 ok(file_1 != nullptr, "file key 1");
720 file_2 = find_file_class(2);
721 ok(file_2 != nullptr, "file key 2");
722 file_3 = find_file_class(3);
723 ok(file_3 != nullptr, "file key 3");
724
725 socket_1 = find_socket_class(1);
726 ok(socket_1 != nullptr, "socket key 1");
727 socket_2 = find_socket_class(2);
728 ok(socket_2 != nullptr, "socket key 2");
729 socket_3 = find_socket_class(3);
730 ok(socket_3 != nullptr, "socket key 3");
731
732 #ifdef LATER
733 set_wait_stat(mutex_1);
734 set_wait_stat(mutex_2);
735 set_wait_stat(mutex_3);
736 set_wait_stat(rwlock_1);
737 set_wait_stat(rwlock_2);
738 set_wait_stat(rwlock_3);
739 set_wait_stat(cond_1);
740 set_wait_stat(cond_2);
741 set_wait_stat(cond_3);
742 set_wait_stat(file_1);
743 set_wait_stat(file_2);
744 set_wait_stat(file_3);
745
746 ok(!is_empty_stat(mutex_1), "mutex_1 stat is populated");
747 ok(!is_empty_stat(mutex_2), "mutex_2 stat is populated");
748 ok(!is_empty_stat(mutex_3), "mutex_3 stat is populated");
749 ok(!is_empty_stat(rwlock_1), "rwlock_1 stat is populated");
750 ok(!is_empty_stat(rwlock_2), "rwlock_2 stat is populated");
751 ok(!is_empty_stat(rwlock_3), "rwlock_3 stat is populated");
752 ok(!is_empty_stat(cond_1), "cond_1 stat is populated");
753 ok(!is_empty_stat(cond_2), "cond_2 stat is populated");
754 ok(!is_empty_stat(cond_3), "cond_3 stat is populated");
755 ok(!is_empty_stat(file_1), "file_1 stat is populated");
756 ok(!is_empty_stat(file_2), "file_2 stat is populated");
757 ok(!is_empty_stat(file_3), "file_3 stat is populated");
758
759 reset_global_wait_stat();
760
761 ok(is_empty_stat(mutex_1), "mutex_1 stat is cleared");
762 ok(is_empty_stat(mutex_2), "mutex_2 stat is cleared");
763 ok(is_empty_stat(mutex_3), "mutex_3 stat is cleared");
764 ok(is_empty_stat(rwlock_1), "rwlock_1 stat is cleared");
765 ok(is_empty_stat(rwlock_2), "rwlock_2 stat is cleared");
766 ok(is_empty_stat(rwlock_3), "rwlock_3 stat is cleared");
767 ok(is_empty_stat(cond_1), "cond_1 stat is cleared");
768 ok(is_empty_stat(cond_2), "cond_2 stat is cleared");
769 ok(is_empty_stat(cond_3), "cond_3 stat is cleared");
770 ok(is_empty_stat(file_1), "file_1 stat is cleared");
771 ok(is_empty_stat(file_2), "file_2 stat is cleared");
772 ok(is_empty_stat(file_3), "file_3 stat is cleared");
773 #endif
774
775 cleanup_sync_class();
776 cleanup_file_class();
777 cleanup_socket_class();
778 }
779
780 static void do_all_tests() {
781 test_no_registration();
782 test_mutex_registration();
783 test_rwlock_registration();
784 test_cond_registration();
785 test_thread_registration();
786 test_file_registration();
787 test_socket_registration();
788 test_table_registration();
789 test_memory_registration();
790 test_instruments_reset();
791 }
792
793 int main(int, char **) {
794 plan(209);
795 MY_INIT("pfs_instr_info-t");
796 do_all_tests();
797 my_end(0);
798 return (exit_status());
799 }