Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qualify location of libccalltest #12212

Merged
merged 1 commit into from
Jul 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions test/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import Base.copy, Base.==
const verbose = false
ccall((:set_verbose, "./libccalltest"), Void, (Int32,), verbose)
const libccalltest = joinpath(dirname(@__FILE__), "libccalltest")
ccall((:set_verbose, libccalltest), Void, (Int32,), verbose)

# Test for proper argument register truncation
ccall_test_func(x) = ccall((:testUcharX, "./libccalltest"), Int32, (UInt8,), x % UInt8)
ccall_test_func(x) = ccall((:testUcharX, libccalltest), Int32, (UInt8,), x % UInt8)
@test ccall_test_func(3) == 1
@test ccall_test_func(259) == 1

# Test for proper round-trip of Ref{T} type
ccall_echo_func{T,U}(x, ::Type{T}, ::Type{U}) = ccall((:test_echo_p, "./libccalltest"), T, (U,), x)
ccall_echo_func{T,U}(x, ::Type{T}, ::Type{U}) = ccall((:test_echo_p, libccalltest), T, (U,), x)
# Make sure object x is still valid (rooted as argument)
# when loading the pointer. This works as long as we still keep the argument
# rooted but might fail if we are smarter about eliminating dead root.
Expand Down Expand Up @@ -41,38 +42,38 @@ end

# Tests for passing and returning structs
ci = 20+51im
b = ccall((:ctest, "./libccalltest"), Complex{Int}, (Complex{Int},), ci)
b = ccall((:ctest, libccalltest), Complex{Int}, (Complex{Int},), ci)
@test b == ci + 1 - 2im
ci_ary = [ci] # Make sure the array is alive during unsafe_load
b = unsafe_load(ccall((:cptest, "./libccalltest"), Ptr{Complex{Int}},
b = unsafe_load(ccall((:cptest, libccalltest), Ptr{Complex{Int}},
(Ptr{Complex{Int}},), ci_ary))
@test b == ci + 1 - 2im
@test ci == 20+51im

b = ccall((:cptest_static, "./libccalltest"), Ptr{Complex{Int}}, (Ptr{Complex{Int}},), &ci)
b = ccall((:cptest_static, libccalltest), Ptr{Complex{Int}}, (Ptr{Complex{Int}},), &ci)
@test unsafe_load(b) == ci
Libc.free(convert(Ptr{Void},b))

cf64 = 2.84+5.2im
b = ccall((:cgtest, "./libccalltest"), Complex128, (Complex128,), cf64)
b = ccall((:cgtest, libccalltest), Complex128, (Complex128,), cf64)
@test b == cf64 + 1 - 2im
cf64_ary = [cf64] # Make sure the array is alive during unsafe_load
b = unsafe_load(ccall((:cgptest, "./libccalltest"), Ptr{Complex128}, (Ptr{Complex128},), cf64_ary))
b = unsafe_load(ccall((:cgptest, libccalltest), Ptr{Complex128}, (Ptr{Complex128},), cf64_ary))
@test b == cf64 + 1 - 2im
@test cf64 == 2.84+5.2im

cf32 = 3.34f0+53.2f0im
b = ccall((:cftest, "./libccalltest"), Complex64, (Complex64,), cf32)
b = ccall((:cftest, libccalltest), Complex64, (Complex64,), cf32)
@test b == cf32 + 1 - 2im
cf32_ary = [cf32] # Make sure the array is alive during unsafe_load
b = unsafe_load(ccall((:cfptest, "./libccalltest"), Ptr{Complex64}, (Ptr{Complex64},), cf32_ary))
b = unsafe_load(ccall((:cfptest, libccalltest), Ptr{Complex64}, (Ptr{Complex64},), cf32_ary))
@test b == cf32 + 1 - 2im
@test cf32 == 3.34f0+53.2f0im


# Tests for native Julia data types
@test_throws MethodError ccall((:cptest, "./libccalltest"), Ptr{Complex{Int}}, (Ptr{Complex{Int}},), cf32)
@test_throws ErrorException ccall((:cptest, "./libccalltest"), Ptr{Complex{Int}}, (Complex{Int},), &cf32) #compile-time error
@test_throws MethodError ccall((:cptest, libccalltest), Ptr{Complex{Int}}, (Ptr{Complex{Int}},), cf32)
@test_throws ErrorException ccall((:cptest, libccalltest), Ptr{Complex{Int}}, (Complex{Int},), &cf32) #compile-time error

# Tests for various sized data types (ByVal)
type Struct1
Expand All @@ -83,7 +84,7 @@ end
copy(a::Struct1) = Struct1(a.x, a.y)
s1 = Struct1(352.39422f23, 19.287577)
a = copy(s1)
b = ccall((:test_1, "./libccalltest"), Struct1, (Struct1,), a)
b = ccall((:test_1, libccalltest), Struct1, (Struct1,), a)
@test a.x == s1.x && a.y == s1.y
@test !(a === b)
@test b.x == s1.x + 1 && b.y == s1.y - 2
Expand All @@ -95,21 +96,21 @@ function foos1(s::Struct1)
end

ci32 = Complex{Int32}(Int32(10),Int32(31))
ba = ccall((:test_2a, "./libccalltest"), Complex{Int32}, (Complex{Int32},), ci32)
bb = ccall((:test_2b, "./libccalltest"), Complex{Int32}, (Complex{Int32},), ci32)
ba = ccall((:test_2a, libccalltest), Complex{Int32}, (Complex{Int32},), ci32)
bb = ccall((:test_2b, libccalltest), Complex{Int32}, (Complex{Int32},), ci32)
@test ba == bb == ci32 + 1 - 2im
@test ci32 == Complex{Int32}(Int32(10),Int32(31))

ci64 = Complex{Int64}(Int64(20),Int64(51))
ba = ccall((:test_3a, "./libccalltest"), Complex{Int64}, (Complex{Int64},), ci64)
bb = ccall((:test_3b, "./libccalltest"), Complex{Int64}, (Complex{Int64},), ci64)
bc = ccall((:test_128, "./libccalltest"), Complex{Int64}, (Complex{Int64},), ci64)
ba = ccall((:test_3a, libccalltest), Complex{Int64}, (Complex{Int64},), ci64)
bb = ccall((:test_3b, libccalltest), Complex{Int64}, (Complex{Int64},), ci64)
bc = ccall((:test_128, libccalltest), Complex{Int64}, (Complex{Int64},), ci64)
@test ba == bb == ci64 + 1 - 2im
@test bc == ci64 + 1
@test ci64 == Complex{Int64}(Int64(20),Int64(51))

i128 = Int128(0x7f00123456789abc)<<64 + typemax(UInt64)
b = ccall((:test_128, "./libccalltest"), Int128, (Int128,), i128)
b = ccall((:test_128, libccalltest), Int128, (Int128,), i128)
@test b == i128 + 1
@test i128 == Int128(0x7f00123456789abc)<<64 + typemax(UInt64)

Expand All @@ -123,7 +124,7 @@ copy(a::Struct_Big) = Struct_Big(a.x, a.y, a.z)
sbig = Struct_Big(424,-5,Int8('Z'))

a = copy(sbig)
b = ccall((:test_big, "./libccalltest"), Struct_Big, (Struct_Big,), a)
b = ccall((:test_big, libccalltest), Struct_Big, (Struct_Big,), a)
@test a.x == sbig.x && a.y == sbig.y && a.z == sbig.z
@test b.x == sbig.x + 1
@test b.y == sbig.y - 2
Expand Down
4 changes: 4 additions & 0 deletions test/libdl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ end
@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__)]))

# dlopen should be able to handle absolute and relative paths, with and without dlext
Expand Down Expand Up @@ -162,3 +164,5 @@ let dl = C_NULL
Libdl.dlclose(dl)
end
end

end
1 change: 1 addition & 0 deletions test/lineedit.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

using Base.LineEdit
isdefined(:TestHelpers) || include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
using TestHelpers

a_foo = 0
Expand Down
1 change: 1 addition & 0 deletions test/repl.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file is a part of Julia. License is MIT: http://julialang.org/license

# REPL tests
isdefined(:TestHelpers) || include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
using TestHelpers
import Base: REPL, LineEdit

Expand Down