Skip to content

Commit

Permalink
test: add tests for disabled optimization
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <[email protected]>
  • Loading branch information
alegrey91 committed Feb 3, 2025
1 parent 98ebd04 commit 1c51d52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/integration.txtar
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# this testscript test the 'analyze' command

# skip if go is not installed
[!exec:go] skip
#[!exec:go] skip

# move on the testcases directory
cd testcases/example-app/
Expand Down Expand Up @@ -111,6 +111,7 @@ symbolsOrigins:
- github.com/alegrey91/seccomp-test-coverage/pkg/randomic.ThrowDice
- github.com/alegrey91/seccomp-test-coverage/pkg/randomic.FlipCoin
- github.com/alegrey91/seccomp-test-coverage/pkg/randomic.DoSomethingSpecial
- github.com/alegrey91/seccomp-test-coverage/pkg/randomic.DoNothing

-- testcases/example-app/expected-profile.json --
{
Expand Down
11 changes: 11 additions & 0 deletions tests/testcases/example-app/pkg/randomic/randomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ func DoForTenSec() {
time.Sleep(time.Second)
}
}

// DoNothing is an empty function,
// made to test the compilation of test binaries
// with optimization disabled: "all=-N -l"
// This will make the compiler create the symbol
// for the function, even if it's not needed.
// This is needed since harpoon uses the symbols
// to attach the uprobres and trace their syscalls.
func DoNothing() bool {
return true
}
19 changes: 19 additions & 0 deletions tests/testcases/example-app/pkg/randomic/randomic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,22 @@ func TestDoSomethingSpecial(t *testing.T) {
})
}
}

func TestDoNothing(t *testing.T) {
tests := []struct {
name string
want bool
}{
{
name: "this test doesn't test anything",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := DoNothing(); got != tt.want {
t.Errorf("DoNothing() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 1c51d52

Please sign in to comment.