-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c322c30
commit 548dcce
Showing
3 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package elf | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReadNotes(t *testing.T) { | ||
input := `Displaying notes found in: .note.gnu.build-id | ||
Owner Data size Description | ||
GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) | ||
Build ID: 30d4ef247fb97a94101adda2291644ccdcb8cc77 | ||
Displaying notes found in: .note.stapsdt | ||
Owner Data size Description | ||
stapsdt 0x00000045 NT_STAPSDT (SystemTap probe descriptors) | ||
Provider: compass | ||
Name: request_shutdown | ||
Location: 0x000000000000cfa8, Base: 0x0000000000056537, Semaphore: 0x0000000000000000 | ||
Arguments: -8@x19 -8@x20 -8@x0 | ||
stapsdt 0x0000004f NT_STAPSDT (SystemTap probe descriptors) | ||
Provider: compass | ||
Name: php_function | ||
Location: 0x000000000000e794, Base: 0x0000000000056537, Semaphore: 0x0000000000000000 | ||
Arguments: -8@x19 -8@x20 -8@x0 -8@x23 -8@x24` | ||
|
||
have, err := ReadNotes(input) | ||
assert.NoError(t, err) | ||
|
||
want := []SystemTapNote{ | ||
{ | ||
Provider: "compass", | ||
Name: "request_shutdown", | ||
Args: []string{ | ||
"-8@x19", | ||
"-8@x20", | ||
"-8@x0", | ||
}, | ||
}, | ||
{ | ||
Provider: "compass", | ||
Name: "php_function", | ||
Args: []string{ | ||
"-8@x19", | ||
"-8@x20", | ||
"-8@x0", | ||
"-8@x23", | ||
"-8@x24", | ||
}, | ||
}, | ||
} | ||
|
||
assert.Equal(t, want, have) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package replace | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/skpr/compass/collector/scripts/bpftmpl/elf" | ||
) | ||
|
||
func TestUsingNotesAmd64(t *testing.T) { | ||
notes := []elf.SystemTapNote{ | ||
{ | ||
Provider: "compass", | ||
Name: "request_shutdown", | ||
Args: []string{ | ||
"-8@%rbx", | ||
"-8@%r14", | ||
"-8@%rdi", | ||
}, | ||
}, | ||
{ | ||
Provider: "compass", | ||
Name: "php_function", | ||
Args: []string{ | ||
"-8@%rbx", | ||
"-8@%r14", | ||
"-8@%rax", | ||
"-8@%r13", | ||
"-8@%rbp", | ||
}, | ||
}, | ||
} | ||
|
||
replacements := []string{ | ||
"PHP_FUNCTION_ARG_FUNCTION_NAME", | ||
"PHP_FUNCTION_ARG_CLASS_NAME", | ||
"PHP_FUNCTION_ARG_FUNCTION_NAME", | ||
"PHP_FUNCTION_ARG_START_TIME", | ||
"PHP_FUNCTION_ARG_END_TIME", | ||
"REQUEST_SHUTDOWN_ARG_REQUEST_ID", | ||
"REQUEST_SHUTDOWN_ARG_URI", | ||
"REQUEST_SHUTDOWN_ARG_URI", | ||
} | ||
|
||
program, err := UsingNotes("amd64", notes, strings.Join(replacements, ",")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "ax,r14,ax,r13,bp,bx,r14,r14", program) | ||
} | ||
|
||
func TestUsingNotesArm64(t *testing.T) { | ||
notes := []elf.SystemTapNote{ | ||
{ | ||
Provider: "compass", | ||
Name: "request_shutdown", | ||
Args: []string{ | ||
"-8@x19", | ||
"-8@x20", | ||
"-8@x0", | ||
}, | ||
}, | ||
{ | ||
Provider: "compass", | ||
Name: "php_function", | ||
Args: []string{ | ||
"-8@x19", | ||
"-8@x20", | ||
"-8@x0", | ||
"-8@x23", | ||
"-8@x24", | ||
}, | ||
}, | ||
} | ||
|
||
replacements := []string{ | ||
"PHP_FUNCTION_ARG_FUNCTION_NAME", | ||
"PHP_FUNCTION_ARG_CLASS_NAME", | ||
"PHP_FUNCTION_ARG_FUNCTION_NAME", | ||
"PHP_FUNCTION_ARG_START_TIME", | ||
"PHP_FUNCTION_ARG_END_TIME", | ||
"REQUEST_SHUTDOWN_ARG_REQUEST_ID", | ||
"REQUEST_SHUTDOWN_ARG_URI", | ||
"REQUEST_SHUTDOWN_ARG_URI", | ||
} | ||
|
||
program, err := UsingNotes("arm64", notes, strings.Join(replacements, ",")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "regs[0],regs[20],regs[0],regs[23],regs[24],regs[19],regs[20],regs[20]", program) | ||
} |