0
|
1 %% Copyright (c) 2014 Erik Mackdanz <erikmack@gmail.com>
|
|
2
|
|
3 %% Permission to use, copy, modify, and distribute this software for any
|
|
4 %% purpose with or without fee is hereby granted, provided that the above
|
|
5 %% copyright notice and this permission notice appear in all copies.
|
|
6
|
|
7 %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
8 %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
9 %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
10 %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
11 %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
12 %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
13 %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
|
15 -module(callf_SUITE).
|
|
16 -compile(export_all).
|
|
17 -define(VMSZ, 1024).
|
|
18
|
|
19 all() ->
|
|
20 [
|
|
21 argf_one,
|
|
22 argf_excessive_format,
|
|
23 argf_excessive_args,
|
|
24 argf_struct,
|
|
25 callf_one,
|
|
26 callf_bool,
|
|
27 callf_void,
|
|
28 callf_char,
|
|
29 callf_uchar,
|
|
30 callf_short,
|
|
31 callf_ushort,
|
|
32 callf_int,
|
|
33 callf_uint,
|
|
34 callf_long,
|
|
35 callf_ulong,
|
|
36 callf_longlong,
|
|
37 callf_ulonglong,
|
|
38 callf_float,
|
|
39 callf_double,
|
|
40 callf_pointer,
|
|
41 callf_struct
|
|
42 ].
|
|
43
|
|
44 argf_one(_) ->
|
|
45 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
46 {ok,Sym} = dyncall:find_symbol(Libm, "several_args"),
|
|
47 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
48 ok = dyncall:argf(CallVm,"jcZf)Z",[-125,$[,"foo",6.2]),
|
|
49 {ok,"Your args were -125, [, foo, 6.2"} = dyncall:call_string(CallVm,Sym).
|
|
50
|
|
51 argf_excessive_format(_) ->
|
|
52 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
53 {error,invalid_format} = dyncall:argf(CallVm,"jjjjjjjjcZf)Z",[-125,91,"foo",6.2]).
|
|
54
|
|
55 argf_excessive_args(_) ->
|
|
56 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
57 {error,invalid_format} = dyncall:argf(CallVm,"jcZf)Z",[-125,91,"foo",6.2,7,7,7,7,7,7]).
|
|
58
|
|
59 argf_struct(_) ->
|
|
60 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
61 {error,not_implemented} = dyncall:argf(CallVm,"jTZf)Z",[-125,91,"foo",6.2]).
|
|
62
|
|
63 callf_one(_) ->
|
|
64 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
65 {ok,Sym} = dyncall:find_symbol(Libm, "several_args"),
|
|
66 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
67 {ok,"Your args were -125, [, foo, 6.2"} =
|
|
68 dyncall:callf(CallVm,Sym,"jcZf)Z",[-125,91,"foo",6.2]).
|
|
69
|
|
70 callf_bool(_) ->
|
|
71 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
72 {ok,Sym} = dyncall:find_symbol(Libm, "is_false"),
|
|
73 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
74 {ok,true} =
|
|
75 dyncall:callf(CallVm,Sym,"B)B",[false]).
|
|
76
|
|
77 callf_void(_) ->
|
|
78 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
79 {ok,Sym} = dyncall:find_symbol(Libm, "noop"),
|
|
80 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
81 ok = dyncall:callf(CallVm,Sym,")v",[]).
|
|
82
|
|
83 callf_struct(_) ->
|
|
84 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
85 {ok,Sym} = dyncall:find_symbol(Libm, "several_args"),
|
|
86 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
87 {error,not_implemented} =
|
|
88 dyncall:callf(CallVm,Sym,"jcZf)T",[-125,91,"foo",6.2]).
|
|
89
|
|
90 callf_char(_) ->
|
|
91 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
92 {ok,Sym} = dyncall:find_symbol(Libm, "get_next_char"),
|
|
93 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
94 {ok,120} =
|
|
95 dyncall:callf(CallVm,Sym,"c)c",[119]).
|
|
96
|
|
97 callf_uchar(_) ->
|
|
98 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
99 {ok,Sym} = dyncall:find_symbol(Libm, "get_next_char_u"),
|
|
100 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
101 {ok,222} =
|
|
102 dyncall:callf(CallVm,Sym,"C)C",[221]).
|
|
103
|
|
104 callf_short(_) ->
|
|
105 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
106 {ok,Sym} = dyncall:find_symbol(Libm, "times_three"),
|
|
107 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
108 {ok,-12} =
|
|
109 dyncall:callf(CallVm,Sym,"s)s",[-4]).
|
|
110
|
|
111 callf_ushort(_) ->
|
|
112 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
113 {ok,Sym} = dyncall:find_symbol(Libm, "times_three_u"),
|
|
114 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
115 {ok,12} =
|
|
116 dyncall:callf(CallVm,Sym,"S)S",[4]).
|
|
117
|
|
118 callf_int(_) ->
|
|
119 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
120 {ok,Sym} = dyncall:find_symbol(Libm, "is_false"),
|
|
121 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
122 {ok,1} =
|
|
123 dyncall:callf(CallVm,Sym,"i)i",[0]).
|
|
124
|
|
125 callf_uint(_) ->
|
|
126 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
127 {ok,Sym} = dyncall:find_symbol(Libm, "dual_increment_u"),
|
|
128 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
129 {ok,6} =
|
|
130 dyncall:callf(CallVm,Sym,"I)I",[4]).
|
|
131
|
|
132 callf_long(_) ->
|
|
133 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
134 {ok,Sym} = dyncall:find_symbol(Libm, "add_nineteen"),
|
|
135 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
136 {ok,19} =
|
|
137 dyncall:callf(CallVm,Sym,"j)j",[0]).
|
|
138
|
|
139 callf_ulong(_) ->
|
|
140 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
141 {ok,Sym} = dyncall:find_symbol(Libm, "add_nineteen_u"),
|
|
142 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
143 {ok,23} =
|
|
144 dyncall:callf(CallVm,Sym,"J)J",[4]).
|
|
145
|
|
146 callf_longlong(_) ->
|
|
147 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
148 {ok,Sym} = dyncall:find_symbol(Libm, "subtract_four"),
|
|
149 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
150 {ok,-1} =
|
|
151 dyncall:callf(CallVm,Sym,"l)l",[3]).
|
|
152
|
|
153 callf_ulonglong(_) ->
|
|
154 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
155 {ok,Sym} = dyncall:find_symbol(Libm, "subtract_four_u"),
|
|
156 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
157 {ok,5} =
|
|
158 dyncall:callf(CallVm,Sym,"L)L",[9]).
|
|
159
|
|
160 callf_float(_) ->
|
|
161 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
162 {ok,Sym} = dyncall:find_symbol(Libm, "calculate_pi"),
|
|
163 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
164 {ok,3.0} =
|
|
165 dyncall:callf(CallVm,Sym,"f)f",[1.0]).
|
|
166
|
|
167 callf_double(_) ->
|
|
168 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
169 {ok,Sym} = dyncall:find_symbol(Libm, "times_pi"),
|
|
170 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
171 {ok,6.2} =
|
|
172 dyncall:callf(CallVm,Sym,"d)d",[2.0]).
|
|
173
|
|
174 callf_pointer(_) ->
|
|
175 {ok,Libm} = dyncall:load_library("erldc_testtargets"),
|
|
176 {ok,Sym} = dyncall:find_symbol(Libm, "coolmalloc"),
|
|
177 {ok,CallVm} = dyncall:new_call_vm(?VMSZ),
|
|
178 {ok,MyMemory} =
|
|
179 dyncall:callf(CallVm,Sym,"j)p",[42]),
|
|
180 ok = dyncall:reset(CallVm),
|
|
181 {ok,Sym2} = dyncall:find_symbol(Libm, "coolidentity"),
|
|
182 %% Surprisingly, this works. The _resource handle
|
|
183 %% returned to erlang from callf compares equal in
|
|
184 %% erlang to the _resource handle passed as an arg.
|
|
185 {ok,MyMemory} =
|
|
186 dyncall:callf(CallVm,Sym2,"p)p",[MyMemory]).
|
|
187
|
|
188
|
|
189
|
|
190
|
|
191
|
|
192
|