github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/pkg/report/impact_score_test.go (about)

     1  // Copyright 2025 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 report
     5  
     6  import (
     7  	"slices"
     8  	"testing"
     9  
    10  	"github.com/google/syzkaller/pkg/report/crash"
    11  )
    12  
    13  const testHangTitle = "BUG: soft lockup in some function"
    14  const testKASANInvalidFreeTitle = "KASAN: invalid-free"
    15  
    16  func TestImpactScore(t *testing.T) {
    17  	tests := []struct {
    18  		name     string
    19  		title    string
    20  		expected int
    21  	}{
    22  		{
    23  			name:     "unknown",
    24  			title:    "KGSAN: ",
    25  			expected: -1,
    26  		},
    27  		{
    28  			name:     "unknown KASAN",
    29  			title:    "KASAN: unknown",
    30  			expected: -1,
    31  		},
    32  		{
    33  			name:     "known Hang",
    34  			title:    testHangTitle,
    35  			expected: 1, // lowest priority we can think about
    36  		},
    37  	}
    38  	for _, test := range tests {
    39  		t.Run(test.name, func(t *testing.T) {
    40  			got := TitlesToImpact(test.title)
    41  			if got != test.expected {
    42  				t.Errorf("report.TitlesToImpact(%q) = %d, want %d", test.title, got, test.expected)
    43  			}
    44  		})
    45  	}
    46  }
    47  
    48  func TestTitlesToImpact2(t *testing.T) {
    49  	got := TitlesToImpact(testHangTitle, testKASANInvalidFreeTitle)
    50  	if got == 1 { // lowest priority we can think about (crash.Hang)
    51  		t.Errorf("report.TitlesToImpact(%q, %q) = %d, want %d",
    52  			testHangTitle, testKASANInvalidFreeTitle,
    53  			got, len(impactOrder)-slices.Index(impactOrder, crash.KASANInvalidFree))
    54  	}
    55  }