|
| 1 | +#!/usr/bin/env perl |
| 2 | +use strict; |
| 3 | +use warnings; |
| 4 | +no warnings 'once'; |
| 5 | +use Test::More; |
| 6 | +use File::Basename; |
| 7 | +use File::Spec; |
| 8 | + |
| 9 | +my $script = File::Spec->rel2abs(File::Spec->catfile(dirname(__FILE__), '..', 'mysqltuner.pl')); |
| 10 | + |
| 11 | +# Mocking and loading mysqltuner.pl |
| 12 | +{ |
| 13 | + local @ARGV = (); |
| 14 | + no warnings 'redefine'; |
| 15 | + require $script; |
| 16 | +} |
| 17 | + |
| 18 | +# Silence console printing from within the test |
| 19 | +{ |
| 20 | + no warnings 'redefine'; |
| 21 | + no warnings 'once'; |
| 22 | + *main::badprint = sub { }; |
| 23 | + *main::goodprint = sub { }; |
| 24 | + *main::debugprint = sub { }; |
| 25 | + *main::infoprint = sub { }; |
| 26 | + *main::subheaderprint = sub { }; |
| 27 | + *main::prettyprint = sub { }; |
| 28 | +} |
| 29 | + |
| 30 | +# Mock transport and system commands |
| 31 | +{ |
| 32 | + no warnings 'redefine'; |
| 33 | + no warnings 'once'; |
| 34 | + *main::get_transport_prefix = sub { return '' }; |
| 35 | + *main::execute_system_command = sub { return '' }; |
| 36 | +} |
| 37 | + |
| 38 | +subtest 'Issue 810 - Verify forcemem MB interpretation correctness (regression test)' => sub { |
| 39 | + # Initialize basic CLI options metadata defaults |
| 40 | + foreach my $o (keys %main::CLI_METADATA) { |
| 41 | + my ($p) = split /\|/, $o; |
| 42 | + $p =~ s/[!+=:].*$//; |
| 43 | + $main::opt{$p} //= $main::CLI_METADATA{$o}->{default}; |
| 44 | + } |
| 45 | + |
| 46 | + # Simulate `--forcemem 32768` (passed in MB for a 32GB system) |
| 47 | + $main::opt{'forcemem'} = 32768; |
| 48 | + $main::opt{'forceswap'} = 0; |
| 49 | + |
| 50 | + # Run OS setup logic to calculate physical memory |
| 51 | + main::os_setup(); |
| 52 | + |
| 53 | + # Verification: |
| 54 | + # 32768 MB must equal 34,359,738,368 bytes (32 GB) |
| 55 | + is($main::physical_memory, 34359738368, "Physical memory must be correctly calculated in bytes (32768 * 1024 * 1024)"); |
| 56 | + |
| 57 | + # Verify that human readable formatting outputs 32.0G and NOT 32.0K (which occurred before the regression fix) |
| 58 | + my $pretty = main::hr_bytes($main::physical_memory); |
| 59 | + is($pretty, "32.0G", "Pretty memory output must be 32.0G"); |
| 60 | + isnt($pretty, "32.0K", "Pretty memory output must not be 32.0K (regression check)"); |
| 61 | +}; |
| 62 | + |
| 63 | +done_testing(); |
0 commit comments