github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/kconfig/kconfig_test.go (about) 1 // Copyright 2020 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package kconfig 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/google/syzkaller/sys/targets" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestParseKConfig(t *testing.T) { 15 type Test struct { 16 in string 17 } 18 tests := []Test{ 19 { 20 in: ` 21 mainmenu "test" 22 config FOO 23 default "$(shell,$(srctree)/scripts/gcc-plugin.sh "$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")" if CC_IS_GCC 24 `, 25 }, 26 { 27 in: ` 28 mainmenu "test_transitional" 29 config FOO 30 transitional 31 `, 32 }, 33 } 34 target := targets.Get("linux", "amd64") 35 for i, test := range tests { 36 t.Run(fmt.Sprint(i), func(t *testing.T) { 37 kconf, err := ParseData(target, []byte(test.in), "Kconfig") 38 if err != nil { 39 t.Fatal(err) 40 } 41 _ = kconf 42 }) 43 } 44 } 45 46 func TestSelectedby(t *testing.T) { 47 configData := ` 48 mainmenu "test" 49 50 config FEATURE_A 51 bool "Feature A" 52 select FEATURE_B 53 54 config FEATURE_B 55 bool "Feature B" 56 select FEATURE_C 57 58 config FEATURE_C 59 bool "Feature C" 60 61 ` 62 target := targets.Get("linux", "amd64") 63 kconf, err := ParseData(target, []byte(configData), "Kconfig") 64 if err != nil { 65 t.Fatal(err) 66 } 67 assert.Empty(t, kconf.SelectedBy("FEATURE_A")) 68 assert.Equal(t, map[string]bool{ 69 "FEATURE_A": true, 70 }, kconf.SelectedBy("FEATURE_B")) 71 assert.Equal(t, map[string]bool{ 72 "FEATURE_A": true, 73 "FEATURE_B": true, 74 }, kconf.SelectedBy("FEATURE_C")) 75 } 76 77 func TestFuzzParseKConfig(t *testing.T) { 78 for _, data := range []string{ 79 ``, 80 } { 81 FuzzParseKConfig([]byte(data)[:len(data):len(data)]) 82 } 83 }