diff options
-rw-r--r-- | .appveyor.yml | 74 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | cmake-test/CMakeLists.txt | 14 | ||||
-rw-r--r-- | test.c | 17 |
4 files changed, 99 insertions, 8 deletions
diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..d97a44e --- /dev/null +++ b/.appveyor.yml | |||
@@ -0,0 +1,74 @@ | |||
1 | # Copyright (c) 2014, Ruslan Baratov | ||
2 | # Copyright (c) 2014, 2016 Alexander Lamaison | ||
3 | # Copyright (c) 2017 Silvio Traversaro | ||
4 | # All rights reserved. | ||
5 | # | ||
6 | # Redistribution and use in source and binary forms, with or without | ||
7 | # modification, are permitted provided that the following conditions are met: | ||
8 | # | ||
9 | # * Redistributions of source code must retain the above copyright notice, this | ||
10 | # list of conditions and the following disclaimer. | ||
11 | # | ||
12 | # * Redistributions in binary form must reproduce the above copyright notice, | ||
13 | # this list of conditions and the following disclaimer in the documentation | ||
14 | # and/or other materials provided with the distribution. | ||
15 | # | ||
16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
20 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
21 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
22 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
23 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
24 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
25 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | |||
27 | os: Visual Studio 2015 | ||
28 | |||
29 | environment: | ||
30 | matrix: | ||
31 | - GENERATOR: "Visual Studio 14 2015" | ||
32 | BUILD_SHARED_LIBS: ON | ||
33 | |||
34 | - GENERATOR: "Visual Studio 14 2015" | ||
35 | BUILD_SHARED_LIBS: OFF | ||
36 | |||
37 | - GENERATOR: "Visual Studio 12 2013" | ||
38 | BUILD_SHARED_LIBS: ON | ||
39 | |||
40 | - GENERATOR: "Visual Studio 12 2013" | ||
41 | BUILD_SHARED_LIBS: OFF | ||
42 | |||
43 | platform: | ||
44 | - x86 | ||
45 | - x64 | ||
46 | |||
47 | configuration: | ||
48 | - Debug | ||
49 | - Release | ||
50 | |||
51 | build_script: | ||
52 | - ps: if($env:PLATFORM -eq "x64") { $env:CMAKE_GEN_SUFFIX=" Win64" } | ||
53 | - md build | ||
54 | - cd build | ||
55 | - cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX="./install" .. | ||
56 | - cmake --build . --config "%CONFIGURATION%" | ||
57 | |||
58 | test_script: | ||
59 | - ctest --output-on-failure --build-config "%CONFIGURATION%" | ||
60 | |||
61 | after_test: | ||
62 | - cmake --build . --config "%CONFIGURATION%" --target INSTALL | ||
63 | # Test also the use of dlfcn-win32 from an external CMake project | ||
64 | # Append the instllation directory of dlfcn-win32 to CMAKE_PREFIX_PATH to make sure that the CMake project is found | ||
65 | - set CMAKE_PREFIX_PATH=%APPVEYOR_BUILD_FOLDER%/build/install | ||
66 | # Append the bin installation directory of dlfcn-win32 to the path to make sure that .dll are found | ||
67 | - set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%/build/install/bin | ||
68 | - cd ../cmake-test | ||
69 | - md build | ||
70 | - cd build | ||
71 | - cmake "-G%GENERATOR%%CMAKE_GEN_SUFFIX%" -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -DBUILD_TESTS=ON .. | ||
72 | - cmake --build . --config "%CONFIGURATION%" | ||
73 | - ctest --output-on-failure --build-config "%CONFIGURATION%" | ||
74 | |||
@@ -1,4 +1,4 @@ | |||
1 | dlfcn-win32 | 1 | dlfcn-win32 [](https://ci.appveyor.com/project/dlfcn-win32/dlfcn-win32/branch/master) |
2 | =========== | 2 | =========== |
3 | 3 | ||
4 | dlfcn-win32 is an implementation of dlfcn for Windows. | 4 | dlfcn-win32 is an implementation of dlfcn for Windows. |
diff --git a/cmake-test/CMakeLists.txt b/cmake-test/CMakeLists.txt new file mode 100644 index 0000000..532f2b8 --- /dev/null +++ b/cmake-test/CMakeLists.txt | |||
@@ -0,0 +1,14 @@ | |||
1 | # Simple CMake project to test the use of dlfcn-win32 | ||
2 | # imported target. The test compiled is the same compiled | ||
3 | # as part of the main dlfcn-win32 project | ||
4 | |||
5 | cmake_minimum_required(VERSION 3.0) | ||
6 | |||
7 | find_package(dlfcn-win32 REQUIRED) | ||
8 | |||
9 | add_library(testdll SHARED ../testdll.c) | ||
10 | set_target_properties(testdll PROPERTIES PREFIX "") | ||
11 | add_executable(t_dlfcn ../test.c) | ||
12 | target_link_libraries(t_dlfcn dlfcn-win32::dl) | ||
13 | enable_testing() | ||
14 | add_test(NAME t_dlfcn COMMAND t_dlfcn) | ||
@@ -24,6 +24,7 @@ | |||
24 | #include <crtdbg.h> | 24 | #include <crtdbg.h> |
25 | #endif | 25 | #endif |
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | #include <string.h> | ||
27 | #include "dlfcn.h" | 28 | #include "dlfcn.h" |
28 | 29 | ||
29 | /* If these dlclose's fails, we don't care as the handles are going to be | 30 | /* If these dlclose's fails, we don't care as the handles are going to be |
@@ -41,7 +42,6 @@ | |||
41 | RETURN_ERROR; \ | 42 | RETURN_ERROR; \ |
42 | } \ | 43 | } \ |
43 | } while( 0 ) | 44 | } while( 0 ) |
44 | |||
45 | 45 | ||
46 | /* This is what this test does: | 46 | /* This is what this test does: |
47 | * - Open library with RTLD_GLOBAL | 47 | * - Open library with RTLD_GLOBAL |
@@ -74,7 +74,7 @@ int main() | |||
74 | void *library; | 74 | void *library; |
75 | char *error; | 75 | char *error; |
76 | int (*function)( void ); | 76 | int (*function)( void ); |
77 | int (*printf_local)( const char * ); | 77 | size_t (*fwrite_local) ( const void *, size_t, size_t, FILE * ); |
78 | int (*nonexistentfunction)( void ); | 78 | int (*nonexistentfunction)( void ); |
79 | int ret; | 79 | int ret; |
80 | 80 | ||
@@ -108,8 +108,8 @@ int main() | |||
108 | else | 108 | else |
109 | printf( "SUCCESS\tGot global handle: %p\n", global ); | 109 | printf( "SUCCESS\tGot global handle: %p\n", global ); |
110 | 110 | ||
111 | printf_local = dlsym(global, "printf"); | 111 | fwrite_local = dlsym(global, "fwrite"); |
112 | if (!printf_local) | 112 | if (!fwrite_local) |
113 | { | 113 | { |
114 | error = dlerror(); | 114 | error = dlerror(); |
115 | printf("ERROR\tCould not get symbol from global handle: %s\n", | 115 | printf("ERROR\tCould not get symbol from global handle: %s\n", |
@@ -119,8 +119,10 @@ int main() | |||
119 | RETURN_ERROR; | 119 | RETURN_ERROR; |
120 | } | 120 | } |
121 | else | 121 | else |
122 | printf("SUCCESS\tGot symbol from global handle: %p\n", printf_local); | 122 | printf("SUCCESS\tGot symbol from global handle: %p\n", fwrite_local); |
123 | printf_local("Hello world from local printf!\n"); | 123 | char * hello_world = "Hello world from local fwrite!\n"; |
124 | fwrite_local(hello_world,sizeof(char),strlen(hello_world),stderr); | ||
125 | fflush(stderr); | ||
124 | 126 | ||
125 | function = dlsym( library, "function" ); | 127 | function = dlsym( library, "function" ); |
126 | if( !function ) | 128 | if( !function ) |
@@ -304,7 +306,7 @@ int main() | |||
304 | error ? error : "" ); | 306 | error ? error : "" ); |
305 | } | 307 | } |
306 | 308 | ||
307 | function = dlsym(global, "printf"); | 309 | function = dlsym(global, "fwrite"); |
308 | if (!function) | 310 | if (!function) |
309 | { | 311 | { |
310 | error = dlerror(); | 312 | error = dlerror(); |
@@ -316,6 +318,7 @@ int main() | |||
316 | } | 318 | } |
317 | else | 319 | else |
318 | printf("SUCCESS\tGot symbol from global handle: %p\n", function); | 320 | printf("SUCCESS\tGot symbol from global handle: %p\n", function); |
321 | |||
319 | 322 | ||
320 | ret = dlclose( library ); | 323 | ret = dlclose( library ); |
321 | if( ret ) | 324 | if( ret ) |