aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/report/impact_score_test.go
blob: 47cdfdc4c71506d7be5ff0532836d1904006dae9 (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
// Copyright 2025 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 report

import (
	"slices"
	"testing"

	"github.com/google/syzkaller/pkg/report/crash"
)

const testHangTitle = "BUG: soft lockup in some function"
const testKASANInvalidFreeTitle = "KASAN: invalid-free"

func TestImpactScore(t *testing.T) {
	tests := []struct {
		name     string
		title    string
		expected int
	}{
		{
			name:     "unknown",
			title:    "KGSAN: ",
			expected: -1,
		},
		{
			name:     "unknown KASAN",
			title:    "KASAN: unknown",
			expected: -1,
		},
		{
			name:     "known Hang",
			title:    testHangTitle,
			expected: 1, // lowest priority we can think about
		},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			got := TitlesToImpact(test.title)
			if got != test.expected {
				t.Errorf("report.TitlesToImpact(%q) = %d, want %d", test.title, got, test.expected)
			}
		})
	}
}

func TestTitlesToImpact2(t *testing.T) {
	got := TitlesToImpact(testHangTitle, testKASANInvalidFreeTitle)
	if got == 1 { // lowest priority we can think about (crash.Hang)
		t.Errorf("report.TitlesToImpact(%q, %q) = %d, want %d",
			testHangTitle, testKASANInvalidFreeTitle,
			got, len(impactOrder)-slices.Index(impactOrder, crash.KASANInvalidFree))
	}
}