diff options
| author | Andrey Artemiev <artemiev@google.com> | 2022-08-06 05:17:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-06 14:17:33 +0200 |
| commit | 88e3a1226bc591d81c1fb98e83cb63cd4f341c6e (patch) | |
| tree | 323b7fa492a8d9698e432c1d3bd4514771fc3252 /pkg/csource/csource_test.go | |
| parent | e853abd9a2542fcccb8e1a23eb8ae475500ecaf9 (diff) | |
pkg/csource, pkg/instance, pkg/ipc, pkg/mgrconfig, tools/syz-prog2c, syz-manager: introduce a new setting 'sandbox_arg' (#3263)
Diffstat (limited to 'pkg/csource/csource_test.go')
| -rw-r--r-- | pkg/csource/csource_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go index 91bd2cccf..491b84b03 100644 --- a/pkg/csource/csource_test.go +++ b/pkg/csource/csource_test.go @@ -18,6 +18,7 @@ import ( "github.com/google/syzkaller/prog" _ "github.com/google/syzkaller/sys" "github.com/google/syzkaller/sys/targets" + "github.com/stretchr/testify/assert" ) func init() { @@ -227,3 +228,37 @@ syscall(SYS_csource6, 0x20000140ul); }) } } + +func generateSandboxFunctionSignatureTestCase(t *testing.T, sandbox string, sandboxArg int, expected, message string) { + actual := generateSandboxFunctionSignature(sandbox, sandboxArg) + assert.Equal(t, actual, expected, message) +} + +func TestGenerateSandboxFunctionSignature(t *testing.T) { + // This test-case intentionally omits the following edge cases: + // - sandbox name as whitespaces, tabs + // - control chars \r, \n and unprintables + // - unsuitable chars - punctuation, emojis, '#', '*', etc + // - character case mismatching function prototype defined in common_linux.h. + // For example 'do_sandbox_android' and 'AnDroid'. + // - non english letters, unicode compound characters + // and focuses on correct handling of sandboxes supporting and not 'sandbox_arg' + // config setting. + generateSandboxFunctionSignatureTestCase(t, + "", // sandbox name + 0, // sandbox arg + "loop();", // expected + "Empty sandbox name should produce 'loop();'") + + generateSandboxFunctionSignatureTestCase(t, + "abrakadabra", // sandbox name + 0, // sandbox arg + "do_sandbox_abrakadabra();", // expected + "Empty sandbox name should produce 'loop();'") + + generateSandboxFunctionSignatureTestCase(t, + "android", // sandbox name + -1234, // sandbox arg + "do_sandbox_android(-1234);", // expected + "Android sandbox function requires an argument") +} |
