1use crate::error::{CoreError, CoreResult, ErrorContext};
8use crate::validation::production::{
9 ValidationContext, ValidationError, ValidationResult, ValidationSeverity,
10};
11use std::collections::HashMap;
12
13#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct PlatformInfo {
16 pub os_family: OsFamily,
18 pub arch: CpuArchitecture,
20 pub simd_support: SimdSupport,
22 pub endianness: Endianness,
24 pub path_separator: char,
26 pub max_path_length: usize,
28 pub page_size: usize,
30 pub memory_mapping_support: bool,
32 pub fp_behavior: FloatingPointBehavior,
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum OsFamily {
39 Windows,
40 Unix, Wasm, Unknown,
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub enum CpuArchitecture {
48 X86_64,
49 AArch64, X86, ARM, RISCV64,
53 PowerPC64,
54 Wasm32, Wasm64, Other(u32),
57}
58
59#[derive(Debug, Clone, PartialEq, Eq)]
61pub struct SimdSupport {
62 pub sse: Option<SseLevel>,
64 pub avx: Option<AvxLevel>,
66 pub neon: bool,
68 pub sve: bool,
70 pub vector_width: usize,
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
76pub enum SseLevel {
77 Sse,
78 Sse2,
79 Sse3,
80 Ssse3,
81 Sse41,
82 Sse42,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
87pub enum AvxLevel {
88 Avx,
89 Avx2,
90 Avx512f,
91 Avx512bw,
92 Avx512dq,
93}
94
95#[derive(Debug, Clone, Copy, PartialEq, Eq)]
97pub enum Endianness {
98 Little,
99 Big,
100}
101
102#[derive(Debug, Clone, PartialEq, Eq)]
104pub struct FloatingPointBehavior {
105 pub denormals_supported: bool,
107 pub rounding_mode: RoundingMode,
109 pub nan_propagation: bool,
111 pub infinity_supported: bool,
113}
114
115#[derive(Debug, Clone, Copy, PartialEq, Eq)]
117pub enum RoundingMode {
118 ToNearest,
119 TowardZero,
120 TowardPositiveInfinity,
121 TowardNegativeInfinity,
122}
123
124pub struct CrossPlatformValidator {
126 platform_info: PlatformInfo,
128 #[allow(dead_code)]
130 context: ValidationContext,
131 cache: HashMap<String, ValidationResult>,
133}
134
135impl CrossPlatformValidator {
136 pub fn new() -> CoreResult<Self> {
138 let platform_info = Self::detect_platform_info()?;
139 Ok(Self {
140 platform_info,
141 context: ValidationContext::default(),
142 cache: HashMap::new(),
143 })
144 }
145
146 pub fn with_context(context: ValidationContext) -> CoreResult<Self> {
148 let platform_info = Self::detect_platform_info()?;
149 Ok(Self {
150 platform_info,
151 context,
152 cache: HashMap::new(),
153 })
154 }
155
156 fn detect_platform_info() -> CoreResult<PlatformInfo> {
158 let os_family = if cfg!(target_family = "wasm") {
159 OsFamily::Wasm
160 } else if cfg!(windows) {
161 OsFamily::Windows
162 } else if cfg!(unix) {
163 OsFamily::Unix
164 } else {
165 OsFamily::Unknown
166 };
167
168 let arch = if cfg!(target_arch = "wasm32") {
169 CpuArchitecture::Wasm32
170 } else if cfg!(target_arch = "wasm64") {
171 CpuArchitecture::Wasm64
172 } else if cfg!(target_arch = "x86_64") {
173 CpuArchitecture::X86_64
174 } else if cfg!(target_arch = "aarch64") {
175 CpuArchitecture::AArch64
176 } else if cfg!(target_arch = "x86") {
177 CpuArchitecture::X86
178 } else if cfg!(target_arch = "arm") {
179 CpuArchitecture::ARM
180 } else if cfg!(target_arch = "riscv64") {
181 CpuArchitecture::RISCV64
182 } else if cfg!(target_arch = "powerpc64") {
183 CpuArchitecture::PowerPC64
184 } else {
185 CpuArchitecture::Other(0)
186 };
187
188 let endianness = if cfg!(target_endian = "little") {
189 Endianness::Little
190 } else {
191 Endianness::Big
192 };
193
194 let path_separator = if cfg!(windows) {
195 '\\'
196 } else {
197 '/' };
199
200 let max_path_length = if cfg!(target_family = "wasm") {
201 1024 } else if cfg!(windows) {
203 260 } else {
205 4096 };
207
208 let simd_support = Self::detect_simd_support(arch);
210
211 let page_size = Self::detect_page_size();
213
214 let memory_mapping_support = !cfg!(target_family = "wasm");
215
216 let fp_behavior = FloatingPointBehavior {
217 denormals_supported: true, rounding_mode: RoundingMode::ToNearest,
219 nan_propagation: true,
220 infinity_supported: true,
221 };
222
223 Ok(PlatformInfo {
224 os_family,
225 arch,
226 simd_support,
227 endianness,
228 path_separator,
229 max_path_length,
230 page_size,
231 memory_mapping_support,
232 fp_behavior,
233 })
234 }
235
236 fn detect_simd_support(arch: CpuArchitecture) -> SimdSupport {
238 match arch {
239 CpuArchitecture::X86_64 | CpuArchitecture::X86 => {
240 SimdSupport {
243 sse: Some(SseLevel::Sse2), avx: if cfg!(target_feature = "avx2") {
245 Some(AvxLevel::Avx2)
246 } else if cfg!(target_feature = "avx") {
247 Some(AvxLevel::Avx)
248 } else {
249 None
250 },
251 neon: false,
252 sve: false,
253 vector_width: if cfg!(target_feature = "avx512f") {
254 512
255 } else if cfg!(target_feature = "avx2") {
256 256
257 } else {
258 128
259 },
260 }
261 }
262 CpuArchitecture::AArch64 | CpuArchitecture::ARM => {
263 SimdSupport {
264 sse: None,
265 avx: None,
266 neon: true, sve: false, vector_width: 128, }
270 }
271 CpuArchitecture::Wasm32 | CpuArchitecture::Wasm64 => {
272 SimdSupport {
273 sse: None,
274 avx: None,
275 neon: false,
276 sve: false,
277 vector_width: if cfg!(target_feature = "simd128") {
278 128 } else {
280 64 },
282 }
283 }
284 _ => {
285 SimdSupport {
286 sse: None,
287 avx: None,
288 neon: false,
289 sve: false,
290 vector_width: 64, }
292 }
293 }
294 }
295
296 fn detect_page_size() -> usize {
298 #[cfg(unix)]
299 {
300 4096
303 }
304 #[cfg(windows)]
305 {
306 4096
309 }
310 #[cfg(not(any(unix, windows)))]
311 {
312 4096 }
314 }
315
316 pub fn validate_file_path(&mut self, path: &str) -> ValidationResult {
318 let mut result = ValidationResult {
319 is_valid: true,
320 errors: Vec::new(),
321 warnings: Vec::new(),
322 metrics: crate::validation::production::ValidationMetrics::default(),
323 };
324
325 if path.len() > self.platform_info.max_path_length {
327 result.is_valid = false;
328 result.errors.push(ValidationError {
329 code: "PATH_TOO_LONG".to_string(),
330 message: format!(
331 "Path length {} exceeds platform maximum of {}",
332 path.len(),
333 self.platform_info.max_path_length
334 ),
335 field: Some(path.to_string()),
336 suggestion: Some("Use shorter path or enable long path support ".to_string()),
337 severity: ValidationSeverity::Error,
338 });
339 }
340
341 match self.platform_info.os_family {
343 OsFamily::Windows => self.validate_windows_path(path, &mut result),
344 OsFamily::Unix => self.validate_unix_path(path, &mut result),
345 OsFamily::Wasm => self.validate_wasm_path(path, &mut result),
346 OsFamily::Unknown => {
347 result
348 .warnings
349 .push("Unknown platform - basic validation only ".to_string());
350 }
351 }
352
353 if path.contains('\0') {
355 result.is_valid = false;
356 result.errors.push(ValidationError {
357 code: "NULL_BYTE_IN_PATH".to_string(),
358 message: "Path contains null byte ".to_string(),
359 field: Some(path.to_string()),
360 suggestion: Some("Remove null bytes from path ".to_string()),
361 severity: ValidationSeverity::Critical,
362 });
363 }
364
365 result
366 }
367
368 fn validate_windows_path(&self, path: &str, result: &mut ValidationResult) {
370 let invalid_chars = r#"<>:"|?*"#.chars().collect::<Vec<_>>();
372 for &ch in &invalid_chars {
373 if path.contains(ch) {
374 result.is_valid = false;
375 result.errors.push(ValidationError {
376 code: "INVALID_WINDOWS_CHAR".to_string(),
377 message: format!("Character '{ch}' is invalid in Windows paths"),
378 field: Some(path.to_string()),
379 suggestion: Some("Remove or replace invalid characters".to_string()),
380 severity: ValidationSeverity::Error,
381 });
382 break;
383 }
384 }
385
386 let reserved_names = [
388 "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7",
389 "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
390 ];
391
392 let path_upper = path.to_uppercase();
393 for &reserved in &reserved_names {
394 if path_upper == reserved || path_upper.starts_with(&format!("{reserved}.")) {
395 result.is_valid = false;
396 result.errors.push(ValidationError {
397 code: "RESERVED_WINDOWS_NAME".to_string(),
398 message: format!("'{reserved}' is a reserved name on Windows"),
399 field: Some(path.to_string()),
400 suggestion: Some("Use a different filename".to_string()),
401 severity: ValidationSeverity::Error,
402 });
403 break;
404 }
405 }
406
407 if path.ends_with(' ') || path.ends_with('.') {
409 result.is_valid = false;
410 result.errors.push(ValidationError {
411 code: "INVALID_WINDOWS_ENDING".to_string(),
412 message: "Windows paths cannot end with spaces or periods".to_string(),
413 field: Some(path.to_string()),
414 suggestion: Some("Remove trailing spaces or periods".to_string()),
415 severity: ValidationSeverity::Error,
416 });
417 }
418 }
419
420 fn validate_unix_path(&self, path: &str, result: &mut ValidationResult) {
422 if path.contains("//") {
426 result
427 .warnings
428 .push("Path contains double slashes".to_string());
429 }
430
431 let system_prefixes = ["/dev/", "/proc/", "/sys/"];
433 for &prefix in &system_prefixes {
434 if path.starts_with(prefix) {
435 result.warnings.push(format!(
436 "Path accesses system directory '{prefix}' - ensure this is intended"
437 ));
438 break;
439 }
440 }
441
442 for component in path.split('/') {
445 if component.len() > 255 {
446 result
447 .warnings
448 .push("Path component exceeds 255 characters".to_string());
449 break;
450 }
451 }
452 }
453
454 fn validate_wasm_path(&self, path: &str, result: &mut ValidationResult) {
456 if path.starts_with("../") || path.contains("/../") {
460 result.is_valid = false;
461 result.errors.push(ValidationError {
462 code: "WASM_SANDBOX_VIOLATION".to_string(),
463 message: "WebAssembly paths cannot escape sandbox with '..'".to_string(),
464 field: Some(path.to_string()),
465 suggestion: Some("Use paths relative to the WASM module".to_string()),
466 severity: ValidationSeverity::Critical,
467 });
468 }
469
470 if path.starts_with('/') {
472 result.warnings.push(
473 "Absolute paths may not be accessible in WebAssembly environment".to_string(),
474 );
475 }
476
477 let special_prefixes = ["file://", "http://", "https://", "ftp://"];
479 for &prefix in &special_prefixes {
480 if path.starts_with(prefix) {
481 result.warnings.push(format!(
482 "Protocol '{prefix}' may not be accessible in WebAssembly environment"
483 ));
484 break;
485 }
486 }
487
488 for component in path.split('/') {
490 if component.len() > 128 {
491 result.warnings.push(
492 "Very long path components may not be supported in WebAssembly".to_string(),
493 );
494 break;
495 }
496 }
497
498 if path.starts_with("/tmp/") || path.starts_with("/temp/") {
500 result.warnings.push(
501 "Temporary directories may have limited persistence in WebAssembly".to_string(),
502 );
503 }
504
505 result
507 .warnings
508 .push("WebAssembly environment has limited file system access".to_string());
509 }
510
511 pub fn validate_numeric_cross_platform<T>(
513 &mut self,
514 value: T,
515 fieldname: &str,
516 ) -> ValidationResult
517 where
518 T: PartialOrd + Copy + std::fmt::Debug + std::fmt::Display + 'static,
519 {
520 let mut result = ValidationResult {
521 is_valid: true,
522 errors: Vec::new(),
523 warnings: Vec::new(),
524 metrics: crate::validation::production::ValidationMetrics::default(),
525 };
526
527 if std::any::TypeId::of::<T>() == std::any::TypeId::of::<f32>()
529 || std::any::TypeId::of::<T>() == std::any::TypeId::of::<f64>()
530 {
531 self.validate_floating_point_value(&value, fieldname, &mut result);
532 }
533
534 if self.platform_info.endianness == Endianness::Big {
536 result.warnings.push(
537 "Running on big-endian platform - verify binary data compatibility".to_string(),
538 );
539 }
540
541 result
542 }
543
544 fn validate_floating_point_value<T>(
546 &self,
547 value: &T,
548 fieldname: &str,
549 result: &mut ValidationResult,
550 ) where
551 T: std::fmt::Debug + std::fmt::Display,
552 {
553 let value_str = format!("{value:?}");
556
557 if value_str.contains("inf") && !self.platform_info.fp_behavior.infinity_supported {
558 result.is_valid = false;
559 result.errors.push(ValidationError {
560 code: "INFINITY_NOT_SUPPORTED".to_string(),
561 message: format!("Infinity values not supported on this platform for {fieldname}"),
562 field: Some(fieldname.to_string()),
563 suggestion: Some("Use finite values only".to_string()),
564 severity: ValidationSeverity::Error,
565 });
566 }
567
568 if value_str.contains("nan") && !self.platform_info.fp_behavior.nan_propagation {
569 result.warnings.push(format!(
570 "NaN value in {fieldname} - platform may not handle NaN propagation correctly"
571 ));
572 }
573 }
574
575 pub fn validate_simd_operation(
577 &mut self,
578 operation: &str,
579 _data_size: usize,
580 vector_size: usize,
581 ) -> ValidationResult {
582 let mut result = ValidationResult {
583 is_valid: true,
584 errors: Vec::new(),
585 warnings: Vec::new(),
586 metrics: crate::validation::production::ValidationMetrics::default(),
587 };
588
589 if vector_size > self.platform_info.simd_support.vector_width {
591 result.is_valid = false;
592 result.errors.push(ValidationError {
593 code: "SIMD_VECTOR_TOO_LARGE".to_string(),
594 message: format!(
595 "Requested vector size {} exceeds platform maximum of {}",
596 vector_size, self.platform_info.simd_support.vector_width
597 ),
598 field: Some(vector_size.to_string()),
599 suggestion: Some(format!(
600 "Use vector size <= {}",
601 self.platform_info.simd_support.vector_width
602 )),
603 severity: ValidationSeverity::Error,
604 });
605 }
606
607 if operation.contains("avx") && self.platform_info.simd_support.avx.is_none() {
609 result.is_valid = false;
610 result.errors.push(ValidationError {
611 code: "AVX_NOT_SUPPORTED".to_string(),
612 message: "AVX instructions not supported on this platform".to_string(),
613 field: Some(operation.to_string()),
614 suggestion: Some("Use SSE fallback or check platform capabilities".to_string()),
615 severity: ValidationSeverity::Error,
616 });
617 }
618
619 if operation.contains("neon") && !self.platform_info.simd_support.neon {
620 result.is_valid = false;
621 result.errors.push(ValidationError {
622 code: "NEON_NOT_SUPPORTED".to_string(),
623 message: "NEON instructions not supported on this platform".to_string(),
624 field: Some(operation.to_string()),
625 suggestion: Some("Use scalar fallback".to_string()),
626 severity: ValidationSeverity::Error,
627 });
628 }
629
630 result
631 }
632
633 pub fn validate_memory_allocation(&mut self, size: usize, purpose: &str) -> ValidationResult {
635 let mut result = ValidationResult {
636 is_valid: true,
637 errors: Vec::new(),
638 warnings: Vec::new(),
639 metrics: crate::validation::production::ValidationMetrics::default(),
640 };
641
642 if size > self.platform_info.page_size && !size.is_multiple_of(self.platform_info.page_size)
644 {
645 result.warnings.push(format!(
646 "Allocation size {} is not page-aligned (page size: {})",
647 size, self.platform_info.page_size
648 ));
649 }
650
651 let max_alloc_size = match self.platform_info.arch {
653 CpuArchitecture::X86 => 2usize.pow(31), CpuArchitecture::ARM => 2usize.pow(31),
655 CpuArchitecture::Wasm32 => 2usize.pow(31), CpuArchitecture::Wasm64 => {
657 4usize.pow(30) }
660 _ => usize::MAX, };
662
663 if size > max_alloc_size {
664 result.is_valid = false;
665 result.errors.push(ValidationError {
666 code: "ALLOCATION_TOO_LARGE".to_string(),
667 message: format!(
668 "Allocation size {size} exceeds platform maximum of {max_alloc_size} for {purpose}"
669 ),
670 field: Some(size.to_string()),
671 suggestion: Some("Reduce allocation size or use memory mapping".to_string()),
672 severity: ValidationSeverity::Error,
673 });
674 }
675
676 if size > 100_000_000 && !self.platform_info.memory_mapping_support {
678 result.warnings.push(format!(
679 "Large allocation ({size} bytes) for {purpose} but memory mapping not supported"
680 ));
681 }
682
683 result
684 }
685
686 pub fn platform_info(&self) -> &PlatformInfo {
688 &self.platform_info
689 }
690
691 pub fn clear_cache(&mut self) {
693 self.cache.clear();
694 }
695
696 pub fn is_feature_available(&self, feature: PlatformFeature) -> bool {
698 match feature {
699 PlatformFeature::MemoryMapping => self.platform_info.memory_mapping_support,
700 PlatformFeature::Avx => self.platform_info.simd_support.avx.is_some(),
701 PlatformFeature::Neon => self.platform_info.simd_support.neon,
702 PlatformFeature::LongPaths => {
703 matches!(self.platform_info.os_family, OsFamily::Unix)
705 }
706 PlatformFeature::DenormalNumbers => self.platform_info.fp_behavior.denormals_supported,
707 PlatformFeature::WasmSimd128 => {
708 matches!(
709 self.platform_info.arch,
710 CpuArchitecture::Wasm32 | CpuArchitecture::Wasm64
711 ) && self.platform_info.simd_support.vector_width >= 128
712 }
713 PlatformFeature::ThreadSupport => {
714 !matches!(self.platform_info.os_family, OsFamily::Wasm)
716 }
717 PlatformFeature::FileSystemAccess => {
718 !matches!(self.platform_info.os_family, OsFamily::Wasm)
720 }
721 }
722 }
723}
724
725#[derive(Debug, Clone, Copy, PartialEq, Eq)]
727pub enum PlatformFeature {
728 MemoryMapping,
729 Avx,
730 Neon,
731 LongPaths,
732 DenormalNumbers,
733 WasmSimd128,
734 ThreadSupport,
735 FileSystemAccess,
736}
737
738impl Default for CrossPlatformValidator {
739 fn default() -> Self {
740 Self::new().expect("Failed to create cross-platform validator")
741 }
742}
743
744#[allow(dead_code)]
747pub fn validate_path(path: &str) -> CoreResult<()> {
748 let mut validator = CrossPlatformValidator::new()?;
749 let result = validator.validate_file_path(path);
750
751 if result.is_valid {
752 Ok(())
753 } else {
754 Err(CoreError::ValidationError(ErrorContext::new(format!(
755 "Path validation failed: {:?}",
756 result.errors
757 ))))
758 }
759}
760
761#[allow(dead_code)]
763pub fn validate_simd_capability(operation: &str, size: usize) -> CoreResult<()> {
764 let mut validator = CrossPlatformValidator::new()?;
765 let result = validator.validate_simd_operation(operation, size, 128);
766
767 if result.is_valid {
768 Ok(())
769 } else {
770 Err(CoreError::ValidationError(ErrorContext::new(format!(
771 "SIMD validation failed: {:?}",
772 result.errors
773 ))))
774 }
775}
776
777#[allow(dead_code)]
779pub fn get_platform_info() -> CoreResult<PlatformInfo> {
780 CrossPlatformValidator::detect_platform_info()
781}
782
783#[cfg(test)]
784mod tests {
785 use super::*;
786
787 #[test]
788 fn test_platform_detection() {
789 let info = CrossPlatformValidator::detect_platform_info().unwrap();
790
791 assert_ne!(info.os_family, OsFamily::Unknown);
793 assert!(info.page_size > 0);
794 assert!(info.max_path_length > 0);
795 assert!(info.simd_support.vector_width > 0);
796 }
797
798 #[test]
799 fn test_path_validation() {
800 let mut validator = CrossPlatformValidator::new().unwrap();
801
802 let result = validator.validate_file_path("/home/user/data.txt");
804 assert!(result.is_valid);
805
806 let result = validator.validate_file_path("/home/user\0/data.txt");
808 assert!(!result.is_valid);
809 }
810
811 #[cfg(windows)]
812 #[test]
813 fn test_windows_path_validation() {
814 let mut validator = CrossPlatformValidator::new().unwrap();
815
816 let result = validator.validate_file_path("C:\\Users\\user\\data.txt");
818 assert!(result.is_valid);
819
820 let result = validator.validate_file_path("C:\\Users\\user<data.txt");
822 assert!(!result.is_valid);
823
824 let result = validator.validate_file_path("CON");
826 assert!(!result.is_valid);
827 }
828
829 #[cfg(unix)]
830 #[test]
831 fn test_unix_path_validation() {
832 let mut validator = CrossPlatformValidator::new().unwrap();
833
834 let result = validator.validate_file_path("/home/user/data.txt");
836 assert!(result.is_valid);
837
838 let result = validator.validate_file_path("/dev/null");
840 assert!(result.is_valid);
841 assert!(!result.warnings.is_empty());
842 }
843
844 #[test]
845 fn test_simd_validation() {
846 let mut validator = CrossPlatformValidator::new().unwrap();
847
848 let result = validator.validate_simd_operation("add", 128, 128);
850 assert!(result.is_valid);
851
852 let result = validator.validate_simd_operation("add", 10000, 10000);
854 assert!(!result.is_valid);
855 }
856
857 #[test]
858 fn test_memory_allocation_validation() {
859 let mut validator = CrossPlatformValidator::new().unwrap();
860
861 let result = validator.validate_memory_allocation(1024, "test");
863 assert!(result.is_valid);
864
865 let result = validator.validate_memory_allocation(usize::MAX - 1, "test");
867 }
869
870 #[test]
871 fn test_feature_availability() {
872 let validator = CrossPlatformValidator::new().unwrap();
873
874 let memory_mapping = validator.is_feature_available(PlatformFeature::MemoryMapping);
876 let avx = validator.is_feature_available(PlatformFeature::Avx);
877 let neon = validator.is_feature_available(PlatformFeature::Neon);
878 }
879
880 #[test]
881 fn test_convenience_functions() {
882 let _ = validate_path("/tmp/test.txt");
884 let _ = validate_simd_capability("add", 128);
885 let _ = get_platform_info();
886 }
887
888 #[test]
889 fn test_wasm_specific_features() {
890 let validator = CrossPlatformValidator::new().unwrap();
891
892 let wasm_simd = validator.is_feature_available(PlatformFeature::WasmSimd128);
894 let thread_support = validator.is_feature_available(PlatformFeature::ThreadSupport);
895 let fs_access = validator.is_feature_available(PlatformFeature::FileSystemAccess);
896
897 }
900
901 #[test]
902 fn test_wasm_path_validation() {
903 let mut validator = CrossPlatformValidator::new().unwrap();
904
905 let result = validator.validate_file_path("data/input.txt");
910 let result = validator.validate_file_path("../../../etc/passwd");
914 }
919
920 #[test]
921 fn test_platform_memory_limits() {
922 let validator = CrossPlatformValidator::new().unwrap();
923
924 let small_alloc = validator.platform_info().page_size * 2;
926 let large_alloc = 2usize.pow(30); let mut validator_mut = CrossPlatformValidator::new().unwrap();
930 let small_result = validator_mut.validate_memory_allocation(small_alloc, "test");
931 let large_result = validator_mut.validate_memory_allocation(large_alloc, "test");
932
933 }
935
936 #[test]
937 fn test_simd_capabilities_cross_platform() {
938 let mut validator = CrossPlatformValidator::new().unwrap();
939
940 let result = validator.validate_simd_operation("generic_add", 64, 64);
942 assert!(result.is_valid); let result = validator.validate_simd_operation("avx2_multiply", 256, 256);
945 let result = validator.validate_simd_operation("neon_add", 128, 128);
948 }
952}