Search code examples
erlangcommon-test

erlang common test: how to start iconv application?


In my application I'm using this implementation of erlang-iconv. Simple test suite:

-module(example_SUITE).

-include_lib("common_test/include/ct.hrl").

-export([all/0, suite/0, init_per_suite/1, end_per_suite/1,
         simple_test_case/1]).

all() ->
    [simple_test_case].

suite() ->
    [{timetrap, {minutes, 1}}].

init_per_suite(Config) ->
    application:start(iconv),
    Config.

end_per_suite(Config) ->
    application:stop(iconv),
    Config.

simple_test_case(_Config) ->
    ok.

On attempt to run this suite:

ct_run -pa ebin/ deps/*/ebin/ deps/*/deps/*/ebin/ -dir test/ -logdir logs/ -suite example_SUITE

...
=INFO REPORT==== 23-Mar-2014::19:45:30 ===
    application: iconv
    exited: {{shutdown,
                 {failed_to_start_child,iconv,
                     {{case_clause,{error,{open_error,-10}}},
                      [{iconv,init,1,[{file,"src/iconv.erl"},{line,49}]},
                       {gen_server,init_it,6,
                           [{file,"gen_server.erl"},{line,304}]},
                       {proc_lib,init_p_do_apply,3,
                           [{file,"proc_lib.erl"},{line,239}]}]}}},
             {iconv_app,start,[normal,[]]}}
    type: temporary
Testing web.wasearch.example_SUITE: TEST COMPLETE, 1 ok, 0 failed of 1 test cases
....

This error is kind of obvious because erlang-iconv depend on C drive in its priv_dir:

init([]) ->
    case erl_ddll:load_driver(get_so_path(), iconv_drv) of
        ok -> ok;
        {error, already_loaded} -> ok
    end,
    Port = open_port({spawn, "iconv_drv"}, []),
    ets:new(iconv_table, [set, public, named_table]),
    ets:insert(iconv_table, {port, Port}),
    {ok, Port}.

get_so_path() ->
    case code:priv_dir(iconv) of
        {error, _} -> "./priv";
        Path -> Path

How can I trick erlang-iconv and force it to look up C driver in other location (absoulute path to iconv's priv_dir in my project's deps directories)?


Solution

  • Shot from the hip: Set ERL_LIBS appropriately.

    Your priv_dir should be set up correctly and belong to the iconv application, but since the Erlang system did not pick that up, I am guessing your -pa adds doesn't track this. Setting ERL_LIBS to include deps might do the trick for the build.