Related
I have running application and in the interactive console I try to run common test suites located in test/common directory:
ct:run("test/common").
But I get a bunch of errors:
Reason: undef
and all tests fail.
I tried to run them from linux shell
ct_run -dir test/common
or like this:
ct_run -boot start_sasl -spec test/common/app_ct.spec -erl_args -config env/dev.config
with the same result.
But when I run them using rebar (the second version, not rebar3)
rebar ct
Everything works, tests pass. But it takes too much time to compile the app and to start it.
In the rebar.config I have:
{ct_dir,"test/common"}.
{ct_log_dir,"test/logs"}.
{ct_extra_params,"-boot start_sasl -pa deps/*/ebin -pa ebin -spec test/common/app_ct.spec -erl_args -config env/dev.config"}.
and in the test/common/app_ct.spec I have:
{verbosity, 100}.
{init, {eval, [{application, ensure_all_started, [app]}, {timer, sleep, [30000]}]}}.
{alias, common, "./test/common/"}.
{suites, "", [app_srv_SUITE, app_client_SUITE]}.
What can I do to run tests from erl console using ct:run("test/common")?
My goal is to be able to recompile single test files individually and run tests from working application console without stopping and recompiling all application.
I recompile singular test module without problems like this:
c("test/common/new_mod_SUITE.erl", [{i, "include"}, {i, "deps"}, {outdir, "test/common"}]).
But I still can't run tests after that.
First of all, need to be sure that all tests is compiled and they are inside of folder what is put as argument into ct:run/1. If need to run only one test from specific folder, can be used ct:run/2. If need to run specific test case from specific folder, can be used specific folder ct:run/3. Examples:
1> ct:run("test/common").
2> ct:run("test/common", "some_SUITE").
However I would recommend using rebar3, in rebar3 was added option like --dir and tests from specific folder can be run like:
$ ./rebar3 ct --dir="test/common"
This probably won't help, but here is what happens for me using rebar3:
~/erlang_programs/myrebar/myapp$ ls
LICENSE _build rebar.lock test
README.md rebar.config src
~/erlang_programs/myrebar/myapp$ cd src
~/erlang_programs/myrebar/myapp/src$ ls
a.erl myapp_app.erl rebar.lock
myapp.app.src myapp_sup.erl
~/erlang_programs/myrebar/myapp/src$ cat a.erl
-module(a).
-compile(export_all).
%%-include("eunit.hrl").
hello() -> io:format("hello").
~/erlang_programs/myrebar/myapp/src$ cd ../test
~/erlang_programs/myrebar/myapp/test$ ls
a_SUITE.erl
~/erlang_programs/myrebar/myapp/test$ cat a_SUITE.erl
-module(a_SUITE).
-compile(export_all).
all() -> [go].
go(_Config) ->
1 = 1.
~/erlang_programs/myrebar/myapp/test$ cd ..
~/erlang_programs/myrebar/myapp$ rebar3 compile
===> Verifying dependencies...
===> Compiling myapp
~/erlang_programs/myrebar/myapp$ rebar3 shell
===> Verifying dependencies...
===> Compiling myapp
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [kernel-poll:false]
Eshell V9.3 (abort with ^G)
1> ===> The rebar3 shell is a development tool; to deploy applications in production, consider using releases (http://www.rebar3.org/docs/releases)
===> Booted myapp
1> ct:run("test").
Common Test: Running make in test directories...
Recompile: a_SUITE
a_SUITE.erl:2: Warning: export_all flag enabled - all functions will be exported
CWD set to: "/Users/7stud/erlang_programs/myrebar/myapp/ct_run.nonode#nohost.2021-02-14_14.26.08"
TEST INFO: 1 test(s), 1 case(s) in 1 suite(s)
Testing myrebar.myapp: Starting test, 1 test cases
Testing myrebar.myapp: TEST COMPLETE, 1 ok, 0 failed of 1 test cases
Updating /Users/7stud/erlang_programs/myrebar/myapp/index.html ... done
Updating /Users/7stud/erlang_programs/myrebar/myapp/all_runs.html ... done
{1,0,{0,0}}
2>
Then after exiting the shell:
~/erlang_programs/myrebar/myapp$
~/erlang_programs/myrebar/myapp$ rebar3 ct
===> Verifying dependencies...
===> Compiling myapp
test/a_SUITE.erl:2: Warning: export_all flag enabled - all functions will be exported
===> Running Common Test suites...
%%% a_SUITE: .
All 1 tests passed.
~/erlang_programs/myrebar/myapp$
I didn't touch rebar.config, it is the default produced by rebar3:
{erl_opts, [debug_info]}.
{deps, [{eleveldb, "2.2.20"}]
}.
{shell, [
% {config, "config/sys.config"},
{apps, [myapp]}
]}.
I would try printing your current working directory when you are in the shell:
2> pwd().
/Users/7stud/erlang_programs/myrebar/myapp
ok
Then try using either a full path or a relative path from that directory, e.g.:
"./test/common"
"Users/../../test/common"
Then, I would move all your *_SUITE.erl files except one into a directory outside your app, and just work with one test file. Then, I would get rid of all that config file stuff and try again.
I installed rebar3 and created a new release with
cd ~/apps
rebar3 new release tunnel
Then
I copied my src files from ~/tunnel/src/* to ~/apps/tunnel/src/
I ran into a compile error with rebar3 run and found Erlang "Kernel pid terminated" error as a possible solution. I renamed everything about tunnel_app to tunnel. So my src contains tunnel.erl , tunnel.app.src and tunnel_sup.erl. I renamed the module definition as appropriate.
Here's the rebar3 run error:
~/apps/tunnel:.rebar3 run
===> Verifying dependencies...
===> Compiling tunnel
===> Starting relx build process ...
===> Resolving OTP Applications from directories:
/Users/quantum/apps/tunnel/_build/default/lib
/Users/quantum/apps/tunnel/apps
/usr/local/Cellar/erlang/19.2/lib/erlang/lib
/Users/quantum/apps/tunnel/_build/default/rel
===> Resolved tunnel-0.1.0
===> Dev mode enabled, release will be symlinked
===> release successfully created!
readlink: illegal option -- f
usage: readlink [-n] [file ...]
Exec: /usr/local/Cellar/erlang/19.2/lib/erlang/erts-8.2/bin/erlexec -boot /Users/quantum/apps/tunnel/_build/default/rel/tunnel/releases/0.1.0/tunnel -mode embedded -boot_var ERTS_LIB_DIR /usr/local/Cellar/erlang/19.2/lib/erlang/lib -config /Users/quantum/apps/tunnel/_build/default/rel/tunnel/releases/0.1.0/sys.config -args_file /Users/quantum/apps/tunnel/_build/default/rel/tunnel/releases/0.1.0/vm.args -pa -- console
Root: /Users/quantum/apps/tunnel/_build/default/rel/tunnel
/Users/quantum/apps/tunnel/_build/default/rel/tunnel
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:30] [hipe] [kernel-poll:true] [dtrace]
=INFO REPORT==== 16-Feb-2017::15:02:21 ===
application: tunnel
exited: {bad_return,
{{tunnel,start,[normal,[]]},
{'EXIT',
{undef,
[{cowboy_router,compile,
[[{'_',
[{"/info",lobby_handler,[]},
{"/join/:name",join_handler,[]},
{"/play/:table_pid/:name/:auth/:team/:action/:x/:y",
play_handler,[]}]}]],
[]},
{tunnel,start,2,
[{file,
"/Users/quantum/apps/tunnel/_build/default/lib/tunnel/src/tunnel.erl"},
{line,8}]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,273}]}]}}}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,tunnel,{bad_return,{{tunnel,start,[normal,[]]},{'EXIT',{undef,[{cowboy_router,compile,[[{'_',[{\"/info\",lobby_handler,[]},{\"/join/:name\",join_handler,[]},{\"/play/:table_pid/:name/:auth/:team/:action/:x/:y\",play_handler,[]}]}]],[]},{tunnel,start,2,[{file,\"/Users/quantum/apps/tunnel/_build/default/lib/tunnel/src/tunnel.erl\"},{line,8}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,273}]}]}}}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,tunnel,{bad_return,{{tunnel,start,[normal,[]]},{'EXIT',{undef,[{cowboy_router,compile,[[{'_',[{"/info",lobby_handler,[]},{"/j
Crash dump is being written
Why is this crashing?
If this is your first experience with rebar3, I suggest starting with an OTP application, not an OTP release:
rebar3 new app tunnel
and then do not blindly copy over the source files because you risk overwriting the files that have been created for you below src. Have a look at the contents of that directory beforehand.
I also suggest to take the time to read the rebar3 https://www.rebar3.org/docs/basic-usage page.
You will also have to read about what an OTP application is. I know, quite a lot to understand and sometimes confusing. A free source is http://learnyousomeerlang.com/building-applications-with-otp. It is also worthwhile to buy a book about Erlang. There are a few, I suggest https://www.manning.com/books/erlang-and-otp-in-action.
There is also an online course, free, that starts in a few days (20th Feb 2017) https://www.mooc-list.com/course/functional-programming-erlang-futurelearn
(Newbie here) I am having an error when trying to run ranch example.
Via rebar I created application and node (please see on github).
But when I am trying to build and run it I am getting undef ranch,start_listener.
Please see full console output:
$ rebar get-deps compile generate && sh rel/reverse/bin/reverse console
WARN: Expected reverse/deps/ranch to be an app dir (containing ebin/*.app), but no .app found.
==> rel (get-deps)
==> reverse (get-deps)
WARN: Expected reverse/deps/ranch to be an app dir (containing ebin/*.app), but no .app found.
Pulling ranch from {git,"git#github.com:ninenines/ranch.git",{tag,"1.1.0"}}
Cloning into 'ranch'...
==> ranch (get-deps)
==> ranch (compile)
Compiled src/ranch_transport.erl
Compiled src/ranch_sup.erl
Compiled src/ranch_ssl.erl
Compiled src/ranch_tcp.erl
Compiled src/ranch_protocol.erl
Compiled src/ranch_listener_sup.erl
Compiled src/ranch_app.erl
Compiled src/ranch_acceptors_sup.erl
Compiled src/ranch_acceptor.erl
Compiled src/ranch_server.erl
Compiled src/ranch.erl
Compiled src/ranch_conns_sup.erl
==> rel (compile)
==> reverse (compile)
Compiled src/reverse_sup.erl
Compiled src/reverse_app.erl
Compiled src/reverse_protocol.erl
==> rel (generate)
WARN: 'generate' command does not apply to directory reverse
Exec: reverse/rel/reverse/erts-6.3/bin/erlexec -boot reverse/rel/reverse/releases/1/reverse -mode embedded -config reverse/rel/reverse/releases/1/sys.config -args_file reverse/rel/reverse/releases/1/vm.args -- console
Root: reverse/rel/reverse
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V6.3 (abort with ^G)
(reverse#127.0.0.1)1>
=INFO REPORT==== 30-Dec-2014::22:47:08 ===
application: reverse
exited: {bad_return,
{{reverse_app,start,[normal,[]]},
{'EXIT',
{undef,
[{ranch,start_listener,
[reverse,10,ranch_tcp,
[{port,5555}],
reverse_protocol,[]],
[]},
{reverse_app,start,2,
[{file,"src/reverse_app.erl"},{line,13}]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,272}]}]}}}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,reverse,{bad_return,{{reverse_app,start,[normal,[]]},{'EXIT',{undef,[{ranch,start_listener,[reverse,10,ranch_tcp,[{port,5555}],reverse_protocol,[]],[]},{reverse_app,start,2,[{file,\"src/reverse_app.erl\"},{line,13}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,272}]}]}}}}}"}
Crash dump was written to: erl_crash.dump
I am not sure I correctly added ranch to reltool.config (please see on github). But If I remove deps from libs_dir path I will get rebar generate error Application version clash. Multiple directories contain version ....
UPDATE if I remove failing call and run it, application:which_applications(). gives me {ranch,[],[]} as one of the running ones.
UPDATE versions
$ erl
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
$ rebar --version
rebar 2.5.1 17 20141223_141030 git 2.5.1-84-gdd9125e
What I am doing wrong?
Thanks in advance!
In the reltool.config, remove the ebin directory from the path to Ranch:
{app, ranch, [{mod_cond, app}, {incl_cond, include}, {lib_dir, "../deps/ranch/"}]}
If you have lots of dependencies it's more convenient to do:
{lib_dirs, ["../deps"]}
instead of having a separate {app, <dep_name>, [...]} for each dependency.
The Application version clash. Multiple directories contain version XXX error indicates that the Ranch application is already installed, probably in the Erlang lib directory, creating conflicts with the deps version downloaded by Rebar.
I am trying to setup a rebar release for my otp application. I followed this guide: https://github.com/basho/rebar/wiki/Getting-started
When I try to generate a release, I get lots of enotdir errors:
~/Projekte/mc-erl/repo $ ./rebar generate
==> rel (generate)
Error reading /home/clonejo/Projekte/mc-erl/repo/rebar/rebar_app_utils.beam's file info: enotdir
Error reading /home/clonejo/Projekte/mc-erl/repo/rebar/rebar_deps.beam's file info: enotdir
Error reading /home/clonejo/Projekte/mc-erl/repo/rebar/rebar_appups.beam's file info: enotdir
[... enotdir errors go on ...]
[... all above enotdir errors are repeated ...]
ERROR: Unable to generate spec: read file info /usr/lib/erlang/man/man1/preunzip.1 failed
This is my version of erlang:
$ erl
Erlang R15B (erts-5.9) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9 (abort with ^G)
I got rebar at http://cloud.github.com/downloads/basho/rebar/rebar (see the GettingStarted wiki page).
Update: Verbose mode only adds one warning, which is unrelated:
WARN: 'generate' command does not apply to directory /home/clonejo/Projekte/mc-erl/repo/apps/mc_erl
Most likely, you have installed the "reloader" module somehow, perhaps via your .erlang? That specific error message originates from there.
Could you run it with -v
There was and maybe still is a bug
http://lists.basho.com/pipermail/rebar_lists.basho.com/2011-July/000932.html
I would suggest to update rebar and run rebar -v to see more info.
I followed the instructions here, to the letter. I then ran the instruction to create an application project structure, and got the following error.
$ ./rebar create-app appid=myapp
Uncaught error in rebar_core: {'EXIT',
{undef,
[{crypto,start,[]},
{rebar_core,run,1},
{rebar,main,1},
{escript,run,2},
{escript,start,1},
{init,start_it,1},
{init,start_em,1}]}}
Any ideas what I'm doing wrong?
It looks like your Erlang was compiled without OpenSSL (the crypto module). crypto is required for many (most?) Erlang applications. You'll need to get a version of Erlang with a working crypto module, and then you shouldn't have any problems like this.
A clarification to YOUR ARGUMENT IS VALID's answer (adding as an answer because the comment is too short).
It may be that Erlang was compiled properly but the OpenSSL libraries are not visible to Erlang, so the crypto server can't be started. I compiled Erlang on Solaris 10 and it didn't complain about OpenSSL not being installed. In fact, it compiled crypto and installed it in: /usr/local/lib/erlang/lib/crypto-2.2/
But Rebar still wasn't working. It's easy to check if the problem is indeed with the crypto module.
Open Erlang shell and type crypto:start(). This was happening on my system:
bash-3.2# erl
Erlang R15B03 (erts-5.9.3.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3.1 (abort with ^G)
1> crypto:start().
** exception error: undefined function crypto:start/0
2>
=ERROR REPORT==== 8-Feb-2013::15:28:43 ===
Unable to load crypto library. Failed with error:
"load_failed, Failed to load NIF library: 'ld.so.1: beam.smp: fatal: relocation error: file /usr/local/lib/erlang/lib/crypto-2.2/priv/lib/crypto.so: symbol DES_ede3_cfb_encrypt: referenced symbol not found'"
OpenSSL might not be installed on this system.
=ERROR REPORT==== 8-Feb-2013::15:28:43 ===
The on_load function for module crypto returned {error,
{load_failed,
"Failed to load NIF library: 'ld.so.1: beam.smp: fatal: relocation error: file /usr/local/lib/erlang/lib/crypto-2.2/priv/lib/crypto.so: symbol DES_ede3_cfb_encrypt: referenced symbol not found'"}}
If OpenSSL is installed in a non-standard location, as it is the case when using OpenCSW to install OpenSSL on Solaris 10, it is easy to fix the problem by adding the library path to the environment variable. For example on Solaris 10 to /etc/profile:
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/csw/lib
export LD_LIBRARY_PATH
Then log-out and log-in or re-load the bash environment, for example like this:
bash-3.2# . /etc/profile
Result:
bash-3.2# erl
Erlang R15B03 (erts-5.9.3.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3.1 (abort with ^G)
1> crypto:start().
ok
I'd recommend using precompiled Erlang which is available from Erlang Solutions: https://www.erlang-solutions.com/downloads/download-erlang-otp
There's one for Windows too.
Getting this error when running make command:
root#hs:/var/www/html/ejabberd-master# make
rm -rf deps/.got
rm -rf deps/.built
/usr/local/lib/erlang/bin/escript rebar get-deps && :> deps/.got
Uncaught error in rebar_core: {'EXIT',
{undef,
[{crypto,start,[],[]},
{rebar,run_aux,2,
[{file,"src/rebar.erl"},{line,163}]},
{rebar,main,1,
[{file,"src/rebar.erl"},{line,58}]},
{escript,run,2,
[{file,"escript.erl"},{line,757}]},
{escript,start,1,
[{file,"escript.erl"},{line,277}]},
{init,start_it,1,[]},
{init,start_em,1,[]}]}}
make: *** [deps/.got] Error 1
The erlang details are:
root#hs:/home/node# erl
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async- threads:10] [hipe] [kernel-poll:false]
Eshell V7.0 (abort with ^G)
1> crypto:start()
1>
Seems like crypto not working, as the command gives "Ok" or "exception error".
Help needed.
Thanks for the answer Ivan. But it seems I figured out the issue:
The ubuntu auto updates were turned off and the dependencies were not installed while compiling erlang (e.g. libssh-dev). Once the auto update was turned on it compiled and make command ran fine.