| package dkms | |
| import ( | |
| "fmt" | |
| "testing" | |
| "github.com/google/go-cmp/cmp" | |
| ) | |
| func TestParseConfig(t *testing.T) { | |
| trees := Trees{ | |
| Source: "testdata/source-tree", | |
| Kernel: "testdata/kernel-source", | |
| Dkms: t.TempDir(), | |
| Install: t.TempDir(), | |
| } | |
| pkg := Package{ | |
| Name: "my-package", | |
| Version: "1.0", | |
| Arch: "x86_64", | |
| KernelVersion: "6.1.100", | |
| Trees: &trees, | |
| } | |
| testCases := []struct { | |
| configString string | |
| expected Config | |
| }{ | |
| { | |
| configString: "", | |
| expected: Config{ | |
| PackageName: pkg.Name, | |
| PackageVersion: pkg.Version, | |
| MakeCommand: fmt.Sprintf("make -C %s M=%s", trees.Kernel, pkg.BuildDir()), | |
| Patches: []string{}, | |
| Modules: []Module{ | |
| { | |
| Package: &pkg, | |
| BuiltName: pkg.Name, | |
| BuiltLocation: "", | |
| DestName: pkg.Name, | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| }, | |
| BuildDepends: []string{}, | |
| BuildExclusiveKernel: ".*", | |
| BuildExclusiveArch: ".*", | |
| }, | |
| }, | |
| { | |
| configString: ` | |
| MAKE=abc | |
| PACKAGE_VERSION=3.0 | |
| PACKAGE_NAME=my-module | |
| BUILT_MODULE_NAME=my-built-module | |
| `, | |
| expected: Config{ | |
| PackageName: "my-module", | |
| PackageVersion: "3.0", | |
| MakeCommand: "abc", | |
| Patches: []string{}, | |
| Modules: []Module{ | |
| { | |
| Package: &pkg, | |
| BuiltName: "my-built-module", | |
| BuiltLocation: "", | |
| DestName: "my-built-module", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| }, | |
| BuildDepends: []string{}, | |
| BuildExclusiveKernel: ".*", | |
| BuildExclusiveArch: ".*", | |
| }, | |
| }, | |
| { | |
| configString: ` | |
| MAKE[2]=abc | |
| PACKAGE_VERSION=3.0 | |
| PACKAGE_NAME=my-module | |
| BUILT_MODULE_NAME[0]=my-built-module | |
| BUILT_MODULE_LOCATION=build/location | |
| BUILT_MODULE_NAME[1]=my-built-module-2 | |
| DEST_MODULE_NAME[1]=my-installed-module-2 | |
| STRIP[0]=no | |
| DEST_MODULE_LOCATION[1]=/kernel/install/location | |
| MAKE[1]="make -C ${kernel_source_dir} M=${dkms_tree}/${module}/${module_version}/build/abc" | |
| MAKE[0]='make 0' | |
| MAKE_MATCH[0]='6\.6\..*' | |
| MAKE_MATCH[1]='6\.1\..*' | |
| CLEAN="make clean" | |
| BUILD_DEPENDS[0]=module-1 | |
| BUILD_DEPENDS[1]=module-2 | |
| PATCH[0]=abc | |
| PATCH[2]=ghi | |
| PATCH[1]=def | |
| PATCH_MATCH[1]='6\.6\..*' | |
| `, | |
| expected: Config{ | |
| PackageName: "my-module", | |
| PackageVersion: "3.0", | |
| MakeCommand: fmt.Sprintf("make -C %s M=%s/%s/%s/build/abc", trees.Kernel, trees.Dkms, pkg.Name, pkg.Version), | |
| Patches: []string{"abc", "ghi"}, | |
| Modules: []Module{ | |
| { | |
| Package: &pkg, | |
| BuiltName: "my-built-module", | |
| BuiltLocation: "build/location", | |
| DestName: "my-built-module", | |
| DestLocation: "/kernel/updates", | |
| Strip: false, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "my-built-module-2", | |
| BuiltLocation: "", | |
| DestName: "my-installed-module-2", | |
| DestLocation: "/kernel/install/location", | |
| Strip: false, | |
| }, | |
| }, | |
| BuildDepends: []string{"module-1", "module-2"}, | |
| BuildExclusiveKernel: ".*", | |
| BuildExclusiveArch: ".*", | |
| }, | |
| }, | |
| { | |
| configString: ` | |
| BUILT_MODULE_NAME=( | |
| libcfs # 0 | |
| lnet # 1 | |
| ksocklnd # 2 | |
| obdclass # 3 | |
| ptlrpc # 4 | |
| fld # 5 | |
| osc # 6 | |
| lov # 7 | |
| fid # 8 | |
| mdc # 9 | |
| lmv # 10 | |
| lustre # 11 | |
| ) | |
| BUILT_MODULE_NAME[30]=abc | |
| `, | |
| expected: Config{ | |
| PackageName: pkg.Name, | |
| PackageVersion: pkg.Version, | |
| MakeCommand: fmt.Sprintf("make -C %s M=%s", trees.Kernel, pkg.BuildDir()), | |
| Patches: []string{}, | |
| Modules: []Module{ | |
| { | |
| Package: &pkg, | |
| BuiltName: "libcfs", | |
| BuiltLocation: "", | |
| DestName: "libcfs", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "lnet", | |
| BuiltLocation: "", | |
| DestName: "lnet", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "ksocklnd", | |
| BuiltLocation: "", | |
| DestName: "ksocklnd", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "obdclass", | |
| BuiltLocation: "", | |
| DestName: "obdclass", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "ptlrpc", | |
| BuiltLocation: "", | |
| DestName: "ptlrpc", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "fld", | |
| BuiltLocation: "", | |
| DestName: "fld", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "osc", | |
| BuiltLocation: "", | |
| DestName: "osc", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "lov", | |
| BuiltLocation: "", | |
| DestName: "lov", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "fid", | |
| BuiltLocation: "", | |
| DestName: "fid", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "mdc", | |
| BuiltLocation: "", | |
| DestName: "mdc", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "lmv", | |
| BuiltLocation: "", | |
| DestName: "lmv", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "lustre", | |
| BuiltLocation: "", | |
| DestName: "lustre", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| { | |
| Package: &pkg, | |
| BuiltName: "abc", | |
| BuiltLocation: "", | |
| DestName: "abc", | |
| DestLocation: "/kernel/updates", | |
| Strip: true, | |
| }, | |
| }, | |
| BuildDepends: []string{}, | |
| BuildExclusiveKernel: ".*", | |
| BuildExclusiveArch: ".*", | |
| }, | |
| }, | |
| } | |
| for i, testCase := range testCases { | |
| config, err := ParseConfig(testCase.configString, &pkg) | |
| if err != nil { | |
| t.Fatalf("failed test case %d: %v", i, err) | |
| } | |
| diff := cmp.Diff(testCase.expected, *config) | |
| if len(diff) > 0 { | |
| t.Fatalf("config for test case %d did not match expected value:\ndiff: %s", i, diff) | |
| } | |
| } | |
| } |