Skip to content

Commit e49ea3b

Browse files
committed
cpu_arch more robust
1 parent 8a007f8 commit e49ea3b

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

+stdlib/+native/cpu_arch.m

Lines changed: 0 additions & 5 deletions
This file was deleted.

+stdlib/cpu_arch.m

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
%% CPU_ARCH get the CPU architecture
1+
%% CPU_ARCH get the Operating System CPU architecture
2+
%
3+
% This function retrieves the CPU architecture of the current operating system.
4+
% The physical CPU architecture can be obscured and even determining it in high-level
5+
% languages like Python is not exactly trivial.
6+
% This method is as used by
7+
% <https://cmake.org/cmake/help/latest/variable/CMAKE_HOST_SYSTEM_PROCESSOR.html CMake>.
28
%
39
%%% Outputs
4-
% * a: Returns the CPU architecture as a string.
5-
% * b: backend used
6-
7-
function [a, b] = cpu_arch(backend)
8-
arguments
9-
backend (1,:) string = ["java", "dotnet", "native"]
10-
end
10+
% * a: the CPU architecture as a character vector:
1111

12-
o = stdlib.Backend(mfilename(), backend);
13-
a = o.func();
12+
function a = cpu_arch()
1413

15-
b = o.backend;
14+
if ispc()
15+
a = getenv("PROCESSOR_ARCHITECTURE");
16+
else
17+
[~, a] = system('uname -m');
18+
a = strip(a);
19+
end
1620

1721
end
File renamed without changes.
File renamed without changes.

test/TestSys.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
properties (TestParameter)
7-
B_cpu_arch
87
B_cpu_load
98
B_ram_free
109
B_ram_total
@@ -17,8 +16,7 @@
1716
end
1817

1918
methods (TestParameterDefinition, Static)
20-
function [B_cpu_arch, B_cpu_load, B_ram_free, B_ram_total, B_is_admin, B_os_version, B_hostname, B_username, B_get_uid, B_get_process_priority] = setupBackends()
21-
B_cpu_arch = init_backend("cpu_arch");
19+
function [B_cpu_load, B_ram_free, B_ram_total, B_is_admin, B_os_version, B_hostname, B_username, B_get_uid, B_get_process_priority] = setupBackends()
2220
B_cpu_load = init_backend("cpu_load");
2321
B_ram_free = init_backend("ram_free");
2422
B_ram_total = init_backend("ram_total");
@@ -97,8 +95,8 @@ function test_username(tc, B_username)
9795
end
9896

9997

100-
function test_cpu_arch(tc, B_cpu_arch)
101-
arch = stdlib.cpu_arch(B_cpu_arch);
98+
function test_cpu_arch(tc)
99+
arch = stdlib.cpu_arch();
102100
tc.verifyClass(arch, 'char')
103101
tc.verifyGreaterThan(strlength(arch), 0, "CPU architecture should not be empty")
104102
end

0 commit comments

Comments
 (0)