MCPcopy Create free account
hub / github.com/FastLED/FastLED / main

Function main

src/platforms/apple/run_unit_test.hpp:117–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115typedef int (*RunTestsFunc)(int argc, const char** argv);
116
117int main(int argc, char** argv) FL_NOEXCEPT {
118 // Setup crash handler BEFORE loading any shared libraries
119 runner_setup_crash_handler();
120
121 std::string so_path;
122 const std::string shared_lib_ext = ".dylib";
123
124 // Determine shared library path: explicit argument or inferred from exe name
125 if (argc > 1 && argv[1][0] != '-') {
126 // First argument is a path (doesn't start with -)
127 so_path = argv[1];
128 } else {
129 // No explicit path: infer from exe name
130 std::string full_exe_path;
131 char path_buf[1024];
132 uint32_t buf_size = sizeof(path_buf);
133 if (_NSGetExecutablePath(path_buf, &buf_size) == 0) {
134 full_exe_path = path_buf;
135 } else {
136 // Buffer too small, fallback to argv[0]
137 full_exe_path = argv[0];
138 }
139
140 if (full_exe_path.empty()) {
141 std::cout << "Error: Failed to get executable path" << std::endl;
142 return 1;
143 }
144
145 // Extract directory and filename
146 size_t last_slash = full_exe_path.find_last_of('/');
147 std::string exe_dir = (last_slash != std::string::npos) ? full_exe_path.substr(0, last_slash) : ".";
148 std::string exe_file = (last_slash != std::string::npos) ? full_exe_path.substr(last_slash + 1) : full_exe_path;
149
150 // Remove executable extension (if any)
151 size_t dot_pos = exe_file.find_last_of('.');
152 std::string exe_name = (dot_pos != std::string::npos) ? exe_file.substr(0, dot_pos) : exe_file;
153
154 // Construct shared library path
155 std::string so_name = exe_name + shared_lib_ext;
156 so_path = exe_dir + "/" + so_name;
157 }
158
159 // Load shared library with RTLD_NOW for immediate symbol resolution
160 // This helps ASAN properly track symbols from the loaded library
161 void* handle = dlopen(so_path.c_str(), RTLD_NOW | RTLD_GLOBAL);
162 if (!handle) {
163 std::cout << "Error: Failed to load " << so_path << " (" << dlerror() << ")" << std::endl;
164 return 1;
165 }
166
167 // Get run_tests function
168 RunTestsFunc run_tests = (RunTestsFunc)dlsym(handle, "run_tests");
169 if (!run_tests) {
170 std::cout << "Error: Failed to find run_tests() in " << so_path << " (" << dlerror() << ")" << std::endl;
171 dlclose(handle);
172 return 1;
173 }
174

Callers

nothing calls this directly

Calls 10

cancelFunction · 0.85
setupFunction · 0.70
run_testsFunction · 0.50
emptyMethod · 0.45
find_last_ofMethod · 0.45
substrMethod · 0.45
c_strMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected