From 841f20c5e5129a057970b3bf6594ae87f3bfb1b3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 5 Apr 2019 19:34:05 +0200 Subject: [PATCH] test_t55x7 logs & stats --- client/scripts/test_t55x7.lua | 177 +++++++++++++++++++--------------- 1 file changed, 99 insertions(+), 78 deletions(-) diff --git a/client/scripts/test_t55x7.lua b/client/scripts/test_t55x7.lua index 015b578c0..3d21cc9e5 100644 --- a/client/scripts/test_t55x7.lua +++ b/client/scripts/test_t55x7.lua @@ -40,7 +40,9 @@ Arguments: ]] local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds -local DEBUG = true -- the debug flag +local DEBUG = false -- the debug flag +local total_tests = 0 +local total_pass = 0 local data_blocks_cmds = { [1] = '00000000', @@ -95,73 +97,6 @@ local function GetConfigs( modulation ) local t = {} - t['ASK'] = { - [1] = '00008040', - [2] = '00048040', - [3] = '00088040', - [4] = '000c8040', - [5] = '00108040', - [6] = '00148040', - [7] = '00188040', - [8] = '001c8040', - } - - t['BI'] = { - [1] = '00010040', - [2] = '00050040', - [3] = '00090040', - [4] = '000d0040', - [5] = '00110040', - [6] = '00150040', - [7] = '00190040', - [8] = '001d0040', - } - - t['FSK2A'] = { - [1] = '00007040', - [2] = '00047040', - [3] = '00087040', - [4] = '000c7040', - [5] = '00107040', - [6] = '00147040', - [7] = '00187040', - [8] = '001c7040', - } - - t['FSK1A'] = { - [1] = '00006040', - [2] = '00046040', - [3] = '00086040', - [4] = '000c6040', - [5] = '00106040', - [6] = '00146040', - [7] = '00186040', - [8] = '001c6040', - } - - t['FSK2'] = { - [1] = '00005040', - [2] = '00045040', - [3] = '00085040', - [4] = '000c5040', - [5] = '00105040', - [6] = '00145040', - [7] = '00185040', - [8] = '001c5040', - } - - t['FSK1'] = { - [1] = '00004040', - [2] = '00004040', - [3] = '00044040', - [4] = '00084040', - [5] = '000c4040', - [6] = '00104040', - [7] = '00144040', - [8] = '00184040', - [9] = '001c4040', - } - t['PSK1'] = { [1] = '00001040', [2] = '00041040', @@ -193,7 +128,75 @@ local function GetConfigs( modulation ) [6] = '00143040', [7] = '00183040', [8] = '001c3040', - } + } + + t['FSK1'] = { + [1] = '00004040', + [2] = '00004040', + [3] = '00044040', + [4] = '00084040', + [5] = '000c4040', + [6] = '00104040', + [7] = '00144040', + [8] = '00184040', + [9] = '001c4040', + } + + t['FSK2'] = { + [1] = '00005040', + [2] = '00045040', + [3] = '00085040', + [4] = '000c5040', + [5] = '00105040', + [6] = '00145040', + [7] = '00185040', + [8] = '001c5040', + } + + t['FSK1A'] = { + [1] = '00006040', + [2] = '00046040', + [3] = '00086040', + [4] = '000c6040', + [5] = '00106040', + [6] = '00146040', + [7] = '00186040', + [8] = '001c6040', + } + + t['FSK2A'] = { + [1] = '00007040', + [2] = '00047040', + [3] = '00087040', + [4] = '000c7040', + [5] = '00107040', + [6] = '00147040', + [7] = '00187040', + [8] = '001c7040', + } + + t['ASK'] = { + [1] = '00008040', + [2] = '00048040', + [3] = '00088040', + [4] = '000c8040', + [5] = '00108040', + [6] = '00148040', + [7] = '00188040', + [8] = '001c8040', + } + + t['BI'] = { + [1] = '00010040', + [2] = '00050040', + [3] = '00090040', + [4] = '000d0040', + [5] = '00110040', + [6] = '00150040', + [7] = '00190040', + [8] = '001d0040', + } + return t[modulation:upper()] end --- @@ -203,17 +206,17 @@ local function WipeCard() print('Wiping card') core.console('lf t55xx wipe') - print('Detecting card'); + print('Detecting card') local res, msg = core.t55xx_detect() if not res then - oops("can't detect modulation. Test failed."); - core.console("rem Failed to detect"); + oops("Can't detect modulation. Test failed.") + core.console("rem [ERR:DETECT:WIPED] Failed to detect after wipe") return false else local wipe_data_cmd = "lf t55xx write b %s d %s" for _ = 1, #data_blocks_cmds do local val = data_blocks_cmds[_] - local c = string.format(wipe_data_cmd, _, val); + local c = string.format(wipe_data_cmd, _, val) core.console(c) end return true @@ -239,7 +242,6 @@ local function test(modulation) local s = ('Start test of %s'):format(modulation) print(s) - core.console('rem '..s) process_block0_cmds = GetConfigs(modulation) @@ -248,6 +250,7 @@ local function test(modulation) for _ = 1, #process_block0_cmds do local p_config_cmd = process_block0_cmds[_] + local errors = 0 core.clearCommandBuffer() -- Write Config block @@ -262,19 +265,30 @@ local function test(modulation) local res, msg = core.t55xx_detect() if not res then print("can't detect modulation, skip to next config") + core.console(format("rem [ERR:DETECT:%s] Failed to detect modulation", p_config_cmd)) + core.console(format('rem [SUMMARY:%s] FAIL detection', p_config_cmd)) + total_tests = total_tests + #data_blocks_cmds else -- Loop block1-2 for _ = 1, #data_blocks_cmds do + total_tests = total_tests + 1 local val = data_blocks_cmds[_] local blockdata, msg = CheckReadBlock(_) if blockdata:lower() ~= val:lower() then print( ('Test %s == %s Failed'):format(val, blockdata)) - core.console( format('rem -- block %d value %s failed', _, val)) + core.console( format('rem [ERR:READ:%s:%d] block %d: read %s instead of %s', p_config_cmd, _, _, blockdata, val)) + errors = errors+1 else print( ('Test %s == %s OK'):format(val, blockdata)) + total_pass = total_pass + 1 end end - end + if errors >0 then + core.console( format('rem [SUMMARY:%s] FAIL %d test%s', p_config_cmd, errors, errors > 1 and "s" or "")) + else + core.console( format('rem [SUMMARY:%s] PASS all tests', p_config_cmd)) + end + end end end @@ -292,15 +306,22 @@ local function main(args) local res -- Adjust this table to set which configurations should be tested +-- local test_modes = { 'PSK1', 'PSK2', 'PSK3', 'FSK1', 'FSK2', 'FSK1A', 'FSK2A', 'ASK', 'BI' } local test_modes = { 'ASK', 'PSK1' } for _ = 1, #test_modes do res = WipeCard() - print (test_modes[_]) - if res then test(test_modes[_]) end + if res then + print (test_modes[_]) + test(test_modes[_]) + else + exitMsg('Abort!') + return + end end exitMsg('Tests finished') + core.console( format('rem [SUMMARY] Success rate: %d/%d tests passed%s', total_pass, total_tests, total_pass < total_tests and ", help me improving that number!" or " \\o/")) end main(args)