Skip to content

Commit c58640b

Browse files
committed
test: ram_* enhance
1 parent a6c03d7 commit c58640b

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

+stdlib/ram_free.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,31 @@
1515
% memory() was added cross-platform to Octave ~ 2021.
1616
% Matlab memory() at least through R2025a is still Windows only.
1717
m = memory();
18-
bytes = uint64(m.MemAvailableAllArrays);
18+
19+
bytes = m.MemAvailableAllArrays;
20+
1921
catch e
2022
switch e.identifier
2123
case {'MATLAB:memory:unsupported', 'Octave:undefined-function'}
22-
b = javaMethod("getOperatingSystemMXBean", "java.lang.management.ManagementFactory");
24+
if stdlib.has_java()
25+
b = javaMethod("getOperatingSystemMXBean", "java.lang.management.ManagementFactory");
2326

24-
if stdlib.java_api() < 14
25-
bytes = b.getFreePhysicalMemorySize();
27+
if stdlib.java_api() < 14
28+
bytes = b.getFreePhysicalMemorySize();
29+
else
30+
bytes = b.getFreeMemorySize();
31+
end
2632
else
27-
bytes = b.getFreeMemorySize();
33+
34+
bytes = 0;
35+
2836
end
29-
bytes = uint64(bytes);
3037
otherwise, rethrow(e)
3138
end
3239
end
3340

41+
bytes = uint64(bytes);
42+
3443
end
3544

3645
%!assert(ram_free()>0)

test/TestSys.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,26 @@ function test_cpu_arch(tc)
7272
tc.verifyGreaterThan(strlength(arch), 0)
7373
end
7474

75-
function test_ram(tc)
75+
function test_ram_total(tc)
7676
tc.assumeTrue(stdlib.has_dotnet() || stdlib.has_java())
7777

7878
t = stdlib.ram_total();
7979
tc.verifyGreaterThan(t, 0)
8080
tc.verifyClass(t, 'uint64')
81+
end
82+
83+
84+
function test_ram_free(tc)
85+
tc.assumeTrue(ispc() || stdlib.has_java())
8186

8287
f = stdlib.ram_free();
8388
tc.verifyGreaterThan(f, 0)
8489
tc.verifyClass(f, 'uint64')
8590

86-
tc.verifyLessThanOrEqual(f, t)
91+
tc.verifyLessThanOrEqual(f, stdlib.ram_total(), ...
92+
"Free RAM should be less than or equal to total RAM")
8793
end
8894

8995
end
96+
9097
end

0 commit comments

Comments
 (0)