// Package cpu provides CPU stress testing with multiple algorithms and chaos modes. package cpu import ( "runtime" "time" ) // types.go defines the configuration types and mode constants for CPU stress testing. type Mode string const ( ModePrime Mode = "prime" ModeMatrix Mode = "matrix" ModeHash Mode = "hash" ModeBitwise Mode = "bitwise" ModeFloat Mode = "float" ModeRecurse Mode = "recurse" ModeCompress Mode = "compress" ModeEncrypt Mode = "encrypt" ModeSort Mode = "sort" ModeBusy Mode = "busy" ) var allModes = []Mode{ ModePrime, ModeMatrix, ModeHash, ModeBitwise, ModeFloat, ModeRecurse, ModeCompress, ModeEncrypt, ModeSort, ModeBusy, } type Config struct { Mode Mode Workers int Duration time.Duration ChaosEnabled bool ChaosInterval time.Duration IntensityMin int IntensityMax int MinCPUs int MaxCPUs int } func (c *Config) normalize() { if c.MinCPUs <= 0 { c.MinCPUs = 1 } if c.MaxCPUs <= 0 { c.MaxCPUs = runtime.NumCPU() } if c.MinCPUs > runtime.NumCPU() { c.MinCPUs = runtime.NumCPU() } if c.MaxCPUs > runtime.NumCPU() { c.MaxCPUs = runtime.NumCPU() } if c.MinCPUs > c.MaxCPUs { c.MinCPUs, c.MaxCPUs = c.MaxCPUs, c.MinCPUs } }