| package dkms |
| |
| import ( |
| "context" |
| "path" |
| "testing" |
| |
| "cos.googlesource.com/cos/tools.git/src/pkg/fakes" |
| "cos.googlesource.com/cos/tools.git/src/pkg/fs" |
| "cos.googlesource.com/cos/tools.git/src/pkg/gcs" |
| ) |
| |
| func TestInstall(t *testing.T) { |
| options := &Options{ |
| Force: false, |
| MakeVariables: "", |
| InstallBuildDependencies: false, |
| } |
| |
| trees := &Trees{ |
| Dkms: t.TempDir(), |
| Source: "testdata/source-tree", |
| Kernel: "testdata/kernel-source/lib/modules/6.1.100/build", |
| Install: t.TempDir(), |
| } |
| |
| pkg := &Package{ |
| Name: "mymodule", |
| Version: "1.0", |
| KernelVersion: "6.1.100", |
| Arch: "x86_64", |
| BuildId: "18244.151.14", |
| Trees: trees, |
| } |
| |
| err := Install(pkg, options) |
| if err != nil { |
| t.Fatalf("%v", err) |
| } |
| |
| makefilePath := path.Join(trees.Dkms, "mymodule", "1.0", "6.1.100", "x86_64", "18244.151.14", "source", "Makefile") |
| if !fs.IsFile(makefilePath) { |
| t.Fatalf("expected to find file %s after adding sources", makefilePath) |
| } |
| |
| buildMakefilePath := path.Join(trees.Dkms, "mymodule", "1.0", "6.1.100", "x86_64", "18244.151.14", "build", "Makefile") |
| if !fs.IsFile(buildMakefilePath) { |
| t.Fatalf("expected to find file %s after building", makefilePath) |
| } |
| |
| builtModulePath := path.Join(trees.Dkms, "mymodule", "1.0", "6.1.100", "x86_64", "18244.151.14", "build", "mymodule.ko") |
| if !fs.IsFile(builtModulePath) { |
| t.Fatalf("expected to find file %s after building", makefilePath) |
| } |
| |
| installPath := path.Join(trees.Install, "kernel", "updates", "mymodule.ko") |
| if !fs.IsFile(installPath) { |
| t.Fatalf("expected to find file %s after installing", installPath) |
| } |
| } |
| |
| func TestCachedInstall(t *testing.T) { |
| options := &Options{ |
| Force: false, |
| MakeVariables: "", |
| InstallBuildDependencies: false, |
| Upload: true, |
| } |
| |
| trees := &Trees{ |
| Dkms: t.TempDir(), |
| Source: "testdata/source-tree", |
| Kernel: "testdata/kernel-source/lib/modules/6.1.100/build", |
| Install: t.TempDir(), |
| } |
| |
| pkg := &Package{ |
| Name: "mymodule", |
| Version: "1.0", |
| KernelVersion: "6.1.100", |
| Arch: "x86_64", |
| BuildId: "18244.151.14", |
| Trees: trees, |
| } |
| |
| ctx := context.Background() |
| fakeGCS := fakes.GCSForTest(t) |
| fakeGCS.LogMissing = false |
| bucket := gcs.NewGCSBucket(fakeGCS.Client, "test", "dkms") |
| err := CachedInstall(ctx, pkg, bucket, options) |
| if err != nil { |
| t.Fatalf("%v", err) |
| } |
| |
| cacheMakefilePath := path.Join("mymodule", "1.0", "6.1.100", "x86_64", "18244.151.14", "source", "Makefile") |
| makefilePath := path.Join(trees.Dkms, cacheMakefilePath) |
| if !fs.IsFile(makefilePath) { |
| t.Fatalf("expected to find file %s after adding sources", makefilePath) |
| } |
| |
| buildMakefilePath := path.Join(trees.Dkms, "mymodule", "1.0", "6.1.100", "x86_64", "18244.151.14", "build", "Makefile") |
| if !fs.IsFile(buildMakefilePath) { |
| t.Fatalf("expected to find file %s after building", makefilePath) |
| } |
| |
| cacheBuiltModulePath := path.Join("mymodule", "1.0", "6.1.100", "x86_64", "18244.151.14", "build", "mymodule.ko") |
| builtModulePath := path.Join(trees.Dkms, cacheBuiltModulePath) |
| if !fs.IsFile(builtModulePath) { |
| t.Fatalf("expected to find file %s after building", makefilePath) |
| } |
| |
| cachedMakefileExists, err := bucket.Exists(ctx, cacheMakefilePath) |
| if err != nil { |
| t.Fatalf("failed to check if %s exists", cacheMakefilePath) |
| } |
| if !cachedMakefileExists { |
| t.Fatalf("expected to find file %s in cache after adding sources", cacheMakefilePath) |
| } |
| |
| cachedModuleExists, err := bucket.Exists(ctx, cacheBuiltModulePath) |
| if err != nil { |
| t.Fatalf("failed to check if %s exists", cacheBuiltModulePath) |
| } |
| if !cachedModuleExists { |
| t.Fatalf("expected to find file %s in cache after building modules", cacheBuiltModulePath) |
| } |
| |
| installPath := path.Join(trees.Install, "kernel", "updates", "mymodule.ko") |
| if !fs.IsFile(installPath) { |
| t.Fatalf("expected to find file %s after installing", installPath) |
| } |
| } |
| |