Skip to content

Commit 3da630e

Browse files
committed
Added a new ctest case (function availablity test); and integrate exsiting and new test cases for ctest
1 parent 1a5318e commit 3da630e

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

plugins/spank_qrmi/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,15 @@ target_include_directories(spank_qrmi
111111
target_compile_options(spank_qrmi
112112
PRIVATE -Wall -Wextra -Werror -O2 -pedantic -Wconversion -Wwrite-strings -Wfloat-equal
113113
)
114+
115+
option(BUILD_TESTING "Build the project tests" OFF)
116+
if(BUILD_TESTING)
117+
enable_testing()
118+
add_executable(base_test ../tests/metadata/src/test.c)
119+
add_test(NAME "Library availability test" COMMAND base_test $<TARGET_FILE:spank_qrmi>)
120+
add_executable(unit_test ../tests/unit/src/unit_test.c)
121+
add_test(NAME "Symbol(function) availability test" COMMAND unit_test $<TARGET_FILE:spank_qrmi>)
122+
else()
123+
message(STATUS "Tests disabled by option 'BUILD_TESTING' set to OFF")
124+
endif()
125+

plugins/tests/unit/src/unit_test.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)