-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trace option to ignore keepalive frames
Z/IP KeepAlive frames are fairly noisy and recording them is really only useful for debugging the keepalives themselves. Keepalive frames can quickly fill the trace buffer, especially in networks with many active nodes. This also makes a minor change to the default trace format to include the expected delay field when printing nack+waiting Z/IP Packet frames.
- Loading branch information
1 parent
c0c95a1
commit 6507707
Showing
3 changed files
with
197 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
defmodule Grizzly.TraceTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Grizzly.Trace | ||
alias Grizzly.ZWave | ||
alias Grizzly.ZWave.Commands.{SwitchBinaryGet, ZIPKeepAlive, ZIPPacket} | ||
|
||
setup %{test: test} = ctx do | ||
opts = | ||
ctx | ||
|> Map.take([:size, :record_keepalives]) | ||
|> Map.put(:name, test) | ||
|> Enum.into([]) | ||
|
||
pid = start_supervised!({Trace, opts}) | ||
Map.put(ctx, :tracer, pid) | ||
end | ||
|
||
@tag size: 2 | ||
test "log/3", %{tracer: tracer} do | ||
{:ok, cmd} = SwitchBinaryGet.new() | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 1) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 2) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), src: "src1", dest: "dest1") | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 3) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), src: "src2", dest: "dest2") | ||
|
||
list = Trace.list(tracer) | ||
assert length(list) == 2 | ||
|
||
assert [ | ||
%{binary: <<_::32, 2, _::binary>>, src: "src1", dest: "dest1"}, | ||
%{binary: <<_::32, 3, _::binary>>, src: "src2", dest: "dest2"} | ||
] = list | ||
end | ||
|
||
@tag size: 1 | ||
test "resize/2", %{tracer: tracer} do | ||
{:ok, cmd} = SwitchBinaryGet.new() | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 1) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 2) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
list = Trace.list(tracer) | ||
assert length(list) == 1 | ||
|
||
assert [%{binary: <<_::32, 2, _::binary>>}] = list | ||
|
||
Trace.resize(tracer, 3) | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 3) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 4) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 5) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
list = Trace.list(tracer) | ||
assert length(list) == 3 | ||
|
||
assert [ | ||
%{binary: <<_::32, 3, _::binary>>}, | ||
%{binary: <<_::32, 4, _::binary>>}, | ||
%{binary: <<_::32, 5, _::binary>>} | ||
] = list | ||
|
||
Trace.resize(tracer, 2) | ||
|
||
list = Trace.list(tracer) | ||
assert length(list) == 2 | ||
|
||
assert [ | ||
%{binary: <<_::32, 4, _::binary>>}, | ||
%{binary: <<_::32, 5, _::binary>>} | ||
] = list | ||
end | ||
|
||
test "clear/1", %{tracer: tracer} do | ||
{:ok, cmd} = SwitchBinaryGet.new() | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 1) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
{:ok, zip_packet} = ZIPPacket.with_zwave_command(cmd, 2) | ||
Trace.log(tracer, ZWave.to_binary(zip_packet), []) | ||
|
||
list = Trace.list(tracer) | ||
assert length(list) == 2 | ||
|
||
Trace.clear(tracer) | ||
|
||
list = Trace.list(tracer) | ||
assert list == [] | ||
end | ||
|
||
test "records keepalives by default", %{tracer: tracer} do | ||
{:ok, keepalive} = ZIPKeepAlive.new(ack_flag: :ack_request) | ||
Trace.log(tracer, ZWave.to_binary(keepalive), []) | ||
|
||
{:ok, keepalive} = ZIPKeepAlive.new(ack_flag: :ack_response) | ||
Trace.log(tracer, ZWave.to_binary(keepalive), []) | ||
|
||
list = Trace.list(tracer) | ||
assert length(list) == 2 | ||
|
||
assert [ | ||
%{binary: <<0x23, 0x03, 0x80>>}, | ||
%{binary: <<0x23, 0x03, 0x40>>} | ||
] = list | ||
end | ||
|
||
@tag record_keepalives: false | ||
test "enable/disable keepalives", %{tracer: tracer} do | ||
{:ok, keepalive} = ZIPKeepAlive.new(ack_flag: :ack_request) | ||
Trace.log(tracer, ZWave.to_binary(keepalive), []) | ||
|
||
list = Trace.list(tracer) | ||
assert list == [] | ||
|
||
Trace.record_keepalives(tracer, true) | ||
Trace.log(tracer, ZWave.to_binary(keepalive), []) | ||
|
||
Trace.record_keepalives(tracer, false) | ||
Trace.log(tracer, ZWave.to_binary(keepalive), []) | ||
|
||
list = Trace.list(tracer) | ||
assert [%{binary: <<0x23, 0x03, 0x80>>}] = list | ||
end | ||
end |