|
| 1 | +/* |
| 2 | + * This code is part of Qiskit. |
| 3 | + * |
| 4 | + * (C) Copyright IBM 2025. |
| 5 | + * |
| 6 | + * This program and the accompanying materials are made available under the |
| 7 | + * terms of the GNU General Public License version 3, as published by the |
| 8 | + * Free Software Foundation. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <[https://www.gnu.org/licenses/gpl-3.0.txt] |
| 17 | + */ |
| 18 | + |
| 19 | +#include <stdio.h> |
| 20 | +#include <dlfcn.h> |
| 21 | +#include <stdlib.h> |
| 22 | + |
| 23 | +typedef void (*generic_func)(); |
| 24 | + |
| 25 | +int main(int argc, char** argv) |
| 26 | +{ |
| 27 | + void *handle; |
| 28 | + char *error; |
| 29 | + |
| 30 | + // List of functions to check |
| 31 | + const char *functions[] = { |
| 32 | + "slurm_spank_exit", |
| 33 | + "slurm_spank_init", |
| 34 | + "slurm_spank_init_post_opt", |
| 35 | + "slurm_spank_task_init"}; |
| 36 | + int num_functions = sizeof(functions) / sizeof(functions[0]); |
| 37 | + |
| 38 | + if (argc != 2) { |
| 39 | + printf("(Error) Missing argument. Specify path to plugin library file.\n"); |
| 40 | + exit(EXIT_FAILURE); |
| 41 | + } |
| 42 | + |
| 43 | + handle = dlopen(argv[1], RTLD_LAZY); |
| 44 | + if (!handle) { |
| 45 | + fprintf(stderr, "Could not open %s: %s\n", argv[1], dlerror()); |
| 46 | + exit(EXIT_FAILURE); |
| 47 | + } |
| 48 | + //printf("Starting existence tests for %s ...\n", argv[1]); |
| 49 | + |
| 50 | + for (int i = 0; i < num_functions; i++) { |
| 51 | + dlerror(); // clear any existing error just in case |
| 52 | + generic_func func_ptr = (generic_func)dlsym(handle, functions[i]); |
| 53 | + error = dlerror(); |
| 54 | + |
| 55 | + if (error != NULL) { |
| 56 | + printf("[FAILED] Function '%s' NOT found. Error: %s\n", functions[i], error); |
| 57 | + exit(EXIT_FAILURE); |
| 58 | + } else if (func_ptr == NULL) { |
| 59 | + // In rare cases, a symbol can exist but have a NULL value |
| 60 | + printf("[WARNING] Function '%s' found but is NULL.\n", functions[i]); |
| 61 | + exit(EXIT_FAILURE); |
| 62 | + } else { |
| 63 | + printf("[PASSED] Function '%s' exists at address %p.\n", functions[i], (void*)func_ptr); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + dlclose(handle); |
| 68 | + return (EXIT_SUCCESS); |
| 69 | +} |
0 commit comments