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_user.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= 0; |
53 | param.m_user_sizing= 1000; |
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 | |
62 | /* Setup */ |
63 | |
64 | stub_alloc_always_fails= false; |
65 | stub_alloc_fails_after_count= 1000; |
66 | |
67 | init_event_name_sizing(& param); |
68 | rc= init_stage_class(param.m_stage_class_sizing); |
69 | ok(rc == 0, "init stage class" ); |
70 | rc= init_statement_class(param.m_statement_class_sizing); |
71 | ok(rc == 0, "init statement class" ); |
72 | |
73 | /* Tests */ |
74 | |
75 | stub_alloc_fails_after_count= 1; |
76 | rc= init_user(& param); |
77 | ok(rc == 1, "oom (user)" ); |
78 | cleanup_user(); |
79 | |
80 | stub_alloc_fails_after_count= 2; |
81 | rc= init_user(& param); |
82 | ok(rc == 1, "oom (user waits)" ); |
83 | cleanup_user(); |
84 | |
85 | stub_alloc_fails_after_count= 3; |
86 | rc= init_user(& param); |
87 | ok(rc == 1, "oom (user stages)" ); |
88 | cleanup_user(); |
89 | |
90 | stub_alloc_fails_after_count= 4; |
91 | rc= init_user(& param); |
92 | ok(rc == 1, "oom (user statements)" ); |
93 | cleanup_user(); |
94 | |
95 | cleanup_statement_class(); |
96 | cleanup_stage_class(); |
97 | } |
98 | |
99 | void do_all_tests() |
100 | { |
101 | test_oom(); |
102 | } |
103 | |
104 | int main(int, char **) |
105 | { |
106 | plan(6); |
107 | MY_INIT("pfs_user-oom-t" ); |
108 | do_all_tests(); |
109 | my_end(0); |
110 | return (exit_status()); |
111 | } |
112 | |
113 | |