Skip to content

Commit

Permalink
tests(argon2) add tests to ensure JIT compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Jan 19, 2017
1 parent 36ab069 commit 49569ae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ install:
- luarocks make

script:
- make lint && busted -v --coverage -o gtest --repeat 3 spec
- make lint
- busted --exclude-tags=JIT -v --coverage -o gtest --repeat 3 spec
- if [ "$LUA" == "luajit 2.1" ]; then busted -v -o gtest --tags JIT fi

after_success:
- luacov-coveralls -i ./src/argon2.lua
Expand Down
40 changes: 40 additions & 0 deletions spec/argon2_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,46 @@ describe("verify()", function()
end)
end)

describe("#JIT", function()

local function read_trace(outfile)
local f = assert(io.open(outfile, "r"))
local t = f:read("*a")
f:close()
return t
end

it("hash_encoded() JITs", function()
local v = require "jit.v"
local outfile = os.tmpname()
v.on(outfile)

for _ = 1, 100 do
argon2.hash_encoded("password", "somesalt")
end

local trace = read_trace(outfile)
assert.matches("argon2_spec%.lua:%d+ loop", trace)
assert.not_matches("NYI", trace)
end)

it("verify() JITs", function()
local v = require "jit.v"
local outfile = os.tmpname()
v.on(outfile)

local hash = assert(argon2.hash_encoded("password", "somesalt"))

for _ = 1, 100 do
argon2.verify(hash, "password")
end

local trace = read_trace(outfile)
assert.matches("argon2_spec%.lua:%d+ loop", trace)
assert.not_matches("NYI", trace)
end)
end)

--[[
pending("module settings", function()
Expand Down

0 comments on commit 49569ae

Please sign in to comment.