Best Syzkaller code snippet using kconfig.String
main.go
Source:main.go
...87}88var IOAPICIRQs map[PCIAddr]IOAPICIRQ = map[PCIAddr]IOAPICIRQ{}89var KconfigBool map[string]bool = map[string]bool{}90var KconfigComment map[string]string = map[string]string{}91var KconfigString map[string]string = map[string]string{}92var KconfigStringUnquoted map[string]string = map[string]string{}93var KconfigHex map[string]uint32 = map[string]uint32{}94var KconfigInt map[string]int = map[string]int{}95var ROMSizeKB = 096var ROMProtocol = ""97var FlashROMSupport = ""98func GetLE16(inp []byte) uint16 {99 return uint16(inp[0]) | (uint16(inp[1]) << 8)100}101func FormatHexLE16(inp []byte) string {102 return fmt.Sprintf("0x%04x", GetLE16(inp))103}104func FormatHex32(u uint32) string {105 return fmt.Sprintf("0x%08x", u)106}107func FormatHex8(u uint8) string {108 return fmt.Sprintf("0x%02x", u)109}110func FormatInt32(u uint32) string {111 return fmt.Sprintf("%d", u)112}113func FormatHexLE32(d []uint8) string {114 u := uint32(d[0]) | (uint32(d[1]) << 8) | (uint32(d[2]) << 16) | (uint32(d[3]) << 24)115 return FormatHex32(u)116}117func FormatBool(inp bool) string {118 if inp {119 return "1"120 } else {121 return "0"122 }123}124func sanitize(inp string) string {125 result := strings.ToLower(inp)126 result = strings.Replace(result, " ", "_", -1)127 result = strings.Replace(result, ",", "_", -1)128 for strings.HasSuffix(result, ".") {129 result = result[0 : len(result)-1]130 }131 return result132}133func AddROMStageFile(Name string, Condition string) {134 ROMStageFiles[Name] = Condition135}136func AddRAMStageFile(Name string, Condition string) {137 RAMStageFiles[Name] = Condition138}139func AddSMMFile(Name string, Condition string) {140 SMMFiles[Name] = Condition141}142func IsIOPortUsedBy(ctx Context, port uint16, name string) bool {143 for _, io := range ctx.InfoSource.GetIOPorts() {144 if io.Start <= port && port <= io.End && io.Usage == name {145 return true146 }147 }148 return false149}150var FlagOutDir = flag.String("coreboot_dir", ".", "Resulting coreboot directory")151func writeMF(mf *os.File, files map[string]string, category string) {152 keys := []string{}153 for file, _ := range files {154 keys = append(keys, file)155 }156 sort.Strings(keys)157 for _, file := range keys {158 condition := files[file]159 if condition == "" {160 fmt.Fprintf(mf, "%s-y += %s\n", category, file)161 } else {162 fmt.Fprintf(mf, "%s-$(%s) += %s\n", category,163 condition, file)164 }165 }166}167func Create(ctx Context, name string) *os.File {168 li := strings.LastIndex(name, "/")169 if li > 0 {170 os.MkdirAll(ctx.BaseDirectory+"/"+name[0:li], 0700)171 }172 mf, err := os.Create(ctx.BaseDirectory + "/" + name)173 if err != nil {174 log.Fatal(err)175 }176 return mf177}178func Add_gpl(fp *os.File) {179 fp.WriteString(`/*180 * This file is part of the coreboot project.181 *182 * Copyright (C) 2008-2009 coresystems GmbH183 * Copyright (C) 2014 Vladimir Serbinenko184 *185 * This program is free software; you can redistribute it and/or186 * modify it under the terms of the GNU General Public License as187 * published by the Free Software Foundation; version 2 of188 * the License.189 *190 * This program is distributed in the hope that it will be useful,191 * but WITHOUT ANY WARRANTY; without even the implied warranty of192 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the193 * GNU General Public License for more details.194 */195`)196}197func RestorePCI16Simple(f *os.File, pcidev PCIDevData, addr uint16) {198 fmt.Fprintf(f, " pci_write_config16(PCI_DEV(%d, 0x%02x, %d), 0x%02x, 0x%02x%02x);\n",199 pcidev.Bus, pcidev.Dev, pcidev.Func, addr,200 pcidev.ConfigDump[addr+1],201 pcidev.ConfigDump[addr])202}203func RestorePCI32Simple(f *os.File, pcidev PCIDevData, addr uint16) {204 fmt.Fprintf(f, " pci_write_config32(PCI_DEV(%d, 0x%02x, %d), 0x%02x, 0x%02x%02x%02x%02x);\n",205 pcidev.Bus, pcidev.Dev, pcidev.Func, addr,206 pcidev.ConfigDump[addr+3],207 pcidev.ConfigDump[addr+2],208 pcidev.ConfigDump[addr+1],209 pcidev.ConfigDump[addr])210}211func RestoreRCBA32(f *os.File, inteltool InteltoolData, addr uint16) {212 fmt.Fprintf(f, "\tRCBA32(0x%04x) = 0x%08x;\n", addr, inteltool.RCBA[addr])213}214type PCISlot struct {215 PCIAddr216 additionalComment string217 writeEmpty bool218}219type DevTreeNode struct {220 Bus int221 Dev int222 Func int223 Disabled bool224 Registers map[string]string225 IOs map[uint16]uint16226 Children []DevTreeNode227 PCISlots []PCISlot228 PCIController bool229 ChildPCIBus int230 MissingParent string231 SubVendor uint16232 SubSystem uint16233 Chip string234 Comment string235}236var DevTree DevTreeNode237var MissingChildren map[string][]DevTreeNode = map[string][]DevTreeNode{}238var unmatchedPCIChips map[PCIAddr]DevTreeNode = map[PCIAddr]DevTreeNode{}239var unmatchedPCIDevices map[PCIAddr]DevTreeNode = map[PCIAddr]DevTreeNode{}240func Offset(dt *os.File, offset int) {241 for i := 0; i < offset; i++ {242 fmt.Fprintf(dt, "\t")243 }244}245func MatchDev(dev *DevTreeNode) {246 for idx := range dev.Children {247 MatchDev(&dev.Children[idx])248 }249 for _, slot := range dev.PCISlots {250 slotChip, ok := unmatchedPCIChips[slot.PCIAddr]251 if !ok {252 continue253 }254 if slot.additionalComment != "" && slotChip.Comment != "" {255 slotChip.Comment = slot.additionalComment + " " + slotChip.Comment256 } else {257 slotChip.Comment = slot.additionalComment + slotChip.Comment258 }259 delete(unmatchedPCIChips, slot.PCIAddr)260 MatchDev(&slotChip)261 dev.Children = append(dev.Children, slotChip)262 }263 if dev.PCIController {264 for slot, slotDev := range unmatchedPCIChips {265 if slot.Bus == dev.ChildPCIBus {266 delete(unmatchedPCIChips, slot)267 MatchDev(&slotDev)268 dev.Children = append(dev.Children, slotDev)269 }270 }271 }272 for _, slot := range dev.PCISlots {273 slotDev, ok := unmatchedPCIDevices[slot.PCIAddr]274 if !ok {275 if slot.writeEmpty {276 dev.Children = append(dev.Children,277 DevTreeNode{278 Registers: map[string]string{},279 Chip: "pci",280 Bus: slot.Bus,281 Dev: slot.Dev,282 Func: slot.Func,283 Comment: slot.additionalComment,284 Disabled: true,285 },286 )287 }288 continue289 }290 if slot.additionalComment != "" && slotDev.Comment != "" {291 slotDev.Comment = slot.additionalComment + " " + slotDev.Comment292 } else {293 slotDev.Comment = slot.additionalComment + slotDev.Comment294 }295 MatchDev(&slotDev)296 dev.Children = append(dev.Children, slotDev)297 delete(unmatchedPCIDevices, slot.PCIAddr)298 }299 if dev.MissingParent != "" {300 for _, child := range MissingChildren[dev.MissingParent] {301 MatchDev(&child)302 dev.Children = append(dev.Children, child)303 }304 delete(MissingChildren, dev.MissingParent)305 }306 if dev.PCIController {307 for slot, slotDev := range unmatchedPCIDevices {308 if slot.Bus == dev.ChildPCIBus {309 MatchDev(&slotDev)310 dev.Children = append(dev.Children, slotDev)311 delete(unmatchedPCIDevices, slot)312 }313 }314 }315}316func writeOn(dt *os.File, dev DevTreeNode) {317 if dev.Disabled {318 fmt.Fprintf(dt, "off")319 } else {320 fmt.Fprintf(dt, "on")321 }322}323func WriteDev(dt *os.File, offset int, dev DevTreeNode) {324 Offset(dt, offset)325 switch dev.Chip {326 case "cpu_cluster", "lapic", "domain", "ioapic":327 fmt.Fprintf(dt, "device %s 0x%x ", dev.Chip, dev.Dev)328 writeOn(dt, dev)329 case "pci", "pnp":330 fmt.Fprintf(dt, "device %s %02x.%x ", dev.Chip, dev.Dev, dev.Func)331 writeOn(dt, dev)332 case "i2c":333 fmt.Fprintf(dt, "device %s %02x ", dev.Chip, dev.Dev)334 writeOn(dt, dev)335 default:336 fmt.Fprintf(dt, "chip %s", dev.Chip)337 }338 if dev.Comment != "" {339 fmt.Fprintf(dt, " # %s", dev.Comment)340 }341 fmt.Fprintf(dt, "\n")342 if dev.Chip == "pci" && dev.SubSystem != 0 && dev.SubVendor != 0 {343 Offset(dt, offset+1)344 fmt.Fprintf(dt, "subsystemid 0x%04x 0x%04x\n", dev.SubVendor, dev.SubSystem)345 }346 ioapic, ok := IOAPICIRQs[PCIAddr{Bus: dev.Bus, Dev: dev.Dev, Func: dev.Func}]347 if dev.Chip == "pci" && ok {348 for pin, irq := range ioapic.IRQNO {349 if irq != 0 {350 Offset(dt, offset+1)351 fmt.Fprintf(dt, "ioapic_irq %d INT%c 0x%x\n", ioapic.APICID, 'A'+pin, irq)352 }353 }354 }355 keys := []string{}356 for reg, _ := range dev.Registers {357 keys = append(keys, reg)358 }359 sort.Strings(keys)360 for _, reg := range keys {361 val := dev.Registers[reg]362 Offset(dt, offset+1)363 fmt.Fprintf(dt, "register \"%s\" = \"%s\"\n", reg, val)364 }365 ios := []int{}366 for reg, _ := range dev.IOs {367 ios = append(ios, int(reg))368 }369 sort.Ints(ios)370 for _, reg := range ios {371 val := dev.IOs[uint16(reg)]372 Offset(dt, offset+1)373 fmt.Fprintf(dt, "io 0x%x = 0x%x\n", reg, val)374 }375 for _, child := range dev.Children {376 WriteDev(dt, offset+1, child)377 }378 Offset(dt, offset)379 fmt.Fprintf(dt, "end\n")380}381func PutChip(domain string, cur DevTreeNode) {382 MissingChildren[domain] = append(MissingChildren[domain], cur)383}384func PutPCIChip(addr PCIDevData, cur DevTreeNode) {385 unmatchedPCIChips[addr.PCIAddr] = cur386}387func PutPCIDevParent(addr PCIDevData, comment string, parent string) {388 cur := DevTreeNode{389 Registers: map[string]string{},390 Chip: "pci",391 Bus: addr.Bus,392 Dev: addr.Dev,393 Func: addr.Func,394 MissingParent: parent,395 Comment: comment,396 }397 if addr.ConfigDump[0xa] == 0x04 && addr.ConfigDump[0xb] == 0x06 {398 cur.PCIController = true399 cur.ChildPCIBus = int(addr.ConfigDump[0x19])400 loopCtr := 0401 for capPtr := addr.ConfigDump[0x34]; capPtr != 0; capPtr = addr.ConfigDump[capPtr+1] {402 /* Avoid hangs. There are only 0x100 different possible values for capPtr.403 If we iterate longer than that, we're in endless loop. */404 loopCtr++405 if loopCtr > 0x100 {406 break407 }408 if addr.ConfigDump[capPtr] == 0x0d {409 cur.SubVendor = GetLE16(addr.ConfigDump[capPtr+4 : capPtr+6])410 cur.SubSystem = GetLE16(addr.ConfigDump[capPtr+6 : capPtr+8])411 }412 }413 } else {414 cur.SubVendor = GetLE16(addr.ConfigDump[0x2c:0x2e])415 cur.SubSystem = GetLE16(addr.ConfigDump[0x2e:0x30])416 }417 unmatchedPCIDevices[addr.PCIAddr] = cur418}419func PutPCIDev(addr PCIDevData, comment string) {420 PutPCIDevParent(addr, comment, "")421}422type GenericPCI struct {423 Comment string424 Bus0Subdiv string425 MissingParent string426}427type GenericVGA struct {428 GenericPCI429}430type DSDTInclude struct {431 Comment string432 File string433}434type DSDTDefine struct {435 Key string436 Comment string437 Value string438}439var DSDTIncludes []DSDTInclude440var DSDTPCI0Includes []DSDTInclude441var DSDTDefines []DSDTDefine442func (g GenericPCI) Scan(ctx Context, addr PCIDevData) {443 PutPCIDevParent(addr, g.Comment, g.MissingParent)444}445func (g GenericVGA) Scan(ctx Context, addr PCIDevData) {446 KconfigString["VGA_BIOS_ID"] = fmt.Sprintf("%04x,%04x",447 addr.PCIVenID,448 addr.PCIDevID)449 KconfigString["VGA_BIOS_FILE"] = fmt.Sprintf("pci%04x,%04x.rom",450 addr.PCIVenID,451 addr.PCIDevID)452 PutPCIDevParent(addr, g.Comment, g.MissingParent)453}454func makeKconfigName(ctx Context) {455 kn := Create(ctx, "Kconfig.name")456 defer kn.Close()457 fmt.Fprintf(kn, "config %s\n\tbool \"%s\"\n", ctx.KconfigName, ctx.Model)458}459func makeComment(name string) string {460 cmt, ok := KconfigComment[name]461 if !ok {462 return ""463 }464 return " # " + cmt465}466func makeKconfig(ctx Context) {467 kc := Create(ctx, "Kconfig")468 defer kc.Close()469 fmt.Fprintf(kc, "if %s\n\n", ctx.KconfigName)470 fmt.Fprintf(kc, "config BOARD_SPECIFIC_OPTIONS # dummy\n\tdef_bool y\n")471 keys := []string{}472 for name, val := range KconfigBool {473 if val {474 keys = append(keys, name)475 }476 }477 sort.Strings(keys)478 for _, name := range keys {479 fmt.Fprintf(kc, "\tselect %s%s\n", name, makeComment(name))480 }481 keys = nil482 for name, val := range KconfigBool {483 if !val {484 keys = append(keys, name)485 }486 }487 sort.Strings(keys)488 for _, name := range keys {489 fmt.Fprintf(kc, `490config %s%s491 bool492 default n493`, name, makeComment(name))494 }495 keys = nil496 for name, _ := range KconfigStringUnquoted {497 keys = append(keys, name)498 }499 sort.Strings(keys)500 for _, name := range keys {501 fmt.Fprintf(kc, `502config %s%s503 string504 default %s505`, name, makeComment(name), KconfigStringUnquoted[name])506 }507 keys = nil508 for name, _ := range KconfigString {509 keys = append(keys, name)510 }511 sort.Strings(keys)512 for _, name := range keys {513 fmt.Fprintf(kc, `514config %s%s515 string516 default "%s"517`, name, makeComment(name), KconfigString[name])518 }519 keys = nil520 for name, _ := range KconfigHex {521 keys = append(keys, name)522 }523 sort.Strings(keys)524 for _, name := range keys {525 fmt.Fprintf(kc, `526config %s%s527 hex528 default 0x%x529`, name, makeComment(name), KconfigHex[name])530 }531 keys = nil532 for name, _ := range KconfigInt {533 keys = append(keys, name)534 }535 sort.Strings(keys)536 for _, name := range keys {537 fmt.Fprintf(kc, `538config %s%s539 int540 default %d541`, name, makeComment(name), KconfigInt[name])542 }543 fmt.Fprintf(kc, "endif\n")544}545const MoboDir = "/src/mainboard/"546func makeVendor(ctx Context) {547 vendor := ctx.Vendor548 vendorSane := ctx.SaneVendor549 vendorDir := *FlagOutDir + MoboDir + vendorSane550 vendorUpper := strings.ToUpper(vendorSane)551 kconfig := vendorDir + "/Kconfig"552 if _, err := os.Stat(kconfig); os.IsNotExist(err) {553 f, err := os.Create(kconfig)554 if err != nil {555 log.Fatal(err)556 }557 defer f.Close()558 f.WriteString(`if VENDOR_` + vendorUpper + `559choice560 prompt "Mainboard model"561source "src/mainboard/` + vendorSane + `/*/Kconfig.name"562endchoice563source "src/mainboard/` + vendorSane + `/*/Kconfig"564config MAINBOARD_VENDOR565 string566 default "` + vendor + `"567endif # VENDOR_` + vendorUpper + "\n")568 }569 kconfigName := vendorDir + "/Kconfig.name"570 if _, err := os.Stat(kconfigName); os.IsNotExist(err) {571 f, err := os.Create(kconfigName)572 if err != nil {573 log.Fatal(err)574 }575 defer f.Close()576 f.WriteString(`config VENDOR_` + vendorUpper + `577 bool "` + vendor + `"578`)579 }580}581func GuessECGPE(ctx Context) int {582 /* FIXME:XX Use iasl -d and/or better parsing */583 dsdt := ctx.InfoSource.GetACPI()["DSDT"]584 idx := bytes.Index(dsdt, []byte{0x08, '_', 'G', 'P', 'E', 0x0a}) /* Name (_GPE, byte). */585 if idx > 0 {586 return int(dsdt[idx+6])587 }588 return -1589}590func GuessSPDMap(ctx Context) []uint8 {591 dmi := ctx.InfoSource.GetDMI()592 if dmi.Vendor == "LENOVO" {593 return []uint8{0x50, 0x52, 0x51, 0x53}594 }595 return []uint8{0x50, 0x51, 0x52, 0x53}596}597func main() {598 flag.Parse()599 ctx := Context{}600 ctx.InfoSource = MakeLogReader()601 dmi := ctx.InfoSource.GetDMI()602 ctx.Vendor = dmi.Vendor603 if dmi.Vendor == "LENOVO" {604 ctx.Model = dmi.Version605 } else {606 ctx.Model = dmi.Model607 }608 if dmi.IsLaptop {609 KconfigBool["SYSTEM_TYPE_LAPTOP"] = true610 }611 ctx.SaneVendor = sanitize(ctx.Vendor)612 for {613 last := ctx.SaneVendor614 for _, suf := range []string{"_inc", "_co", "_corp"} {615 ctx.SaneVendor = strings.TrimSuffix(ctx.SaneVendor, suf)616 }617 if last == ctx.SaneVendor {618 break619 }620 }621 ctx.MoboID = ctx.SaneVendor + "/" + sanitize(ctx.Model)622 ctx.KconfigName = "BOARD_" + strings.ToUpper(ctx.SaneVendor+"_"+sanitize(ctx.Model))623 ctx.BaseDirectory = *FlagOutDir + MoboDir + ctx.MoboID624 KconfigStringUnquoted["MAINBOARD_DIR"] = ctx.MoboID625 KconfigString["MAINBOARD_PART_NUMBER"] = ctx.Model626 os.MkdirAll(ctx.BaseDirectory, 0700)627 makeVendor(ctx)628 ScanRoot(ctx)629 if len(ROMStageFiles) > 0 || len(RAMStageFiles) > 0 || len(SMMFiles) > 0 {630 mf := Create(ctx, "Makefile.inc")631 defer mf.Close()632 writeMF(mf, ROMStageFiles, "romstage")633 writeMF(mf, RAMStageFiles, "ramstage")634 writeMF(mf, SMMFiles, "smm")635 }636 devtree := Create(ctx, "devicetree.cb")637 defer devtree.Close()638 MatchDev(&DevTree)639 WriteDev(devtree, 0, DevTree)640 if MainboardInit != "" || MainboardEnable != "" || MainboardIncludes != nil {641 mainboard := Create(ctx, "mainboard.c")642 defer mainboard.Close()643 mainboard.WriteString("#include <device/device.h>\n")644 for _, include := range MainboardIncludes {645 mainboard.WriteString("#include <" + include + ">\n")646 }647 mainboard.WriteString("\n")648 if MainboardInit != "" {649 mainboard.WriteString(`static void mainboard_init(device_t dev)650{651` + MainboardInit + "}\n\n")652 }653 if MainboardInit != "" || MainboardEnable != "" {654 mainboard.WriteString("static void mainboard_enable(device_t dev)\n{\n")655 if MainboardInit != "" {656 mainboard.WriteString("\tdev->ops->init = mainboard_init;\n\n")657 }658 mainboard.WriteString(MainboardEnable)659 mainboard.WriteString("}\n\n")660 mainboard.WriteString(`struct chip_operations mainboard_ops = {661 .enable_dev = mainboard_enable,662};663`)664 }665 }666 at := Create(ctx, "acpi_tables.c")667 defer at.Close()668 at.WriteString("/* dummy */\n")669 bi := Create(ctx, "board_info.txt")670 defer bi.Close()671 fixme := ""672 if dmi.IsLaptop {673 bi.WriteString("Category: laptop\n")674 } else {675 bi.WriteString("Category: desktop\n")676 fixme += "check category, "677 }678 missing := "ROM package, ROM socketed"679 if ROMProtocol != "" {680 fmt.Fprintf(bi, "ROM protocol: %s\n", ROMProtocol)681 } else {682 missing += ", ROM protocol"683 }684 if FlashROMSupport != "" {685 fmt.Fprintf(bi, "Flashrom support: %s\n", FlashROMSupport)686 } else {687 missing += ", Flashrom support"688 }689 missing += ", Release year"690 if fixme != "" {691 fmt.Fprintf(bi, "FIXME: %s, put %s\n", fixme, missing)692 } else {693 fmt.Fprintf(bi, "FIXME: put %s\n", missing)694 }695 rs := Create(ctx, "romstage.c")696 defer rs.Close()697 rs.WriteString("/* dummy file */\n")698 if ROMSizeKB == 0 {699 KconfigBool["BOARD_ROMSIZE_KB_2048"] = true700 KconfigComment["BOARD_ROMSIZE_KB_2048"] = "FIXME: correct this"701 } else {702 KconfigBool[fmt.Sprintf("BOARD_ROMSIZE_KB_%d", ROMSizeKB)] = true703 }704 makeKconfig(ctx)705 makeKconfigName(ctx)706 dsdt := Create(ctx, "dsdt.asl")707 defer dsdt.Close()708 for _, define := range DSDTDefines {709 if define.Comment != "" {710 fmt.Fprintf(dsdt, "\t/* %s. */\n", define.Comment)711 }712 dsdt.WriteString("#define " + define.Key + " " + define.Value + "\n")713 }714 dsdt.WriteString(715 `DefinitionBlock(716 "dsdt.aml",717 "DSDT",718 0x03, // DSDT revision: ACPI v3.0719 "COREv4", // OEM id720 "COREBOOT", // OEM table id721 0x20141018 // OEM revision722)723{724 // Some generic macros725 #include "acpi/platform.asl"726`)727 for _, x := range DSDTIncludes {728 if x.Comment != "" {729 fmt.Fprintf(dsdt, "\t/* %s. */\n", x.Comment)730 }731 fmt.Fprintf(dsdt, "\t#include <%s>\n", x.File)732 }733 dsdt.WriteString(`734 Scope (\_SB) {735 Device (PCI0)736 {737`)738 for _, x := range DSDTPCI0Includes {739 if x.Comment != "" {740 fmt.Fprintf(dsdt, "\t/* %s. */\n", x.Comment)741 }742 fmt.Fprintf(dsdt, "\t\t#include <%s>\n", x.File)743 }744 dsdt.WriteString(745 ` }746 }747}748`)749}...
config.go
Source:config.go
...42 }43)44func InitDownload() {45 initGlobal()46 Kconfig.Mirror = strings.TrimSpace(viper.GetString("mirror"))47 Kconfig.OnlyOne = viper.GetString("only-one")48 Kconfig.CheckMD5 = viper.GetBool("check-md5")49 Kconfig.Cache = viper.GetBool("use-cache")50}51func initGlobal() {52 Kconfig.InventoryFile = viper.GetString("inventory-file")53 Kconfig.DownloadDir = "."54 Kconfig.Template = ""55 Kconfig.TemplateDir = "./"56 Kconfig.Yes = viper.GetBool("yes")57 Kconfig.Show = viper.GetBool("debug")58 if viper.GetBool("debug") {59 log.Log.SetLevel(logrus.DebugLevel)60 log.Log.SetFormatter(&logrus.TextFormatter{TimestampFormat: "2006-01-02 15:04:05", FullTimestamp: true})61 }62}63func InitPrepare() {64 initGlobal()65}66func InitWeb() {67 initGlobal()68 Kconfig.Mirror = viper.GetString("mirror")69 Kconfig.Port = viper.GetInt("port")70}71func InitInstall() {72 initGlobal()73 Kconfig.UseDocker = false74 Kconfig.ExtraArgs = viper.GetString("extra-args")75}76func InitStatus() {77 initGlobal()78}79func InitUninstall() {80 initGlobal()81}82func InitUpgrade() {83 initGlobal()84}85func InitAddNode() {86 initGlobal()87 Kconfig.Hostname = strings.TrimSpace(viper.GetString("hostname"))88 Kconfig.Ip = strings.TrimSpace(viper.GetString("ip"))89 Kconfig.OnlyUpdateInventory = viper.GetBool("only-update-inventory")90 if Kconfig.Hostname == "" || Kconfig.Ip == "" {91 pkg.Help("node", "add")92 os.Exit(0)93 }94}95func InitRemoveNode() {96 initGlobal()97 Kconfig.Hostname = strings.TrimSpace(viper.GetString("hostname"))98 Kconfig.RemoveData = viper.GetBool("remove-data")99 Kconfig.OnlyUpdateInventory = viper.GetBool("only-update-inventory")100 if Kconfig.Hostname == "" {101 pkg.Help("node", "del")102 os.Exit(0)103 }104}...
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!!