Documentation ¶
Overview ¶
Package crash contains utilties common to tests that use crash_reporter and crash_sender.
Index ¶
- Constants
- func ChromePreWithVerboseConsent() testing.Precondition
- func CreatePerUserConsent(ctx context.Context, enable bool) error
- func CreateRandomFile(path string, size int64) error
- func DefaultDirs() []string
- func DeleteCoreDumps(ctx context.Context) error
- func DisableCrashBlocking() error
- func DisableCrashFiltering() error
- func EnableCrashBlocking(ctx context.Context, filter string) error
- func EnableCrashFiltering(ctx context.Context, filter string) error
- func EnableMockSending(success bool) error
- func GetCrashDir(ctx context.Context, username string) (string, error)
- func GetCrashes(dirs ...string) ([]string, error)
- func GetDaemonStoreConsentDirs(ctx context.Context) ([]string, error)
- func GetDaemonStoreCrashDirs(ctx context.Context) ([]string, error)
- func IsBreakpadDmpFileForPID(fileName string, pid int) (bool, error)
- func ListSendRecords() ([]os.FileInfo, error)
- func MarkTestDone(ctx context.Context) error
- func MarkTestInProgress(ctx context.Context, name string) error
- func MoveFilesToOut(ctx context.Context, outDir string, files ...string) error
- func RemoveAllFiles(ctx context.Context, files map[string][]string) error
- func RemovePerUserConsent(ctx context.Context) error
- func RestartAnomalyDetector(ctx context.Context) error
- func RestartAnomalyDetectorWithSendAll(ctx context.Context, sendAll bool) error
- func SetConsent(ctx context.Context, cr *chrome.Chrome, consent bool) error
- func SetCrashTestInProgress() error
- func SetUpCrashTest(ctx context.Context, opts ...Option) error
- func TearDownCrashTest(ctx context.Context, opts ...tearDownOption) error
- func UnsetCrashTestInProgress() error
- func WaitForCrashFiles(ctx context.Context, dirs, regexes []string, opts ...WaitForCrashFilesOpt) (map[string][]string, error)
- type ConsentType
- type Option
- type RegexesNotFound
- type SendData
- type SendResult
- type WaitForCrashFilesOpt
Constants ¶
const ( // EarlyCrashDir is the directory where system crashes are stored in absence of persistent storage. EarlyCrashDir = "/run/crash_reporter/crash" // SystemCrashDir is the directory where system crash reports go. SystemCrashDir = "/var/spool/crash" // LocalCrashDir is the directory where user crash reports go. LocalCrashDir = "/home/chronos/crash" // UserCrashDir is the directory where crash reports of currently logged in user go. UserCrashDir = "/home/chronos/user/crash" // ClobberCrashDir is a directory where crash reports after an FS clobber go. ClobberCrashDir = "/mnt/stateful_partition/reboot_vault/crash" // FilterInPath is the path to the filter-in file. FilterInPath = "/run/crash_reporter/filter-in" // FilterOutPath is the path to the filter-out file. FilterOutPath = "/run/crash_reporter/filter-out" // BIOSExt is the extension for bios crash files. BIOSExt = ".bios_log" // CoreExt is the extension for core files. CoreExt = ".core" // MinidumpExt is the extension for minidump crash files. MinidumpExt = ".dmp" // LogExt is the extension for log files containing additional information that are written by crash_reporter. LogExt = ".log" // InfoExt is the extention for info files. InfoExt = ".info" // ProclogExt is the extention for proclog files. ProclogExt = ".proclog" // KCrashExt is the extension for log files created by kernel warnings and crashes. KCrashExt = ".kcrash" // GPUStateExt is the extension for GPU state files written by crash_reporter. GPUStateExt = ".i915_error_state.log.xz" // MetadataExt is the extension for metadata files written by crash collectors and read by crash_sender. MetadataExt = ".meta" // CompressedTxtExt is an extension on the compressed log files written by crash_reporter. CompressedTxtExt = ".txt.gz" // CompressedLogExt is an extension on the compressed log files written by crash_reporter. CompressedLogExt = ".log.gz" // DevCoredumpExt is an extension for device coredump files. DevCoredumpExt = ".devcore.gz" // ECCrashExt is an extension for ec crash dumps ECCrashExt = ".eccrash" // JavaScriptStackExt is the extension for JavaScript stacks. JavaScriptStackExt = ".js_stack" // ChromeVerboseConsentFlags provides the flags to enable verbose logging about consent. ChromeVerboseConsentFlags = "--vmodule=stats_reporting_controller=1,autotest_private_api=1" // FilterInIgnoreAllCrashes is a value to put in the filter-in file if // you wish to ignore all crashes that happen during a test. FilterInIgnoreAllCrashes = "none" )
const ( // SendRecordDir is the path to the directory containing send record files. // A send record file represents an upload event of a crash report. Its content is // serialized crash.SendRecord protocol buffers message, and its timestamp indicates // when the upload was performed. SendRecordDir = "/var/lib/crash_sender" )
Variables ¶
This section is empty.
Functions ¶
func ChromePreWithVerboseConsent ¶
func ChromePreWithVerboseConsent() testing.Precondition
ChromePreWithVerboseConsent returns a precondition that will start chrome with the ChromeVerboseConsentFlags.
func CreatePerUserConsent ¶
CreatePerUserConsent creates the per-user consent file with the specified state.
func CreateRandomFile ¶
CreateRandomFile creates a file at the given path, of |size| bytes and random contents.
func DefaultDirs ¶
func DefaultDirs() []string
DefaultDirs returns all standard directories to which crashes are written.
func DeleteCoreDumps ¶
DeleteCoreDumps deletes core dumps whose corresponding minidumps are available. It waits for crash_reporter to finish if it is running, in order to avoid deleting intermediate core dumps used to generate minidumps. Deleted core dumps are logged via ctx.
func DisableCrashBlocking ¶
func DisableCrashBlocking() error
DisableCrashBlocking removes the filter-in-block file using the default path. Next time crash_reporter is invoked, it will not block crashes.
func DisableCrashFiltering ¶
func DisableCrashFiltering() error
DisableCrashFiltering removes the filter_in file using the default path. Next time the crash reporter is invoked, it will not filter crashes.
func EnableCrashBlocking ¶
EnableCrashBlocking enables *negative* crash filtering -- crash_reporter will ignore all crashes matching the specified command-line filter.
func EnableCrashFiltering ¶
EnableCrashFiltering enables crash filtering with the specified command-line filter.
func EnableMockSending ¶
EnableMockSending tells crash_sender to not send crash reports to the server actually. If success is true, crash_sender always emulates successful uploads; otherwise it emulates failed uploads.
func GetCrashDir ¶
GetCrashDir gives the path to the crash directory for given username.
func GetCrashes ¶
GetCrashes returns the paths of all files in dirs generated in response to crashes. Nonexistent directories are skipped.
func GetDaemonStoreConsentDirs ¶
GetDaemonStoreConsentDirs gives the paths to the daemon store consent directories for the currently active sessions.
func GetDaemonStoreCrashDirs ¶
GetDaemonStoreCrashDirs gives the paths to the daemon store crash directories for the currently active sessions.
func IsBreakpadDmpFileForPID ¶
IsBreakpadDmpFileForPID scans the given breakpad/crashpad format .dmp file to see if it is the minidump file for the pid process ID. It returns true if the file is the minidump for that process ID.
This only works for the .dmp files created directly by breakpad or crashpad. It does not work for the .dmp files created by crash_reporter.
func ListSendRecords ¶
ListSendRecords returns a list of send record files under SendRecordDir. A send record file represents an upload event of a crash report. Its content is serialized crash.SendRecord protocol buffers message, and its timestamp indicates when the upload was performed.
func MarkTestDone ¶
MarkTestDone removes the file indicating which test is running.
func MarkTestInProgress ¶
MarkTestInProgress writes |name| to |testInProgressPath|, indicating to crash_reporter that the given test is in progress.
func MoveFilesToOut ¶
MoveFilesToOut moves all given files to s.OutDir(). Useful when further investigation of some files is needed to debug a test failure.
func RemoveAllFiles ¶
RemoveAllFiles removes all files in the values of map.
func RemovePerUserConsent ¶
RemovePerUserConsent deletes the per-user consent files so that we fall back to device policy state.
func RestartAnomalyDetector ¶
RestartAnomalyDetector restarts the anomaly detector and waits for it to open the journal. This is useful for tests that need to clear its cache of previously seen hashes and ensure that the anomaly detector runs for an artificially-induced crash.
func RestartAnomalyDetectorWithSendAll ¶
RestartAnomalyDetectorWithSendAll restarts anomaly detector, setting the "--testonly-send-all" flag to the value specified by sendAll.
func SetConsent ¶
SetConsent enables or disables metrics consent, based on the value of consent. Pre: cr must point to a logged-in chrome session.
func SetCrashTestInProgress ¶
func SetCrashTestInProgress() error
SetCrashTestInProgress creates a file to tell crash_reporter that a crash_reporter test is in progress.
func SetUpCrashTest ¶
SetUpCrashTest indicates that we are running a test that involves the crash reporting system (crash_reporter, crash_sender, or anomaly_detector). The test should "defer TearDownCrashTest(ctx)" after calling this. If developer image behavior is required for the test, call SetUpDevImageCrashTest instead.
func TearDownCrashTest ¶
TearDownCrashTest undoes the work of SetUpCrashTest. We assume here that the set of active sessions hasn't changed since SetUpCrashTest was called for the purpose of restoring the per-user-cryptohome crash directories.
func UnsetCrashTestInProgress ¶
func UnsetCrashTestInProgress() error
UnsetCrashTestInProgress tells crash_reporter that no crash_reporter test is in progress.
func WaitForCrashFiles ¶
func WaitForCrashFiles(ctx context.Context, dirs, regexes []string, opts ...WaitForCrashFilesOpt) (map[string][]string, error)
WaitForCrashFiles waits for each regex in regexes to match a file in dirs. The directory is not matched against the regex, and the regex must match the entire filename. (So /var/spool/crash/hello_world.20200331.1234.log will NOT match 'world\.\d{1,8}\.\d{1,8}\.log'.) One might use it by 1. Doing some operation that will create new files in that directory (e.g. inducing a crash). 2. Calling this method to wait for the expected files to appear. On success, WaitForCrashFiles returns a map from a regex to a list of files that matched that regex. If any regex was not matched, instead returns an error of type RegexesNotFound.
When it comes to deleting files, tests should:
- Remove matching files that they expect to generate
- Leave matching files they do not expect to generate
If there are more matches than expected and the test can't tell which are expected, it shouldn't delete any.
Types ¶
type ConsentType ¶
type ConsentType int
ConsentType is to be used for parameters to tests, to allow them to determine whether they should use mock consent or real consent.
const ( // MockConsent indicates that a test should use the mock consent system. MockConsent ConsentType = iota // RealConsent indicates that a test should use the real consent system. RealConsent // RealConsentPerUserOn indicates that a test should use the real // consent system, and also turn *on* per-user consent. RealConsentPerUserOn // RealConsentPerUserOff indicates that a test should use the real // consent system, and also turn *off* per-user consent. // Crashes should not be collected in this case. RealConsentPerUserOff )
type Option ¶
type Option func(p *setUpParams)
Option is a self-referential function can be used to configure crash tests. See https://commandcenter.blogspot.com.au/2014/01/self-referential-functions-and-design.html for details about this pattern.
func DevImage ¶
func DevImage() Option
DevImage prevents the test library from indicating to the DUT that a crash test is in progress, allowing the test to complete with standard developer image behavior.
func FilterCrashes ¶
FilterCrashes puts s into the filter-in file, so that the crash reporter only processes matching crashes.
func RebootingTest ¶
func RebootingTest() Option
RebootingTest indicates that this test will reboot the machine, and the crash reporting state files (e.g. crash-test-in-progress) should also be placed in rebootPersistDir (so that the persist-crash-test task moves them over to /run/crash_reporter on boot).
func WithConsent ¶
WithConsent indicates that the test should enable metrics consent. Pre: cr should be a logged-in chrome session.
func WithMockConsent ¶
func WithMockConsent() Option
WithMockConsent indicates that the test should touch the mock metrics consent file which causes crash_reporter and crash_sender to act as if they had consent to process crashes.
type RegexesNotFound ¶
type RegexesNotFound struct { // Missing lists all the regexs that weren't matched. Missing []string // Files lists all the files that were checked against the regexes. Files []string // PartialMatches gives all the regexes that were matched and the files that // matched them. PartialMatches map[string][]string // Dirs lists all directories where files are searched. Dirs []string }
RegexesNotFound is an error type, used to indicate that WaitForCrashFiles didn't find matches for all of the regexs.
func (RegexesNotFound) Error ¶
func (e RegexesNotFound) Error() string
Error returns a string describing the error. The classic Error function for the error interface.
type SendData ¶
type SendData struct { MetadataPath string PayloadPath string PayloadKind string Product string Version string Board string HWClass string Executable string ImageType string BootMode string }
SendData is the data of a single crash dump entry sent to the server by crash_sender.
func AddFakeKernelCrash ¶
AddFakeKernelCrash adds a fake kernel crash entry to crash.SystemCrashDir and returns a SendData expected to be reported by crash_sender when it processes the entry.
type SendResult ¶
SendResult is the result of crash_sender sending a single crash dump entry.
func RunSender ¶
func RunSender(ctx context.Context) ([]*SendResult, error)
RunSender runs crash_sender to process pending crash dumps and returns the send results by parsing its syslog output. crash_sender is run with --ignore_pause_file to ignore the pause file created by crash.SetUpCrashTest.
func RunSenderNoIgnorePauseFile ¶
func RunSenderNoIgnorePauseFile(ctx context.Context) ([]*SendResult, error)
RunSenderNoIgnorePauseFile is similar to RunSender but does not instruct crash_sender to ignore the pause file.
type WaitForCrashFilesOpt ¶
type WaitForCrashFilesOpt func(w *waitForCrashFilesOptions)
WaitForCrashFilesOpt is a self-referential function can be used to configure WaitForCrashFiles. See https://commandcenter.blogspot.com.au/2014/01/self-referential-functions-and-design.html for details about this pattern.
func OptionalRegexes ¶
func OptionalRegexes(optionalRegexes []string) WaitForCrashFilesOpt
OptionalRegexes instructs WaitForCrashFiles to look for files matching the given regexes and return those as normal in the return map. However, if the optional regexes are not matched, the polling loop will still exit and WaitForCrashFiles will not return an error.
func Timeout ¶
func Timeout(timeout time.Duration) WaitForCrashFilesOpt
Timeout returns a WaitForCrashFilesOpts which will set the timeout of WaitForCrashFiles to the indicated duration.