aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/kconfig/kconfig_test.go
blob: 8939f21ddd24800f7a9e12274b4eb9f11485b16e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2020 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package kconfig

import (
	"fmt"
	"testing"

	"github.com/google/syzkaller/sys/targets"
	"github.com/stretchr/testify/assert"
)

func TestParseKConfig(t *testing.T) {
	type Test struct {
		in string
	}
	tests := []Test{
		{
			in: `
mainmenu "test"
config FOO
	default "$(shell,$(srctree)/scripts/gcc-plugin.sh "$(preferred-plugin-hostcc)" "$(HOSTCXX)" "$(CC)")" if CC_IS_GCC
`,
		},
		{
			in: `
mainmenu "test_transitional"
config FOO
	transitional
`,
		},
	}
	target := targets.Get("linux", "amd64")
	for i, test := range tests {
		t.Run(fmt.Sprint(i), func(t *testing.T) {
			kconf, err := ParseData(target, []byte(test.in), "Kconfig")
			if err != nil {
				t.Fatal(err)
			}
			_ = kconf
		})
	}
}

func TestSelectedby(t *testing.T) {
	configData := `
mainmenu "test"

config FEATURE_A
    bool "Feature A"
    select FEATURE_B

config FEATURE_B
    bool "Feature B"
    select FEATURE_C

config FEATURE_C
    bool "Feature C"

`
	target := targets.Get("linux", "amd64")
	kconf, err := ParseData(target, []byte(configData), "Kconfig")
	if err != nil {
		t.Fatal(err)
	}
	assert.Empty(t, kconf.SelectedBy("FEATURE_A"))
	assert.Equal(t, map[string]bool{
		"FEATURE_A": true,
	}, kconf.SelectedBy("FEATURE_B"))
	assert.Equal(t, map[string]bool{
		"FEATURE_A": true,
		"FEATURE_B": true,
	}, kconf.SelectedBy("FEATURE_C"))
}

func TestFuzzParseKConfig(t *testing.T) {
	for _, data := range []string{
		``,
	} {
		FuzzParseKConfig([]byte(data)[:len(data):len(data)])
	}
}