Cleanup armsrc/string.c and string.h (#964)
[legacy-proxmark3.git] / client / scripts / tracetest.lua
blobae4055aed40a9a6c891a42b62af7cb42369f2fcc
1 local cmds = require('commands')
2 local getopt = require('getopt')
3 local bin = require('bin')
4 local utils = require('utils')
5 local dumplib = require('html_dumplib')
7 example =[[
8 1. script run tracetest
9 ]]
10 author = "Iceman"
11 usage = "script run tracetest"
12 desc =[[
13 This script will load several traces files in ../traces/ folder and do
14 "data load"
15 "lf search 1 u"
17 The following tracefiles will be loaded:
18 em*.pm3
19 m*.pm3
21 Arguments:
22 -h : this help
25 local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
26 local DEBUG = true -- the debug flag
27 ---
28 -- A debug printout-function
29 function dbg(args)
30 if not DEBUG then
31 return
32 end
34 if type(args) == "table" then
35 local i = 1
36 while result[i] do
37 dbg(result[i])
38 i = i+1
39 end
40 else
41 print("###", args)
42 end
43 end
44 ---
45 -- This is only meant to be used when errors occur
46 function oops(err)
47 print("ERROR: ",err)
48 end
49 ---
50 -- Usage help
51 function help()
52 print(desc)
53 print("Example usage")
54 print(example)
55 end
57 -- Exit message
58 function ExitMsg(msg)
59 print( string.rep('--',20) )
60 print( string.rep('--',20) )
61 print(msg)
62 print()
63 end
66 local function main(args)
68 print( string.rep('--',20) )
69 print( string.rep('--',20) )
71 local cmdDataLoad = 'data load %s';
72 local tracesEM = "find '../traces/' -iname 'em*.pm3' -type f"
73 local tracesMOD = "find '../traces/' -iname 'm*.pm3' -type f"
75 local write2File = false
76 local outputTemplate = os.date("testtest_%Y-%m-%d_%H%M%S")
78 -- Arguments for the script
79 for o, arg in getopt.getopt(args, 'h') do
80 if o == "h" then return help() end
81 end
83 core.clearCommandBuffer()
85 local files = {}
87 -- Find a set of traces staring with EM
88 local p = assert( io.popen(tracesEM))
89 for file in p:lines() do
90 table.insert(files, file)
91 end
92 p.close();
94 -- Find a set of traces staring with MOD
95 p = assert( io.popen(tracesMOD) )
96 for file in p:lines() do
97 table.insert(files, file)
98 end
99 p.close();
101 local cmdLFSEARCH = "lf search 1 u"
103 -- main loop
104 io.write('Starting to test traces > ')
105 for _,file in pairs(files) do
107 local x = "data load "..file
108 dbg(x)
109 core.console(x)
111 dbg(cmdLFSEARCH)
112 core.console(cmdLFSEARCH)
114 core.clearCommandBuffer()
116 if core.ukbhit() then
117 print("aborted by user")
118 break
121 io.write('\n')
123 print( string.rep('--',20) )
126 main(args)