STABLE, 36.3% Firmware coverage.
parent
80d353664b
commit
b59075c9aa
|
@ -502,8 +502,14 @@ defmodule FarmbotFirmware do
|
|||
end
|
||||
end
|
||||
|
||||
def handle_call({_tag, _code} = gcode, from, state) do
|
||||
handle_command(gcode, from, state)
|
||||
def handle_call({tag, {kind, args}}, from, state) do
|
||||
handle_command({tag, {kind, args}}, from, state)
|
||||
end
|
||||
|
||||
# TODO(RICK): Not sure if this is required.
|
||||
# Some commands were missing a tag.
|
||||
def handle_call({kind, args}, from, state) do
|
||||
handle_command({nil, {kind, args}}, from, state)
|
||||
end
|
||||
|
||||
@doc false
|
||||
|
|
|
@ -6,84 +6,57 @@ defmodule FarmbotFirmware.CommandTest do
|
|||
import ExUnit.CaptureLog
|
||||
@subject FarmbotFirmware.Command
|
||||
|
||||
def try_command(pid, cmd) do
|
||||
# @subject.command(pid, cmd)
|
||||
GenServer.call(pid, cmd, :infinity)
|
||||
end
|
||||
|
||||
def firmware_server do
|
||||
arg = [transport: FarmbotFirmware.StubTransport]
|
||||
{:ok, pid} = FarmbotFirmware.start_link(arg, [])
|
||||
send(pid, :timeout)
|
||||
try_command(pid, {nil, {:command_emergency_lock, []}})
|
||||
try_command(pid, {nil, {:command_emergency_unlock, []}})
|
||||
pid
|
||||
end
|
||||
|
||||
def try_command(cmd, pid \\ firmware_server()) do
|
||||
@subject.command(pid, cmd)
|
||||
end
|
||||
|
||||
@tag :this_is_the_bug
|
||||
test "direct call (delete this later)" do
|
||||
test "various command()s" do
|
||||
pid = firmware_server()
|
||||
|
||||
{:error, result} =
|
||||
GenServer.call(pid, {:command_emergency_lock, []}, :infinity)
|
||||
cmds = [
|
||||
# TEST VALUES EXTRACTED FROM A REAL BOT
|
||||
# They may change over time, so a test failure
|
||||
# is not necessarily indicitive of a defect,
|
||||
# but it *IS* indicitve of a change (perhaps unepxected?)
|
||||
# in runtime behavior.
|
||||
#
|
||||
# Approach with caution.
|
||||
{:pin_mode_write, [p: 13, m: 1]},
|
||||
{"1", {:position_write_zero, [:x]}},
|
||||
{"23", {:parameter_write, [movement_invert_2_endpoints_y: 1.0]}},
|
||||
{"24", {:parameter_write, [movement_stop_at_home_x: 0.0]}},
|
||||
{"40", {:pin_write, [p: 13, v: 0, m: 0]}},
|
||||
{"49", {:pin_mode_write, [p: 13, m: 1]}},
|
||||
{"55", {:pin_mode_write, [p: 13, m: 1]}},
|
||||
{"59", {:pin_mode_write, [p: 13, m: 1]}},
|
||||
{"94", {:parameter_write, [movement_home_up_y: 1.0]}},
|
||||
{"94", {:pin_write, [p: 13, v: 1, m: 0]}},
|
||||
{"98", {:parameter_write, [movement_home_up_y: 0.0]}},
|
||||
{"99", {:parameter_write, [movement_stop_at_home_x: 1.0]}},
|
||||
{nil, {:command_emergency_lock, []}},
|
||||
{nil, {:command_emergency_lock, []}},
|
||||
{nil,
|
||||
{:command_movement,
|
||||
[x: 0.0, y: 0.0, z: 0.0, a: 400.0, b: 400.0, c: 400.0]}},
|
||||
{nil,
|
||||
{:command_movement,
|
||||
[x: 0.0, y: 0.0, z: 10.0, a: 400.0, b: 400.0, c: 400.0]}},
|
||||
{nil, {:command_emergency_lock, []}}
|
||||
]
|
||||
|
||||
assert result == :transport_boot
|
||||
end
|
||||
|
||||
@tag :skip
|
||||
test "various command()s" do
|
||||
assert {:ok, nil} == try_command({:command_emergency_lock, []})
|
||||
assert {:ok, "1"} == try_command({:pin_mode_write, [p: 13, m: 1]})
|
||||
assert {:ok, "1"} == try_command({"1", {:position_write_zero, [:x]}})
|
||||
|
||||
assert {:ok, "23"} ==
|
||||
try_command(
|
||||
{"23", {:parameter_write, [movement_invert_2_endpoints_y: 1.0]}}
|
||||
)
|
||||
|
||||
assert {:ok, "24"} ==
|
||||
try_command(
|
||||
{"24", {:parameter_write, [movement_stop_at_home_x: 0.0]}}
|
||||
)
|
||||
|
||||
assert {:ok, "40"} == try_command({"40", {:pin_write, [p: 13, v: 0, m: 0]}})
|
||||
assert {:ok, "49"} == try_command({"49", {:pin_mode_write, [p: 13, m: 1]}})
|
||||
assert {:ok, "55"} == try_command({"55", {:pin_mode_write, [p: 13, m: 1]}})
|
||||
assert {:ok, "59"} == try_command({"59", {:pin_mode_write, [p: 13, m: 1]}})
|
||||
|
||||
assert {:ok, "94"} ==
|
||||
try_command({"94", {:parameter_write, [movement_home_up_y: 1.0]}})
|
||||
|
||||
assert {:ok, "94"} == try_command({"94", {:pin_write, [p: 13, v: 1, m: 0]}})
|
||||
|
||||
assert {:ok, "98"} ==
|
||||
try_command({"98", {:parameter_write, [movement_home_up_y: 0.0]}})
|
||||
|
||||
assert {:ok, "99"} ==
|
||||
try_command(
|
||||
{"99", {:parameter_write, [movement_stop_at_home_x: 1.0]}}
|
||||
)
|
||||
|
||||
assert {:ok, nil} == try_command({nil, {:command_emergency_lock, []}})
|
||||
assert {:ok, nil} == try_command({nil, {:command_emergency_lock, []}})
|
||||
|
||||
assert {:ok, nil} ==
|
||||
try_command(
|
||||
{nil,
|
||||
{:command_movement,
|
||||
[x: 0.0, y: 0.0, z: 0.0, a: 400.0, b: 400.0, c: 400.0]}}
|
||||
)
|
||||
|
||||
assert {:ok, nil} ==
|
||||
try_command(
|
||||
{nil,
|
||||
{:command_movement,
|
||||
[x: 0.0, y: 0.0, z: 10.0, a: 400.0, b: 400.0, c: 400.0]}}
|
||||
)
|
||||
end
|
||||
|
||||
test "command(), error with tag" do
|
||||
assert {:error, _} = @subject.command(firmware_server(), {:x, {:y, :z}})
|
||||
end
|
||||
|
||||
test "command(), error no tag" do
|
||||
assert {:error, _} = @subject.command(firmware_server(), {:x, :z})
|
||||
Enum.map(cmds, fn {tag, cmd} ->
|
||||
assert {:ok, tag} = try_command(pid, {tag, cmd})
|
||||
end)
|
||||
end
|
||||
|
||||
test "enable_debug_logs" do
|
||||
|
|
Loading…
Reference in New Issue