From dd07cdcfcc952507b80125b92d8c58448706e6d9 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Wed, 18 Jan 2017 21:19:05 -0800 Subject: [PATCH] tests(argon2) add tests to ensure JIT compilation --- .travis.yml | 4 +++- spec/argon2_spec.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f36c61f..d8156c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/spec/argon2_spec.lua b/spec/argon2_spec.lua index 26e6d6a..b6bcbc2 100644 --- a/spec/argon2_spec.lua +++ b/spec/argon2_spec.lua @@ -79,6 +79,10 @@ describe("hash_encoded()", function() argon2.hash_encoded("", "", {parallelism = ""}) end, "bad argument #3 to 'hash_encoded' (expected parallelism to be a number, got string)") + assert.has_error(function() + argon2.hash_encoded("", "", {hash_len = ""}) + end, "bad argument #3 to 'hash_encoded' (expected hash_len to be a number, got string)") + --[[ assert.has_error(function() argon2.hash_encoded("", "", {}, "") @@ -233,6 +237,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()