1 /* Copyright (c) 2011, 2021, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22
23 #include <my_global.h>
24 #include <my_thread.h>
25 #include <pfs_instr.h>
26 #include <pfs_stat.h>
27 #include <pfs_global.h>
28 #include <pfs_host.h>
29 #include <pfs_buffer_container.h>
30 #include <tap.h>
31
32 #include "stub_pfs_global.h"
33 #include "stub_global_status_var.h"
34
35 #include <string.h> /* memset */
36
37 extern struct PSI_bootstrap PFS_bootstrap;
38
test_oom()39 void test_oom()
40 {
41 PSI *psi;
42 PFS_global_param param;
43 PSI_bootstrap *boot;
44
45 memset(& param, 0xFF, sizeof(param));
46 param.m_enabled= true;
47 param.m_mutex_class_sizing= 0;
48 param.m_rwlock_class_sizing= 0;
49 param.m_cond_class_sizing= 0;
50 param.m_thread_class_sizing= 10;
51 param.m_table_share_sizing= 0;
52 param.m_file_class_sizing= 0;
53 param.m_socket_class_sizing= 0;
54 param.m_mutex_sizing= 0;
55 param.m_rwlock_sizing= 0;
56 param.m_cond_sizing= 0;
57 param.m_thread_sizing= 1000;
58 param.m_table_sizing= 0;
59 param.m_file_sizing= 0;
60 param.m_file_handle_sizing= 0;
61 param.m_socket_sizing= 0;
62 param.m_events_waits_history_sizing= 10;
63 param.m_events_waits_history_long_sizing= 0;
64 param.m_setup_actor_sizing= 0;
65 param.m_setup_object_sizing= 0;
66 param.m_user_sizing= 0;
67 param.m_host_sizing= 1000;
68 param.m_account_sizing= 0;
69 param.m_stage_class_sizing= 50;
70 param.m_events_stages_history_sizing= 0;
71 param.m_events_stages_history_long_sizing= 0;
72 param.m_statement_class_sizing= 50;
73 param.m_events_statements_history_sizing= 0;
74 param.m_events_statements_history_long_sizing= 0;
75 param.m_events_transactions_history_sizing= 0;
76 param.m_events_transactions_history_long_sizing= 0;
77 param.m_digest_sizing= 0;
78 param.m_session_connect_attrs_sizing= 0;
79 param.m_program_sizing= 0;
80 param.m_statement_stack_sizing= 0;
81 param.m_memory_class_sizing= 10;
82 param.m_metadata_lock_sizing= 0;
83 param.m_max_digest_length= 0;
84 param.m_max_sql_text_length= 0;
85
86 /* Setup */
87
88 stub_alloc_always_fails= false;
89 stub_alloc_fails_after_count= 1000;
90
91 pre_initialize_performance_schema();
92 boot= initialize_performance_schema(¶m);
93 psi= (PSI *)boot->get_interface(PSI_VERSION_1);
94
95 PSI_thread_key thread_key_1;
96 PSI_thread_info all_thread[]=
97 {
98 {&thread_key_1, "T-1", 0}
99 };
100 psi->register_thread("test", all_thread, 1);
101
102 PSI_thread *thread_1= psi->new_thread(thread_key_1, NULL, 0);
103 psi->set_thread(thread_1);
104
105 /* Tests */
106
107 int first_fail= 1;
108 stub_alloc_fails_after_count= first_fail;
109 psi->set_thread_account("", 0, "host1", 5);
110 ok(global_host_container.m_lost == 1, "oom (host)");
111
112 stub_alloc_fails_after_count= first_fail + 1;
113 psi->set_thread_account("", 0, "host2", 5);
114 ok(global_host_container.m_lost == 2, "oom (host waits)");
115
116 stub_alloc_fails_after_count= first_fail + 2;
117 psi->set_thread_account("", 0, "host3", 5);
118 ok(global_host_container.m_lost == 3, "oom (host stages)");
119
120 stub_alloc_fails_after_count= first_fail + 3;
121 psi->set_thread_account("", 0, "host4", 5);
122 ok(global_host_container.m_lost == 4, "oom (host statements)");
123
124 stub_alloc_fails_after_count= first_fail + 4;
125 psi->set_thread_account("", 0, "host5", 5);
126 ok(global_host_container.m_lost == 5, "oom (host transactions)");
127
128 stub_alloc_fails_after_count= first_fail + 5;
129 psi->set_thread_account("", 0, "host6", 5);
130 ok(global_host_container.m_lost == 6, "oom (host memory)");
131
132 shutdown_performance_schema();
133 }
134
do_all_tests()135 void do_all_tests()
136 {
137 test_oom();
138 }
139
main(int,char **)140 int main(int, char **)
141 {
142 plan(6);
143 MY_INIT("pfs_host-oom-t");
144 do_all_tests();
145 return (exit_status());
146 }
147
148