Debian Codegraph @

storage/perfschema/unittest/pfs_host-oom-t.cc

raw symbols SCIP
1 /* Copyright (c) 2011, 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 "storage/perfschema/unittest/pfs_unit_test_conf.h"
25
26 #include <string.h> /* memset */
27
28 #include "my_thread.h"
29 #include "storage/perfschema/pfs_buffer_container.h"
30 #include "storage/perfschema/pfs_global.h"
31 #include "storage/perfschema/pfs_host.h"
32 #include "storage/perfschema/pfs_instr.h"
33 #include "storage/perfschema/pfs_stat.h"
34 #include "storage/perfschema/unittest/stub_digest.h"
35 #include "storage/perfschema/unittest/stub_pfs_global.h"
36 #include "storage/perfschema/unittest/stub_pfs_plugin_table.h"
37 #include "storage/perfschema/unittest/stub_pfs_tls_channel.h"
38 #include "storage/perfschema/unittest/stub_server_telemetry.h"
39 #include "unittest/mytap/tap.h"
40
41 extern struct PSI_bootstrap PFS_bootstrap;
42
43 static void test_oom() {
44 int rc;
45 PFS_global_param param;
46 PSI_thread_service_t *thread_service;
47 PSI_thread_bootstrap *thread_boot;
48 PSI_mutex_bootstrap *mutex_boot;
49 PSI_rwlock_bootstrap *rwlock_boot;
50 PSI_cond_bootstrap *cond_boot;
51 PSI_file_bootstrap *file_boot;
52 PSI_socket_bootstrap *socket_boot;
53 PSI_table_bootstrap *table_boot;
54 PSI_mdl_bootstrap *mdl_boot;
55 PSI_idle_bootstrap *idle_boot;
56 PSI_stage_bootstrap *stage_boot;
57 PSI_statement_bootstrap *statement_boot;
58 PSI_transaction_bootstrap *transaction_boot;
59 PSI_memory_bootstrap *memory_boot;
60 PSI_error_bootstrap *error_boot;
61 PSI_data_lock_bootstrap *data_lock_boot;
62 PSI_system_bootstrap *system_boot;
63 PSI_tls_channel_bootstrap *tls_channel_boot;
64
65 memset(&param, 0xFF, sizeof(param));
66 param.m_enabled = true;
67 param.m_mutex_class_sizing = 0;
68 param.m_rwlock_class_sizing = 0;
69 param.m_cond_class_sizing = 0;
70 param.m_thread_class_sizing = 10;
71 param.m_table_share_sizing = 0;
72 param.m_file_class_sizing = 0;
73 param.m_socket_class_sizing = 0;
74 param.m_mutex_sizing = 0;
75 param.m_rwlock_sizing = 0;
76 param.m_cond_sizing = 0;
77 param.m_thread_sizing = 1000;
78 param.m_table_sizing = 0;
79 param.m_file_sizing = 0;
80 param.m_file_handle_sizing = 0;
81 param.m_socket_sizing = 0;
82 param.m_events_waits_history_sizing = 10;
83 param.m_events_waits_history_long_sizing = 0;
84 param.m_setup_actor_sizing = 0;
85 param.m_setup_object_sizing = 0;
86 param.m_user_sizing = 0;
87 param.m_host_sizing = 1000;
88 param.m_account_sizing = 0;
89 param.m_stage_class_sizing = 50;
90 param.m_events_stages_history_sizing = 0;
91 param.m_events_stages_history_long_sizing = 0;
92 param.m_statement_class_sizing = 50;
93 param.m_events_statements_history_sizing = 0;
94 param.m_events_statements_history_long_sizing = 0;
95 param.m_events_transactions_history_sizing = 0;
96 param.m_events_transactions_history_long_sizing = 0;
97 param.m_digest_sizing = 0;
98 param.m_session_connect_attrs_sizing = 0;
99 param.m_program_sizing = 0;
100 param.m_statement_stack_sizing = 0;
101 param.m_memory_class_sizing = 10;
102 param.m_metadata_lock_sizing = 0;
103 param.m_max_digest_length = 0;
104 param.m_max_sql_text_length = 0;
105 param.m_error_sizing = 0;
106 param.m_consumer_events_stages_current_enabled = false;
107 param.m_consumer_events_stages_history_enabled = false;
108 param.m_consumer_events_stages_history_long_enabled = false;
109 param.m_consumer_events_statements_cpu_enabled = false;
110 param.m_consumer_events_statements_current_enabled = false;
111 param.m_consumer_events_statements_history_enabled = false;
112 param.m_consumer_events_statements_history_long_enabled = false;
113 param.m_consumer_events_transactions_current_enabled = false;
114 param.m_consumer_events_transactions_history_enabled = false;
115 param.m_consumer_events_transactions_history_long_enabled = false;
116 param.m_consumer_events_waits_current_enabled = false;
117 param.m_consumer_events_waits_history_enabled = false;
118 param.m_consumer_events_waits_history_long_enabled = false;
119 param.m_consumer_global_instrumentation_enabled = false;
120 param.m_consumer_thread_instrumentation_enabled = false;
121 param.m_consumer_statement_digest_enabled = false;
122
123 /* Setup */
124
125 stub_alloc_always_fails = false;
126 stub_alloc_fails_after_count = 1000;
127
128 pre_initialize_performance_schema();
129 rc = initialize_performance_schema(
130 &param, &thread_boot, &mutex_boot, &rwlock_boot, &cond_boot, &file_boot,
131 &socket_boot, &table_boot, &mdl_boot, &idle_boot, &stage_boot,
132 &statement_boot, &transaction_boot, &memory_boot, &error_boot,
133 &data_lock_boot, &system_boot, &tls_channel_boot);
134 ok(rc == 0, "init ok");
135 thread_service = (PSI_thread_service_t *)thread_boot->get_interface(
136 PSI_CURRENT_THREAD_VERSION);
137
138 PSI_thread_key thread_key_1;
139 PSI_thread_info all_thread[] = {{&thread_key_1, "T-1", "T-1", 0, 0, ""}};
140 thread_service->register_thread("test", all_thread, 1);
141
142 PSI_thread *thread_1 =
143 thread_service->new_thread(thread_key_1, 0, nullptr, 0);
144 thread_service->set_thread(thread_1);
145
146 /* Tests */
147
148 int first_fail = 1;
149 stub_alloc_fails_after_count = first_fail;
150 thread_service->set_thread_account("", 0, "host1", 5);
151 ok(global_host_container.m_lost == 1, "oom (host)");
152
153 stub_alloc_fails_after_count = first_fail + 1;
154 thread_service->set_thread_account("", 0, "host2", 5);
155 ok(global_host_container.m_lost == 2, "oom (host waits)");
156
157 stub_alloc_fails_after_count = first_fail + 2;
158 thread_service->set_thread_account("", 0, "host3", 5);
159 ok(global_host_container.m_lost == 3, "oom (host stages)");
160
161 stub_alloc_fails_after_count = first_fail + 3;
162 thread_service->set_thread_account("", 0, "host4", 5);
163 ok(global_host_container.m_lost == 4, "oom (host statements)");
164
165 stub_alloc_fails_after_count = first_fail + 4;
166 thread_service->set_thread_account("", 0, "host5", 5);
167 ok(global_host_container.m_lost == 5, "oom (host transactions)");
168
169 stub_alloc_fails_after_count = first_fail + 5;
170 thread_service->set_thread_account("", 0, "host6", 5);
171 ok(global_host_container.m_lost == 6, "oom (host memory)");
172
173 shutdown_performance_schema();
174 }
175
176 static void do_all_tests() { test_oom(); }
177
178 int main(int, char **) {
179 plan(7);
180 MY_INIT("pfs_host-oom-t");
181 do_all_tests();
182 my_end(0);
183 return (exit_status());
184 }