1 /* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
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, Fifth Floor, Boston, MA 02110-1335 USA */
22 
23 #include <my_global.h>
24 #include <my_pthread.h>
25 #include <pfs_instr.h>
26 #include <pfs_stat.h>
27 #include <pfs_global.h>
28 #include <pfs_user.h>
29 #include <tap.h>
30 
31 #include "stub_pfs_global.h"
32 
33 #include <string.h> /* memset */
34 
35 void test_oom()
36 {
37   int rc;
38   PFS_global_param param;
39 
40   memset(& param, 0xFF, sizeof(param));
41   param.m_enabled= true;
42   param.m_mutex_class_sizing= 0;
43   param.m_rwlock_class_sizing= 0;
44   param.m_cond_class_sizing= 0;
45   param.m_thread_class_sizing= 10;
46   param.m_table_share_sizing= 0;
47   param.m_file_class_sizing= 0;
48   param.m_mutex_sizing= 0;
49   param.m_rwlock_sizing= 0;
50   param.m_cond_sizing= 0;
51   param.m_thread_sizing= 1000;
52   param.m_table_sizing= 0;
53   param.m_file_sizing= 0;
54   param.m_file_handle_sizing= 0;
55   param.m_events_waits_history_sizing= 10;
getParameterId()56   param.m_events_waits_history_long_sizing= 0;
57   param.m_setup_actor_sizing= 0;
58   param.m_setup_object_sizing= 0;
59   param.m_host_sizing= 0;
60   param.m_user_sizing= 1000;
setParamID(ParamID pID)61   param.m_account_sizing= 0;
62   param.m_stage_class_sizing= 50;
63   param.m_events_stages_history_sizing= 0;
64   param.m_events_stages_history_long_sizing= 0;
65   param.m_statement_class_sizing= 50;
66   param.m_events_statements_history_sizing= 0;
67   param.m_events_statements_history_long_sizing= 0;
68 
69   /* Setup */
ParameterQueueValueParameterQueueValue70 
71   stub_alloc_always_fails= false;
72   stub_alloc_fails_after_count= 1000;
73 
74   init_event_name_sizing(& param);
75   rc= init_stage_class(param.m_stage_class_sizing);
76   ok(rc == 0, "init stage class");
77   rc= init_statement_class(param.m_statement_class_sizing);
78   ok(rc == 0, "init statement class");
79 
80   /* Tests */
81 
82   stub_alloc_fails_after_count= 1;
83   rc= init_user(& param);
84   ok(rc == 1, "oom (user)");
85   cleanup_user();
86 
87   stub_alloc_fails_after_count= 2;
88   rc= init_user(& param);
89   ok(rc == 1, "oom (user waits)");
90   cleanup_user();
91 
92   stub_alloc_fails_after_count= 3;
93   rc= init_user(& param);
94   ok(rc == 1, "oom (user stages)");
95   cleanup_user();
96 
97   stub_alloc_fails_after_count= 4;
98   rc= init_user(& param);
99   ok(rc == 1, "oom (user statements)");
100   cleanup_user();
101 
102   cleanup_statement_class();
103   cleanup_stage_class();
104 }
105 
106 void do_all_tests()
107 {
108   test_oom();
109 }
110 
111 int main(int, char **)
112 {
113   plan(6);
114   MY_INIT("pfs_user-oom-t");
115   do_all_tests();
116   my_end(0);
117   return (exit_status());
118 }
119 
120