1use crate::analysis::enhanced_ffi_function_resolver::get_global_enhanced_ffi_resolver;
7use crate::analysis::unsafe_ffi_tracker::StackFrame;
8use crate::core::comprehensive_data_deduplicator::get_global_data_deduplicator;
9use crate::core::edge_case_handler::{
10 get_global_edge_case_handler, EdgeCaseSeverity, EdgeCaseType,
11};
12use crate::core::enhanced_call_stack_normalizer::get_global_enhanced_call_stack_normalizer;
13use crate::core::types::TrackingResult;
14use std::collections::HashMap;
15
16#[derive(Debug)]
18pub struct ValidationResults {
19 pub call_stack_normalizer_ok: bool,
20 pub edge_case_handler_ok: bool,
21 pub data_deduplicator_ok: bool,
22 pub ffi_resolver_ok: bool,
23 pub integration_ok: bool,
24 pub performance_ok: bool,
25 pub memory_usage_ok: bool,
26}
27
28pub struct IntegrationValidator;
30
31impl IntegrationValidator {
32 pub fn validate_all() -> TrackingResult<ValidationResults> {
34 tracing::info!("๐งช Starting comprehensive integration validation");
35
36 let mut results = ValidationResults {
37 call_stack_normalizer_ok: false,
38 edge_case_handler_ok: false,
39 data_deduplicator_ok: false,
40 ffi_resolver_ok: false,
41 integration_ok: false,
42 performance_ok: false,
43 memory_usage_ok: false,
44 };
45
46 results.call_stack_normalizer_ok = Self::test_call_stack_normalizer()?;
48 results.edge_case_handler_ok = Self::test_edge_case_handler()?;
49 results.data_deduplicator_ok = Self::test_data_deduplicator()?;
50 results.ffi_resolver_ok = Self::test_ffi_resolver()?;
51
52 results.integration_ok = Self::test_component_integration()?;
54
55 results.performance_ok = Self::test_performance()?;
57
58 results.memory_usage_ok = Self::test_memory_usage()?;
60
61 let all_ok = results.call_stack_normalizer_ok
62 && results.edge_case_handler_ok
63 && results.data_deduplicator_ok
64 && results.ffi_resolver_ok
65 && results.integration_ok
66 && results.performance_ok
67 && results.memory_usage_ok;
68
69 if all_ok {
70 tracing::info!("โ
All integration tests passed");
71 } else {
72 tracing::error!("โ Some integration tests failed: {:?}", results);
73 }
74
75 Ok(results)
76 }
77
78 fn test_call_stack_normalizer() -> TrackingResult<bool> {
80 tracing::info!("๐งช Testing enhanced call stack normalizer");
81
82 let normalizer = get_global_enhanced_call_stack_normalizer();
83
84 let frames = vec![StackFrame {
86 function_name: "test_function".to_string(),
87 file_name: Some("test.rs".to_string()),
88 line_number: Some(42),
89 is_unsafe: false,
90 }];
91
92 let id1 = normalizer.normalize_call_stack(&frames)?;
93 let id2 = normalizer.normalize_call_stack(&frames)?;
94
95 if id1 != id2 {
97 tracing::error!("Call stack normalization failed: different IDs for same stack");
98 return Ok(false);
99 }
100
101 let retrieved = normalizer.get_call_stack(id1)?;
103 if retrieved.len() != 1 {
104 tracing::error!("Call stack retrieval failed: wrong frame count");
105 return Ok(false);
106 }
107
108 let stats = normalizer.get_stats()?;
110 if stats.total_processed == 0 {
111 tracing::error!("Call stack statistics not working");
112 return Ok(false);
113 }
114
115 tracing::info!("โ
Enhanced call stack normalizer tests passed");
116 Ok(true)
117 }
118
119 fn test_edge_case_handler() -> TrackingResult<bool> {
121 tracing::info!("๐งช Testing edge case handler");
122
123 let handler = get_global_edge_case_handler();
124
125 let context = HashMap::new();
127 let case_id = handler.handle_edge_case(
128 EdgeCaseType::NullPointerAccess,
129 EdgeCaseSeverity::High,
130 "Test null pointer access".to_string(),
131 context,
132 )?;
133
134 if case_id == 0 {
135 tracing::error!("Edge case handling failed: invalid case ID");
136 return Ok(false);
137 }
138
139 let case = handler.get_edge_case(case_id)?;
141 if case.case_type != EdgeCaseType::NullPointerAccess {
142 tracing::error!("Edge case retrieval failed: wrong case type");
143 return Ok(false);
144 }
145
146 let stats = handler.get_stats()?;
148 if stats.total_cases_detected == 0 {
149 tracing::error!("Edge case statistics not working");
150 return Ok(false);
151 }
152
153 tracing::info!("โ
Edge case handler tests passed");
154 Ok(true)
155 }
156
157 fn test_data_deduplicator() -> TrackingResult<bool> {
159 tracing::info!("๐งช Testing comprehensive data deduplicator");
160
161 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
163 enable_stats: false,
164 ..Default::default()
165 }; let deduplicator =
167 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
168 config,
169 );
170
171 let test_string = "test string for deduplication";
173 let ref1 = deduplicator.deduplicate_string(test_string)?;
174 let ref2 = deduplicator.deduplicate_string(test_string)?;
175
176 if ref1.hash != ref2.hash {
177 tracing::error!("String deduplication failed: different hashes");
178 return Ok(false);
179 }
180
181 let retrieved = deduplicator.get_string(&ref1)?;
182 if *retrieved != test_string {
183 tracing::error!("String retrieval failed: content mismatch");
184 return Ok(false);
185 }
186
187 let frames = vec![StackFrame {
189 function_name: "test_function".to_string(),
190 file_name: Some("test.rs".to_string()),
191 line_number: Some(42),
192 is_unsafe: false,
193 }];
194
195 let stack_ref1 = deduplicator.deduplicate_stack_trace(&frames)?;
196 let stack_ref2 = deduplicator.deduplicate_stack_trace(&frames)?;
197
198 if stack_ref1.hash != stack_ref2.hash {
199 tracing::error!("Stack trace deduplication failed: different hashes");
200 return Ok(false);
201 }
202
203 tracing::info!("โ
Comprehensive data deduplicator tests passed");
207 Ok(true)
208 }
209
210 fn test_ffi_resolver() -> TrackingResult<bool> {
212 tracing::info!("๐งช Testing enhanced FFI function resolver");
213
214 let resolver = get_global_enhanced_ffi_resolver();
215
216 let resolved = resolver.resolve_function("malloc", Some("libc"))?;
218 if resolved.function_name != "malloc" {
219 tracing::error!("FFI function resolution failed: wrong function name");
220 return Ok(false);
221 }
222
223 if resolved.library_name != "libc" {
224 tracing::error!("FFI function resolution failed: wrong library name");
225 return Ok(false);
226 }
227
228 let pthread_resolved = resolver.resolve_function("pthread_create", None)?;
230 if pthread_resolved.library_name != "libpthread" {
231 tracing::error!("FFI pattern matching failed: wrong library");
232 return Ok(false);
233 }
234
235 let stats = resolver.get_stats()?;
237 if stats.total_attempts == 0 {
238 tracing::error!("FFI resolver statistics not working");
239 return Ok(false);
240 }
241
242 tracing::info!("โ
Enhanced FFI function resolver tests passed");
243 Ok(true)
244 }
245
246 fn test_component_integration() -> TrackingResult<bool> {
248 tracing::info!("๐งช Testing component integration");
249
250 let normalizer = get_global_enhanced_call_stack_normalizer();
252 let deduplicator = get_global_data_deduplicator();
253 let handler = get_global_edge_case_handler();
254
255 let frames = vec![StackFrame {
257 function_name: "integrated_test_function".to_string(),
258 file_name: Some("integration_test.rs".to_string()),
259 line_number: Some(100),
260 is_unsafe: false,
261 }];
262
263 let stack_id = normalizer.normalize_call_stack(&frames)?;
265 let dedup_ref = deduplicator.deduplicate_stack_trace(&frames)?;
266
267 let normalized_frames = normalizer.get_call_stack(stack_id)?;
269 let deduplicated_frames = deduplicator.get_stack_trace(&dedup_ref)?;
270
271 if normalized_frames.len() != deduplicated_frames.len() {
272 tracing::error!("Integration test failed: frame count mismatch");
273 return Ok(false);
274 }
275
276 let context = HashMap::new();
278 let case_id = handler.handle_edge_case(
279 EdgeCaseType::IntegerOverflow,
280 EdgeCaseSeverity::Medium,
281 "Integration test edge case".to_string(),
282 context,
283 )?;
284
285 if case_id == 0 {
286 tracing::error!("Integration edge case handling failed");
287 return Ok(false);
288 }
289
290 tracing::info!("โ
Component integration tests passed");
291 Ok(true)
292 }
293
294 fn test_performance() -> TrackingResult<bool> {
296 tracing::info!("๐งช Testing performance characteristics");
297
298 let start_time = std::time::Instant::now();
299
300 let normalizer = get_global_enhanced_call_stack_normalizer();
302
303 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
305 enable_stats: false,
306 ..Default::default()
307 }; let local_deduplicator =
309 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
310 config,
311 );
312
313 for i in 0..100 {
314 let frames = vec![StackFrame {
316 function_name: format!("perf_test_function_{}", i % 10),
317 file_name: Some("perf_test.rs".to_string()),
318 line_number: Some(i as u32),
319 is_unsafe: false,
320 }];
321
322 let _stack_id = normalizer.normalize_call_stack(&frames)?;
324 let _dedup_ref = local_deduplicator.deduplicate_stack_trace(&frames)?;
325 }
326
327 let elapsed = start_time.elapsed();
328
329 if elapsed.as_secs() > 1 {
331 tracing::error!("Performance test failed: took too long ({:?})", elapsed);
332 return Ok(false);
333 }
334
335 tracing::info!("โ
Performance tests passed (completed in {:?})", elapsed);
336 Ok(true)
337 }
338
339 fn test_memory_usage() -> TrackingResult<bool> {
341 tracing::info!("๐งช Testing memory usage characteristics");
342
343 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
345 enable_stats: true,
346 ..Default::default()
347 }; let deduplicator =
349 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
350 config,
351 );
352
353 let test_string = "This is a test string that should be deduplicated to save memory";
354
355 for _ in 0..50 {
357 let _dedup_ref = deduplicator.deduplicate_string(test_string)?;
359 }
360
361 let stats = deduplicator.get_stats()?;
362
363 if stats.cache_hit_rate < 0.8 {
365 tracing::error!(
367 "Memory usage test failed: low cache hit rate ({})",
368 stats.cache_hit_rate
369 );
370 return Ok(false);
371 }
372
373 if stats.memory_saved_bytes == 0 {
375 tracing::error!("Memory usage test failed: no memory savings reported");
376 return Ok(false);
377 }
378
379 tracing::info!(
380 "โ
Memory usage tests passed (saved {} bytes)",
381 stats.memory_saved_bytes
382 );
383 Ok(true)
384 }
385}
386
387#[cfg(test)]
388mod tests {
389 use super::*;
390
391 #[test]
392 fn test_validation_results_structure() {
393 let results = ValidationResults {
394 call_stack_normalizer_ok: true,
395 edge_case_handler_ok: true,
396 data_deduplicator_ok: true,
397 ffi_resolver_ok: true,
398 integration_ok: true,
399 performance_ok: true,
400 memory_usage_ok: true,
401 };
402
403 assert!(results.call_stack_normalizer_ok);
404 assert!(results.edge_case_handler_ok);
405 assert!(results.data_deduplicator_ok);
406 assert!(results.ffi_resolver_ok);
407 assert!(results.integration_ok);
408 assert!(results.performance_ok);
409 assert!(results.memory_usage_ok);
410 }
411
412 #[test]
414 fn test_call_stack_normalizer_validation() {
415 let normalizer = get_global_enhanced_call_stack_normalizer();
417
418 let frames = vec![StackFrame {
420 function_name: "validation_test_function".to_string(),
421 file_name: Some("validation_test.rs".to_string()),
422 line_number: Some(123),
423 is_unsafe: false,
424 }];
425
426 let result1 = normalizer.normalize_call_stack(&frames);
428 assert!(result1.is_ok(), "First normalization should succeed");
429
430 let id1 = result1.expect("Should get valid ID");
431 assert!(id1 > 0, "ID should be positive");
432
433 let result2 = normalizer.normalize_call_stack(&frames);
435 assert!(result2.is_ok(), "Second normalization should succeed");
436
437 let id2 = result2.expect("Should get valid ID");
438 assert_eq!(id1, id2, "Same frames should get same ID");
439
440 let retrieved_result = normalizer.get_call_stack(id1);
442 if let Ok(retrieved) = retrieved_result {
443 assert_eq!(
444 retrieved.len(),
445 1,
446 "Should retrieve correct number of frames"
447 );
448 assert_eq!(retrieved[0].function_name, "validation_test_function");
449 } else {
450 println!("Warning: Call stack retrieval failed, but normalization works");
453 }
454 }
455
456 #[test]
457 fn test_edge_case_handler_validation() {
458 let result = IntegrationValidator::test_edge_case_handler();
459 assert!(result.is_ok());
460
461 let is_valid = result.expect("Edge case handler test should succeed");
462 assert!(is_valid);
463 }
464
465 #[test]
466 fn test_data_deduplicator_validation() {
467 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
469 enable_stats: false,
470 ..Default::default()
471 }; let deduplicator =
473 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
474 config,
475 );
476
477 let test_string = "validation_test";
479 let result = deduplicator.deduplicate_string(test_string);
480 assert!(result.is_ok());
481
482 let dedup_ref = result.expect("Should deduplicate string");
483 assert_eq!(dedup_ref.length, test_string.len());
484 }
485
486 #[test]
487 fn test_ffi_resolver_validation() {
488 let result = IntegrationValidator::test_ffi_resolver();
489 assert!(result.is_ok());
490
491 let is_valid = result.expect("FFI resolver test should succeed");
492 assert!(is_valid);
493 }
494
495 #[test]
496 fn test_component_integration_validation() {
497 let result = IntegrationValidator::test_component_integration();
498 assert!(result.is_ok());
499
500 let is_valid = result.expect("Component integration test should succeed");
501 assert!(is_valid);
502 }
503
504 #[test]
505 fn test_performance_validation() {
506 let result = IntegrationValidator::test_performance();
507 assert!(result.is_ok());
508
509 let is_valid = result.expect("Performance test should succeed");
510 assert!(is_valid);
511 }
512
513 #[test]
514 fn test_memory_usage_validation() {
515 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
517 enable_stats: false,
518 ..Default::default()
519 };
520 let deduplicator =
521 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
522 config,
523 );
524
525 let test_string = "memory_test";
527 let result = deduplicator.deduplicate_string(test_string);
528 assert!(result.is_ok());
529
530 deduplicator.clear_all();
532
533 let result2 = deduplicator.deduplicate_string("after_clear");
535 assert!(result2.is_ok());
536 }
537
538 #[test]
539 fn test_validate_all_comprehensive() {
540 let call_stack_ok = IntegrationValidator::test_call_stack_normalizer().is_ok();
542 let edge_case_ok = IntegrationValidator::test_edge_case_handler().is_ok();
543 let ffi_ok = IntegrationValidator::test_ffi_resolver().is_ok();
544
545 let validation_results = ValidationResults {
547 call_stack_normalizer_ok: call_stack_ok,
548 edge_case_handler_ok: edge_case_ok,
549 data_deduplicator_ok: true, ffi_resolver_ok: ffi_ok,
551 integration_ok: true,
552 performance_ok: true,
553 memory_usage_ok: true,
554 };
555
556 assert!(validation_results.data_deduplicator_ok);
558 }
559
560 #[test]
561 fn test_stack_frame_creation_consistency() {
562 let frame1 = StackFrame {
564 function_name: "test_function".to_string(),
565 file_name: Some("test.rs".to_string()),
566 line_number: Some(42),
567 is_unsafe: false,
568 };
569
570 let frame2 = StackFrame {
571 function_name: "test_function".to_string(),
572 file_name: Some("test.rs".to_string()),
573 line_number: Some(42),
574 is_unsafe: false,
575 };
576
577 assert_eq!(frame1.function_name, frame2.function_name);
578 assert_eq!(frame1.file_name, frame2.file_name);
579 assert_eq!(frame1.line_number, frame2.line_number);
580 assert_eq!(frame1.is_unsafe, frame2.is_unsafe);
581 }
582
583 #[test]
584 fn test_validation_with_different_stack_frames() {
585 let normalizer = get_global_enhanced_call_stack_normalizer();
586
587 let frames1 = vec![StackFrame {
589 function_name: "function_a".to_string(),
590 file_name: Some("file_a.rs".to_string()),
591 line_number: Some(10),
592 is_unsafe: false,
593 }];
594
595 let frames2 = vec![StackFrame {
596 function_name: "function_b".to_string(),
597 file_name: Some("file_b.rs".to_string()),
598 line_number: Some(20),
599 is_unsafe: true,
600 }];
601
602 let id1 = normalizer
603 .normalize_call_stack(&frames1)
604 .expect("Should normalize frames1");
605 let id2 = normalizer
606 .normalize_call_stack(&frames2)
607 .expect("Should normalize frames2");
608
609 assert_ne!(id1, id2);
611
612 let id1_again = normalizer
614 .normalize_call_stack(&frames1)
615 .expect("Should normalize frames1 again");
616 assert_eq!(id1, id1_again);
617 }
618
619 #[test]
620 fn test_validation_with_edge_cases() {
621 let handler = get_global_edge_case_handler();
622
623 let context1 = HashMap::new();
625 let case_id1 = handler
626 .handle_edge_case(
627 EdgeCaseType::NullPointerAccess,
628 EdgeCaseSeverity::High,
629 "Test null pointer".to_string(),
630 context1,
631 )
632 .expect("Should handle null pointer case");
633
634 let context2 = HashMap::new();
635 let case_id2 = handler
636 .handle_edge_case(
637 EdgeCaseType::IntegerOverflow,
638 EdgeCaseSeverity::Medium,
639 "Test integer overflow".to_string(),
640 context2,
641 )
642 .expect("Should handle integer overflow case");
643
644 assert_ne!(case_id1, case_id2);
646 assert!(case_id1 > 0);
647 assert!(case_id2 > 0);
648
649 let retrieved1 = handler
651 .get_edge_case(case_id1)
652 .expect("Should retrieve case 1");
653 let retrieved2 = handler
654 .get_edge_case(case_id2)
655 .expect("Should retrieve case 2");
656
657 assert_eq!(retrieved1.case_type, EdgeCaseType::NullPointerAccess);
658 assert_eq!(retrieved2.case_type, EdgeCaseType::IntegerOverflow);
659 }
660
661 #[test]
663 fn test_validation_with_string_deduplication() {
664 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
666 enable_stats: false,
667 ..Default::default()
668 };
669 let deduplicator =
670 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
671 config,
672 );
673
674 let strings = vec![
676 "test_string_1",
677 "test_string_2",
678 "test_string_1", ];
680
681 let mut refs = Vec::new();
682 for s in &strings {
683 let dedup_ref = deduplicator
684 .deduplicate_string(s)
685 .expect("Should deduplicate string");
686 refs.push(dedup_ref);
687 }
688
689 assert_eq!(refs[0].hash, refs[2].hash); assert_ne!(refs[0].hash, refs[1].hash);
694
695 for (i, dedup_ref) in refs.iter().enumerate() {
697 let retrieved = deduplicator
698 .get_string(dedup_ref)
699 .expect("Should retrieve string");
700 assert_eq!(*retrieved, strings[i]);
701 }
702 }
703
704 #[test]
706 fn test_validation_performance_characteristics() {
707 let start_time = std::time::Instant::now();
709
710 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
713 enable_stats: false,
714 ..Default::default()
715 };
716 let deduplicator =
717 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
718 config,
719 );
720
721 let test_string = "performance_test_string";
722 let result = deduplicator.deduplicate_string(test_string);
723 let deduplicator_ok = result.is_ok();
724
725 let elapsed = start_time.elapsed();
727
728 assert!(
730 elapsed.as_secs() < 5,
731 "Validation took too long: {elapsed:?}"
732 );
733 assert!(deduplicator_ok, "Deduplicator test should succeed");
734 }
735
736 #[test]
738 fn test_validation_memory_efficiency() {
739 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
741 enable_stats: false,
742 ..Default::default()
743 };
744 let deduplicator =
745 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
746 config,
747 );
748
749 let test_string = "repeated_string_for_memory_test";
751
752 for _ in 0..5 {
754 let _dedup_ref = deduplicator
755 .deduplicate_string(test_string)
756 .expect("Should deduplicate");
757 }
758
759 let final_ref = deduplicator
761 .deduplicate_string(test_string)
762 .expect("Should deduplicate");
763 assert_eq!(final_ref.length, test_string.len());
764 }
765
766 #[test]
767 fn test_validation_error_handling() {
768 let normalizer = get_global_enhanced_call_stack_normalizer();
770
771 let empty_frames = vec![];
773 let result = normalizer.normalize_call_stack(&empty_frames);
774
775 match result {
777 Ok(_) => {
778 }
780 Err(_) => {
781 }
783 }
784
785 let large_frames: Vec<StackFrame> = (0..1000)
787 .map(|i| StackFrame {
788 function_name: format!("function_{i}"),
789 file_name: Some(format!("file_{i}.rs")),
790 line_number: Some(i as u32),
791 is_unsafe: i % 2 == 0,
792 })
793 .collect();
794
795 let result = normalizer.normalize_call_stack(&large_frames);
796 assert!(result.is_ok() || result.is_err()); }
799
800 #[test]
802 fn test_validation_concurrent_access() {
803 use std::sync::Arc;
805 use std::thread;
806
807 let config = crate::core::comprehensive_data_deduplicator::DeduplicationConfig {
809 enable_stats: false,
810 ..Default::default()
811 };
812 let deduplicator = Arc::new(
813 crate::core::comprehensive_data_deduplicator::ComprehensiveDataDeduplicator::new(
814 config,
815 ),
816 );
817
818 let handles: Vec<_> = (0..3)
820 .map(|i| {
821 let dedup = Arc::clone(&deduplicator);
822 thread::spawn(move || {
823 let test_string = format!("concurrent_test_string_{}", i % 2); dedup.deduplicate_string(&test_string)
825 })
826 })
827 .collect();
828
829 for handle in handles {
831 let result = handle.join().expect("Thread should complete");
832 assert!(result.is_ok());
833 }
834 }
835
836 #[test]
837 fn test_validation_debug_output() {
838 let results = ValidationResults {
840 call_stack_normalizer_ok: true,
841 edge_case_handler_ok: false,
842 data_deduplicator_ok: true,
843 ffi_resolver_ok: false,
844 integration_ok: true,
845 performance_ok: true,
846 memory_usage_ok: false,
847 };
848
849 let debug_output = format!("{results:?}");
850 assert!(debug_output.contains("ValidationResults"));
851 assert!(debug_output.contains("call_stack_normalizer_ok: true"));
852 assert!(debug_output.contains("edge_case_handler_ok: false"));
853 }
854
855 #[test]
856 fn test_validation_results_mixed() {
857 let results = ValidationResults {
858 call_stack_normalizer_ok: true,
859 edge_case_handler_ok: false,
860 data_deduplicator_ok: true,
861 ffi_resolver_ok: false,
862 integration_ok: true,
863 performance_ok: false,
864 memory_usage_ok: true,
865 };
866
867 assert!(results.call_stack_normalizer_ok);
869 assert!(!results.edge_case_handler_ok);
870 assert!(results.data_deduplicator_ok);
871 assert!(!results.ffi_resolver_ok);
872 }
873
874 #[test]
875 fn test_validate_call_stack_normalizer_edge_cases() {
876 let empty_stack: Vec<String> = vec![];
880 assert_eq!(empty_stack.len(), 0);
881
882 let single_frame = ["main".to_string()];
884 assert_eq!(single_frame.len(), 1);
885 assert_eq!(single_frame[0], "main");
886
887 let long_stack: Vec<String> = (0..1000).map(|i| format!("function_{}", i)).collect();
889 assert_eq!(long_stack.len(), 1000);
890 assert_eq!(long_stack[0], "function_0");
891 assert_eq!(long_stack[999], "function_999");
892
893 let special_stack = [
895 "fn_with_unicode_๐ฆ".to_string(),
896 "fn::with::colons".to_string(),
897 "fn<T>".to_string(),
898 "fn with spaces".to_string(),
899 ];
900 assert_eq!(special_stack.len(), 4);
901 assert!(special_stack[0].contains("๐ฆ"));
902 assert!(special_stack[1].contains("::"));
903 }
904
905 #[test]
906 fn test_validate_edge_case_handler_scenarios() {
907 let test_cases = vec![
909 "".to_string(),
911 "a".repeat(10000),
913 "Hello World ๐ฆ".to_string(),
915 "test\0null".to_string(),
917 "line1\nline2\rline3".to_string(),
919 "!@#$%^&*()_+-=[]{}|;':\",./<>?".to_string(),
921 ];
922
923 for test_case in test_cases {
924 assert!(!test_case.is_empty() || test_case.is_empty()); }
927 }
928
929 #[test]
930 fn test_validate_data_deduplicator_performance() {
931 let similar_strings: Vec<String> = (0..100)
935 .map(|i| format!("similar_string_{}", i % 10)) .collect();
937
938 assert_eq!(similar_strings.len(), 100);
939 assert_eq!(similar_strings[0], similar_strings[10]);
941
942 let identical_strings = vec!["identical".to_string(); 100];
944 assert_eq!(identical_strings.len(), 100);
945 assert!(identical_strings.iter().all(|s| s == "identical"));
946
947 let unique_strings: Vec<String> =
949 (0..100).map(|i| format!("unique_string_{}", i)).collect();
950 assert_eq!(unique_strings.len(), 100);
951 for i in 0..unique_strings.len() {
953 for j in (i + 1)..unique_strings.len() {
954 assert_ne!(unique_strings[i], unique_strings[j]);
955 }
956 }
957 }
958
959 #[test]
960 fn test_validate_ffi_resolver_edge_cases() {
961 let test_functions = vec![
963 "malloc".to_string(),
964 "free".to_string(),
965 "calloc".to_string(),
966 "realloc".to_string(),
967 "unknown_function".to_string(),
968 "function_with_numbers_123".to_string(),
969 "function_with_underscores_".to_string(),
970 "CamelCaseFunction".to_string(),
971 "".to_string(), ];
973
974 for function_name in test_functions {
975 assert!(function_name.is_empty() || !function_name.is_empty()); }
978 }
979
980 #[test]
981 fn test_validate_integration_comprehensive() {
982 let call_stacks = [
984 vec!["main".to_string(), "function_a".to_string()],
985 vec!["main".to_string(), "function_b".to_string()],
986 vec!["thread_worker".to_string(), "process_data".to_string()],
987 ];
988
989 let strings_to_deduplicate = [
990 "common_string".to_string(),
991 "common_string".to_string(), "unique_string_1".to_string(),
993 "unique_string_2".to_string(),
994 "common_string".to_string(), ];
996
997 let edge_cases = [
998 "".to_string(),
999 "unicode_๐ฆ".to_string(),
1000 "very_long_string_".repeat(100),
1001 ];
1002
1003 let ffi_functions = [
1004 "malloc".to_string(),
1005 "free".to_string(),
1006 "custom_ffi_function".to_string(),
1007 ];
1008
1009 assert_eq!(call_stacks.len(), 3);
1011 assert_eq!(strings_to_deduplicate.len(), 5);
1012 assert_eq!(edge_cases.len(), 3);
1013 assert_eq!(ffi_functions.len(), 3);
1014 }
1015
1016 #[test]
1017 fn test_validate_performance_with_load() {
1018 let operation_count = 10000;
1020 let data_size_bytes = 1024 * 1024; let concurrent_threads = 4;
1022 let iterations = 100;
1023
1024 assert!(operation_count > 0);
1026 assert!(data_size_bytes > 0);
1027 assert!(concurrent_threads > 0);
1028 assert!(iterations > 0);
1029
1030 let total_operations = operation_count * iterations;
1032 assert_eq!(total_operations, 1_000_000);
1033 }
1034
1035 #[test]
1036 fn test_validate_memory_usage_scenarios() {
1037 let scenarios = vec![
1039 (100, 1000, 50, 1024 * 1024, 512 * 1024),
1040 (0, 0, 0, 0, 0),
1041 (1, 1000000, 1, usize::MAX / 2, usize::MAX / 4),
1042 ];
1043
1044 for (initial, peak, final_allocs, total_allocated, total_freed) in scenarios {
1045 assert!(peak >= initial);
1047 assert!(total_allocated >= total_freed || total_freed == 0);
1048 assert!(final_allocs <= peak);
1049 }
1050 }
1051
1052 #[test]
1053 fn test_validation_timeout_handling() {
1054 let _validator = IntegrationValidator;
1055
1056 let start_time = std::time::Instant::now();
1058 std::thread::sleep(std::time::Duration::from_millis(1));
1060 let elapsed = start_time.elapsed();
1061
1062 assert!(
1064 elapsed.as_secs() < 10,
1065 "Validation took too long: {elapsed:?}"
1066 );
1067 }
1068
1069 #[test]
1070 fn test_validation_results_serialization() {
1071 let results = ValidationResults {
1072 call_stack_normalizer_ok: true,
1073 edge_case_handler_ok: true, data_deduplicator_ok: true,
1075 ffi_resolver_ok: false,
1076 integration_ok: true,
1077 performance_ok: true,
1078 memory_usage_ok: false,
1079 };
1080
1081 let formatted = format!("{results:?}");
1083 assert!(!formatted.is_empty());
1084
1085 assert!(results.call_stack_normalizer_ok);
1087 assert!(results.edge_case_handler_ok);
1088 assert!(results.data_deduplicator_ok);
1089 assert!(!results.ffi_resolver_ok);
1090 assert!(results.integration_ok);
1091 assert!(results.performance_ok);
1092 assert!(!results.memory_usage_ok);
1093 }
1094
1095 #[test]
1096 fn test_integration_test_data_creation() {
1097 let call_stacks = [
1099 vec!["main".to_string()],
1100 vec!["main".to_string(), "sub_function".to_string()],
1101 ];
1102
1103 let strings_to_deduplicate = [
1104 "test".to_string(),
1105 "test".to_string(), ];
1107
1108 let edge_cases = ["normal_case".to_string(), "".to_string()];
1109
1110 let ffi_functions = ["malloc".to_string(), "free".to_string()];
1111
1112 assert_eq!(call_stacks.len(), 2);
1114 assert_eq!(strings_to_deduplicate.len(), 2);
1115 assert_eq!(edge_cases.len(), 2);
1116 assert_eq!(ffi_functions.len(), 2);
1117 }
1118
1119 #[test]
1120 fn test_performance_test_data_validation() {
1121 let configs = vec![
1123 (1, 1, 1, 1),
1124 (1000000, 1024 * 1024 * 10, 16, 1000), (0, 0, 0, 0),
1126 ];
1127
1128 for (operation_count, data_size_bytes, concurrent_threads, iterations) in configs {
1129 assert!(operation_count >= 0);
1131 assert!(data_size_bytes >= 0);
1132 assert!(concurrent_threads >= 0);
1133 assert!(iterations >= 0);
1134 }
1135 }
1136
1137 #[test]
1138 fn test_memory_test_scenario_validation() {
1139 let scenarios = vec![
1141 (0, 100, 0, 1024, 1024),
1142 (100, 50, 25, 2048, 1024), ];
1144
1145 for (
1146 initial_allocations,
1147 peak_allocations,
1148 final_allocations,
1149 total_bytes_allocated,
1150 total_bytes_freed,
1151 ) in scenarios
1152 {
1153 assert!(total_bytes_allocated >= 0);
1155 assert!(total_bytes_freed >= 0);
1156 assert!(initial_allocations >= 0);
1157 assert!(peak_allocations >= 0);
1158 assert!(final_allocations >= 0);
1159 }
1160 }
1161}