style(audio): fix formatting and add missing newlines

- Fix indentation and alignment in performance tests
- Add missing newlines at end of files
- Clean up error message formatting for consistency
This commit is contained in:
Alex P 2025-08-27 20:54:50 +00:00
parent 9dda569523
commit e3e7b898b5
4 changed files with 34 additions and 34 deletions

View File

@ -320,4 +320,4 @@ func (als *AudioLoggerStandards) WithSubComponent(subComponent string) *AudioLog
logger: als.logger.With().Str("sub_component", subComponent).Logger(),
component: als.component + "." + subComponent,
}
}
}

View File

@ -45,7 +45,7 @@ func TestPerformanceCriticalPaths(t *testing.T) {
// This is the most critical path that must not interfere with KVM
func testAudioFrameProcessingLatency(t *testing.T) {
const (
frameCount = 1000
frameCount = 1000
maxLatencyPerFrame = 100 * time.Microsecond // Very strict requirement
)
@ -61,7 +61,7 @@ func testAudioFrameProcessingLatency(t *testing.T) {
// Simulate the critical path: validation + metrics update
err := ValidateAudioFrameFast(frameData)
require.NoError(t, err)
// Record frame received (atomic operation)
RecordFrameReceived(len(frameData))
}
@ -69,22 +69,22 @@ func testAudioFrameProcessingLatency(t *testing.T) {
avgLatencyPerFrame := elapsed / frameCount
t.Logf("Average frame processing latency: %v", avgLatencyPerFrame)
// Ensure frame processing is fast enough to not interfere with KVM
assert.Less(t, avgLatencyPerFrame, maxLatencyPerFrame,
"Frame processing latency %v exceeds maximum %v - may interfere with KVM",
assert.Less(t, avgLatencyPerFrame, maxLatencyPerFrame,
"Frame processing latency %v exceeds maximum %v - may interfere with KVM",
avgLatencyPerFrame, maxLatencyPerFrame)
// Ensure total processing time is reasonable
maxTotalTime := 50 * time.Millisecond
assert.Less(t, elapsed, maxTotalTime,
assert.Less(t, elapsed, maxTotalTime,
"Total processing time %v exceeds maximum %v", elapsed, maxTotalTime)
}
// testMetricsUpdateOverhead tests the overhead of metrics updates
func testMetricsUpdateOverhead(t *testing.T) {
const iterations = 10000
// Test RecordFrameReceived performance
start := time.Now()
for i := 0; i < iterations; i++ {
@ -202,7 +202,7 @@ func testMemoryAllocationPatterns(t *testing.T) {
// testConcurrentAccessPerformance tests performance under concurrent access
func testConcurrentAccessPerformance(t *testing.T) {
const (
numGoroutines = 10
numGoroutines = 10
operationsPerGoroutine = 1000
)
@ -215,7 +215,7 @@ func testConcurrentAccessPerformance(t *testing.T) {
go func() {
defer wg.Done()
frameData := make([]byte, 1920)
for j := 0; j < operationsPerGoroutine; j++ {
// Simulate concurrent audio processing
_ = ValidateAudioFrameFast(frameData)
@ -232,7 +232,7 @@ func testConcurrentAccessPerformance(t *testing.T) {
totalOperations := numGoroutines * operationsPerGoroutine * 4 // 4 operations per iteration
avgLatency := elapsed / time.Duration(totalOperations)
t.Logf("Concurrent access: %d operations in %v (avg: %v per operation)",
t.Logf("Concurrent access: %d operations in %v (avg: %v per operation)",
totalOperations, elapsed, avgLatency)
// Concurrent access should not significantly degrade performance
@ -306,7 +306,7 @@ func TestRegressionDetection(t *testing.T) {
start := time.Now()
for i := 0; i < 100; i++ {
_ = ValidateAudioFrameFast(frameData)
RecordFrameReceived(len(frameData))
RecordFrameReceived(len(frameData))
}
frameProcessingTime := time.Since(start) / 100
@ -335,13 +335,13 @@ func TestRegressionDetection(t *testing.T) {
// - ARM Cortex-A7 @ 1GHz single core
// - 256MB DDR3L RAM
// - Must not interfere with primary KVM functionality
assert.Less(t, frameProcessingTime, baselines["frame_processing"],
assert.Less(t, frameProcessingTime, baselines["frame_processing"],
"Frame processing regression: %v > %v", frameProcessingTime, baselines["frame_processing"])
assert.Less(t, metricsUpdateTime, 100*time.Microsecond,
assert.Less(t, metricsUpdateTime, 100*time.Microsecond,
"Metrics update regression: %v > 100μs", metricsUpdateTime)
assert.Less(t, configAccessTime, 10*time.Microsecond,
assert.Less(t, configAccessTime, 10*time.Microsecond,
"Config access regression: %v > 10μs", configAccessTime)
assert.Less(t, validationTime, 10*time.Microsecond,
assert.Less(t, validationTime, 10*time.Microsecond,
"Validation regression: %v > 10μs", validationTime)
t.Logf("Performance results:")
@ -384,6 +384,6 @@ func TestMemoryLeakDetection(t *testing.T) {
t.Logf("Memory growth after 10,000 operations: %d bytes", memoryGrowth)
// Memory growth should be minimal (less than 1MB)
assert.Less(t, memoryGrowth, int64(1024*1024),
assert.Less(t, memoryGrowth, int64(1024*1024),
"Excessive memory growth detected: %d bytes", memoryGrowth)
}
}

View File

@ -29,7 +29,7 @@ var (
func ValidateAudioQuality(quality AudioQuality) error {
// Validate enum range
if quality < AudioQualityLow || quality > AudioQualityUltra {
return fmt.Errorf("%w: quality value %d outside valid range [%d, %d]",
return fmt.Errorf("%w: quality value %d outside valid range [%d, %d]",
ErrInvalidAudioQuality, int(quality), int(AudioQualityLow), int(AudioQualityUltra))
}
return nil
@ -43,21 +43,21 @@ func ValidateFrameData(data []byte) error {
if len(data) == 0 {
return fmt.Errorf("%w: frame data is empty", ErrInvalidFrameData)
}
config := GetConfig()
// Check minimum frame size
if len(data) < config.MinFrameSize {
return fmt.Errorf("%w: frame size %d below minimum %d",
return fmt.Errorf("%w: frame size %d below minimum %d",
ErrInvalidFrameSize, len(data), config.MinFrameSize)
}
// Check maximum frame size
if len(data) > config.MaxAudioFrameSize {
return fmt.Errorf("%w: frame size %d exceeds maximum %d",
return fmt.Errorf("%w: frame size %d exceeds maximum %d",
ErrInvalidFrameSize, len(data), config.MaxAudioFrameSize)
}
// Validate frame alignment for audio samples (must be even for 16-bit samples)
if len(data)%2 != 0 {
return fmt.Errorf("%w: frame size %d not aligned for 16-bit samples",
return fmt.Errorf("%w: frame size %d not aligned for 16-bit samples",
ErrInvalidFrameSize, len(data))
}
return nil
@ -89,7 +89,7 @@ func ValidateBufferSize(size int) error {
// Use SocketMaxBuffer as the upper limit for general buffer validation
// This allows for socket buffers while still preventing extremely large allocations
if size > config.SocketMaxBuffer {
return fmt.Errorf("%w: buffer size %d exceeds maximum %d",
return fmt.Errorf("%w: buffer size %d exceeds maximum %d",
ErrInvalidBufferSize, size, config.SocketMaxBuffer)
}
return nil
@ -99,7 +99,7 @@ func ValidateBufferSize(size int) error {
func ValidateThreadPriority(priority int) error {
const minPriority, maxPriority = -20, 19
if priority < minPriority || priority > maxPriority {
return fmt.Errorf("%w: priority %d outside valid range [%d, %d]",
return fmt.Errorf("%w: priority %d outside valid range [%d, %d]",
ErrInvalidPriority, priority, minPriority, maxPriority)
}
return nil
@ -113,11 +113,11 @@ func ValidateLatency(latency time.Duration) error {
config := GetConfig()
minLatency := time.Millisecond // Minimum reasonable latency
if latency > 0 && latency < minLatency {
return fmt.Errorf("%w: latency %v below minimum %v",
return fmt.Errorf("%w: latency %v below minimum %v",
ErrInvalidLatency, latency, minLatency)
}
if latency > config.MaxLatency {
return fmt.Errorf("%w: latency %v exceeds maximum %v",
return fmt.Errorf("%w: latency %v exceeds maximum %v",
ErrInvalidLatency, latency, config.MaxLatency)
}
return nil
@ -233,7 +233,7 @@ func ValidateSampleRate(sampleRate int) error {
return nil
}
}
return fmt.Errorf("%w: sample rate %d not in supported rates %v",
return fmt.Errorf("%w: sample rate %d not in supported rates %v",
ErrInvalidSampleRate, sampleRate, validRates)
}
@ -244,7 +244,7 @@ func ValidateChannelCount(channels int) error {
}
config := GetConfig()
if channels > config.MaxChannels {
return fmt.Errorf("%w: channel count %d exceeds maximum %d",
return fmt.Errorf("%w: channel count %d exceeds maximum %d",
ErrInvalidChannels, channels, config.MaxChannels)
}
return nil
@ -259,11 +259,11 @@ func ValidateBitrate(bitrate int) error {
// Convert kbps to bps for comparison with config limits
bitrateInBps := bitrate * 1000
if bitrateInBps < config.MinOpusBitrate {
return fmt.Errorf("%w: bitrate %d kbps (%d bps) below minimum %d bps",
return fmt.Errorf("%w: bitrate %d kbps (%d bps) below minimum %d bps",
ErrInvalidBitrate, bitrate, bitrateInBps, config.MinOpusBitrate)
}
if bitrateInBps > config.MaxOpusBitrate {
return fmt.Errorf("%w: bitrate %d kbps (%d bps) exceeds maximum %d bps",
return fmt.Errorf("%w: bitrate %d kbps (%d bps) exceeds maximum %d bps",
ErrInvalidBitrate, bitrate, bitrateInBps, config.MaxOpusBitrate)
}
return nil
@ -276,11 +276,11 @@ func ValidateFrameDuration(duration time.Duration) error {
}
config := GetConfig()
if duration < config.MinFrameDuration {
return fmt.Errorf("%w: frame duration %v below minimum %v",
return fmt.Errorf("%w: frame duration %v below minimum %v",
ErrInvalidFrameDuration, duration, config.MinFrameDuration)
}
if duration > config.MaxFrameDuration {
return fmt.Errorf("%w: frame duration %v exceeds maximum %v",
return fmt.Errorf("%w: frame duration %v exceeds maximum %v",
ErrInvalidFrameDuration, duration, config.MaxFrameDuration)
}
return nil

View File

@ -553,4 +553,4 @@ func TestValidationPerformance(t *testing.T) {
// Audio processing must not interfere with primary KVM functionality
assert.Less(t, perIteration, 200*time.Microsecond, "Validation should not impact KVM performance")
t.Logf("Validation performance: %v per iteration", perIteration)
}
}