How to use Shell method of kconfig Package

Best Syzkaller code snippet using kconfig.Shell

kconf.go

Source:kconf.go Github

copy

Full Screen

...175 }176 if err := ctx.mrProper(); err != nil {177 return err178 }179 if err := ctx.executeShell(); err != nil {180 return err181 }182 configFile := filepath.Join(ctx.BuildDir, ".config")183 cf, err := kconfig.ParseConfig(configFile)184 if err != nil {185 return err186 }187 if !ctx.Inst.Features[featBaseline] {188 if err := ctx.addUSBConfigs(cf); err != nil {189 return err190 }191 }192 ctx.applyConfigs(cf)193 cf.ModToYes()194 // Set all configs that are not present (actually not present, rather than "is not set") to "is not set".195 // This avoids olddefconfig turning on random things we did not ask for.196 for _, cfg := range ctx.Kconf.Configs {197 if (cfg.Type == kconfig.TypeTristate || cfg.Type == kconfig.TypeBool) && cf.Map[cfg.Name] == nil {198 cf.Set(cfg.Name, kconfig.No)199 }200 }201 original := cf.Serialize()202 if err := osutil.WriteFile(configFile, original); err != nil {203 return fmt.Errorf("failed to write .config file: %v", err)204 }205 // Save what we've got before olddefconfig for debugging purposes, it allows to see if we did not set a config,206 // or olddefconfig removed it. Save as .tmp so that it's not checked-in accidentially.207 outputFile := filepath.Join(ctx.ConfigDir, ctx.Inst.Name+".config")208 outputFileTmp := outputFile + ".tmp"209 if err := osutil.WriteFile(outputFileTmp, original); err != nil {210 return fmt.Errorf("failed to write tmp config file: %v", err)211 }212 if err := ctx.Make("olddefconfig"); err != nil {213 return err214 }215 cf, err = kconfig.ParseConfig(configFile)216 if err != nil {217 return err218 }219 if err := ctx.verifyConfigs(cf); err != nil {220 return fmt.Errorf("%vsaved config before olddefconfig to %v", err, outputFileTmp)221 }222 cf.ModToNo()223 config := []byte(fmt.Sprintf(`# Automatically generated by syz-kconf; DO NOT EDIT.224# Kernel: %v %v225%s226%s227`,228 ctx.Inst.Kernel.Repo, ctx.Inst.Kernel.Tag, cf.Serialize(), ctx.Inst.Verbatim))229 return osutil.WriteFile(outputFile, config)230}231func (ctx *Context) executeShell() error {232 for _, shell := range ctx.Inst.Shell {233 if !ctx.Inst.Features.Match(shell.Constraints) {234 continue235 }236 args := strings.Split(shell.Cmd, " ")237 for i := 1; i < len(args); i++ {238 args[i] = ctx.replaceVars(args[i])239 }240 if args[0] == "make" {241 if err := ctx.Make(args[1:]...); err != nil {242 return err243 }244 continue245 }246 if _, err := osutil.RunCmd(10*time.Minute, ctx.SourceDir, args[0], args[1:]...); err != nil {...

Full Screen

Full Screen

parser.go

Source:parser.go Github

copy

Full Screen

...17 Kernel Kernel18 Compiler string19 Linker string20 Verbatim []byte21 Shell []Shell22 Features Features23 ConfigMap map[string]*Config24 Configs []*Config25}26type Config struct {27 Name string28 Value string29 Optional bool30 Constraints []string31 File string32 Line int33}34type Kernel struct {35 Repo string36 Tag string37}38type Shell struct {39 Cmd string40 Constraints []string41}42type Features map[string]bool43func (features Features) Match(constraints []string) bool {44 for _, feat := range constraints {45 if feat[0] == '-' {46 if features[feat[1:]] {47 return false48 }49 } else if !features[feat] {50 return false51 }52 }53 return true54}55func constraintsInclude(constraints []string, what string) bool {56 for _, feat := range constraints {57 if feat == what {58 return true59 }60 }61 return false62}63type rawMain struct {64 Instances []map[string][]string65 Includes []map[string][]string66}67type rawFile struct {68 Kernel struct {69 Repo string70 Tag string71 }72 Compiler string73 Linker string74 Shell []yaml.Node75 Verbatim string76 Config []yaml.Node77}78func parseMainSpec(file string) ([]*Instance, []string, error) {79 data, err := ioutil.ReadFile(file)80 if err != nil {81 return nil, nil, fmt.Errorf("failed to read config file: %v", err)82 }83 dec := yaml.NewDecoder(bytes.NewReader(data))84 dec.KnownFields(true)85 raw := new(rawMain)86 if err := dec.Decode(raw); err != nil {87 return nil, nil, fmt.Errorf("failed to parse %v: %v", file, err)88 }89 var unusedFeatures []string90 var instances []*Instance91 for _, inst := range raw.Instances {92 for name, features := range inst {93 if name == "_" {94 unusedFeatures = features95 continue96 }97 inst, err := parseInstance(name, filepath.Dir(file), features, raw.Includes)98 if err != nil {99 return nil, nil, fmt.Errorf("%v: %v", name, err)100 }101 instances = append(instances, inst)102 if constraintsInclude(features, featBaseline) {103 continue104 }105 inst, err = parseInstance(name+"-base", filepath.Dir(file), append(features, featBaseline), raw.Includes)106 if err != nil {107 return nil, nil, err108 }109 instances = append(instances, inst)110 }111 }112 return instances, unusedFeatures, nil113}114func parseInstance(name, configDir string, features []string, includes []map[string][]string) (*Instance, error) {115 inst := &Instance{116 Name: name,117 Features: make(Features),118 ConfigMap: make(map[string]*Config),119 }120 for _, feat := range features {121 inst.Features[feat] = true122 }123 errs := new(Errors)124 for _, include := range includes {125 for file, features := range include {126 raw, err := parseFile(filepath.Join(configDir, "bits", file))127 if err != nil {128 return nil, err129 }130 if inst.Features.Match(features) {131 mergeFile(inst, raw, file, errs)132 } else if inst.Features[featReduced] && constraintsInclude(features, "-"+featReduced) {133 // For fragments that we exclude because of "reduced" config,134 // we want to disable all configs listed there.135 // For example, if the fragment enables config FOO, and we the defconfig136 // also enabled FOO, we want to disable FOO to get reduced config.137 for _, node := range raw.Config {138 mergeConfig(inst, file, node, true, errs)139 }140 }141 }142 }143 inst.Verbatim = bytes.TrimSpace(inst.Verbatim)144 return inst, errs.err()145}146func parseFile(file string) (*rawFile, error) {147 data, err := ioutil.ReadFile(file)148 if err != nil {149 return nil, fmt.Errorf("failed to read %v: %v", file, err)150 }151 dec := yaml.NewDecoder(bytes.NewReader(data))152 dec.KnownFields(true)153 raw := new(rawFile)154 if err := dec.Decode(raw); err != nil {155 return nil, fmt.Errorf("failed to parse %v: %v", file, err)156 }157 return raw, nil158}159func mergeFile(inst *Instance, raw *rawFile, file string, errs *Errors) {160 if raw.Kernel.Repo != "" || raw.Kernel.Tag != "" {161 if !vcs.CheckRepoAddress(raw.Kernel.Repo) {162 errs.push("%v: bad kernel repo %q", file, raw.Kernel.Repo)163 }164 if !vcs.CheckBranch(raw.Kernel.Tag) {165 errs.push("%v: bad kernel tag %q", file, raw.Kernel.Tag)166 }167 if inst.Kernel.Repo != "" {168 errs.push("%v: kernel is set twice", file)169 }170 inst.Kernel = raw.Kernel171 }172 if raw.Compiler != "" {173 if inst.Compiler != "" {174 errs.push("%v: compiler is set twice", file)175 }176 inst.Compiler = raw.Compiler177 }178 if raw.Linker != "" {179 if inst.Linker != "" {180 errs.push("%v: linker is set twice", file)181 }182 inst.Linker = raw.Linker183 }184 for _, node := range raw.Shell {185 cmd, _, constraints, err := parseNode(node)186 if err != nil {187 errs.push("%v:%v: %v", file, node.Line, err)188 }189 inst.Shell = append(inst.Shell, Shell{190 Cmd: cmd,191 Constraints: constraints,192 })193 }194 if raw.Verbatim != "" {195 inst.Verbatim = append(append(inst.Verbatim, strings.TrimSpace(raw.Verbatim)...), '\n')196 }197 for _, node := range raw.Config {198 mergeConfig(inst, file, node, false, errs)199 }200}201func mergeConfig(inst *Instance, file string, node yaml.Node, reduced bool, errs *Errors) {202 name, val, constraints, err := parseNode(node)203 if err != nil {...

Full Screen

Full Screen

Shell

Using AI Code Generation

copy

Full Screen

1import (2type (3 User struct {4 }5 UserForm struct {6 }7 UserController struct {8 }9 UserService interface {10 GetByID(int64) *User11 GetByUsername(string) *User12 GetAll() []*User13 Insert(string, string, string, string) error14 Update(int64, string, string, string, string) error15 Delete(int64) error16 }17 UserServiceMock struct {18 }19 UserServiceGorm struct {20 }21var (

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful