From b2ad202397490ce5ae494c9e688eae5e694ce862 Mon Sep 17 00:00:00 2001 From: Martin Teichmann <martin.teichmann@xfel.eu> Date: Fri, 26 Feb 2021 10:23:24 +0000 Subject: [PATCH] fix ktime --- ebpfcat/ebpf.py | 6 +++--- ebpfcat/ebpf_test.py | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ebpfcat/ebpf.py b/ebpfcat/ebpf.py index 4960a2e..84d2a87 100644 --- a/ebpfcat/ebpf.py +++ b/ebpfcat/ebpf.py @@ -759,7 +759,7 @@ class PseudoFd(Expression): self.fd = fd @contextmanager - def calculate(self, dst, long, signed, force): + def calculate(self, dst, long, signed, force=False): with self.ebpf.get_free_register(dst) as dst: self.ebpf.append(Opcode.DW, dst, 1, 0, self.fd) self.ebpf.append(Opcode.W, 0, 0, 0, 0) @@ -771,13 +771,13 @@ class ktime(Expression): self.ebpf = ebpf @contextmanager - def calculate(self, dst, long, signed, force): + def calculate(self, dst, long, signed, force=False): with self.ebpf.get_free_register(dst) as dst: with self.ebpf.save_registers([i for i in range(6) if i != dst]): self.ebpf.call(FuncId.ktime_get_ns) if dst != 0: self.ebpf.r[dst] = self.ebpf.r0 - yield dst, True, False + yield dst, True, False class RegisterDesc: diff --git a/ebpfcat/ebpf_test.py b/ebpfcat/ebpf_test.py index cba4236..8cea647 100644 --- a/ebpfcat/ebpf_test.py +++ b/ebpfcat/ebpf_test.py @@ -541,12 +541,17 @@ class Tests(TestCase): def test_ktime(self): e = EBPF() + e.r0 = 3 e.r3 = ktime(e) self.assertEqual(e.opcodes, [ - Instruction(opcode=O.REG+O.MOV+O.LONG, dst=6, src=1, off=0, imm=0), + Instruction(opcode=O.LONG+O.MOV, dst=0, src=0, off=0, imm=3), + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=6, src=0, off=0, imm=0), + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=7, src=1, off=0, imm=0), Instruction(opcode=O.CALL, dst=0, src=0, off=0, imm=5), Instruction(opcode=O.REG+O.MOV+O.LONG, dst=3, src=0, off=0, imm=0), - Instruction(opcode=O.REG+O.MOV+O.LONG, dst=1, src=6, off=0, imm=0)]) + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=0, src=6, off=0, imm=0), + Instruction(opcode=O.REG+O.MOV+O.LONG, dst=1, src=7, off=0, imm=0) + ]) def test_xdp(self): e = XDP(license="GPL") -- GitLab