Best Syzkaller code snippet using kconfig.Serialize
linux.go
Source:linux.go
...123 }124 linuxAlterConfigs(cf, tags)125 env := &BisectEnv{126 Compiler: filepath.Join(binDir, "gcc-"+linuxCompilerVersion(tags), "bin", "gcc"),127 KernelConfig: cf.Serialize(),128 }129 // v4.0 doesn't boot with our config nor with defconfig, it halts on an interrupt in x86_64_start_kernel.130 if !tags["v4.1"] {131 _, err := ctx.git.git("cherry-pick", "--no-commit", "99124e4db5b7b70daeaaf1d88a6a8078a0004c6e")132 if err != nil {133 return nil, err134 }135 }136 return env, nil137}138func linuxCompilerVersion(tags map[string]bool) string {139 switch {140 case tags["v5.9"]:141 return "10.1.0"142 case tags["v4.12"]:143 return "8.1.0"144 case tags["v4.11"]:145 return "7.3.0"146 default:147 return "5.5.0"148 }149}150func linuxAlterConfigs(cf *kconfig.ConfigFile, tags map[string]bool) {151 const disableAlways = "disable-always"152 // If tags is nil, disable only configs marked as disableAlways.153 checkTag := func(tag string) bool {154 return tags != nil && !tags[tag] ||155 tags == nil && tag == disableAlways156 }157 disable := map[string]string{158 // 5.2 has CONFIG_SECURITY_TOMOYO_INSECURE_BUILTIN_SETTING which allows to test tomoyo better.159 // This config also enables CONFIG_SECURITY_TOMOYO_OMIT_USERSPACE_LOADER160 // but we need it disabled to boot older kernels.161 "SECURITY_TOMOYO_OMIT_USERSPACE_LOADER": "v5.2",162 // Kernel is boot broken before 4.15 due to double-free in vudc_probe:163 // https://lkml.org/lkml/2018/9/7/648164 // Fixed by e28fd56ad5273be67d0fae5bedc7e1680e729952.165 "USBIP_VUDC": "v4.15",166 // CONFIG_CAN causes:167 // all runs: crashed: INFO: trying to register non-static key in can_notifier168 // for v4.11..v4.12 and v4.12..v4.13 ranges.169 // Fixed by 74b7b490886852582d986a33443c2ffa50970169.170 "CAN": "v4.13",171 // Setup of network devices is broken before v4.12 with a "WARNING in hsr_get_node".172 // Fixed by 675c8da049fd6556eb2d6cdd745fe812752f07a8.173 "HSR": "v4.12",174 // Setup of network devices is broken before v4.12 with a "WARNING: ODEBUG bug in __sk_destruct"175 // coming from smc_release.176 "SMC": "v4.12",177 // Kernel is boot broken before 4.10 with a lockdep warning in vhci_hcd_probe.178 "USBIP_VHCI_HCD": "v4.10",179 "BT_HCIVHCI": "v4.10",180 // Setup of network devices is broken before v4.7 with a deadlock involving team.181 "NET_TEAM": "v4.7",182 // Setup of network devices is broken before v4.5 with a warning in batadv_tvlv_container_remove.183 "BATMAN_ADV": "v4.5",184 // UBSAN is broken in multiple ways before v5.3, see:185 // https://github.com/google/syzkaller/issues/1523#issuecomment-696514105186 "UBSAN": "v5.3",187 // First, we disable coverage in pkg/bisect because it fails machine testing starting from 4.7.188 // Second, at 6689da155bdcd17abfe4d3a8b1e245d9ed4b5f2c CONFIG_KCOV selects CONFIG_GCC_PLUGIN_SANCOV189 // (why?), which is build broken for hundreds of revisions.190 "KCOV": disableAlways,191 // This helps to produce stable binaries in presence of kernel tag changes.192 "LOCALVERSION_AUTO": disableAlways,193 // BTF fails lots of builds with:194 // pahole version v1.9 is too old, need at least v1.13195 // Failed to generate BTF for vmlinux. Try to disable CONFIG_DEBUG_INFO_BTF.196 "DEBUG_INFO_BTF": disableAlways,197 // This config only adds debug output. It should not be enabled at all,198 // but it was accidentially enabled on some instances for some periods of time,199 // and kernel is boot-broken for prolonged ranges of commits with deadlock200 // which makes bisections take weeks.201 "DEBUG_KOBJECT": disableAlways,202 // This config is causing problems to kernel signature calculation as new initramfs is generated203 // as a part of every build. Due to this init.data section containing this generated initramfs204 // is differing between builds causing signture being random number.205 "BLK_DEV_INITRD": disableAlways,206 }207 for cfg, tag := range disable {208 if checkTag(tag) {209 cf.Unset(cfg)210 }211 }212 alter := []struct {213 From string214 To string215 Tag string216 }{217 // Even though ORC unwinder was introduced a long time ago, it might have been broken for218 // some time. 5.4 is chosen as a version tag, where ORC unwinder seems to work properly.219 {"UNWINDER_ORC", "UNWINDER_FRAME_POINTER", "v5.4"},220 }221 for _, a := range alter {222 if checkTag(a.Tag) {223 cf.Unset(a.From)224 cf.Set(a.To, kconfig.Yes)225 }226 }227}228func (ctx *linux) Bisect(bad, good string, dt debugtracer.DebugTracer, pred func() (BisectResult,229 error)) ([]*Commit, error) {230 commits, err := ctx.git.Bisect(bad, good, dt, pred)231 if len(commits) == 1 {232 ctx.addMaintainers(commits[0])233 }234 return commits, err235}236func (ctx *linux) addMaintainers(com *Commit) {237 if len(com.Recipients) > 2 {238 return239 }240 mtrs := ctx.getMaintainers(com.Hash, false)241 if len(mtrs) < 3 {242 mtrs = ctx.getMaintainers(com.Hash, true)243 }244 com.Recipients = append(com.Recipients, mtrs...)245 sort.Sort(com.Recipients)246}247func (ctx *linux) getMaintainers(hash string, blame bool) Recipients {248 // See #1441 re --git-min-percent.249 args := "git show " + hash + " | " +250 filepath.FromSlash("scripts/get_maintainer.pl") +251 " --git-min-percent=20"252 if blame {253 args += " --git-blame"254 }255 output, err := osutil.RunCmd(time.Minute, ctx.git.dir, "bash", "-c", args)256 if err != nil {257 return nil258 }259 return ParseMaintainersLinux(output)260}261func ParseMaintainersLinux(text []byte) Recipients {262 lines := strings.Split(string(text), "\n")263 reRole := regexp.MustCompile(` \([^)]+\)$`)264 var mtrs Recipients265 // LMKL is To by default, but it changes to Cc if there's also a subsystem list.266 lkmlType := To267 foundLkml := false268 for _, line := range lines {269 role := reRole.FindString(line)270 address := strings.Replace(line, role, "", 1)271 addr, err := mail.ParseAddress(address)272 if err != nil {273 continue274 }275 var roleType RecipientType276 if addr.Address == "linux-kernel@vger.kernel.org" {277 foundLkml = true278 continue279 } else if strings.Contains(role, "list") {280 lkmlType = Cc281 roleType = To282 } else if strings.Contains(role, "maintainer") || strings.Contains(role, "supporter") {283 roleType = To284 } else {285 roleType = Cc // Reviewer or other role; default to Cc.286 }287 mtrs = append(mtrs, RecipientInfo{*addr, roleType})288 }289 if foundLkml {290 mtrs = append(mtrs, RecipientInfo{mail.Address{Address: "linux-kernel@vger.kernel.org"}, lkmlType})291 }292 sort.Sort(mtrs)293 return mtrs294}295const configBisectTag = "# Minimized by syzkaller"296func (ctx *linux) Minimize(target *targets.Target, original, baseline []byte,297 dt debugtracer.DebugTracer, pred func(test []byte) (BisectResult, error)) ([]byte, error) {298 if bytes.HasPrefix(original, []byte(configBisectTag)) {299 dt.Log("# configuration already minimized\n")300 return original, nil301 }302 kconf, err := kconfig.Parse(target, filepath.Join(ctx.git.dir, "Kconfig"))303 if err != nil {304 return nil, fmt.Errorf("failed to parse Kconfig: %v", err)305 }306 originalConfig, err := kconfig.ParseConfigData(original, "original")307 if err != nil {308 return nil, err309 }310 baselineConfig, err := kconfig.ParseConfigData(baseline, "baseline")311 if err != nil {312 return nil, err313 }314 linuxAlterConfigs(originalConfig, nil)315 linuxAlterConfigs(baselineConfig, nil)316 kconfPred := func(candidate *kconfig.ConfigFile) (bool, error) {317 res, err := pred(serialize(candidate))318 return res == BisectBad, err319 }320 minConfig, err := kconf.Minimize(baselineConfig, originalConfig, kconfPred, dt)321 if err != nil {322 return nil, err323 }324 return serialize(minConfig), nil325}326func serialize(cf *kconfig.ConfigFile) []byte {327 return []byte(fmt.Sprintf("%v, rev: %v\n%s", configBisectTag, prog.GitRevision, cf.Serialize()))328}...
minconfig.go
Source:minconfig.go
...52 res, err := kconf.Minimize(base, full, pred, gt)53 if err != nil {54 tool.Fail(err)55 }56 os.Stdout.Write(res.Serialize())57}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!