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 as published by |
5 | the Free Software Foundation; version 2 of the License. |
6 | |
7 | This program is distributed in the hope that it will be useful, |
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | GNU General Public License for more details. |
11 | |
12 | You should have received a copy of the GNU General Public License |
13 | along with this program; if not, write to the Free Software Foundation, |
14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ |
15 | |
16 | #include <my_global.h> |
17 | #include <my_pthread.h> |
18 | #include <pfs_instr.h> |
19 | #include <pfs_stat.h> |
20 | #include <pfs_global.h> |
21 | #include <pfs_host.h> |
22 | #include <tap.h> |
23 | |
24 | #include "stub_pfs_global.h" |
25 | |
26 | #include <string.h> /* memset */ |
27 | |
28 | void test_oom() |
29 | { |
30 | int rc; |
31 | PFS_global_param param; |
32 | |
33 | memset(& param, 0xFF, sizeof(param)); |
34 | param.m_enabled= true; |
35 | param.m_mutex_class_sizing= 0; |
36 | param.m_rwlock_class_sizing= 0; |
37 | param.m_cond_class_sizing= 0; |
38 | param.m_thread_class_sizing= 10; |
39 | param.m_table_share_sizing= 0; |
40 | param.m_file_class_sizing= 0; |
41 | param.m_mutex_sizing= 0; |
42 | param.m_rwlock_sizing= 0; |
43 | param.m_cond_sizing= 0; |
44 | param.m_thread_sizing= 1000; |
45 | param.m_table_sizing= 0; |
46 | param.m_file_sizing= 0; |
47 | param.m_file_handle_sizing= 0; |
48 | param.m_events_waits_history_sizing= 10; |
49 | param.m_events_waits_history_long_sizing= 0; |
50 | param.m_setup_actor_sizing= 0; |
51 | param.m_setup_object_sizing= 0; |
52 | param.m_host_sizing= 1000; |
53 | param.m_user_sizing= 0; |
54 | param.m_account_sizing= 0; |
55 | param.m_stage_class_sizing= 50; |
56 | param.m_events_stages_history_sizing= 0; |
57 | param.m_events_stages_history_long_sizing= 0; |
58 | param.m_statement_class_sizing= 50; |
59 | param.m_events_statements_history_sizing= 0; |
60 | param.m_events_statements_history_long_sizing= 0; |
61 | param.m_session_connect_attrs_sizing= 0; |
62 | |
63 | /* Setup */ |
64 | |
65 | stub_alloc_always_fails= false; |
66 | stub_alloc_fails_after_count= 1000; |
67 | |
68 | init_event_name_sizing(& param); |
69 | rc= init_stage_class(param.m_stage_class_sizing); |
70 | ok(rc == 0, "init stage class" ); |
71 | rc= init_statement_class(param.m_statement_class_sizing); |
72 | ok(rc == 0, "init statement class" ); |
73 | |
74 | /* Tests */ |
75 | |
76 | stub_alloc_fails_after_count= 1; |
77 | rc= init_host(& param); |
78 | ok(rc == 1, "oom (host)" ); |
79 | cleanup_host(); |
80 | |
81 | stub_alloc_fails_after_count= 2; |
82 | rc= init_host(& param); |
83 | ok(rc == 1, "oom (host waits)" ); |
84 | cleanup_host(); |
85 | |
86 | stub_alloc_fails_after_count= 3; |
87 | rc= init_host(& param); |
88 | ok(rc == 1, "oom (host stages)" ); |
89 | cleanup_host(); |
90 | |
91 | stub_alloc_fails_after_count= 4; |
92 | rc= init_host(& param); |
93 | ok(rc == 1, "oom (host statements)" ); |
94 | cleanup_host(); |
95 | |
96 | cleanup_statement_class(); |
97 | cleanup_stage_class(); |
98 | } |
99 | |
100 | void do_all_tests() |
101 | { |
102 | test_oom(); |
103 | } |
104 | |
105 | int main(int, char **) |
106 | { |
107 | plan(6); |
108 | MY_INIT("pfs_host-oom-t" ); |
109 | do_all_tests(); |
110 | my_end(0); |
111 | return (exit_status()); |
112 | } |
113 | |
114 | |