【问题标题】:erlang common test: how to start iconv application?erlang常见测试:如何启动iconv应用程序?
【发布时间】:2014-04-30 22:38:00
【问题描述】:

在我的应用程序中,我使用了this erlang-iconv 的实现。 简单的测试套件:

-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.

在尝试运行此套件时:

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
....

这个错误有点明显,因为 erlang-iconv 在其priv_dir 中依赖于 C 盘:

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

如何欺骗 erlang-iconv 并强制它在其他位置查找 C 驱动程序(我项目的 deps 目录中 iconv 的 priv_dir 的绝对路径)?

【问题讨论】:

  • 你试过-pa deps/erlang-iconv(或类似的东西,我不知道路径。尝试将-pa指向erlang-iconv目录)?

标签: erlang common-test


【解决方案1】:

从臀部拍摄:适当设置 ERL_LIBS。

您的priv_dir 应该正确设置并且属于iconv 应用程序,但是由于Erlang 系统没有选择它,我猜您的-pa 添加不会跟踪这个。将 ERL_LIBS 设置为包含 deps 可能会对构建起到作用。

【讨论】:

  • 所以,问题出在 erlang-iconv 依赖的文件夹名称上!将其从 erlang-iconv 重命名为 iconv - code:priv_dir(iconv) 开始返回正确的路径。它可以在没有 ERL_LIBS 变量的情况下工作,但感谢您的提示 - 阅读有关 code 模块的文档帮助我找到了答案。
猜你喜欢
  • 1970-01-01
  • 2013-01-08
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
  • 2015-03-02
  • 2012-06-16
  • 1970-01-01
  • 2012-10-11
相关资源
最近更新 更多