Skip to content

Commit

Permalink
Added a slightly more complex test involving external functions and s…
Browse files Browse the repository at this point in the history
…trings
  • Loading branch information
rferraz committed Jan 23, 2011
1 parent 83a3195 commit e0a53f7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/call_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,20 @@ def test_external
assert_equal -10.abs, run_function_on_module(test_module, "test_function", -10).to_i
end

def test_external_string
test_module = define_module("test_module") do |host_module|
global = host_module.globals.add(LLVM::Array(LLVM::Int8, 5), "path")
global.linkage = :internal
global.initializer = LLVM::ConstantArray.string("PATH")
external = host_module.functions.add("getenv", [LLVM::Pointer(LLVM::Int8)], LLVM::Pointer(LLVM::Int8))
define_function(host_module, "test_function", [], LLVM::Pointer(LLVM::Int8)) do |builder, function, *arguments|
entry = function.basic_blocks.append
builder.position_at_end(entry)
parameter = builder.gep(global, [LLVM::Int(0), LLVM::Int(0)])
builder.ret(builder.call(external, parameter))
end
end
assert_equal ENV["PATH"], run_function_on_module(test_module, "test_function").to_ptr.read_pointer.read_string_to_null
end

end

0 comments on commit e0a53f7

Please sign in to comment.