diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-02-17 18:15:34 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-02-18 14:23:32 +0000 |
| commit | d20955ead8fad68c995174fadc471c56147a69a5 (patch) | |
| tree | 1a38d6929fe89a03232a1923a56b36f4adb153a6 /syz-cluster/pkg/db | |
| parent | ec05e4c30271d38daa3a17bae6cafe5a7477c943 (diff) | |
syz-cluster: build latest revisions of base kernels
Once a new kernel revision becomes available, build it to figure out
whether it's buildable. This information will be used in the triage step
to figure out the right base kernel revision.
Diffstat (limited to 'syz-cluster/pkg/db')
| -rw-r--r-- | syz-cluster/pkg/db/build_repo.go | 42 | ||||
| -rw-r--r-- | syz-cluster/pkg/db/build_repo_test.go | 28 |
2 files changed, 53 insertions, 17 deletions
diff --git a/syz-cluster/pkg/db/build_repo.go b/syz-cluster/pkg/db/build_repo.go index 8bc3deaed..318144acc 100644 --- a/syz-cluster/pkg/db/build_repo.go +++ b/syz-cluster/pkg/db/build_repo.go @@ -33,18 +33,40 @@ func (repo *BuildRepository) Insert(ctx context.Context, build *Build) error { return repo.genericEntityOps.Insert(ctx, build) } -func (repo *BuildRepository) LastBuiltTree(ctx context.Context, arch, tree, config string) (*Build, error) { +type LastBuildParams struct { + Arch string + TreeName string + ConfigName string + Status string + Commit string +} + +func (repo *BuildRepository) LastBuiltTree(ctx context.Context, params *LastBuildParams) (*Build, error) { stmt := spanner.Statement{ - SQL: "SELECT * FROM `Builds` WHERE `TreeName` = @tree" + - " AND `Arch` = @arch AND `ConfigName` = @config" + - " AND `SeriesID` IS NULL AND `Status` = 'success'" + - " ORDER BY `CommitDate` DESC LIMIT 1", - Params: map[string]interface{}{ - "tree": tree, - "arch": arch, - "config": config, - }, + SQL: "SELECT * FROM `Builds` WHERE 1=1", + Params: map[string]interface{}{}, + } + if params.Arch != "" { + stmt.SQL += " AND `Arch` = @arch" + stmt.Params["arch"] = params.Arch + } + if params.TreeName != "" { + stmt.SQL += " AND `TreeName` = @tree" + stmt.Params["tree"] = params.TreeName + } + if params.ConfigName != "" { + stmt.SQL += " AND `ConfigName` = @config" + stmt.Params["config"] = params.ConfigName + } + if params.Status != "" { + stmt.SQL += " AND `Status` = @status" + stmt.Params["status"] = params.Status + } + if params.Commit != "" { + stmt.SQL += " AND `CommitHash` = @commit" + stmt.Params["commit"] = params.Commit } + stmt.SQL += " ORDER BY `CommitDate` DESC LIMIT 1" iter := repo.client.Single().Query(ctx, stmt) defer iter.Stop() return readOne[Build](iter) diff --git a/syz-cluster/pkg/db/build_repo_test.go b/syz-cluster/pkg/db/build_repo_test.go index 3b070a12a..6836a5a6a 100644 --- a/syz-cluster/pkg/db/build_repo_test.go +++ b/syz-cluster/pkg/db/build_repo_test.go @@ -14,7 +14,13 @@ func TestLastSuccessfulBuild(t *testing.T) { client, ctx := NewTransientDB(t) repo := NewBuildRepository(client) - build, err := repo.LastBuiltTree(ctx, "amd64", "mainline", "kasan") + params := &LastBuildParams{ + Arch: "amd64", + TreeName: "mainline", + ConfigName: "kasan", + Status: BuildSuccess, + } + build, err := repo.LastBuiltTree(ctx, params) assert.NoError(t, err) assert.Nil(t, build) @@ -30,10 +36,17 @@ func TestLastSuccessfulBuild(t *testing.T) { assert.NoError(t, err) // It should not be queried. - build, err = repo.LastBuiltTree(ctx, "amd64", "mainline", "kasan") + build, err = repo.LastBuiltTree(ctx, params) assert.NoError(t, err) assert.Nil(t, build) + // .. but if don't specify the status, it should be there. + build, err = repo.LastBuiltTree(ctx, &LastBuildParams{ + TreeName: "mainline", + }) + assert.NoError(t, err) + assert.NotNil(t, build) + // Insert the correct one. err = repo.Insert(ctx, &Build{ Arch: "amd64", @@ -46,15 +59,16 @@ func TestLastSuccessfulBuild(t *testing.T) { assert.NoError(t, err) // It should be in the output. - build, err = repo.LastBuiltTree(ctx, "amd64", "mainline", "kasan") + build, err = repo.LastBuiltTree(ctx, params) assert.NoError(t, err) assert.Equal(t, "good", build.CommitHash) // But not for different arguments. - build, err = repo.LastBuiltTree(ctx, "arm64", "mainline", "kasan") - assert.NoError(t, err) - assert.Nil(t, build) - build, err = repo.LastBuiltTree(ctx, "amd64", "mainline", "kmsan") + build, err = repo.LastBuiltTree(ctx, &LastBuildParams{ + Arch: "arm64", + TreeName: "mainline", + ConfigName: "kasan", + }) assert.NoError(t, err) assert.Nil(t, build) } |
