summaryrefslogtreecommitdiff
path: root/jstests/core/hostinfo.js
blob: 04f341a659d9e49e3d698dbc7b83ee2cee5cadd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// @tags: [
//     # `hostInfo` command is not available on embedded
//     incompatible_with_embedded,
// ]
// SERVER-4615:  Ensure hostInfo() command returns expected results on each platform

(function() {
"use strict";
assert.commandWorked(db.hostInfo());
var hostinfo = db.hostInfo();

// test for os-specific fields
if (hostinfo.os.type == "Windows") {
    assert.neq(hostinfo.os.name, "" || null, "Missing Windows os name");
    assert.neq(hostinfo.os.version, "" || null, "Missing Windows version");

} else if (hostinfo.os.type == "Linux") {
    assert.neq(hostinfo.os.name, "" || null, "Missing Linux os/distro name");
    assert.neq(hostinfo.os.version, "" || null, "Missing Lindows version");

} else if (hostinfo.os.type == "Darwin") {
    assert.neq(hostinfo.os.name, "" || null, "Missing Darwin os name");
    assert.neq(hostinfo.os.version, "" || null, "Missing Darwin version");

} else if (hostinfo.os.type == "BSD") {
    assert.neq(hostinfo.os.name, "" || null, "Missing FreeBSD os name");
    assert.neq(hostinfo.os.version, "" || null, "Missing FreeBSD version");
}

jsTest.log(hostinfo);
// comment out this block for systems which have not implemented hostinfo.
if (hostinfo.os.type != "") {
    assert.neq(hostinfo.system.hostname, "" || null, "Missing Hostname");
    assert.neq(hostinfo.system.currentTime, "" || null, "Missing Current Time");
    assert.neq(hostinfo.system.cpuAddrSize, "" || null || 0, "Missing CPU Address Size");
    assert.neq(hostinfo.system.memSizeMB, "" || null, "Missing Memory Size");
    assert.neq(hostinfo.system.numCores, "" || null || 0, "Missing Number of Cores");
    assert.neq(hostinfo.system.cpuArch, "" || null, "Missing CPU Architecture");
    assert.neq(hostinfo.system.numaEnabled, "" || null, "Missing NUMA flag");
}

var buildInfo = assert.commandWorked(db.runCommand({buildInfo: 1}));
if (buildInfo.buildEnvironment && buildInfo.buildEnvironment.target_arch) {
    let targetArch = buildInfo.buildEnvironment.target_arch;
    if (targetArch == "i386")
        assert.eq(hostinfo.system.cpuAddrSize, 32);
    else
        assert.eq(hostinfo.system.cpuAddrSize, 64);
    assert.eq(hostinfo.system.cpuAddrSize, buildInfo.bits);
}
})();