Debian Codegraph @

unittest/gunit/components/mysql_server/minimal_chassis_test_driver-t.cc

raw symbols SCIP
1 /* Copyright (c) 2020, 2026, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #include <gtest/gtest.h>
25 #include <mysql/components/minimal_chassis.h>
26 #include <mysql/components/my_service.h>
27 #include <mysql/components/services/mysql_server_runnable_service.h>
28 #include <stdlib.h>
29 #include <string>
30 #include "my_io.h"
31 #include "my_sys.h"
32 #include "unit_test_common.h"
33
34 /* This is the test driver which uses the minimal chassis library
35
36 This testdriver does the following:
37 * minimal_chassis_init() Which makes the registry and dynamic loader
38 services ready.
39 * load mysql_server component, this will register the server component
40 services to the registry.
41 * acquire "mysql_libminchassis_runnable" service from the registry.
42 * call run() service api.
43 * unregisters all the services at the exit time.
44 */
45
46 using registry_type_t = SERVICE_TYPE_NO_CONST(registry);
47 using runnable_type_t = SERVICE_TYPE_NO_CONST(mysql_server_runnable);
48 using loader_type_t = SERVICE_TYPE_NO_CONST(dynamic_loader);
49 using registrator_type_t = SERVICE_TYPE_NO_CONST(registry_registration);
50 SERVICE_TYPE_NO_CONST(registry) * registry_ptr;
51 SERVICE_TYPE_NO_CONST(dynamic_loader) * loader;
52 SERVICE_TYPE_NO_CONST(registry_registration) * registrator;
53 const char *progname;
54 const char *urn;
55 std::string path;
56
57 extern mysql_component_t mysql_component_mysql_server;
58
59 SERVICE_TYPE(mysql_server_runnable) * runnable;
60
61 static void atexit_main(void) {
62 /* set back the dynamic_loader_scheme_file service to minimal_chassis
63 service */
64 registrator->set_default("dynamic_loader_scheme_file.mysql_minimal_chassis");
65 registry_ptr->release(reinterpret_cast<my_h_service>(
66 const_cast<registrator_type_t *>(registrator)));
67 registry_ptr->release(
68 reinterpret_cast<my_h_service>(const_cast<runnable_type_t *>(runnable)));
69 registry_ptr->release(
70 reinterpret_cast<my_h_service>(const_cast<loader_type_t *>(loader)));
71 /* Before unloading the test component we need to set the global
72 service handles to minimal chassis services */
73 minimal_chassis_services_refresh(true);
74 loader->unload(&urn, 1);
75 minimal_chassis_deinit(registry_ptr, &COMPONENT_REF(mysql_server));
76 }
77
78 int main(int argc, char **argv) {
79 INIT(argv[0]);
80
81 char realpath_buf[FN_REFLEN];
82 char basedir_buf[FN_REFLEN];
83 size_t res_length;
84 static const char *urns[] = {"file://component_example_component1"};
85
86 make_realpath(realpath_buf, progname);
87 make_dirname_part(basedir_buf, realpath_buf, &res_length);
88 if (res_length > 0) basedir_buf[res_length - 1] = '\0';
89 make_setwd(basedir_buf);
90 minimal_chassis_init((&registry_ptr), &COMPONENT_REF(mysql_server));
91
92 registry_ptr->acquire("dynamic_loader", (my_h_service *)&loader);
93
94 make_absolute_urn(*urns, &path);
95 urn = path.c_str();
96 loader->load(&urn, 1);
97 /* After loading the test component, update the global service
98 handles to mysql_server services */
99 minimal_chassis_services_refresh(false);
100
101 registry_ptr->acquire("mysql_server_runnable",
102 reinterpret_cast<my_h_service *>(
103 const_cast<runnable_type_t **>(&runnable)));
104 registry_ptr->acquire("registry_registration",
105 reinterpret_cast<my_h_service *>(
106 const_cast<registrator_type_t **>(&registrator)));
107 /* runnable->run() method may call the exit, so to handle that we need
108 atexit() registration to clean the resources */
109 atexit(atexit_main);
110 /* This method calls the test executables with passed arguments */
111 runnable->run(argc - 1, (argv + 1));
112
113 return 0;
114 }