1 /* Copyright (c) 2008, 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_class.h>
26 #include <pfs_instr.h>
27 #include <pfs_global.h>
28 #include <tap.h>
29 #include <sql_class.h>
30 #include <pfs_buffer_container.h>
31 
32 #include "stub_pfs_global.h"
33 #include "stub_global_status_var.h"
34 
test_oom()35 void test_oom()
36 {
37   int rc;
38   PFS_global_param param;
39   TABLE_SHARE table_share;
40   PFS_thread pfs_thread;
41   PFS_table_share *pfs_table_share;
42 
43   rc= init_sync_class(1000, 0, 0);
44   ok(rc == 1, "oom (mutex)");
45   rc= init_sync_class(0, 1000, 0);
46   ok(rc == 1, "oom (rwlock)");
47   rc= init_sync_class(0, 0, 1000);
48   ok(rc == 1, "oom (cond)");
49   rc= init_thread_class(1000);
50   ok(rc == 1, "oom (thread)");
51   rc= init_file_class(1000);
52   ok(rc == 1, "oom (file)");
53   rc= init_socket_class(1000);
54   ok(rc == 1, "oom (socket)");
55   rc= init_stage_class(1000);
56   ok(rc == 1, "oom (stage)");
57   rc= init_statement_class(1000);
58   ok(rc == 1, "oom (statement)");
59   rc= init_memory_class(1000);
60   ok(rc == 1, "oom (memory)");
61 
62   cleanup_sync_class();
63   cleanup_thread_class();
64   cleanup_file_class();
65   cleanup_table_share();
66   cleanup_socket_class();
67   cleanup_stage_class();
68   cleanup_statement_class();
69   cleanup_memory_class();
70 
71   /* Table share classes. */
72   memset(&param, 0, sizeof(param));
73   param.m_enabled= true;
74   param.m_table_share_sizing= 100;
75   param.m_setup_object_sizing= 100;
76 
77   pfs_thread.m_table_share_hash_pins= NULL;
78   pfs_thread.m_setup_object_hash_pins= NULL;
79 
80   char db_name[]= "schema 1";
81   char table_name[]= "table 1";
82   table_share.db.str= db_name;
83   table_share.db.length= strlen(db_name);
84   table_share.table_name.str= table_name;
85   table_share.table_name.length= strlen(table_name);
86 
87   init_table_share(param.m_table_share_sizing);
88   init_table_share_hash(&param);
89   init_setup_object_hash(&param);
90 
91   stub_alloc_always_fails= false;
92   pfs_table_share= find_or_create_table_share(&pfs_thread, false, &table_share);
93   ok(pfs_table_share == NULL, "oom (pfs table share)");
94   ok(global_table_share_container.m_lost == 1, "oom (table share)");
95 
96   cleanup_table_share();
97   cleanup_table_share_hash();
98   cleanup_setup_object_hash();
99 }
100 
do_all_tests()101 void do_all_tests()
102 {
103   test_oom();
104 }
105 
main(int,char **)106 int main(int, char **)
107 {
108   plan(11);
109   MY_INIT("pfs_instr_info-oom-t");
110   do_all_tests();
111   return (exit_status());
112 }
113 
114