github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/cover/manager_to_ci_test.go (about) 1 // Copyright 2024 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 cover 5 6 import ( 7 "bytes" 8 "encoding/json" 9 "testing" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 var sampleCoverJSON = []byte(`{"file_path":"main.c","func_name":"main",` + 15 `"sl":1,"sc":0,"el":1,"ec":-1,"hit_count":1,"inline":false,"pc":12345}`) 16 17 func TestWriteCIJSONLine(t *testing.T) { 18 expectedJSON := 19 `{"version":1,` + 20 `"timestamp":"2014-04-14 00:00:00.000",` + 21 `"fuzzing_minutes":360,` + 22 `"arch":"x86",` + 23 `"build_id":"sample_buildid",` + 24 `"manager":"sample_manager",` + 25 `"kernel_repo":"sample_repo_path",` + 26 `"kernel_branch":"",` + 27 `"kernel_commit":"",` + 28 `"file_path":"main.c",` + 29 `"func_name":"main",` + 30 `"sl":1,"sc":0,"el":1,"ec":-1,` + 31 `"hit_count":1,` + 32 `"inline":false,` + 33 `"pc":12345} 34 ` 35 36 covInfo := CoverageInfo{} 37 assert.NoError(t, json.Unmarshal(sampleCoverJSON, &covInfo)) 38 39 buf := new(bytes.Buffer) 40 assert.NoError(t, WriteCIJSONLine(buf, covInfo, CIDetails{ 41 Version: 1, 42 Timestamp: "2014-04-14 00:00:00.000", 43 FuzzingMinutes: 360, 44 Arch: "x86", 45 BuildID: "sample_buildid", 46 Manager: "sample_manager", 47 KernelRepo: "sample_repo_path", 48 })) 49 assert.Equal(t, expectedJSON, buf.String()) 50 }