github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/asset/type.go (about)

     1  // Copyright 2022 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 asset
     5  
     6  import (
     7  	"github.com/google/syzkaller/dashboard/dashapi"
     8  	"github.com/google/syzkaller/sys/targets"
     9  )
    10  
    11  type TypeDescription struct {
    12  	AllowMultiple     bool
    13  	GetTitle          QueryTypeTitle
    14  	ContentType       string
    15  	ContentEncoding   string
    16  	ReportingPrio     int // the smaller, the higher the asset is on the list during reporting
    17  	NoReporting       bool
    18  	customCompressor  Compressor
    19  	preserveExtension bool
    20  }
    21  
    22  var assetTypes = map[dashapi.AssetType]*TypeDescription{
    23  	dashapi.BootableDisk: {
    24  		GetTitle:      constTitle("disk image"),
    25  		ReportingPrio: 1,
    26  	},
    27  	dashapi.NonBootableDisk: {
    28  		GetTitle:      constTitle("disk image (non-bootable)"),
    29  		ReportingPrio: 2,
    30  	},
    31  	dashapi.KernelObject: {
    32  		GetTitle: func(target *targets.Target) string {
    33  			if target != nil && target.KernelObject != "" {
    34  				return target.KernelObject
    35  			}
    36  			return "kernel object"
    37  		},
    38  		ReportingPrio: 3,
    39  	},
    40  	dashapi.KernelImage: {
    41  		GetTitle:      constTitle("kernel image"),
    42  		ReportingPrio: 4,
    43  	},
    44  	dashapi.HTMLCoverageReport: {
    45  		GetTitle:          constTitle("coverage report(html)"),
    46  		AllowMultiple:     true,
    47  		ContentType:       "text/html",
    48  		ContentEncoding:   "gzip", // We do want to decompress than right in the browser.
    49  		NoReporting:       true,
    50  		customCompressor:  gzipCompressor,
    51  		preserveExtension: true,
    52  	},
    53  	dashapi.MountInRepro: {
    54  		GetTitle:      constTitle("mounted in repro"),
    55  		ReportingPrio: 5,
    56  		// It feels that such images are very well compressible, so we can just use
    57  		// the omnipresent gzip compression.
    58  		customCompressor: gzipCompressor,
    59  	},
    60  }
    61  
    62  type QueryTypeTitle func(*targets.Target) string
    63  
    64  func constTitle(title string) QueryTypeTitle {
    65  	return func(*targets.Target) string {
    66  		return title
    67  	}
    68  }
    69  
    70  func GetTypeDescription(assetType dashapi.AssetType) *TypeDescription {
    71  	return assetTypes[assetType]
    72  }