Skip to content

Commit

Permalink
Add test for UCI-over-TCP connection
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBRO committed Feb 13, 2022
1 parent feb9036 commit ac427bd
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ jobs:
run: brew install rebar3
- name: Install Stockfish
run: brew install stockfish
- name: Start Stockfish TCP Server
run: launchctl load test/stockfish-tcp/org.stockfish.plist
- name: Cache Hex packages
uses: actions/cache@v2
with:
Expand All @@ -101,6 +103,8 @@ jobs:
- name: CT tests
run: |
export BINBO_UCI_ENGINE_PATH=/usr/local/bin/stockfish
export BINBO_UCI_ENGINE_HOST=localhost
export BINBO_UCI_ENGINE_PORT=9010
rebar3 ct
- name: Code coverage
run: rebar3 cover
Expand Down
32 changes: 32 additions & 0 deletions test/stockfish-tcp/org.stockfish.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.stockfishchess.stockfishd</string>

<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/stockfish</string>
</array>

<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>

<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockServiceName</key>
<string>9010</string>
<key>SockType</key>
<string>stream</string>
<key>SockFamily</key>
<string>IPv4</string>
</dict>
</dict>
</dict>
</plist>
70 changes: 56 additions & 14 deletions test/uci_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,75 @@
-include("binbo_test_lib.hrl").

-export([all/0]).
-export([groups/0]).
-export([init_per_suite/1, end_per_suite/1]).
-export([uci_test/1]).
-export([init_per_testcase/2, end_per_testcase/2]).

-export([
uci_test_engine_local/1,
uci_test_engine_tcp/1
]).

%% all/0
all() -> [uci_test].
all() -> [{group, all_uci_tests}].

%% groups/0
groups() ->
[{all_uci_tests, [parallel], [
uci_test_engine_local,
uci_test_engine_tcp
]}].


%% init_per_suite/1
init_per_suite(Config) ->
ok = binbo_test_lib:all_group_testcases_exported(?MODULE),
{ok, _} = binbo:start(),
Config.

%% end_per_suite/1
end_per_suite(_Config) ->
ok = binbo:stop(),
ok.

%% init_per_testcase/2
init_per_testcase(uci_test_engine_local, Config) ->
EnginePath = os:getenv("BINBO_UCI_ENGINE_PATH"),
case validate_engine_path(EnginePath) of
case validate_engine_file_path(EnginePath) of
ok ->
{ok, _} = binbo:start(),
[{engine_path, EnginePath} | Config];
{error, Reason} ->
{skip, {Reason, EnginePath}}
end;
init_per_testcase(uci_test_engine_tcp, Config) ->
EnvEngineHost = os:getenv("BINBO_UCI_ENGINE_HOST"),
EnvEnginePort = os:getenv("BINBO_UCI_ENGINE_PORT"),
case {EnvEngineHost, EnvEnginePort} of
{[_|_], [_|_]} ->
EnginePort = erlang:list_to_integer(EnvEnginePort),
EnginePath = {EnvEngineHost, EnginePort, 5000},
[{engine_path, EnginePath} | Config];
{_, _} ->
{skip, {{engine_host, EnvEngineHost}, {engine_port, EnvEnginePort}}}
end.

%% end_per_suite/1
end_per_suite(_Config) ->
ok = binbo:stop(),

%% end_per_testcase/2
end_per_testcase(_TestCase, _Config) ->
ok.

%% uci_test_engine_local/1
uci_test_engine_local(Config) ->
_ = uci_test_play_game(Config),
ok.

%% uci_test_engine_tcp/1
uci_test_engine_tcp(Config) ->
_ = uci_test_play_game(Config),
ok.

%% uci_test/1
uci_test(Config) ->
%% uci_test_play_game/1
uci_test_play_game(Config) ->
EnginePath = ?value(engine_path, Config),
InitialFen = binbo_fen:initial(),

Expand Down Expand Up @@ -93,10 +137,8 @@ uci_test(Config) ->
ok = binbo:stop_server(Pid),
ok.



%% validate_engine_path/1
validate_engine_path([_|_] = EnginePath) ->
%% validate_engine_file_path/1
validate_engine_file_path([_|_] = EnginePath) ->
case file:read_file_info(EnginePath) of
{ok, #file_info{type = regular}} ->
ok;
Expand All @@ -105,5 +147,5 @@ validate_engine_path([_|_] = EnginePath) ->
{error, Reason} ->
{error, Reason}
end;
validate_engine_path(_) ->
validate_engine_file_path(_) ->
{error, no_egine_path_provided}.

0 comments on commit ac427bd

Please sign in to comment.