~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/erl_interface/test/port_call_SUITE.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2010-03-09 17:34:57 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100309173457-4yd6hlcb2osfhx31
Tags: 1:13.b.4-dfsg-3
Manpages in section 1 are needed even if only arch-dependent packages are
built. So, re-enabled them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%% 
 
4
%% Copyright Ericsson AB 2001-2009. All Rights Reserved.
 
5
%% 
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%% 
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%% 
 
17
%% %CopyrightEnd%
 
18
%%
 
19
 
 
20
%%
 
21
-module(port_call_SUITE).
 
22
 
 
23
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
24
%%% Checks if the dynamic driver and linker loader works.
 
25
%%%
 
26
%%% These tests can only be run installed (outside clearcase).
 
27
%%%
 
28
%%% XXX In this suite is missing test cases for reference counts
 
29
%%% and that drivers are unloaded when their processes die.
 
30
%%% (For me to add :-)
 
31
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
32
 
 
33
 
 
34
-export([all/1, basic/1]).
 
35
% Private exports
 
36
-include("test_server.hrl").
 
37
 
 
38
 
 
39
all(suite) -> 
 
40
    [basic].
 
41
 
 
42
basic(suite) -> [];
 
43
basic(Config) when is_list(Config) ->
 
44
    case os:type() of
 
45
        {unix, sunos} ->
 
46
            do_basic(Config);
 
47
        {win32,_} ->
 
48
            do_basic(Config);
 
49
        _ ->
 
50
            {skipped, "Dynamic linking and erl_interface not fully examined"
 
51
             " on this platform..."}        
 
52
    end.
 
53
 
 
54
do_basic(Config) ->
 
55
    ?line Dog = test_server:timetrap(test_server:seconds(10)),
 
56
    ?line Path = ?config(data_dir, Config),
 
57
 
 
58
    ?line erl_ddll:start(),
 
59
 
 
60
    %% Load the echo driver and verify that it was loaded.
 
61
    {ok,L1,L2}=load_port_call_driver(Path),
 
62
 
 
63
    %% Verify that the driver works.
 
64
 
 
65
    ?line Port = open_port({spawn, port_call_drv}, [eof]),
 
66
    ?line {hej, "hopp",4711,123445567436543653} = 
 
67
        erlang:port_call(Port,{hej, "hopp",4711,123445567436543653}),
 
68
    ?line {hej, "hopp",4711,123445567436543653} = 
 
69
        erlang:port_call(Port,0,{hej, "hopp",4711,123445567436543653}),
 
70
    ?line {[], a, [], b, c} = 
 
71
        erlang:port_call(Port,1,{hej, "hopp",4711,123445567436543653}),
 
72
    ?line {return, {[], a, [], b, c}} = 
 
73
        erlang:port_call(Port,2,{[], a, [], b, c}),
 
74
    ?line List = lists:duplicate(200,5),
 
75
    ?line {return, List} = erlang:port_call(Port,2,List),
 
76
    ?line {'EXIT',{badarg,_}} = (catch erlang:port_call(Port,4711,[])),
 
77
    ?line {'EXIT',{badarg,_}} = (catch erlang:port_call(sune,2,[])),
 
78
    ?line register(gunnar,Port),
 
79
    ?line {return, List} = erlang:port_call(gunnar,2,List),
 
80
    ?line {return, a} = erlang:port_call(gunnar,2,a),
 
81
    ?line erlang:port_close(Port),
 
82
    %% Unload the driver and verify that it was unloaded.
 
83
    ok=unload_port_call_driver(L1,L2),
 
84
 
 
85
    ?line {error, {already_started, _}} = erl_ddll:start(),
 
86
    ?line ok = erl_ddll:stop(),
 
87
 
 
88
    ?line test_server:timetrap_cancel(Dog),
 
89
    ok.
 
90
 
 
91
load_port_call_driver(Path) ->
 
92
    ?line {ok, L1} = erl_ddll:loaded_drivers(),
 
93
    ?line ok = erl_ddll:load_driver(Path, port_call_drv),
 
94
    ?line {ok, L2} = erl_ddll:loaded_drivers(),
 
95
    ?line ["port_call_drv"] = ordsets:to_list(ordsets:subtract(ordsets:from_list(L2), 
 
96
                                                               ordsets:from_list(L1))),
 
97
    {ok,L1,L2}.
 
98
 
 
99
unload_port_call_driver(L1,L2) ->
 
100
    ?line {ok, L2} = erl_ddll:loaded_drivers(),
 
101
    ?line ok = erl_ddll:unload_driver(port_call_drv),
 
102
    ?line {ok, L3} = erl_ddll:loaded_drivers(),
 
103
    ?line [] = ordsets:to_list(ordsets:subtract(ordsets:from_list(L3),
 
104
                                                ordsets:from_list(L1))),
 
105
    ok.
 
106