Debian Codegraph @

storage/innobase/ut/ut0test.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2020, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 #ifdef UNIV_DEBUG
29 #include "ut0test.h"
30 #include "buf0flu.h"
31 #include "dict0dd.h"
32 #include "dict0dict.h"
33 #include "fil0fil.h"
34
35 #define CALL_MEMBER_FN(object, ptrToMember) ((object).*(ptrToMember))
36
37 /** A macro to define a dispatch function or a command function. They all
38 have the same signature.
39 @param[in] func_ the function that is being declared. */
40 #define DISPATCH_FUNCTION_DEF(func_) \
41 /* @param[in] tokens the command line */ \
42 /* @return RET_PASS on success, or the error code. */ \
43 Ret_t func_(std::vector<std::string> &tokens) noexcept
44
45 namespace ib {
46
47 thread_local Tester tl_interpreter;
48
49 typedef Tester::Ret_t Ret_t;
50
51 #define DISPATCH(x) m_dispatch[#x] = &Tester::x
52
53 Tester::Tester() noexcept {
54 /* Kindly keep the commands in alphabetical order. */
55 DISPATCH(corrupt_ondisk_page0);
56 DISPATCH(corrupt_ondisk_root_page);
57 DISPATCH(count_page_type);
58 DISPATCH(count_used_and_free);
59 DISPATCH(dblwr_force_crash);
60 DISPATCH(find_fil_page_lsn);
61 DISPATCH(find_flush_sync_lsn);
62 DISPATCH(find_ondisk_page_type);
63 DISPATCH(find_root_page_no);
64 DISPATCH(find_space_id);
65 DISPATCH(find_tablespace_file_name);
66 DISPATCH(find_tablespace_physical_page_size);
67 DISPATCH(make_ondisk_root_page_zeroes);
68 DISPATCH(make_page_dirty);
69 DISPATCH(open_table);
70 DISPATCH(print_dblwr_has_encrypted_pages);
71 }
72
73 void Tester::init() noexcept {
74 TLOG("Tester::init()");
75 std::ostringstream sout;
76 m_thd = current_thd;
77 XLOG("Initialization successfully completed");
78 set_output(sout);
79 }
80
81 void scan_page_type(space_id_t space_id,
82 std::map<page_type_t, page_no_t> &result_map) {
83 mtr_t mtr;
84
85 bool found;
86 const page_size_t page_size = fil_space_get_page_size(space_id, &found);
87 ut_ad(found);
88 fil_space_t *space = fil_space_acquire(space_id);
89
90 for (page_no_t page_no = 0; page_no < space->size; ++page_no) {
91 const page_id_t page_id(space_id, page_no);
92 mtr_start(&mtr);
93 buf_block_t *block =
94 buf_page_get(page_id, page_size, RW_S_LATCH, UT_LOCATION_HERE, &mtr);
95 page_type_t page_type = block->get_page_type();
96 result_map[page_type]++;
97 mtr_commit(&mtr);
98 }
99
100 fil_space_release(space);
101 }
102
103 DISPATCH_FUNCTION_DEF(Tester::count_page_type) {
104 std::ostringstream sout;
105 mtr_t mtr;
106 std::map<page_type_t, page_no_t> result_map;
107
108 TLOG("Tester::count_page_type()");
109 ut_ad(tokens.size() == 2);
110 ut_ad(tokens[0] == "count_page_type");
111
112 const std::string space_name = tokens[1];
113
114 const space_id_t space_id = fil_space_get_id_by_name(space_name.c_str());
115
116 scan_page_type(space_id, result_map);
117
118 page_no_t total = 0;
119 for (auto it : result_map) {
120 sout << fil_get_page_type_str(it.first) << ": " << it.second << std::endl;
121 total += it.second;
122 }
123 sout << "Total: " << total << std::endl;
124 set_output(sout);
125
126 return RET_PASS;
127 }
128
129 DISPATCH_FUNCTION_DEF(Tester::count_used_and_free) {
130 std::ostringstream sout;
131 mtr_t mtr;
132 std::map<page_type_t, page_no_t> result_map;
133
134 TLOG("Tester::count_used_and_free()");
135 ut_ad(tokens.size() == 2);
136 ut_ad(tokens[0] == "count_used_and_free");
137
138 const std::string space_name = tokens[1];
139
140 const space_id_t space_id = fil_space_get_id_by_name(space_name.c_str());
141
142 scan_page_type(space_id, result_map);
143
144 page_no_t total = 0;
145 for (auto it : result_map) {
146 total += it.second;
147 }
148 const page_no_t pages_free = result_map[FIL_PAGE_TYPE_ALLOCATED];
149 const page_no_t used = total - pages_free;
150 const double fill_factor = (used / (double)total) * 100;
151 const double free_factor = (pages_free / (double)total) * 100;
152 sout << "Total= " << total << ", used=" << used << ", free=" << pages_free
153 << std::endl;
154 sout << "Fill factor= " << fill_factor << ", free factor= " << free_factor
155 << std::endl;
156 set_output(sout);
157
158 return RET_PASS;
159 }
160
161 dict_table_t *Tester::is_table_open(
162 const std::string &table_name) const noexcept {
163 for (auto iter = m_open_tables.begin(); iter != m_open_tables.end(); ++iter) {
164 dict_table_t *table = *iter;
165 std::string tmp(table->name.m_name);
166 if (table_name == tmp) {
167 return table;
168 }
169 }
170
171 return nullptr;
172 }
173
174 Ret_t Tester::open_table(std::vector<std::string> &tokens) noexcept {
175 TLOG("Tester::open_table()");
176 ut_ad(tokens[0] == "open_table");
177 ut_ad(tokens.size() == 2);
178 std::ostringstream sout;
179 Ret_t ret;
180
181 std::string table_name = tokens[1];
182 dict_table_t *table = is_table_open(table_name);
183 if (table == nullptr) {
184 table = dict_table_open_on_name(table_name.c_str(), false, false,
185 DICT_ERR_IGNORE_NONE);
186 }
187 if (table == nullptr) {
188 XLOG("FAIL: Could not open table: " << table_name);
189 ret = RET_FAIL;
190 } else {
191 m_open_tables.push_back(table);
192 XLOG("PASS: Successfully opened table=" << table_name);
193 ret = RET_PASS;
194 }
195 set_output(sout);
196 return ret;
197 }
198
199 Ret_t Tester::find_space_id(std::vector<std::string> &tokens) noexcept {
200 TLOG("Tester::find_space_id");
201 ut_ad(tokens.size() == 2);
202
203 std::string table_name = tokens[1];
204 ut_ad(tokens[0] == "find_space_id");
205 dict_table_t *table = is_table_open(table_name);
206
207 ut_ad(table != nullptr);
208
209 space_id_t space_id = table->space;
210
211 dict_index_t *clust_index = table->first_index();
212 page_no_t root_page_no = clust_index->page;
213
214 TLOG("table_name=" << table_name << ", space_id=" << space_id
215 << ", root_page_no=" << root_page_no);
216
217 {
218 std::ostringstream sout;
219 sout << space_id;
220 set_output(sout);
221 }
222
223 return RET_PASS;
224 }
225
226 Ret_t Tester::find_root_page_no(std::vector<std::string> &tokens) noexcept {
227 TLOG("Tester::find_root_page_no");
228 ut_ad(tokens[0] == "find_root_page_no");
229 ut_ad(tokens.size() == 2);
230
231 std::string table_name = tokens[1];
232 dict_table_t *table = is_table_open(table_name);
233
234 ut_ad(table != nullptr);
235
236 space_id_t space_id = table->space;
237
238 dict_index_t *clust_index = table->first_index();
239 page_no_t root_page_no = clust_index->page;
240
241 TLOG("table_name=" << table_name << ", space_id=" << space_id
242 << ", root_page_no=" << root_page_no);
243
244 {
245 std::ostringstream sout;
246 sout << root_page_no;
247 set_output(sout);
248 }
249
250 return RET_PASS;
251 }
252
253 Ret_t Tester::find_fil_page_lsn(std::vector<std::string> &tokens) noexcept {
254 ut_ad(tokens[0] == "find_fil_page_lsn");
255 std::string space_id_str = tokens[1];
256 std::string page_no_str = tokens[2];
257 space_id_t space_id = std::stoul(space_id_str);
258 space_id_t page_no = std::stoul(page_no_str);
259
260 page_id_t page_id(space_id, page_no);
261 bool found;
262 page_size_t page_size = fil_space_get_page_size(space_id, &found);
263 ut_ad(found);
264
265 mtr_t mtr;
266 mtr_start(&mtr);
267 buf_block_t *block =
268 buf_page_get(page_id, page_size, RW_X_LATCH, UT_LOCATION_HERE, &mtr);
269 lsn_t newest_lsn = block->page.get_newest_lsn();
270 mtr_commit(&mtr);
271
272 std::ostringstream sout;
273 sout << newest_lsn;
274 set_output(sout);
275
276 return RET_PASS;
277 }
278
279 Ret_t Tester::find_ondisk_page_type(std::vector<std::string> &tokens) noexcept {
280 TLOG("Tester::find_ondisk_page_type()");
281 ut_ad(tokens.size() == 3);
282
283 ut_ad(tokens[0] == "find_ondisk_page_type");
284 const std::string space_id_str = tokens[1];
285 const std::string page_no_str = tokens[2];
286
287 const space_id_t space_id = std::stoul(space_id_str);
288 space_id_t page_no = std::stoul(page_no_str);
289
290 /* Calculate the offset here. */
291 bool found;
292 page_size_t page_size = fil_space_get_page_size(space_id, &found);
293 ut_ad(found);
294
295 const page_id_t page_id(space_id, page_no);
296
297 /* The buffer into which file page header is read. */
298 alignas(OS_FILE_LOG_BLOCK_SIZE) std::array<byte, OS_FILE_LOG_BLOCK_SIZE> buf;
299
300 fil_space_t *space = fil_space_get(space_id);
301 ut_ad(space != nullptr);
302
303 const fil_node_t *node = space->get_file_node(&page_no);
304 ut_ad(node->is_open);
305
306 const os_offset_t offset = page_no * page_size.physical();
307
308 /* When the space file is currently open we are not able to write to it
309 directly on Windows. We must use the currently opened handle. Moreover,
310 on Windows a file opened for the asynchronous access must be accessed only in
311 a way that allows asynchronous completion of the request. This requires that
312 the i/o buffer be aligned to OS block size and also its size divisible by OS
313 block size. */
314
315 IORequest read_io_type(IORequest::READ);
316 const dberr_t err = os_file_read(read_io_type, node->name, node->handle,
317 buf.data(), offset, OS_FILE_LOG_BLOCK_SIZE);
318 if (err != DB_SUCCESS) {
319 page_type_t page_type = fil_page_get_type(buf.data());
320 TLOG("Could not read page_id=" << page_id << ", page_type=" << page_type
321 << ", err=" << err);
322 /* Since we do not pass encryption information in IORequest, if page is
323 encrypted on disk, it cannot be decrypted by i/o layer. But the encrypted
324 data will be available in the provided buffer. */
325
326 if (err == DB_IO_DECRYPT_FAIL) {
327 /* We expect this only for encrypted pages. For this function, this error
328 is OK because we will only read one header field and the header is not
329 encrypted. */
330 ut_ad(Encryption::is_encrypted_page(buf.data()));
331 } else {
332 return RET_FAIL;
333 }
334 }
335
336 const byte *page = buf.data();
337 const page_type_t type = fil_page_get_type(page);
338 const char *page_type = fil_get_page_type_str(type);
339
340 TLOG("page_type=" << type);
341 TLOG("page_type=" << page_type);
342
343 std::ostringstream sout;
344 sout << page_type;
345 set_output(sout);
346
347 return RET_PASS;
348 }
349
350 Ret_t Tester::find_tablespace_file_name(
351 std::vector<std::string> &tokens) noexcept {
352 std::ostringstream sout;
353
354 TLOG("Tester::find_tablespace_file_name()");
355 ut_ad(tokens.size() == 2);
356 ut_ad(tokens[0] == "find_tablespace_file_name");
357
358 std::string space_name = tokens[1];
359 space_id_t space_id = fil_space_get_id_by_name(space_name.c_str());
360 char *filename = fil_space_get_first_path(space_id);
361 sout << filename;
362 set_output(sout);
363 ut::free(filename);
364 return RET_PASS;
365 }
366
367 DISPATCH_FUNCTION_DEF(Tester::find_tablespace_physical_page_size) {
368 std::ostringstream sout;
369
370 TLOG("Tester::find_tablespace_physical_page_size()");
371 ut_ad(tokens.size() == 2);
372 ut_ad(tokens[0] == "find_tablespace_physical_page_size");
373
374 std::string space_name = tokens[1];
375 space_id_t space_id = fil_space_get_id_by_name(space_name.c_str());
376 bool found;
377 page_size_t page_size = fil_space_get_page_size(space_id, &found);
378 ut_ad(found);
379 sout << page_size.physical();
380 set_output(sout);
381 return RET_PASS;
382 }
383
384 DISPATCH_FUNCTION_DEF(Tester::make_ondisk_root_page_zeroes) {
385 TLOG("Tester::make_ondisk_root_page_zeroes()");
386 ut_ad(tokens.size() == 2);
387 ut_ad(tokens[0] == "make_ondisk_root_page_zeroes");
388
389 const std::string table_name = tokens[1];
390 const dict_table_t *const table = is_table_open(table_name);
391
392 ut_ad(table != nullptr);
393
394 const dict_index_t *const clust_index = table->first_index();
395 const page_no_t root_page_no = clust_index->page;
396 const page_size_t page_size = dict_table_page_size(table);
397
398 return clear_page_prefix(table->space, root_page_no, page_size.physical());
399 }
400
401 Ret_t Tester::corrupt_ondisk_root_page(
402 std::vector<std::string> &tokens) noexcept {
403 std::ostringstream sout;
404
405 TLOG("Tester::corrupt_ondisk_root_page()");
406 ut_ad(tokens.size() == 2);
407 ut_ad(tokens[0] == "corrupt_ondisk_root_page");
408
409 const std::string table_name = tokens[1];
410 const dict_table_t *table = is_table_open(table_name);
411
412 if (table == nullptr) {
413 std::vector<std::string> cmd{"open_table", table_name};
414 Ret_t st = open_table(cmd);
415
416 if (st != RET_PASS) {
417 XLOG("Failed to open table: " << table_name);
418 set_output(sout);
419 return st;
420 }
421
422 table = is_table_open(table_name);
423 }
424
425 if (table == nullptr) {
426 XLOG("Failed to open table: " << table_name);
427 set_output(sout);
428 return RET_FAIL;
429 }
430
431 const dict_index_t *const clust_index = table->first_index();
432 const page_no_t root_page_no = clust_index->page;
433
434 return clear_page_prefix(table->space, root_page_no, FIL_PAGE_DATA);
435 }
436
437 Ret_t Tester::clear_page_prefix(const space_id_t space_id, page_no_t page_no,
438 const size_t prefix_length) {
439 TLOG("Tester::clear_page_prefix()");
440 ut::aligned_array_pointer<byte, OS_FILE_LOG_BLOCK_SIZE> mem;
441 /* We read before write, as writes have to have length divisible by
442 OS_FILE_LOG_BLOCK_SIZE thus we need to learn the content of non-zeroed suffix.
443 Also, it's easier to spot errors during read than write, and this requires
444 reading at least the FIL_PAGE_DATA first bytes */
445 const auto buf_size =
446 ut_uint64_align_up(prefix_length, OS_FILE_LOG_BLOCK_SIZE);
447
448 mem.alloc(ut::Count(buf_size));
449 const page_id_t page_id{space_id, page_no};
450 fil_space_t *space = fil_space_get(space_id);
451
452 // Note: this call adjusts page_no, so it becomes relative to the node
453 fil_node_t *node = space->get_file_node(&page_no);
454 ut_ad(node->is_open);
455
456 const page_size_t page_size(space->flags);
457 const size_t page_size_bytes = page_size.physical();
458 ut_a(buf_size <= page_size_bytes);
459
460 // Note: we use updated page_no here, as os_aio needs offset relative to node
461 const os_offset_t offset = page_no * page_size_bytes;
462
463 /* When the space file is currently open we are not able to write to it
464 directly on Windows. We must use the currently opened handle. Moreover,
465 on Windows a file opened for the AIO access must be accessed only by AIO
466 methods. The AIO requires the operations to be aligned and with size
467 divisible by OS block size, so we first read block of the first page, to
468 corrupt it and write back. */
469
470 byte *buf = mem;
471 IORequest read_io_type(IORequest::READ);
472 dberr_t err = os_file_read(read_io_type, node->name, node->handle, buf,
473 offset, buf_size);
474 if (err != DB_SUCCESS) {
475 page_type_t page_type = fil_page_get_type(buf);
476 TLOG("Could not read page_id=" << page_id << ", page type=" << page_type
477 << ", err=" << err);
478
479 if (err == DB_IO_DECRYPT_FAIL) {
480 /* We expect this only for encrypted pages. Since this function doesn't
481 actually read (or use) the contents, this error is OK. */
482 ut_ad(Encryption::is_encrypted_page(buf));
483 } else {
484 return RET_FAIL;
485 }
486 }
487
488 ut_ad(prefix_length <= buf_size);
489 memset(buf, 0x00, prefix_length);
490
491 IORequest write_io_type(IORequest::WRITE);
492 err = os_file_write(write_io_type, node->name, node->handle, buf, offset,
493 buf_size);
494 if (err == DB_SUCCESS) {
495 TLOG("Successfully zeroed prefix of page_id=" << page_id << ", prefix="
496 << prefix_length);
497 } else {
498 TLOG("Could not write zeros to page_id=" << page_id << ", err=" << err);
499 return RET_FAIL;
500 }
501 return RET_PASS;
502 }
503
504 DISPATCH_FUNCTION_DEF(Tester::dblwr_force_crash) {
505 TLOG("Tester::dblwr_force_crash()");
506 ut_ad(tokens.size() == 3);
507 ut_ad(tokens[0] == "dblwr_force_crash");
508
509 std::string space_id_str = tokens[1];
510 std::string page_no_str = tokens[2];
511 space_id_t space_id = std::stoul(space_id_str);
512 space_id_t page_no = std::stoul(page_no_str);
513
514 page_id_t page_id(space_id, page_no);
515 dblwr::Force_crash = page_id;
516 return RET_PASS;
517 }
518
519 Ret_t Tester::corrupt_ondisk_page0(std::vector<std::string> &tokens) noexcept {
520 TLOG("Tester::corrupt_ondisk_page0()");
521 ut_ad(tokens.size() == 2);
522 ut_ad(tokens[0] == "corrupt_ondisk_page0");
523
524 const std::string table_name = tokens[1];
525 const dict_table_t *const table = is_table_open(table_name);
526 ut_ad(table != nullptr);
527
528 return clear_page_prefix(table->space, 0, FIL_PAGE_DATA);
529 }
530
531 DISPATCH_FUNCTION_DEF(Tester::make_page_dirty) {
532 TLOG("Tester::make_page_dirty()");
533 ut_ad(tokens.size() == 3);
534 ut_ad(tokens[0] == "make_page_dirty");
535
536 mtr_t mtr;
537 std::string space_id_str = tokens[1];
538 std::string page_no_str = tokens[2];
539 space_id_t space_id = std::stoul(space_id_str);
540 space_id_t page_no = std::stoul(page_no_str);
541
542 page_id_t page_id(space_id, page_no);
543
544 fil_space_t *space = fil_space_acquire_silent(space_id);
545
546 if (space == nullptr) {
547 return RET_FAIL;
548 }
549
550 if (page_no > space->size) {
551 fil_space_release(space);
552 return RET_FAIL;
553 }
554
555 mtr.start();
556
557 buf_block_t *block = buf_page_get(page_id, page_size_t(space->flags),
558 RW_X_LATCH, UT_LOCATION_HERE, &mtr);
559
560 if (block != nullptr) {
561 byte *page = block->frame;
562 page_type_t page_type = fil_page_get_type(page);
563
564 /* Don't dirty a page that is not yet used. */
565 if (page_type != FIL_PAGE_TYPE_ALLOCATED) {
566 ib::info(ER_IB_MSG_574)
567 << "Dirtying page: " << page_id
568 << ", page_type=" << fil_get_page_type_str(page_type);
569
570 mlog_write_ulint(page + FIL_PAGE_TYPE, page_type, MLOG_2BYTES, &mtr);
571 }
572 }
573
574 mtr.commit();
575
576 fil_space_release(space);
577
578 if (block != nullptr) {
579 buf_flush_sync_all_buf_pools();
580 }
581
582 return RET_PASS;
583 }
584
585 Ret_t Tester::print_dblwr_has_encrypted_pages(
586 std::vector<std::string> &) noexcept {
587 std::ostringstream sout;
588 if (dblwr::has_encrypted_pages()) {
589 std::string m1("Double write file has encrypted pages.");
590 TLOG(m1);
591 sout << m1;
592 } else {
593 std::string m1("Double write file has NO encrypted pages.");
594 TLOG(m1);
595 sout << m1;
596 }
597
598 set_output(sout);
599 return RET_PASS;
600 }
601
602 void Tester::close_table(dict_table_t *table) noexcept {
603 for (auto iter = m_open_tables.begin(); iter != m_open_tables.end(); ++iter) {
604 dict_table_t *tmp = *iter;
605 if (tmp == table) {
606 m_open_tables.erase(iter);
607 break;
608 }
609 }
610
611 dict_table_close(table, false, false);
612 }
613
614 void Tester::destroy() noexcept {
615 for (auto iter = m_open_tables.begin(); iter != m_open_tables.end(); ++iter) {
616 dict_table_t *table = *iter;
617 dict_table_close(table, false, false);
618 }
619
620 m_open_tables.clear();
621 }
622
623 Ret_t Tester::find_flush_sync_lsn(std::vector<std::string> &tokens) noexcept {
624 ut_ad(tokens.size() == 1);
625 ut_ad(tokens[0] == "find_flush_sync_lsn");
626
627 std::ostringstream sout;
628 sout << get_flush_sync_lsn();
629 set_output(sout);
630 return RET_PASS;
631 }
632
633 Ret_t Tester::run(const std::string &cmdline) noexcept {
634 Ret_t ret = RET_PASS;
635 std::vector<std::string> tokens;
636
637 std::istringstream sin(cmdline);
638
639 while (!sin.eof()) {
640 std::string token;
641 std::getline(sin, token, ' ');
642 tokens.push_back(token);
643 }
644
645 std::string command = tokens[0];
646
647 /* Save the current command token. This will be the value of the
648 innodb_interpreter variable. */
649 m_command = command;
650
651 if (command == "init") {
652 init();
653 } else if (command == "destroy") {
654 destroy();
655 } else if (command == "buf_flush_sync_all_buf_pools") {
656 buf_flush_sync_all_buf_pools();
657 TLOG("Executed buf_flush_sync_all_buf_pools()");
658 ret = RET_PASS;
659 } else {
660 ret = RET_CMD_TBD;
661 }
662
663 /* Second approach. */
664 if (ret == RET_CMD_TBD) {
665 auto cmd = m_dispatch.find(command);
666
667 if (cmd != m_dispatch.end()) {
668 ret = CALL_MEMBER_FN(*this, cmd->second)(tokens);
669 } else {
670 ret = RET_CMD_TBD;
671 }
672 }
673
674 if (ret == RET_CMD_TBD) {
675 ret = RET_FAIL;
676 }
677
678 return ret;
679 }
680
681 void Tester::update_thd_variable() noexcept {
682 char **output = thd_innodb_interpreter_output(m_thd);
683 *output = const_cast<char *>(m_log.c_str());
684
685 char **output2 = thd_innodb_interpreter(m_thd);
686 *output2 = const_cast<char *>(m_command.c_str());
687 }
688
689 void Tester::set_output(const std::ostringstream &sout) noexcept {
690 m_log = sout.str();
691 }
692
693 void Tester::set_output(const std::string &log) noexcept { m_log = log; }
694
695 void Tester::clear_output() noexcept { m_log = ""; }
696
697 void Tester::append_output(const std::string &log) noexcept { m_log += log; }
698
699 int interpreter_run(const char *command) noexcept {
700 return (int)tl_interpreter.run(command);
701 }
702
703 } // namespace ib
704
705 void ib_interpreter_update(MYSQL_THD thd [[maybe_unused]],
706 SYS_VAR *var [[maybe_unused]],
707 void *var_ptr [[maybe_unused]],
708 const void *save [[maybe_unused]]) {
709 TLOG("ib_interpreter_update");
710
711 /* Point the THD variables - innodb_interpreter and innodb_interpreter_output
712 to the correct values. */
713 ib::tl_interpreter.update_thd_variable();
714 }
715
716 int ib_interpreter_check(THD *thd [[maybe_unused]],
717 SYS_VAR *var [[maybe_unused]], void *save,
718 struct st_mysql_value *value) {
719 TLOG("ib_interpreter_check");
720 char buff[STRING_BUFFER_USUAL_SIZE];
721 int len = sizeof(buff);
722
723 ut_a(save != nullptr);
724 ut_a(value != nullptr);
725
726 const char *cmd = value->val_str(value, buff, &len);
727
728 int ret = ib::interpreter_run(cmd ? cmd : "");
729
730 TLOG("ib_interpreter_check() is returning: " << ret);
731 *static_cast<const char **>(save) = cmd;
732 return ret;
733 }
734 #endif /* UNIV_DEBUG */