diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-11-27 17:23:09 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-12-11 15:22:17 +0000 |
| commit | 299ee674e6c124a35f1cf258df4f0f3c6e1db1f3 (patch) | |
| tree | 416b515e959a1d0a64a9516b1524a062ae63ba7d /pkg/vminfo | |
| parent | ff949d2512c5ac33d0407d26d80f1df77b2de0e7 (diff) | |
executor: query globs in the test program context
We query globs for 2 reasons:
1. Expand glob types in syscall descriptions.
2. Dynamic file probing for automatic descriptions generation.
In both of these contexts are are interested in files
that will be present during test program execution
(rather than normal unsandboxed execution).
For example, some files may not be accessible to test programs
after pivot root. On the other hand, we create and link
some additional files for the test program that don't
normally exist.
Add a new request type for querying of globs that are
executed in the test program context.
Diffstat (limited to 'pkg/vminfo')
| -rw-r--r-- | pkg/vminfo/syscalls.go | 36 | ||||
| -rw-r--r-- | pkg/vminfo/vminfo.go | 3 | ||||
| -rw-r--r-- | pkg/vminfo/vminfo_test.go | 27 |
3 files changed, 49 insertions, 17 deletions
diff --git a/pkg/vminfo/syscalls.go b/pkg/vminfo/syscalls.go index 21ae6edd1..9793cfee8 100644 --- a/pkg/vminfo/syscalls.go +++ b/pkg/vminfo/syscalls.go @@ -57,7 +57,8 @@ func newCheckContext(ctx context.Context, cfg *Config, impl checker, executor qu } } -func (ctx *checkContext) start(fileInfos []*flatrpc.FileInfo) { +func (ctx *checkContext) do(fileInfos []*flatrpc.FileInfo, featureInfos []*flatrpc.FeatureInfo) ( + map[*prog.Syscall]bool, map[*prog.Syscall]string, Features, error) { sysTarget := targets.Get(ctx.cfg.Target.OS, ctx.cfg.Target.Arch) ctx.fs = createVirtualFilesystem(fileInfos) for _, id := range ctx.cfg.Syscalls { @@ -91,10 +92,37 @@ func (ctx *checkContext) start(fileInfos []*flatrpc.FileInfo) { }() } ctx.startFeaturesCheck() -} -func (ctx *checkContext) wait(featureInfos []*flatrpc.FeatureInfo) ( - map[*prog.Syscall]bool, map[*prog.Syscall]string, Features, error) { + var globReqs []*queue.Request + for _, glob := range ctx.target.RequiredGlobs() { + req := &queue.Request{ + Type: flatrpc.RequestTypeGlob, + GlobPattern: glob, + ExecOpts: flatrpc.ExecOpts{ + EnvFlags: ctx.cfg.Sandbox, + SandboxArg: ctx.cfg.SandboxArg, + }, + Important: true, + } + ctx.executor.Submit(req) + globReqs = append(globReqs, req) + } + + // Up to this point we submit all requests (start submitting goroutines), + // so that all requests execute in parallel. After this point we wait + // for request completion and handle results. + + globs := make(map[string][]string) + for _, req := range globReqs { + res := req.Wait(ctx.ctx) + if res.Status != queue.Success { + return nil, nil, nil, fmt.Errorf("failed to execute glob: %w (%v)\n%s\n%s", + res.Err, res.Status, req.GlobPattern, res.Output) + } + globs[req.GlobPattern] = res.GlobFiles() + } + ctx.target.UpdateGlobs(globs) + enabled := make(map[*prog.Syscall]bool) disabled := make(map[*prog.Syscall]string) for i := 0; i < ctx.pendingSyscalls; i++ { diff --git a/pkg/vminfo/vminfo.go b/pkg/vminfo/vminfo.go index d2a728585..dee1924b5 100644 --- a/pkg/vminfo/vminfo.go +++ b/pkg/vminfo/vminfo.go @@ -103,8 +103,7 @@ func (checker *Checker) Run(files []*flatrpc.FileInfo, featureInfos []*flatrpc.F map[*prog.Syscall]bool, map[*prog.Syscall]string, Features, error) { ctx := checker.checkContext checker.checkContext = nil - ctx.start(files) - return ctx.wait(featureInfos) + return ctx.do(files, featureInfos) } // Implementation of the queue.Source interface. diff --git a/pkg/vminfo/vminfo_test.go b/pkg/vminfo/vminfo_test.go index 398cf93e2..4bdccc09e 100644 --- a/pkg/vminfo/vminfo_test.go +++ b/pkg/vminfo/vminfo_test.go @@ -104,18 +104,23 @@ func createSuccessfulResults(source queue.Source, stop chan struct{}) { // Currently we have 641 (when we failed to properly dedup syscall tests, it was 4349). panic("too many test programs") } - info := &flatrpc.ProgInfo{} - for range req.Prog.Calls { - info.Calls = append(info.Calls, &flatrpc.CallInfo{ - Cover: []uint64{1}, - Signal: []uint64{1}, - Comps: []*flatrpc.Comparison{{Op1: 1, Op2: 2}}, - }) - } - req.Done(&queue.Result{ + res := &queue.Result{ Status: queue.Success, - Info: info, - }) + } + switch req.Type { + case flatrpc.RequestTypeProgram: + res.Info = &flatrpc.ProgInfo{} + for range req.Prog.Calls { + res.Info.Calls = append(res.Info.Calls, &flatrpc.CallInfo{ + Cover: []uint64{1}, + Signal: []uint64{1}, + Comps: []*flatrpc.Comparison{{Op1: 1, Op2: 2}}, + }) + } + case flatrpc.RequestTypeGlob: + res.Output = []byte("/some/file\n") + } + req.Done(res) } } |
