2

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)?

evnu
  • 6,450
  • 2
  • 27
  • 38
Anton Koval'
  • 4,863
  • 5
  • 31
  • 44
  • Did you try `-pa deps/erlang-iconv` (or sth similar, I don't know the paths. Try to point `-pa` to the `erlang-iconv` directory)? – evnu Mar 24 '14 at 13:01

1 Answers1

0

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.

I GIVE CRAP ANSWERS
  • 18,739
  • 3
  • 42
  • 47
  • So, the problem was in name of folder for erlang-iconv dependency! After renaming it from erlang-iconv to iconv - `code:priv_dir(iconv)` begins to return correct path. It works without ERL_LIBS variable, but thanks for the hint - reading documentation about `code` module helped me to find an answer. – Anton Koval' Mar 24 '14 at 20:38