1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
/* Copyright (c) 2008, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "storage/perfschema/pfs_stat.h"
#include "unittest/mytap/tap.h"
static void test_basic() {
PFS_all_memory_stat stat;
diag("test_basic()");
stat.reset();
ok(stat.get_session_size() == 0, "size 0");
ok(stat.get_session_max() == 0, "max 0");
stat.count_alloc(1000);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1000, "max 1000");
stat.count_alloc(500);
ok(stat.get_session_size() == 1500, "size 1500");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_free(500);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_alloc(300);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_alloc(300);
ok(stat.get_session_size() == 1600, "size 1600");
ok(stat.get_session_max() == 1600, "max 1600");
}
static void test_free_unclaimed() {
PFS_all_memory_stat stat;
diag("test_free_unclaimed()");
stat.reset();
ok(stat.get_session_size() == 0, "size 0");
ok(stat.get_session_max() == 0, "max 0");
stat.count_alloc(1000);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1000, "max 1000");
stat.count_alloc(500);
ok(stat.get_session_size() == 1500, "size 1500");
ok(stat.get_session_max() == 1500, "max 1500");
// Free unclaimed memory
stat.count_free(700);
ok(stat.get_session_size() == 800, "size 800");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_free(1000);
ok(stat.get_session_size() == 0, "size 0");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_free(500);
ok(stat.get_session_size() == 0, "size 0");
ok(stat.get_session_max() == 1500, "max 1500");
}
static void test_top() {
PFS_all_memory_stat stat;
size_t size;
diag("test_top()");
stat.reset();
ok(stat.get_session_size() == 0, "size 0");
ok(stat.get_session_max() == 0, "max 0");
stat.count_alloc(1000);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1000, "max 1000");
stat.count_alloc(500);
ok(stat.get_session_size() == 1500, "size 1500");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_free(500);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1500, "max 1500");
stat.start_top_statement();
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_alloc(300);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_alloc(300);
ok(stat.get_session_size() == 1600, "size 1600");
ok(stat.get_session_max() == 1600, "max 1600");
stat.count_free(200);
ok(stat.get_session_size() == 1400, "size 1600");
ok(stat.get_session_max() == 1600, "max 1600");
stat.end_top_statement(&size);
ok(stat.get_session_size() == 1400, "size 1400");
ok(stat.get_session_max() == 1600, "max 1600");
ok(size == 1600, "stmt size 1600");
}
static void test_nest_shallow() {
PFS_all_memory_stat stat;
size_t size;
size_t local_start_1;
size_t stmt_start_1;
size_t local_start_2;
size_t stmt_start_2;
size_t local_start_3;
size_t stmt_start_3;
diag("test_nest_shallow()");
stat.reset();
ok(stat.get_session_size() == 0, "size 0");
ok(stat.get_session_max() == 0, "max 0");
stat.count_alloc(1000);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1000, "max 1000");
stat.count_alloc(500);
ok(stat.get_session_size() == 1500, "size 1500");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_free(500);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1500, "max 1500");
stat.start_top_statement();
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_alloc(300);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 1500, "max 1500");
/* Nested STMT 1 */
stat.start_nested_statement(&local_start_1, &stmt_start_1);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 1500, "max 1500");
ok(local_start_1 == 1300, "local start_1 1300");
ok(stmt_start_1 == 1300, "stmt start_1 1300");
stat.count_alloc(300);
ok(stat.get_session_size() == 1600, "size 1600");
ok(stat.get_session_max() == 1600, "max 1600");
stat.count_free(200);
ok(stat.get_session_size() == 1400, "size 1600");
ok(stat.get_session_max() == 1600, "max 1600");
stat.count_alloc(2000);
ok(stat.get_session_size() == 3400, "size 3400");
ok(stat.get_session_max() == 3400, "max 3400");
stat.count_free(2000);
ok(stat.get_session_size() == 1400, "size 1400");
ok(stat.get_session_max() == 3400, "max 3400");
stat.end_nested_statement(local_start_1, stmt_start_1, &size);
ok(stat.get_session_size() == 1400, "size 1400");
ok(stat.get_session_max() == 3400, "max 3400");
ok(size == 2100, "stmt1 size 2100");
/* Nested STMT 2 */
stat.start_nested_statement(&local_start_2, &stmt_start_2);
ok(stat.get_session_size() == 1400, "size 1400");
ok(stat.get_session_max() == 3400, "max 3400");
ok(local_start_2 == 1400, "local start_2 1400");
ok(stmt_start_2 == 3400, "stmt start_2 3400");
stat.count_alloc(5000);
ok(stat.get_session_size() == 6400, "size 6400");
ok(stat.get_session_max() == 6400, "max 6400");
stat.count_free(4500);
ok(stat.get_session_size() == 1900, "size 1900");
ok(stat.get_session_max() == 6400, "max 6400");
stat.end_nested_statement(local_start_2, stmt_start_2, &size);
ok(stat.get_session_size() == 1900, "size 1900");
ok(stat.get_session_max() == 6400, "max 6400");
ok(size == 5000, "stmt2 size 5000");
/* Nested STMT 3 */
stat.start_nested_statement(&local_start_3, &stmt_start_3);
ok(stat.get_session_size() == 1900, "size 1900");
ok(stat.get_session_max() == 6400, "max 6400");
ok(local_start_3 == 1900, "local start_3 1900");
ok(stmt_start_3 == 6400, "stmt start_3 6400");
stat.end_nested_statement(local_start_3, stmt_start_3, &size);
ok(stat.get_session_size() == 1900, "size 1900");
ok(stat.get_session_max() == 6400, "max 6400");
ok(size == 0, "stmt3 size 0");
stat.count_free(700);
ok(stat.get_session_size() == 1200, "size 1200");
ok(stat.get_session_max() == 6400, "max 6400");
stat.end_top_statement(&size);
ok(stat.get_session_size() == 1200, "size 1200");
ok(stat.get_session_max() == 6400, "max 6400");
ok(size == 6400, "stmt size 6400");
}
static void test_nest_deep() {
PFS_all_memory_stat stat;
size_t size;
size_t local_start_1;
size_t stmt_start_1;
size_t local_start_2;
size_t stmt_start_2;
size_t local_start_3;
size_t stmt_start_3;
diag("test_nest_deep()");
stat.reset();
ok(stat.get_session_size() == 0, "size 0");
ok(stat.get_session_max() == 0, "max 0");
stat.count_alloc(1000);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1000, "max 1000");
stat.count_alloc(500);
ok(stat.get_session_size() == 1500, "size 1500");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_free(500);
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1500, "max 1500");
/* Top statement(begin) */
stat.start_top_statement();
ok(stat.get_session_size() == 1000, "size 1000");
ok(stat.get_session_max() == 1500, "max 1500");
stat.count_alloc(300);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 1500, "max 1500");
/* Nested STMT 1 (begin) */
stat.start_nested_statement(&local_start_1, &stmt_start_1);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 1500, "max 1500");
ok(local_start_1 == 1300, "local start_1 1300");
ok(stmt_start_1 == 1300, "stmt start_1 1300");
stat.count_alloc(1000);
ok(stat.get_session_size() == 2300, "size 2300");
ok(stat.get_session_max() == 2300, "max 2300");
/* Nested STMT 2 (begin) */
stat.start_nested_statement(&local_start_2, &stmt_start_2);
ok(stat.get_session_size() == 2300, "size 2300");
ok(stat.get_session_max() == 2300, "max 2300");
ok(local_start_2 == 2300, "local start_2 2300");
ok(stmt_start_2 == 2300, "stmt start_2 2300");
stat.count_alloc(2000);
ok(stat.get_session_size() == 4300, "size 4300");
ok(stat.get_session_max() == 4300, "max 4300");
/* Nested STMT 3 (begin) */
stat.start_nested_statement(&local_start_3, &stmt_start_3);
ok(stat.get_session_size() == 4300, "size 4300");
ok(stat.get_session_max() == 4300, "max 4300");
ok(local_start_3 == 4300, "local start_3 4300");
ok(stmt_start_3 == 4300, "stmt start_3 4300");
stat.count_alloc(3000);
ok(stat.get_session_size() == 7300, "size 7300");
ok(stat.get_session_max() == 7300, "max 7300");
stat.count_free(3000);
ok(stat.get_session_size() == 4300, "size 4300");
ok(stat.get_session_max() == 7300, "max 7300");
/* Nested STMT 3 (begin) */
stat.end_nested_statement(local_start_3, stmt_start_3, &size);
ok(stat.get_session_size() == 4300, "size 4300");
ok(stat.get_session_max() == 7300, "max 7300");
ok(size == 3000, "stmt3 size 3000");
stat.count_free(2000);
ok(stat.get_session_size() == 2300, "size 2300");
ok(stat.get_session_max() == 7300, "max 7300");
/* Nested STMT 2 (end) */
stat.end_nested_statement(local_start_2, stmt_start_2, &size);
ok(stat.get_session_size() == 2300, "size 2300");
ok(stat.get_session_max() == 7300, "max 7300");
ok(size == 5000, "stmt2 size 5000");
stat.count_free(1000);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 7300, "max 7300");
/* Nested STMT 1 (end) */
stat.end_nested_statement(local_start_1, stmt_start_1, &size);
ok(stat.get_session_size() == 1300, "size 1300");
ok(stat.get_session_max() == 7300, "max 7300");
ok(size == 6000, "stmt1 size 6000");
stat.count_free(700);
ok(stat.get_session_size() == 600, "size 600");
ok(stat.get_session_max() == 7300, "max 7300");
/* Top statement(end) */
stat.end_top_statement(&size);
ok(stat.get_session_size() == 600, "size 600");
ok(stat.get_session_max() == 7300, "max 7300");
ok(size == 7300, "stmt size 7300");
}
static void do_all_tests() {
test_basic();
test_free_unclaimed();
test_top();
test_nest_shallow();
test_nest_deep();
}
int main(int, char **) {
plan(143);
MY_INIT("pfs_mem-t");
do_all_tests();
my_end(0);
return (exit_status());
}
|