| 419 | // ============================================================================ |
| 420 | |
| 421 | int test_phase1_validation() { |
| 422 | printf("\n\n"); |
| 423 | printf("================================================================================\n"); |
| 424 | printf("JSON PHASE 1 VALIDATION TEST - ZERO HEAP ALLOCATIONS\n"); |
| 425 | printf("================================================================================\n"); |
| 426 | |
| 427 | #ifdef _WIN32 |
| 428 | init_real_allocators(); |
| 429 | #endif |
| 430 | |
| 431 | // Test Phase 1 validation with complex JSON |
| 432 | const char* test_json = STRESS_TEST_JSON; |
| 433 | printf("JSON size: %zu bytes\n", ::strlen(test_json)); |
| 434 | printf("Testing Phase 1 validation (tokenization + validation only)...\n\n"); |
| 435 | |
| 436 | g_stats.reset(); |
| 437 | g_tracking_enabled = true; |
| 438 | |
| 439 | // Phase 1 validation only - this MUST allocate ZERO heap memory |
| 440 | // Use zero-copy string_view to avoid fl::string allocation |
| 441 | bool valid = json::parse2_validate_only(fl::string_view(test_json, ::strlen(test_json))); |
| 442 | |
| 443 | g_tracking_enabled = false; |
| 444 | |
| 445 | printf("Validation result: %s\n", valid ? "VALID" : "INVALID"); |
| 446 | |
| 447 | // Check results |
| 448 | size_t phase1_allocs = g_stats.alloc_count.load(); |
| 449 | size_t phase1_bytes = g_stats.total_allocated.load(); |
| 450 | |
| 451 | printf("Phase 1 Validation Results:\n"); |
| 452 | printf(" Allocations: %zu\n", phase1_allocs); |
| 453 | printf(" Total bytes: %zu\n", phase1_bytes); |
| 454 | printf("\n"); |
| 455 | |
| 456 | // CRITICAL: Phase 1 must allocate ZERO heap memory |
| 457 | if (phase1_allocs == 0 && phase1_bytes == 0) { |
| 458 | printf("✓✓✓ PASS: Phase 1 validation allocates ZERO heap memory\n"); |
| 459 | } else { |
| 460 | printf("✗✗✗ FAIL: Phase 1 validation allocated memory!\n"); |
| 461 | printf(" Expected: 0 allocations, 0 bytes\n"); |
| 462 | printf(" Actual: %zu allocations, %zu bytes\n", phase1_allocs, phase1_bytes); |
| 463 | printf("================================================================================\n\n"); |
| 464 | return 1; // Failure |
| 465 | } |
| 466 | printf("================================================================================\n\n"); |
| 467 | return 0; // Success |
| 468 | } |
| 469 | |
| 470 | int test_small_json_profiling() { |
| 471 | profile_json_memory("SMALL JSON MEMORY PROFILE (10KB Synthetic)", STRESS_TEST_JSON); |
no test coverage detected