github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/tools/syz-trace2syz/proggen/call_selector_test.go (about)

     1  // Copyright 2019 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 proggen
     5  
     6  import "testing"
     7  
     8  func TestMatchFilename(t *testing.T) {
     9  	sc := selectorCommon{}
    10  	type Test struct {
    11  		file1 string
    12  		file2 string
    13  		devID int
    14  		match bool
    15  	}
    16  	tests := []Test{
    17  		{
    18  			"/dev/zero", "/dev/zero", -1, true,
    19  		}, {
    20  			"/dev/loop#", "/dev/loop1", 1, true,
    21  		}, {
    22  			"", "a", -1, false,
    23  		}, {
    24  			"/dev/loop#/loop", "/dev/loop0/looq", -1, false,
    25  		}, {
    26  			"/dev/i2c-#\x00", "/dev/i2c-1", 1, true,
    27  		}, {
    28  			"/dev/some#/some#", "/dev/some1/some1", 11, true,
    29  		}, {
    30  			"/dev/some/some#", "/dev/some", -1, false,
    31  		}, {
    32  			"/dev/some", "/dev/some/some", -1, false,
    33  		},
    34  	}
    35  	for _, test := range tests {
    36  		match, devID := sc.matchFilename([]byte(test.file1), []byte(test.file2))
    37  		if test.match != match || test.devID != devID {
    38  			t.Errorf("failed to match %s and %s\nexpected: %t, %d\n\ngot: %t, %d\n",
    39  				test.file1, test.file2, test.match, test.devID, match, devID)
    40  		}
    41  	}
    42  }