Skip to content

Commit

Permalink
apps.test.match: Add `modest' option.
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Apr 8, 2016
1 parent 3719753 commit 29a6767
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/apps/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ keys are defined:
*Optional.* If this key is `true` packets from `rx` that do not match the next
packet from `comparator` are ignored. The default is `false`.

— Key **modest**

*Optional.* If this key is `true` unmatched packets from `comparator` are
ignored if at least one packet from ´rx´ was successfully matched. The default
is `false`.


## Synth (apps.test.synth)

Expand Down
27 changes: 20 additions & 7 deletions src/apps/test/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Match = {}

function Match:new (arg)
local conf = arg and config.parse_app_arg(arg) or {}
return setmetatable({ fuzzy = conf.fuzzy, seen = 0, errs = { } },
return setmetatable({ fuzzy = conf.fuzzy,
modest = conf.modest,
seen = 0,
errs = { } },
{ __index=Match })
end

Expand Down Expand Up @@ -41,10 +44,12 @@ function Match:report ()
end

function Match:errors ()
while not link.empty(self.input.comparator) do
local p = link.receive(self.input.comparator)
table.insert(self.errs, "Not matched:\n"..dump(p))
packet.free(p)
if not (self.modest and self.seen > 0) then
while not link.empty(self.input.comparator) do
local p = link.receive(self.input.comparator)
table.insert(self.errs, "Not matched:\n"..dump(p))
packet.free(p)
end
end
return self.errs
end
Expand All @@ -53,11 +58,19 @@ function selftest()
local basic_apps = require("apps.basic.basic_apps")
local c = config.new()

config.app(c, "sink", Match, {modest=true})
config.app(c, "comparator", basic_apps.Source, 8)
config.link(c, "comparator.output -> sink.comparator")
engine.configure(c)
engine.app_table.sink.input.rx = link.new("null")
engine.app_table.sink.seen = 1
engine.main({duration=0.0001})
assert(#engine.app_table.sink:errors() == 0)

engine.configure(config.new())
config.app(c, "sink", Match)
config.app(c, "src", basic_apps.Source, 8)
config.app(c, "comparator", basic_apps.Source, 8)
config.link(c, "src.output -> sink.rx")
config.link(c, "comparator.output -> sink.comparator")
engine.configure(c)
engine.main({duration=0.0001})
assert(#engine.app_table.sink:errors() == 0)
Expand Down

0 comments on commit 29a6767

Please sign in to comment.