github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/cover/manager_to_ci.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  	"encoding/json"
     8  	"fmt"
     9  	"io"
    10  )
    11  
    12  // CIDetails fields will be added to every CSV line.
    13  type CIDetails struct {
    14  	Version        int    `json:"version"`
    15  	Timestamp      string `json:"timestamp"`
    16  	FuzzingMinutes int    `json:"fuzzing_minutes"`
    17  	Arch           string `json:"arch"`
    18  	BuildID        string `json:"build_id"`
    19  	Manager        string `json:"manager"`
    20  	KernelRepo     string `json:"kernel_repo"`
    21  	KernelBranch   string `json:"kernel_branch"`
    22  	KernelCommit   string `json:"kernel_commit"`
    23  }
    24  
    25  type dbCoverageRecord struct {
    26  	CIDetails
    27  	CoverageInfo
    28  }
    29  
    30  func writeJSLine(w io.Writer, covInfo dbCoverageRecord) error {
    31  	bs, err := json.Marshal(covInfo)
    32  	if err != nil {
    33  		return fmt.Errorf("failed to marshal covInfo: %w", err)
    34  	}
    35  	bs = append(bs, '\n')
    36  	if _, err = w.Write(bs); err != nil {
    37  		return fmt.Errorf("failed to write js data: %w", err)
    38  	}
    39  	return nil
    40  }
    41  
    42  func WriteCIJSONLine(w io.Writer, managerCover CoverageInfo, ciDetails CIDetails) error {
    43  	dbLine := dbCoverageRecord{
    44  		CIDetails:    ciDetails,
    45  		CoverageInfo: managerCover,
    46  	}
    47  	if err := writeJSLine(w, dbLine); err != nil {
    48  		return fmt.Errorf("failed to serialize func line: %w", err)
    49  	}
    50  	return nil
    51  }