Skip to content

Commit aab7618

Browse files
committed
Add spec for Truffle::POSIX when returning unsigned values
1 parent 8bd58f1 commit aab7618

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ src/main/c/truffleposix/truffleposix.o
4444
src/main/c/truffleposix/libtruffleposix.so
4545
src/main/c/truffleposix/libtruffleposix.dylib
4646

47+
spec/truffle/fixtures/libtestnfi.so
48+
spec/truffle/fixtures/libtestnfi.dylib
49+
4750
test/truffle/cexts/**/Makefile
4851
test/truffle/cexts/**/*.bc
4952
test/truffle/cexts/**/*.su

spec/truffle.mspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ if i = ARGV.index('slow') and ARGV[i-1] == '--excl-tag' and MSpecScript.child_pr
188188
]
189189

190190
module Kernel
191+
alias_method :mspec_old_system, :system
192+
private :mspec_old_system
193+
191194
alias_method :"mspec_old_`", :`
192195
private :"mspec_old_`"
193196
end

spec/truffle/fixtures/libtestnfi.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <limits.h>
2+
3+
unsigned short max_ushort(void) {
4+
return USHRT_MAX;
5+
}
6+
7+
unsigned int max_uint(void) {
8+
return UINT_MAX;
9+
}

spec/truffle/posix_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
require_relative '../ruby/spec_helper'
10+
11+
describe "Trffle::POSIX returns the correct value for an identity function returning" do
12+
before :all do
13+
src = fixture __FILE__, "libtestnfi.c"
14+
lib = src[0...-1] + RbConfig::CONFIG['NATIVE_DLEXT']
15+
unless system "cc", "-shared", "-o", lib, src
16+
abort "Could not compile libtestnfi"
17+
end
18+
19+
lazy_library = Truffle::POSIX::LazyLibrary.new do
20+
Polyglot.eval('nfi', "load '#{lib}'")
21+
end
22+
23+
@libtestnfi = Module.new do
24+
Truffle::POSIX.attach_function :max_ushort, [], :ushort, lazy_library, false, :max_ushort, self
25+
Truffle::POSIX.attach_function :max_uint, [], :uint, lazy_library, false, :max_uint, self
26+
end
27+
end
28+
29+
it "the maximum unsigned short" do
30+
@libtestnfi.max_ushort.should == 65535
31+
end
32+
33+
it "the maximum unsigned int" do
34+
@libtestnfi.max_uint.should == 4294967295
35+
end
36+
end

0 commit comments

Comments
 (0)