forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder_spec.lua
More file actions
31 lines (29 loc) · 910 Bytes
/
decoder_spec.lua
File metadata and controls
31 lines (29 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
describe('decoder', function()
-- Decode simple function
local bytecode = require('bpf.ljbytecode')
local f = function (x) return x + 1 end
it('should decode functions', function()
-- Make sure it calls LJ decoder
local bc = bytecode.decoder(f)
assert.truthy(bc)
-- Decode bytecode bytecode to instructions
local jutil = require("jit.util")
spy.on(jutil, 'funcbc')
local pc, op = bc()
-- Check bytecode for sanity (starts with ADDVN(x, 1))
assert.equal(pc, 1)
assert.equal(op, 'ADDVN')
for pc, op in bc do
assert.truthy(pc and op)
end
assert.spy(jutil.funcbc).was.called()
end)
it('should fail on bad input', function()
assert.has_error(function() bytecode.decoder(nil)() end)
assert.has_error(function() bytecode.decoder(5)() end)
assert.has_error(function() bytecode.decoder('test')() end)
end)
it('should dump bytecode', function()
bytecode.dump(f)
end)
end)