/usr/share/julia/test/libdl.jl is in julia-common 0.4.7-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | # This file is a part of Julia. License is MIT: http://julialang.org/license
# these could fail on an embedded installation
# but for now, we don't handle that case
dlls = Libdl.dllist()
@test !isempty(dlls)
@test length(dlls) > 3 # at a bare minimum, probably have some version of libstdc, libgcc, libjulia, ...
if @unix? true : (Base.windows_version() >= Base.WINDOWS_VISTA_VER)
for dl in dlls
if isfile(dl) && (Libdl.dlopen_e(dl) != C_NULL)
@test Base.samefile(Libdl.dlpath(dl), dl)
end
end
end
@test length(filter(dlls) do dl
return ismatch(Regex("^libjulia(?:.*)\.$(Libdl.dlext)(?:\..+)?\$"), basename(dl))
end) == 1 # look for something libjulia-like (but only one)
# library handle pointer must not be NULL
@test_throws ArgumentError Libdl.dlsym(C_NULL, :foo)
@test_throws ArgumentError Libdl.dlsym_e(C_NULL, :foo)
cd(dirname(@__FILE__)) do
# @test !isempty(Libdl.find_library(["libccalltest"], [dirname(@__FILE__)]))
# Find the private library directory by finding the path of libjulia (or libjulia-debug, as the case may be)
if ccall(:jl_is_debugbuild, Cint, ()) != 0
private_libdir = dirname(abspath(Libdl.dlpath("libjulia-debug")))
else
private_libdir = dirname(abspath(Libdl.dlpath("libjulia")))
end
# dlopen should be able to handle absolute and relative paths, with and without dlext
let dl = C_NULL
try
dl = Libdl.dlopen_e(abspath(joinpath(private_libdir, "libccalltest")))
@test dl != C_NULL
finally
Libdl.dlclose(dl)
end
end
let dl = C_NULL
try
dl = Libdl.dlopen_e(abspath(joinpath(private_libdir, "libccalltest.$(Libdl.dlext)")))
@test dl != C_NULL
finally
Libdl.dlclose(dl)
end
end
let dl = C_NULL
try
dl = Libdl.dlopen_e(relpath(joinpath(private_libdir, "libccalltest")))
@test dl != C_NULL
finally
Libdl.dlclose(dl)
end
end
let dl = C_NULL
try
dl = Libdl.dlopen_e(relpath(joinpath(private_libdir, "libccalltest.$(Libdl.dlext)")))
@test dl != C_NULL
finally
Libdl.dlclose(dl)
end
end
let dl = C_NULL
try
dl = Libdl.dlopen_e("./foo")
@test dl == C_NULL
finally
Libdl.dlclose(dl)
end
end
# unqualified names present in DL_LOAD_PATH
let dl = C_NULL
try
dl = Libdl.dlopen_e("libccalltest")
@test dl != C_NULL
finally
Libdl.dlclose(dl)
end
end
let dl = C_NULL
try
dl = Libdl.dlopen_e(string("libccalltest",".",Libdl.dlext))
@test dl != C_NULL
finally
Libdl.dlclose(dl)
end
end
# path with dlopen-able file first in load path
#=
let dl = C_NULL,
tmpdir = mktempdir(),
fpath = joinpath(tmpdir,"libccalltest")
try
write(open(fpath,"w"))
push!(Libdl.DL_LOAD_PATH, dirname(@__FILE__))
push!(Libdl.DL_LOAD_PATH, dirname(fpath))
dl = Libdl.dlopen_e("libccalltest")
@test dl != C_NULL
finally
pop!(Libdl.DL_LOAD_PATH)
pop!(Libdl.DL_LOAD_PATH)
rm(tmpdir, recursive=true)
end
end
=#
# path with dlopen-able file second in load path
#=
let dl = C_NULL,
tmpdir = mktempdir(),
fpath = joinpath(tmpdir,"libccalltest")
try
write(open(fpath,"w"))
push!(Libdl.DL_LOAD_PATH, dirname(fpath))
push!(Libdl.DL_LOAD_PATH, dirname(@__FILE__))
dl = Libdl.dlopen_e("libccalltest")
@test dl != C_NULL
finally
pop!(Libdl.DL_LOAD_PATH)
pop!(Libdl.DL_LOAD_PATH)
rm(tmpdir, recursive=true)
end
end
=#
# test dlpath
let dl = C_NULL
try
path = abspath(joinpath(private_libdir, "libccalltest"))
dl = Libdl.dlopen(path)
@test dl != C_NULL
@test Base.samefile(abspath(Libdl.dlpath(dl)),
abspath(Libdl.dlpath(path)))
@test Base.samefile(abspath(Libdl.dlpath(dl)),
string(path,".",Libdl.dlext))
finally
Libdl.dlclose(dl)
end
end
# opening a library that does not exist throws an ErrorException
@test_throws ErrorException Libdl.dlopen("./foo")
# test dlsym
let dl = C_NULL
try
dl = Libdl.dlopen(abspath(joinpath(private_libdir, "libccalltest")))
fptr = Libdl.dlsym(dl, :set_verbose)
@test fptr != C_NULL
@test_throws ErrorException Libdl.dlsym(dl, :foo)
fptr = Libdl.dlsym_e(dl, :set_verbose)
@test fptr != C_NULL
fptr = Libdl.dlsym_e(dl, :foo)
@test fptr == C_NULL
finally
Libdl.dlclose(dl)
end
end
end
|