Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/test/pkg/integration/fuse.go
2498 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package integration
6
7
import (
8
"fmt"
9
10
agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"
11
)
12
13
const (
14
fuseProgram = `
15
#define _GNU_SOURCE
16
#include <unistd.h>
17
18
#include <sys/syscall.h>
19
#include <linux/fs.h>
20
#include <sys/types.h>
21
#include <sys/stat.h>
22
#include <fcntl.h>
23
#include <stdio.h>
24
25
26
int main() {
27
const char* src_path = "/dev/fuse";
28
unsigned int flags = O_RDWR;
29
printf("RET: %ld\n", syscall(SYS_openat, AT_FDCWD, src_path, flags));
30
}
31
`
32
)
33
34
func HasFuseDevice(rsa *RpcClient) (bool, error) {
35
var resp agent.WriteFileResponse
36
err := rsa.Call("WorkspaceAgent.WriteFile", &agent.WriteFileRequest{
37
Path: "/workspace/fuse_test.c",
38
Content: []byte(fuseProgram),
39
Mode: 0644,
40
}, &resp)
41
if err != nil {
42
return false, err
43
}
44
45
var execResp agent.ExecResponse
46
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
47
Dir: "/workspace",
48
Command: "gcc",
49
Args: []string{"fuse_test.c", "-o", "fuse_test"},
50
}, &execResp)
51
if err != nil {
52
return false, err
53
}
54
if execResp.ExitCode != 0 {
55
return false, fmt.Errorf("gcc failed with code %d: %s", execResp.ExitCode, execResp.Stderr)
56
}
57
58
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
59
Dir: "/workspace",
60
Command: "./fuse_test",
61
}, &execResp)
62
if err != nil {
63
return false, err
64
}
65
if execResp.ExitCode != 0 {
66
return false, fmt.Errorf("fuse_test failed with code %d: %s", execResp.ExitCode, execResp.Stderr)
67
}
68
69
if execResp.Stdout != "RET: 3\n" {
70
return false, fmt.Errorf("fuse_test returned unexpected output: %s", execResp.Stdout)
71
}
72
return true, nil
73
}
74
75