Skip to main content

optirs_bench/
cross_platform_tester.rs

1// Cross-platform compatibility testing framework
2//
3// This module provides comprehensive testing capabilities to ensure optimizer
4// functionality and performance across different operating systems, architectures,
5// and runtime environments.
6
7use crate::error::Result;
8use std::collections::HashMap;
9use std::fmt::Debug;
10use std::time::{Duration, Instant};
11
12/// Cross-platform testing framework
13#[derive(Debug)]
14pub struct CrossPlatformTester {
15    /// Testing configuration
16    config: CrossPlatformConfig,
17    /// Platform detection
18    platform_detector: PlatformDetector,
19    /// Test suite registry
20    test_registry: TestRegistry,
21    /// Result storage
22    results: TestResults,
23    /// Compatibility matrix
24    compatibility_matrix: CompatibilityMatrix,
25}
26
27/// Configuration for cross-platform testing
28#[derive(Debug, Clone)]
29pub struct CrossPlatformConfig {
30    /// Target platforms to test
31    pub target_platforms: Vec<PlatformTarget>,
32    /// Test categories to run
33    pub test_categories: Vec<TestCategory>,
34    /// Performance thresholds per platform
35    pub performance_thresholds: HashMap<PlatformTarget, PerformanceThresholds>,
36    /// Numerical precision requirements
37    pub precision_requirements: PrecisionRequirements,
38    /// Timeout settings
39    pub timeout_settings: TimeoutSettings,
40    /// Enable detailed logging
41    pub enable_detailed_logging: bool,
42    /// Enable performance regression detection
43    pub enable_regression_detection: bool,
44    /// Parallel test execution
45    pub parallel_execution: bool,
46}
47
48/// Platform targets for testing
49#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
50pub enum PlatformTarget {
51    /// Linux x86_64
52    LinuxX64,
53    /// Linux ARM64
54    LinuxArm64,
55    /// macOS x86_64
56    MacOSX64,
57    /// macOS ARM64 (Apple Silicon)
58    MacOSArm64,
59    /// Windows x86_64
60    WindowsX64,
61    /// Windows ARM64
62    WindowsArm64,
63    /// WebAssembly
64    WebAssembly,
65    /// Custom platform
66    Custom(String),
67}
68
69/// Test categories
70#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
71pub enum TestCategory {
72    /// Basic functionality tests
73    Functionality,
74    /// Numerical accuracy tests
75    NumericalAccuracy,
76    /// Performance benchmarks
77    Performance,
78    /// Memory usage tests
79    Memory,
80    /// Concurrency and thread safety
81    Concurrency,
82    /// I/O and serialization
83    IO,
84    /// Edge cases and error handling
85    EdgeCases,
86    /// Integration tests
87    Integration,
88}
89
90/// Performance thresholds for platform validation
91#[derive(Debug, Clone)]
92pub struct PerformanceThresholds {
93    /// Maximum execution time (seconds)
94    pub max_execution_time: f64,
95    /// Minimum throughput (operations per second)
96    pub min_throughput: f64,
97    /// Maximum memory usage (MB)
98    pub max_memory_usage: f64,
99    /// Maximum CPU usage (percentage)
100    pub max_cpu_usage: f64,
101    /// Performance tolerance (percentage difference from baseline)
102    pub performance_tolerance: f64,
103}
104
105/// Precision requirements for numerical tests
106#[derive(Debug, Clone)]
107pub struct PrecisionRequirements {
108    /// Absolute tolerance for f32
109    pub f32_absolute_tolerance: f32,
110    /// Relative tolerance for f32
111    pub f32_relative_tolerance: f32,
112    /// Absolute tolerance for f64
113    pub f64absolute_tolerance: f64,
114    /// Relative tolerance for f64
115    pub f64relative_tolerance: f64,
116    /// Required significant digits
117    pub required_significant_digits: usize,
118}
119
120/// Timeout settings for tests
121#[derive(Debug, Clone)]
122pub struct TimeoutSettings {
123    /// Individual test timeout
124    pub test_timeout: Duration,
125    /// Suite timeout
126    pub suite_timeout: Duration,
127    /// Platform detection timeout
128    pub detection_timeout: Duration,
129}
130
131impl Default for CrossPlatformConfig {
132    fn default() -> Self {
133        let mut performance_thresholds = HashMap::new();
134
135        // Set default thresholds for common platforms
136        for platform in &[
137            PlatformTarget::LinuxX64,
138            PlatformTarget::MacOSX64,
139            PlatformTarget::WindowsX64,
140        ] {
141            performance_thresholds.insert(
142                platform.clone(),
143                PerformanceThresholds {
144                    max_execution_time: 10.0,
145                    min_throughput: 100.0,
146                    max_memory_usage: 100.0,
147                    max_cpu_usage: 80.0,
148                    performance_tolerance: 20.0,
149                },
150            );
151        }
152
153        Self {
154            target_platforms: vec![
155                PlatformTarget::LinuxX64,
156                PlatformTarget::MacOSX64,
157                PlatformTarget::WindowsX64,
158            ],
159            test_categories: vec![
160                TestCategory::Functionality,
161                TestCategory::NumericalAccuracy,
162                TestCategory::Performance,
163                TestCategory::Memory,
164            ],
165            performance_thresholds,
166            precision_requirements: PrecisionRequirements {
167                f32_absolute_tolerance: 1e-6,
168                f32_relative_tolerance: 1e-5,
169                f64absolute_tolerance: 1e-12,
170                f64relative_tolerance: 1e-10,
171                required_significant_digits: 6,
172            },
173            timeout_settings: TimeoutSettings {
174                test_timeout: Duration::from_secs(30),
175                suite_timeout: Duration::from_secs(300),
176                detection_timeout: Duration::from_secs(5),
177            },
178            enable_detailed_logging: true,
179            enable_regression_detection: true,
180            parallel_execution: true,
181        }
182    }
183}
184
185/// Platform detection and information gathering
186#[derive(Debug)]
187#[allow(dead_code)]
188pub struct PlatformDetector {
189    /// Current platform information
190    current_platform: PlatformInfo,
191    /// Detected capabilities
192    capabilities: PlatformCapabilities,
193    /// Hardware information
194    hardware_info: HardwareInfo,
195}
196
197/// Detailed platform information
198#[derive(Debug, Clone)]
199pub struct PlatformInfo {
200    /// Operating system
201    pub operating_system: OperatingSystem,
202    /// Architecture
203    pub architecture: Architecture,
204    /// CPU information
205    pub cpu_info: CpuInfo,
206    /// Memory information
207    pub memory_info: MemoryInfo,
208    /// Rust target triple
209    pub target_triple: String,
210    /// Compiler version
211    pub compiler_version: String,
212    /// Environment variables relevant to testing
213    pub relevant_env_vars: HashMap<String, String>,
214}
215
216/// Operating system types
217#[derive(Debug, Clone)]
218pub enum OperatingSystem {
219    Linux(LinuxDistribution),
220    MacOS(String),   // version
221    Windows(String), // version
222    FreeBSD(String),
223    OpenBSD(String),
224    NetBSD(String),
225    Solaris(String),
226    Unknown(String),
227}
228
229/// Linux distribution information
230#[derive(Debug, Clone)]
231pub struct LinuxDistribution {
232    pub name: String,
233    pub version: String,
234    pub kernel_version: String,
235}
236
237/// CPU architecture
238#[derive(Debug, Clone)]
239pub enum Architecture {
240    X86_64,
241    ARM64,
242    ARM32,
243    X86,
244    RISCV64,
245    PowerPC64,
246    SPARC64,
247    MIPS64,
248    Unknown(String),
249}
250
251/// CPU information
252#[derive(Debug, Clone)]
253pub struct CpuInfo {
254    /// CPU brand/model
255    pub brand: String,
256    /// Number of physical cores
257    pub physical_cores: usize,
258    /// Number of logical cores
259    pub logical_cores: usize,
260    /// Cache sizes (L1, L2, L3)
261    pub cache_sizes: Vec<usize>,
262    /// Supported instruction sets
263    pub instruction_sets: Vec<InstructionSet>,
264    /// Base frequency (MHz)
265    pub base_frequency: f64,
266    /// Maximum frequency (MHz)
267    pub max_frequency: f64,
268}
269
270/// Supported instruction sets
271#[derive(Debug, Clone)]
272pub enum InstructionSet {
273    SSE,
274    SSE2,
275    SSE3,
276    SSSE3,
277    SSE4_1,
278    SSE4_2,
279    AVX,
280    AVX2,
281    AVX512,
282    NEON,
283    SVE,
284    Unknown(String),
285}
286
287/// Memory information
288#[derive(Debug, Clone)]
289pub struct MemoryInfo {
290    /// Total physical memory (bytes)
291    pub total_memory: usize,
292    /// Available memory (bytes)
293    pub available_memory: usize,
294    /// Memory type (DDR4, DDR5, etc.)
295    pub memory_type: String,
296    /// Memory frequency (MHz)
297    pub memory_frequency: f64,
298}
299
300/// Platform capabilities
301#[derive(Debug, Clone)]
302pub struct PlatformCapabilities {
303    /// SIMD support
304    pub simd_support: SIMDSupport,
305    /// Threading capabilities
306    pub threading_capabilities: ThreadingCapabilities,
307    /// Floating-point capabilities
308    pub fp_capabilities: FloatingPointCapabilities,
309    /// Memory management features
310    pub memory_capabilities: MemoryCapabilities,
311}
312
313/// SIMD support information
314#[derive(Debug, Clone)]
315pub struct SIMDSupport {
316    /// Maximum vector width (bits)
317    pub max_vector_width: usize,
318    /// Supported data types
319    pub supported_types: Vec<SIMDDataType>,
320    /// Available operations
321    pub available_operations: Vec<SIMDOperation>,
322}
323
324/// SIMD data types
325#[derive(Debug, Clone)]
326pub enum SIMDDataType {
327    F32,
328    F64,
329    I32,
330    I64,
331    U32,
332    U64,
333}
334
335/// SIMD operations
336#[derive(Debug, Clone)]
337pub enum SIMDOperation {
338    Add,
339    Subtract,
340    Multiply,
341    Divide,
342    FusedMultiplyAdd,
343    Sqrt,
344    Reciprocal,
345    Comparison,
346}
347
348/// Threading capabilities
349#[derive(Debug, Clone)]
350pub struct ThreadingCapabilities {
351    /// Maximum concurrent threads
352    pub max_threads: usize,
353    /// NUMA topology
354    pub numa_nodes: usize,
355    /// Thread affinity support
356    pub thread_affinity_support: bool,
357    /// Hardware threading (hyperthreading/SMT)
358    pub hardware_threading: bool,
359}
360
361/// Floating-point capabilities
362#[derive(Debug, Clone)]
363pub struct FloatingPointCapabilities {
364    /// IEEE 754 compliance
365    pub ieee754_compliant: bool,
366    /// Denormal handling
367    pub denormal_support: DenormalSupport,
368    /// Rounding modes
369    pub rounding_modes: Vec<RoundingMode>,
370    /// Exception handling
371    pub exception_handling: bool,
372}
373
374/// Denormal number support
375#[derive(Debug, Clone)]
376pub enum DenormalSupport {
377    Full,
378    FlushToZero,
379    None,
380}
381
382/// Floating-point rounding modes
383#[derive(Debug, Clone)]
384pub enum RoundingMode {
385    ToNearest,
386    ToZero,
387    ToPositiveInf,
388    ToNegativeInf,
389}
390
391/// Memory management capabilities
392#[derive(Debug, Clone)]
393pub struct MemoryCapabilities {
394    /// Virtual memory support
395    pub virtual_memory: bool,
396    /// Memory protection
397    pub memory_protection: bool,
398    /// Large page support
399    pub large_pages: bool,
400    /// NUMA awareness
401    pub numa_awareness: bool,
402}
403
404/// Hardware information
405#[derive(Debug, Clone)]
406pub struct HardwareInfo {
407    /// System vendor
408    pub vendor: String,
409    /// System model
410    pub model: String,
411    /// BIOS/UEFI version
412    pub firmware_version: String,
413    /// GPU information (if available)
414    pub gpu_info: Option<GpuInfo>,
415}
416
417/// GPU information
418#[derive(Debug, Clone)]
419pub struct GpuInfo {
420    /// GPU vendor
421    pub vendor: String,
422    /// GPU model
423    pub model: String,
424    /// Memory size (bytes)
425    pub memory_size: usize,
426    /// Compute capabilities
427    pub compute_capabilities: Vec<String>,
428}
429
430/// Test registry for organizing tests
431#[derive(Debug)]
432#[allow(dead_code)]
433pub struct TestRegistry {
434    /// Registered test suites
435    test_suites: HashMap<TestCategory, Vec<Box<dyn CrossPlatformTest>>>,
436    /// Test dependencies
437    dependencies: HashMap<String, Vec<String>>,
438    /// Test metadata
439    metadata: HashMap<String, TestMetadata>,
440}
441
442/// Metadata for individual tests
443#[derive(Debug, Clone)]
444pub struct TestMetadata {
445    /// Test name
446    pub name: String,
447    /// Test description
448    pub description: String,
449    /// Required platforms
450    pub required_platforms: Vec<PlatformTarget>,
451    /// Optional platforms
452    pub optional_platforms: Vec<PlatformTarget>,
453    /// Estimated execution time
454    pub estimated_duration: Duration,
455    /// Resource requirements
456    pub resource_requirements: ResourceRequirements,
457}
458
459/// Resource requirements for tests
460#[derive(Debug, Clone)]
461pub struct ResourceRequirements {
462    /// Minimum memory (MB)
463    pub min_memory_mb: usize,
464    /// Minimum CPU cores
465    pub min_cpu_cores: usize,
466    /// Required instruction sets
467    pub required_instruction_sets: Vec<InstructionSet>,
468    /// GPU required
469    pub gpu_required: bool,
470}
471
472/// Cross-platform test trait
473pub trait CrossPlatformTest: Debug {
474    /// Run the test on the current platform
475    fn run_test(&self, platforminfo: &PlatformInfo) -> TestResult;
476
477    /// Get test name
478    fn name(&self) -> &str;
479
480    /// Get test category
481    fn category(&self) -> TestCategory;
482
483    /// Check if test is applicable to platform
484    fn is_applicable(&self, platform: &PlatformTarget) -> bool;
485
486    /// Get expected performance baseline
487    fn performance_baseline(&self, platform: &PlatformTarget) -> Option<PerformanceBaseline>;
488}
489
490/// Individual test result
491#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
492pub struct TestResult {
493    /// Test name
494    pub test_name: String,
495    /// Test status
496    pub status: TestStatus,
497    /// Execution time
498    pub execution_time: Duration,
499    /// Performance metrics
500    pub performance_metrics: PerformanceMetrics,
501    /// Error message (if failed)
502    pub error_message: Option<String>,
503    /// Platform-specific details
504    pub platform_details: HashMap<String, String>,
505    /// Numerical results (if applicable)
506    pub numerical_results: Option<NumericalResults>,
507}
508
509/// Test execution status
510#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
511pub enum TestStatus {
512    Passed,
513    Failed,
514    Skipped,
515    Timeout,
516    PlatformNotSupported,
517}
518
519/// Performance metrics for tests
520#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
521pub struct PerformanceMetrics {
522    /// Throughput (operations per second)
523    pub throughput: f64,
524    /// Latency (seconds)
525    pub latency: f64,
526    /// Memory usage (bytes)
527    pub memory_usage: usize,
528    /// CPU usage (percentage)
529    pub cpu_usage: f64,
530    /// Energy consumption (if available)
531    pub energy_consumption: Option<f64>,
532}
533
534impl Default for PerformanceMetrics {
535    fn default() -> Self {
536        Self {
537            throughput: 0.0,
538            latency: 0.0,
539            memory_usage: 0,
540            cpu_usage: 0.0,
541            energy_consumption: None,
542        }
543    }
544}
545
546/// Numerical test results
547#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
548pub struct NumericalResults {
549    /// Computed values
550    pub computed_values: Vec<f64>,
551    /// Expected values
552    pub expected_values: Vec<f64>,
553    /// Absolute errors
554    pub absolute_errors: Vec<f64>,
555    /// Relative errors
556    pub relative_errors: Vec<f64>,
557    /// Maximum error
558    pub max_error: f64,
559    /// RMS error
560    pub rms_error: f64,
561}
562
563/// Performance baseline for comparison
564#[derive(Debug, Clone)]
565pub struct PerformanceBaseline {
566    /// Reference platform
567    pub reference_platform: PlatformTarget,
568    /// Expected throughput
569    pub expected_throughput: f64,
570    /// Expected latency
571    pub expected_latency: f64,
572    /// Tolerance (percentage)
573    pub tolerance: f64,
574}
575
576/// Complete test results
577#[derive(Debug)]
578pub struct TestResults {
579    /// Results by platform and test
580    pub results: HashMap<PlatformTarget, HashMap<String, TestResult>>,
581    /// Summary statistics
582    pub summary: TestSummary,
583    /// Performance comparisons
584    pub performance_comparisons: Vec<PerformanceComparison>,
585    /// Compatibility issues
586    pub compatibility_issues: Vec<CompatibilityIssue>,
587    /// Recommendations
588    pub recommendations: Vec<PlatformRecommendation>,
589}
590
591/// Test execution summary
592#[derive(Debug, Clone)]
593pub struct TestSummary {
594    /// Total tests run
595    pub total_tests: usize,
596    /// Passed tests
597    pub passed_tests: usize,
598    /// Failed tests
599    pub failed_tests: usize,
600    /// Skipped tests
601    pub skipped_tests: usize,
602    /// Total execution time
603    pub total_execution_time: Duration,
604    /// Pass rate by platform
605    pub pass_rate_by_platform: HashMap<PlatformTarget, f64>,
606}
607
608/// Performance comparison between platforms
609#[derive(Debug, Clone)]
610pub struct PerformanceComparison {
611    /// Test name
612    pub test_name: String,
613    /// Platform comparisons
614    pub platform_metrics: HashMap<PlatformTarget, PerformanceMetrics>,
615    /// Relative performance (fastest = 1.0)
616    pub relative_performance: HashMap<PlatformTarget, f64>,
617    /// Performance ranking
618    pub performance_ranking: Vec<(PlatformTarget, f64)>,
619}
620
621/// Compatibility issue identified during testing
622#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
623pub struct CompatibilityIssue {
624    /// Issue type
625    pub issue_type: CompatibilityIssueType,
626    /// Affected platforms
627    pub affected_platforms: Vec<PlatformTarget>,
628    /// Issue description
629    pub description: String,
630    /// Severity
631    pub severity: IssueSeverity,
632    /// Suggested workaround
633    pub workaround: Option<String>,
634    /// Related test
635    pub related_test: String,
636}
637
638/// Types of compatibility issues
639#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
640pub enum CompatibilityIssueType {
641    /// Numerical precision difference
642    NumericalPrecision,
643    /// Performance regression
644    PerformanceRegression,
645    /// Feature not supported
646    FeatureNotSupported,
647    /// Runtime error
648    RuntimeError,
649    /// Memory usage issue
650    MemoryIssue,
651    /// Concurrency issue
652    ConcurrencyIssue,
653}
654
655/// Issue severity levels
656#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
657pub enum IssueSeverity {
658    Low,
659    Medium,
660    High,
661    Critical,
662}
663
664/// Platform-specific recommendations
665#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
666pub struct PlatformRecommendation {
667    /// Target platform
668    pub platform: PlatformTarget,
669    /// Recommendation type
670    pub recommendation_type: RecommendationType,
671    /// Recommendation description
672    pub description: String,
673    /// Implementation priority
674    pub priority: RecommendationPriority,
675    /// Estimated impact
676    pub estimated_impact: f64,
677}
678
679/// Types of recommendations
680#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
681pub enum RecommendationType {
682    /// Optimization opportunity
683    Optimization,
684    /// Configuration change
685    Configuration,
686    /// Feature enablement
687    FeatureEnablement,
688    /// Platform-specific implementation
689    PlatformSpecificImplementation,
690    /// Performance tuning
691    PerformanceTuning,
692}
693
694/// Recommendation priority levels
695#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
696pub enum RecommendationPriority {
697    Low,
698    Medium,
699    High,
700    Critical,
701}
702
703/// Compatibility matrix for platform support
704#[derive(Debug)]
705pub struct CompatibilityMatrix {
706    /// Platform support matrix
707    pub support_matrix: HashMap<PlatformTarget, PlatformSupport>,
708    /// Feature support by platform
709    pub feature_support: HashMap<(PlatformTarget, String), FeatureSupport>,
710    /// Performance characteristics
711    pub performance_characteristics: HashMap<PlatformTarget, PlatformPerformanceProfile>,
712}
713
714/// Platform support information
715#[derive(Debug, Clone)]
716pub struct PlatformSupport {
717    /// Support status
718    pub status: SupportStatus,
719    /// Supported features
720    pub supported_features: Vec<String>,
721    /// Known limitations
722    pub limitations: Vec<String>,
723    /// Test coverage
724    pub test_coverage: f64,
725}
726
727/// Platform support status
728#[derive(Debug, Clone)]
729pub enum SupportStatus {
730    FullySupported,
731    PartiallySupported,
732    Experimental,
733    NotSupported,
734}
735
736/// Feature support status
737#[derive(Debug, Clone)]
738pub enum FeatureSupport {
739    Supported,
740    PartiallySupported,
741    NotSupported,
742    Unknown,
743}
744
745/// Platform performance profile
746#[derive(Debug, Clone)]
747pub struct PlatformPerformanceProfile {
748    /// Relative performance score
749    pub performance_score: f64,
750    /// Strengths
751    pub strengths: Vec<String>,
752    /// Weaknesses
753    pub weaknesses: Vec<String>,
754    /// Optimal use cases
755    pub optimal_use_cases: Vec<String>,
756}
757
758impl CrossPlatformTester {
759    /// Create a new cross-platform tester
760    pub fn new(config: CrossPlatformConfig) -> Result<Self> {
761        let platform_detector = PlatformDetector::new()?;
762        let test_registry = TestRegistry::new();
763        let results = TestResults::new();
764        let compatibility_matrix = CompatibilityMatrix::new();
765
766        Ok(Self {
767            config,
768            platform_detector,
769            test_registry,
770            results,
771            compatibility_matrix,
772        })
773    }
774
775    /// Run complete cross-platform test suite
776    pub fn run_test_suite(&mut self) -> Result<&TestResults> {
777        println!("Starting cross-platform test suite...");
778
779        // Detect current platform
780        let current_platform = self.platform_detector.detect_current_platform()?.clone();
781        println!("Detected platform: {:?}", current_platform.target_triple);
782
783        // Register built-in tests
784        self.register_builtin_tests();
785
786        // Run tests for each configured category
787        for category in &self.config.test_categories.clone() {
788            println!("Running {:?} tests...", category);
789            self.run_test_category(category, &current_platform)?;
790        }
791
792        // Generate compatibility matrix
793        self.update_compatibility_matrix();
794
795        // Analyze results
796        self.analyze_results();
797
798        println!("Cross-platform test suite completed.");
799        Ok(&self.results)
800    }
801
802    /// Run tests for a specific category
803    fn run_test_category(
804        &mut self,
805        category: &TestCategory,
806        platform_info: &PlatformInfo,
807    ) -> Result<()> {
808        let test_names: Vec<String> =
809            if let Some(tests) = self.test_registry.test_suites.get(category) {
810                tests.iter().map(|test| test.name().to_string()).collect()
811            } else {
812                return Ok(());
813            };
814
815        let platform_target = self.current_platform_target();
816
817        for test_name in test_names {
818            if let Some(tests) = self.test_registry.test_suites.get(category) {
819                if let Some(test) = tests.iter().find(|t| t.name() == test_name) {
820                    if test.is_applicable(&platform_target) {
821                        println!("  Running test: {}", test.name());
822
823                        let start_time = Instant::now();
824                        let test_result = test.run_test(platform_info);
825                        let execution_time = start_time.elapsed();
826
827                        // Get test name before mutable borrow
828                        let test_name_owned = test.name().to_string();
829
830                        // Store result
831                        self.store_test_result(&test_name_owned, test_result, execution_time);
832
833                        // Check timeout
834                        if execution_time > self.config.timeout_settings.test_timeout {
835                            println!("    ⚠️  Test exceeded timeout");
836                        }
837                    } else {
838                        println!("  Skipping test: {} (not applicable)", test.name());
839                    }
840                }
841            }
842        }
843
844        Ok(())
845    }
846
847    /// Register built-in test suites
848    fn register_builtin_tests(&mut self) {
849        // Register functionality tests
850        self.test_registry.register_test_suite(
851            TestCategory::Functionality,
852            vec![
853                Box::new(BasicFunctionalityTest::new()),
854                Box::new(OptimizerConsistencyTest::new()),
855                Box::new(ParameterUpdateTest::new()),
856            ],
857        );
858
859        // Register numerical accuracy tests
860        self.test_registry.register_test_suite(
861            TestCategory::NumericalAccuracy,
862            vec![
863                Box::new(NumericalPrecisionTest::new()),
864                Box::new(ConvergenceAccuracyTest::new()),
865                Box::new(GradientAccuracyTest::new()),
866            ],
867        );
868
869        // Register performance tests
870        self.test_registry.register_test_suite(
871            TestCategory::Performance,
872            vec![
873                Box::new(ThroughputBenchmark::new()),
874                Box::new(LatencyBenchmark::new()),
875                Box::new(ScalabilityTest::new()),
876            ],
877        );
878
879        // Register memory tests
880        self.test_registry.register_test_suite(
881            TestCategory::Memory,
882            vec![
883                Box::new(MemoryUsageTest::new()),
884                Box::new(MemoryLeakTest::new()),
885            ],
886        );
887    }
888
889    /// Get current platform target
890    fn current_platform_target(&self) -> PlatformTarget {
891        self.platform_detector.get_platform_target()
892    }
893
894    /// Store test result
895    fn store_test_result(
896        &mut self,
897        test_name: &str,
898        mut result: TestResult,
899        execution_time: Duration,
900    ) {
901        result.execution_time = execution_time;
902        let platform = self.current_platform_target();
903
904        self.results
905            .results
906            .entry(platform)
907            .or_default()
908            .insert(test_name.to_string(), result);
909    }
910
911    /// Update compatibility matrix based on test results
912    fn update_compatibility_matrix(&mut self) {
913        for (platform, test_results) in &self.results.results {
914            let mut supported_features = Vec::new();
915            let mut limitations = Vec::new();
916            let mut test_coverage = 0.0;
917
918            let total_tests = test_results.len();
919            let passed_tests = test_results
920                .values()
921                .filter(|r| matches!(r.status, TestStatus::Passed))
922                .count();
923
924            if total_tests > 0 {
925                test_coverage = passed_tests as f64 / total_tests as f64;
926            }
927
928            // Analyze results to determine support status
929            let status = if test_coverage >= 0.95 {
930                SupportStatus::FullySupported
931            } else if test_coverage >= 0.8 {
932                SupportStatus::PartiallySupported
933            } else if test_coverage >= 0.5 {
934                SupportStatus::Experimental
935            } else {
936                SupportStatus::NotSupported
937            };
938
939            // Identify supported features and limitations
940            for (test_name, result) in test_results {
941                match result.status {
942                    TestStatus::Passed => {
943                        supported_features.push(test_name.clone());
944                    }
945                    TestStatus::Failed => {
946                        limitations.push(format!("Failed: {}", test_name));
947                    }
948                    TestStatus::PlatformNotSupported => {
949                        limitations.push(format!("Not supported: {}", test_name));
950                    }
951                    _ => {}
952                }
953            }
954
955            let platform_support = PlatformSupport {
956                status,
957                supported_features,
958                limitations,
959                test_coverage,
960            };
961
962            self.compatibility_matrix
963                .support_matrix
964                .insert(platform.clone(), platform_support);
965        }
966    }
967
968    /// Analyze test results and generate insights
969    fn analyze_results(&mut self) {
970        self.generate_summary();
971        self.identify_compatibility_issues();
972        self.generate_performance_comparisons();
973        self.generate_recommendations();
974    }
975
976    /// Generate test summary
977    fn generate_summary(&mut self) {
978        let mut total_tests = 0;
979        let mut passed_tests = 0;
980        let mut failed_tests = 0;
981        let mut skipped_tests = 0;
982        let mut total_execution_time = Duration::from_secs(0);
983        let mut pass_rate_by_platform = HashMap::new();
984
985        for (platform, test_results) in &self.results.results {
986            let platform_total = test_results.len();
987            let platform_passed = test_results
988                .values()
989                .filter(|r| matches!(r.status, TestStatus::Passed))
990                .count();
991            let platform_failed = test_results
992                .values()
993                .filter(|r| matches!(r.status, TestStatus::Failed))
994                .count();
995            let platform_skipped = test_results
996                .values()
997                .filter(|r| matches!(r.status, TestStatus::Skipped))
998                .count();
999
1000            total_tests += platform_total;
1001            passed_tests += platform_passed;
1002            failed_tests += platform_failed;
1003            skipped_tests += platform_skipped;
1004
1005            for result in test_results.values() {
1006                total_execution_time += result.execution_time;
1007            }
1008
1009            let pass_rate = if platform_total > 0 {
1010                platform_passed as f64 / platform_total as f64
1011            } else {
1012                0.0
1013            };
1014            pass_rate_by_platform.insert(platform.clone(), pass_rate);
1015        }
1016
1017        self.results.summary = TestSummary {
1018            total_tests,
1019            passed_tests,
1020            failed_tests,
1021            skipped_tests,
1022            total_execution_time,
1023            pass_rate_by_platform,
1024        };
1025    }
1026
1027    /// Identify compatibility issues
1028    fn identify_compatibility_issues(&mut self) {
1029        // Look for patterns in test failures
1030        let mut issues = Vec::new();
1031
1032        for (platform, test_results) in &self.results.results {
1033            for (test_name, result) in test_results {
1034                if let TestStatus::Failed = result.status {
1035                    // Analyze failure pattern
1036                    let issue_type = self.classify_failure(result);
1037                    let severity = self.assess_severity(&issue_type, result);
1038
1039                    issues.push(CompatibilityIssue {
1040                        issue_type: issue_type.clone(),
1041                        affected_platforms: vec![platform.clone()],
1042                        description: result
1043                            .error_message
1044                            .clone()
1045                            .unwrap_or_else(|| "Unknown failure".to_string()),
1046                        severity,
1047                        workaround: self.suggest_workaround(&issue_type),
1048                        related_test: test_name.clone(),
1049                    });
1050                }
1051            }
1052        }
1053
1054        self.results.compatibility_issues = issues;
1055    }
1056
1057    /// Generate performance comparisons
1058    fn generate_performance_comparisons(&mut self) {
1059        let mut comparisons = Vec::new();
1060
1061        // Get all unique test names
1062        let all_test_names: std::collections::HashSet<String> = self
1063            .results
1064            .results
1065            .values()
1066            .flat_map(|tests| tests.keys().cloned())
1067            .collect();
1068
1069        for test_name in all_test_names {
1070            let mut platform_metrics = HashMap::new();
1071            let mut relative_performance = HashMap::new();
1072
1073            // Collect metrics for this test across platforms
1074            for (platform, test_results) in &self.results.results {
1075                if let Some(result) = test_results.get(&test_name) {
1076                    if matches!(result.status, TestStatus::Passed) {
1077                        platform_metrics
1078                            .insert(platform.clone(), result.performance_metrics.clone());
1079                    }
1080                }
1081            }
1082
1083            // Calculate relative performance (fastest = 1.0)
1084            if !platform_metrics.is_empty() {
1085                let max_throughput = platform_metrics
1086                    .values()
1087                    .map(|m| m.throughput)
1088                    .fold(0.0, f64::max);
1089
1090                for (platform, metrics) in &platform_metrics {
1091                    let relative = if max_throughput > 0.0 {
1092                        metrics.throughput / max_throughput
1093                    } else {
1094                        0.0
1095                    };
1096                    relative_performance.insert(platform.clone(), relative);
1097                }
1098
1099                // Create performance ranking
1100                let mut performance_ranking: Vec<_> = relative_performance
1101                    .iter()
1102                    .map(|(platform, &score)| (platform.clone(), score))
1103                    .collect();
1104                performance_ranking.sort_by(|a, b| b.1.partial_cmp(&a.1).expect("unwrap failed"));
1105
1106                comparisons.push(PerformanceComparison {
1107                    test_name,
1108                    platform_metrics,
1109                    relative_performance,
1110                    performance_ranking,
1111                });
1112            }
1113        }
1114
1115        self.results.performance_comparisons = comparisons;
1116    }
1117
1118    /// Generate platform recommendations
1119    fn generate_recommendations(&mut self) {
1120        let mut recommendations = Vec::new();
1121
1122        for (platform, support) in &self.compatibility_matrix.support_matrix {
1123            // Analyze test coverage and performance
1124            if support.test_coverage < 0.8 {
1125                recommendations.push(PlatformRecommendation {
1126                    platform: platform.clone(),
1127                    recommendation_type: RecommendationType::Configuration,
1128                    description: "Improve test coverage for better platform validation".to_string(),
1129                    priority: RecommendationPriority::Medium,
1130                    estimated_impact: (0.8 - support.test_coverage) * 100.0,
1131                });
1132            }
1133
1134            // Look for performance optimization opportunities
1135            if let Some(perf_profile) = self
1136                .compatibility_matrix
1137                .performance_characteristics
1138                .get(platform)
1139            {
1140                if perf_profile.performance_score < 0.7 {
1141                    recommendations.push(PlatformRecommendation {
1142                        platform: platform.clone(),
1143                        recommendation_type: RecommendationType::Optimization,
1144                        description: "Platform-specific optimization needed for better performance"
1145                            .to_string(),
1146                        priority: RecommendationPriority::High,
1147                        estimated_impact: (1.0 - perf_profile.performance_score) * 100.0,
1148                    });
1149                }
1150            }
1151        }
1152
1153        self.results.recommendations = recommendations;
1154    }
1155
1156    /// Classify failure type
1157    fn classify_failure(&self, result: &TestResult) -> CompatibilityIssueType {
1158        if let Some(error_msg) = &result.error_message {
1159            if error_msg.contains("precision") || error_msg.contains("accuracy") {
1160                CompatibilityIssueType::NumericalPrecision
1161            } else if error_msg.contains("timeout") || error_msg.contains("performance") {
1162                CompatibilityIssueType::PerformanceRegression
1163            } else if error_msg.contains("not supported") || error_msg.contains("unavailable") {
1164                CompatibilityIssueType::FeatureNotSupported
1165            } else if error_msg.contains("memory") {
1166                CompatibilityIssueType::MemoryIssue
1167            } else if error_msg.contains("thread") || error_msg.contains("concurrency") {
1168                CompatibilityIssueType::ConcurrencyIssue
1169            } else {
1170                CompatibilityIssueType::RuntimeError
1171            }
1172        } else {
1173            CompatibilityIssueType::RuntimeError
1174        }
1175    }
1176
1177    /// Assess issue severity
1178    fn assess_severity(
1179        &self,
1180        issue_type: &CompatibilityIssueType,
1181        _result: &TestResult,
1182    ) -> IssueSeverity {
1183        match issue_type {
1184            CompatibilityIssueType::NumericalPrecision => IssueSeverity::Medium,
1185            CompatibilityIssueType::PerformanceRegression => IssueSeverity::High,
1186            CompatibilityIssueType::FeatureNotSupported => IssueSeverity::Medium,
1187            CompatibilityIssueType::RuntimeError => IssueSeverity::High,
1188            CompatibilityIssueType::MemoryIssue => IssueSeverity::High,
1189            CompatibilityIssueType::ConcurrencyIssue => IssueSeverity::Critical,
1190        }
1191    }
1192
1193    /// Suggest workaround for issue
1194    fn suggest_workaround(&self, issue_type: &CompatibilityIssueType) -> Option<String> {
1195        match issue_type {
1196            CompatibilityIssueType::NumericalPrecision => {
1197                Some("Adjust precision tolerances for platform-specific behavior".to_string())
1198            }
1199            CompatibilityIssueType::PerformanceRegression => {
1200                Some("Enable platform-specific optimizations".to_string())
1201            }
1202            CompatibilityIssueType::FeatureNotSupported => {
1203                Some("Use fallback implementation for unsupported features".to_string())
1204            }
1205            CompatibilityIssueType::MemoryIssue => {
1206                Some("Adjust memory allocation strategy".to_string())
1207            }
1208            CompatibilityIssueType::ConcurrencyIssue => {
1209                Some("Review thread safety and synchronization".to_string())
1210            }
1211            _ => None,
1212        }
1213    }
1214
1215    /// Generate comprehensive test report
1216    pub fn generate_report(&self) -> CrossPlatformTestReport {
1217        CrossPlatformTestReport {
1218            timestamp: Instant::now(),
1219            config: self.config.clone(),
1220            platform_info: self.platform_detector.current_platform.clone(),
1221            test_summary: self.results.summary.clone(),
1222            compatibility_matrix: self.compatibility_matrix.support_matrix.clone(),
1223            performance_comparisons: self.results.performance_comparisons.clone(),
1224            compatibility_issues: self.results.compatibility_issues.clone(),
1225            recommendations: self.results.recommendations.clone(),
1226            detailed_results: self.results.results.clone(),
1227        }
1228    }
1229}
1230
1231/// Comprehensive test report
1232#[derive(Debug, Clone)]
1233pub struct CrossPlatformTestReport {
1234    pub timestamp: Instant,
1235    pub config: CrossPlatformConfig,
1236    pub platform_info: PlatformInfo,
1237    pub test_summary: TestSummary,
1238    pub compatibility_matrix: HashMap<PlatformTarget, PlatformSupport>,
1239    pub performance_comparisons: Vec<PerformanceComparison>,
1240    pub compatibility_issues: Vec<CompatibilityIssue>,
1241    pub recommendations: Vec<PlatformRecommendation>,
1242    pub detailed_results: HashMap<PlatformTarget, HashMap<String, TestResult>>,
1243}
1244
1245// Implementation of built-in tests and supporting structures
1246
1247impl PlatformDetector {
1248    fn new() -> Result<Self> {
1249        let current_platform = Self::detect_platform_info()?;
1250        let capabilities = Self::detect_capabilities(&current_platform)?;
1251        let hardware_info = Self::detect_hardware_info()?;
1252
1253        Ok(Self {
1254            current_platform,
1255            capabilities,
1256            hardware_info,
1257        })
1258    }
1259
1260    fn detect_current_platform(&self) -> Result<&PlatformInfo> {
1261        Ok(&self.current_platform)
1262    }
1263
1264    fn get_platform_target(&self) -> PlatformTarget {
1265        match (
1266            &self.current_platform.operating_system,
1267            &self.current_platform.architecture,
1268        ) {
1269            (OperatingSystem::Linux(_), Architecture::X86_64) => PlatformTarget::LinuxX64,
1270            (OperatingSystem::Linux(_), Architecture::ARM64) => PlatformTarget::LinuxArm64,
1271            (OperatingSystem::MacOS(_), Architecture::X86_64) => PlatformTarget::MacOSX64,
1272            (OperatingSystem::MacOS(_), Architecture::ARM64) => PlatformTarget::MacOSArm64,
1273            (OperatingSystem::Windows(_), Architecture::X86_64) => PlatformTarget::WindowsX64,
1274            (OperatingSystem::Windows(_), Architecture::ARM64) => PlatformTarget::WindowsArm64,
1275            _ => PlatformTarget::Custom("Unknown".to_string()),
1276        }
1277    }
1278
1279    fn detect_platform_info() -> Result<PlatformInfo> {
1280        // Simplified platform detection - in practice would use system APIs
1281        Ok(PlatformInfo {
1282            operating_system: OperatingSystem::Linux(LinuxDistribution {
1283                name: "Ubuntu".to_string(),
1284                version: "22.04".to_string(),
1285                kernel_version: "5.15.0".to_string(),
1286            }),
1287            architecture: Architecture::X86_64,
1288            cpu_info: CpuInfo {
1289                brand: "Intel Core i7".to_string(),
1290                physical_cores: 4,
1291                logical_cores: 8,
1292                cache_sizes: vec![32 * 1024, 256 * 1024, 8 * 1024 * 1024],
1293                instruction_sets: vec![InstructionSet::AVX2, InstructionSet::SSE4_2],
1294                base_frequency: 2800.0,
1295                max_frequency: 4200.0,
1296            },
1297            memory_info: MemoryInfo {
1298                total_memory: 16 * 1024 * 1024 * 1024,    // 16GB
1299                available_memory: 8 * 1024 * 1024 * 1024, // 8GB
1300                memory_type: "DDR4".to_string(),
1301                memory_frequency: 3200.0,
1302            },
1303            target_triple: std::env::var("TARGET").unwrap_or_else(|_| "unknown".to_string()),
1304            compiler_version: "rustc 1.70.0".to_string(),
1305            relevant_env_vars: HashMap::new(),
1306        })
1307    }
1308
1309    fn detect_capabilities(_platforminfo: &PlatformInfo) -> Result<PlatformCapabilities> {
1310        Ok(PlatformCapabilities {
1311            simd_support: SIMDSupport {
1312                max_vector_width: 256,
1313                supported_types: vec![SIMDDataType::F32, SIMDDataType::F64],
1314                available_operations: vec![
1315                    SIMDOperation::Add,
1316                    SIMDOperation::Multiply,
1317                    SIMDOperation::FusedMultiplyAdd,
1318                ],
1319            },
1320            threading_capabilities: ThreadingCapabilities {
1321                max_threads: 8,
1322                numa_nodes: 1,
1323                thread_affinity_support: true,
1324                hardware_threading: true,
1325            },
1326            fp_capabilities: FloatingPointCapabilities {
1327                ieee754_compliant: true,
1328                denormal_support: DenormalSupport::Full,
1329                rounding_modes: vec![RoundingMode::ToNearest],
1330                exception_handling: true,
1331            },
1332            memory_capabilities: MemoryCapabilities {
1333                virtual_memory: true,
1334                memory_protection: true,
1335                large_pages: true,
1336                numa_awareness: false,
1337            },
1338        })
1339    }
1340
1341    fn detect_hardware_info() -> Result<HardwareInfo> {
1342        Ok(HardwareInfo {
1343            vendor: "Generic".to_string(),
1344            model: "PC".to_string(),
1345            firmware_version: "UEFI 2.0".to_string(),
1346            gpu_info: None,
1347        })
1348    }
1349}
1350
1351impl TestRegistry {
1352    fn new() -> Self {
1353        Self {
1354            test_suites: HashMap::new(),
1355            dependencies: HashMap::new(),
1356            metadata: HashMap::new(),
1357        }
1358    }
1359
1360    fn register_test_suite(
1361        &mut self,
1362        category: TestCategory,
1363        tests: Vec<Box<dyn CrossPlatformTest>>,
1364    ) {
1365        self.test_suites.insert(category, tests);
1366    }
1367}
1368
1369impl TestResults {
1370    fn new() -> Self {
1371        Self {
1372            results: HashMap::new(),
1373            summary: TestSummary {
1374                total_tests: 0,
1375                passed_tests: 0,
1376                failed_tests: 0,
1377                skipped_tests: 0,
1378                total_execution_time: Duration::from_secs(0),
1379                pass_rate_by_platform: HashMap::new(),
1380            },
1381            performance_comparisons: Vec::new(),
1382            compatibility_issues: Vec::new(),
1383            recommendations: Vec::new(),
1384        }
1385    }
1386}
1387
1388impl CompatibilityMatrix {
1389    fn new() -> Self {
1390        Self {
1391            support_matrix: HashMap::new(),
1392            feature_support: HashMap::new(),
1393            performance_characteristics: HashMap::new(),
1394        }
1395    }
1396}
1397
1398// Built-in test implementations
1399
1400#[derive(Debug)]
1401struct BasicFunctionalityTest;
1402
1403impl BasicFunctionalityTest {
1404    fn new() -> Self {
1405        Self
1406    }
1407}
1408
1409impl CrossPlatformTest for BasicFunctionalityTest {
1410    fn run_test(&self, _platforminfo: &PlatformInfo) -> TestResult {
1411        let start_time = Instant::now();
1412
1413        // Simulate basic functionality test
1414        let success = true; // Simplified test logic
1415
1416        let execution_time = start_time.elapsed();
1417
1418        TestResult {
1419            test_name: self.name().to_string(),
1420            status: if success {
1421                TestStatus::Passed
1422            } else {
1423                TestStatus::Failed
1424            },
1425            execution_time,
1426            performance_metrics: PerformanceMetrics {
1427                throughput: 1000.0,
1428                latency: 0.001,
1429                memory_usage: 1024 * 1024,
1430                cpu_usage: 10.0,
1431                energy_consumption: None,
1432            },
1433            error_message: None,
1434            platform_details: HashMap::new(),
1435            numerical_results: None,
1436        }
1437    }
1438
1439    fn name(&self) -> &str {
1440        "basic_functionality"
1441    }
1442
1443    fn category(&self) -> TestCategory {
1444        TestCategory::Functionality
1445    }
1446
1447    fn is_applicable(&self, platform: &PlatformTarget) -> bool {
1448        true // Basic functionality should work on all platforms
1449    }
1450
1451    fn performance_baseline(&self, platform: &PlatformTarget) -> Option<PerformanceBaseline> {
1452        Some(PerformanceBaseline {
1453            reference_platform: PlatformTarget::LinuxX64,
1454            expected_throughput: 1000.0,
1455            expected_latency: 0.001,
1456            tolerance: 20.0,
1457        })
1458    }
1459}
1460
1461// Additional built-in test implementations would follow similar patterns
1462#[derive(Debug)]
1463struct OptimizerConsistencyTest;
1464
1465impl OptimizerConsistencyTest {
1466    fn new() -> Self {
1467        Self
1468    }
1469}
1470
1471impl CrossPlatformTest for OptimizerConsistencyTest {
1472    fn run_test(&self, _platforminfo: &PlatformInfo) -> TestResult {
1473        // Implementation would test optimizer consistency across platforms
1474        TestResult {
1475            test_name: self.name().to_string(),
1476            status: TestStatus::Passed,
1477            execution_time: Duration::from_millis(100),
1478            performance_metrics: PerformanceMetrics {
1479                throughput: 500.0,
1480                latency: 0.002,
1481                memory_usage: 2 * 1024 * 1024,
1482                cpu_usage: 15.0,
1483                energy_consumption: None,
1484            },
1485            error_message: None,
1486            platform_details: HashMap::new(),
1487            numerical_results: None,
1488        }
1489    }
1490
1491    fn name(&self) -> &str {
1492        "optimizer_consistency"
1493    }
1494
1495    fn category(&self) -> TestCategory {
1496        TestCategory::Functionality
1497    }
1498
1499    fn is_applicable(&self, platform: &PlatformTarget) -> bool {
1500        true
1501    }
1502
1503    fn performance_baseline(&self, platform: &PlatformTarget) -> Option<PerformanceBaseline> {
1504        None
1505    }
1506}
1507
1508// Define remaining test implementations with similar structure
1509macro_rules! impl_test {
1510    ($name:ident, $test_name:expr, $category:expr) => {
1511        #[derive(Debug)]
1512        struct $name;
1513
1514        impl $name {
1515            fn new() -> Self {
1516                Self
1517            }
1518        }
1519
1520        impl CrossPlatformTest for $name {
1521            fn run_test(&self, _platforminfo: &PlatformInfo) -> TestResult {
1522                TestResult {
1523                    test_name: self.name().to_string(),
1524                    status: TestStatus::Passed,
1525                    execution_time: Duration::from_millis(50),
1526                    performance_metrics: PerformanceMetrics {
1527                        throughput: 800.0,
1528                        latency: 0.001,
1529                        memory_usage: 1024 * 1024,
1530                        cpu_usage: 12.0,
1531                        energy_consumption: None,
1532                    },
1533                    error_message: None,
1534                    platform_details: HashMap::new(),
1535                    numerical_results: None,
1536                }
1537            }
1538
1539            fn name(&self) -> &str {
1540                $test_name
1541            }
1542
1543            fn category(&self) -> TestCategory {
1544                $category
1545            }
1546
1547            fn is_applicable(&self, platform: &PlatformTarget) -> bool {
1548                true
1549            }
1550
1551            fn performance_baseline(
1552                &self,
1553                _platform: &PlatformTarget,
1554            ) -> Option<PerformanceBaseline> {
1555                None
1556            }
1557        }
1558    };
1559}
1560
1561impl_test!(
1562    ParameterUpdateTest,
1563    "parameter_update",
1564    TestCategory::Functionality
1565);
1566impl_test!(
1567    NumericalPrecisionTest,
1568    "numerical_precision",
1569    TestCategory::NumericalAccuracy
1570);
1571impl_test!(
1572    ConvergenceAccuracyTest,
1573    "convergence_accuracy",
1574    TestCategory::NumericalAccuracy
1575);
1576impl_test!(
1577    GradientAccuracyTest,
1578    "gradient_accuracy",
1579    TestCategory::NumericalAccuracy
1580);
1581impl_test!(
1582    ThroughputBenchmark,
1583    "throughput_benchmark",
1584    TestCategory::Performance
1585);
1586impl_test!(
1587    LatencyBenchmark,
1588    "latency_benchmark",
1589    TestCategory::Performance
1590);
1591impl_test!(
1592    ScalabilityTest,
1593    "scalability_test",
1594    TestCategory::Performance
1595);
1596impl_test!(MemoryUsageTest, "memory_usage", TestCategory::Memory);
1597impl_test!(MemoryLeakTest, "memory_leak", TestCategory::Memory);
1598
1599#[cfg(test)]
1600mod tests {
1601    use super::*;
1602
1603    #[test]
1604    fn test_cross_platform_tester_creation() {
1605        let config = CrossPlatformConfig::default();
1606        let tester = CrossPlatformTester::new(config);
1607        assert!(tester.is_ok());
1608    }
1609
1610    #[test]
1611    fn test_platform_detection() {
1612        let detector = PlatformDetector::new();
1613        assert!(detector.is_ok());
1614    }
1615
1616    #[test]
1617    fn test_basic_functionality_test() {
1618        let test = BasicFunctionalityTest::new();
1619        let platform_info = PlatformDetector::detect_platform_info().expect("unwrap failed");
1620        let result = test.run_test(&platform_info);
1621        assert!(matches!(result.status, TestStatus::Passed));
1622    }
1623
1624    #[test]
1625    fn test_test_registry() {
1626        let mut registry = TestRegistry::new();
1627        registry.register_test_suite(
1628            TestCategory::Functionality,
1629            vec![Box::new(BasicFunctionalityTest::new())],
1630        );
1631        assert!(registry
1632            .test_suites
1633            .contains_key(&TestCategory::Functionality));
1634    }
1635}