Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

Commit dc038c0

Browse files
committed
Implement check tool for HAXM
It is required that the host operating system to meet the environmental requirements to execute HAXM. This utility is used to check the system environment for HAXM. It supports: * To check below system status: - Intel CPU vendor - Long (64-bit) mode support status - VMX support status - VMX enabling status - EPT support status - NX support status - NX enabling status - Hyper-V disabling status - OS version - OS architecture - Guest occupancy status * Running on Windows and macOS. Signed-off-by: Wenchao Wang <[email protected]>
1 parent 68fdb30 commit dc038c0

21 files changed

+1813
-0
lines changed

CheckTool/.clang-format

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Refer to:
2+
# https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/.clang-format
3+
4+
BasedOnStyle: Chromium
5+
IndentWidth: 4
6+
ContinuationIndentWidth: 8
7+
AccessModifierOffset: -4

CheckTool/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Windows
2+
*.obj
3+
4+
# macOS
5+
*.o
6+

CheckTool/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Minimum requirement for CMake version
2+
cmake_minimum_required(VERSION 3.4)
3+
4+
# Project information
5+
project(checktool)
6+
7+
set(CMAKE_CXX_STANDARD 11)
8+
9+
set(COMMON_SRCS)
10+
list(APPEND COMMON_SRCS
11+
${PROJECT_SOURCE_DIR}/arg_parser.cpp
12+
${PROJECT_SOURCE_DIR}/common.cpp
13+
${PROJECT_SOURCE_DIR}/cpuid.cpp
14+
${PROJECT_SOURCE_DIR}/feature_detector.cpp
15+
${PROJECT_SOURCE_DIR}/main.cpp
16+
)
17+
18+
set(PLATFORM_SRCS)
19+
if(WIN32)
20+
list(APPEND PLATFORM_SRCS
21+
${PROJECT_SOURCE_DIR}/os_windows.cpp
22+
)
23+
# Replace MDd/MD with MTd/MT to use a multi-threaded statically-linked
24+
# runtime library for building a standalone executable.
25+
set(CXX_FLAGS
26+
CMAKE_CXX_FLAGS_DEBUG
27+
CMAKE_CXX_FLAGS_RELEASE
28+
)
29+
foreach(flag ${CXX_FLAGS})
30+
string(REPLACE "/MD" "/MT" ${flag} "${${flag}}")
31+
endforeach()
32+
elseif(APPLE)
33+
list(APPEND PLATFORM_SRCS
34+
${PROJECT_SOURCE_DIR}/os_darwin.cpp
35+
)
36+
else()
37+
message(FATAL_ERROR "Unsupported Platform")
38+
endif()
39+
40+
if(WIN32)
41+
set(RESOURCES)
42+
list(APPEND RESOURCES
43+
${PROJECT_SOURCE_DIR}/version.rc
44+
)
45+
endif()
46+
47+
# Target
48+
add_executable(checktool ${COMMON_SRCS} ${PLATFORM_SRCS} ${RESOURCES})
49+
50+
if(APPLE)
51+
target_link_options(checktool PRIVATE
52+
LINKER:-sectcreate,__TEXT,__info_plist,${PROJECT_SOURCE_DIR}/Info.plist
53+
)
54+
endif()

CheckTool/CMakeSettings.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "x86-Debug",
5+
"generator": "Ninja",
6+
"configurationType": "Debug",
7+
"inheritEnvironments": [
8+
"msvc_x86"
9+
],
10+
"buildRoot": "${projectDir}\\build\\${name}",
11+
"installRoot": "${projectDir}\\build\\${name}",
12+
"cmakeCommandArgs": "",
13+
"buildCommandArgs": "-v",
14+
"ctestCommandArgs": ""
15+
},
16+
17+
{
18+
"name": "x86-Release",
19+
"generator": "Ninja",
20+
"configurationType": "Release",
21+
"inheritEnvironments": [
22+
"msvc_x86"
23+
],
24+
"buildRoot": "${projectDir}\\build\\${name}",
25+
"installRoot": "${projectDir}\\build\\${name}",
26+
"cmakeCommandArgs": "",
27+
"buildCommandArgs": "-v",
28+
"ctestCommandArgs": ""
29+
},
30+
31+
{
32+
"name": "x64-Debug",
33+
"generator": "Ninja",
34+
"configurationType": "Debug",
35+
"inheritEnvironments": [
36+
"msvc_x64_x64"
37+
],
38+
"buildRoot": "${projectDir}\\build\\${name}",
39+
"installRoot": "${projectDir}\\build\\${name}",
40+
"cmakeCommandArgs": "",
41+
"buildCommandArgs": "-v",
42+
"ctestCommandArgs": ""
43+
},
44+
45+
{
46+
"name": "x64-Release",
47+
"generator": "Ninja",
48+
"configurationType": "Release",
49+
"inheritEnvironments": [
50+
"msvc_x64_x64"
51+
],
52+
"buildRoot": "${projectDir}\\build\\${name}",
53+
"installRoot": "${projectDir}\\build\\${name}",
54+
"cmakeCommandArgs": "",
55+
"buildCommandArgs": "-v",
56+
"ctestCommandArgs": ""
57+
}
58+
]
59+
}

CheckTool/Info.plist

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<!--
4+
Copyright (c) 2020 Intel Corporation
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
POSSIBILITY OF SUCH DAMAGE.
31+
-->
32+
<plist version="1.0">
33+
<dict>
34+
<key>CFBundleName</key>
35+
<string>checktool</string>
36+
<key>CFBundleIconFile</key>
37+
<string></string>
38+
<key>CFBundleVersion</key>
39+
<string>1</string>
40+
<key>NSHumanReadableCopyright</key>
41+
<string>&#xA9; 2020 Intel Corporation</string>
42+
<key>CFBundleGetInfoString</key>
43+
<string>Intel&#xAE; HAXM Check Tool 1.0.0</string>
44+
<key>CFBundleLongVersionString</key>
45+
<string>1.0.0.0</string>
46+
<key>CFBundleShortVersionString</key>
47+
<string>1.0.0</string>
48+
</dict>
49+
</plist>

CheckTool/README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Check Tool for Intel Hardware Accelerated Execution Manager
2+
3+
It is required that the host operating system to meet the environmental
4+
requirements to install HAXM. These requirements include Intel CPU verdor,
5+
enabling VMX, disabling Hyper-V, etc. Only when all the requirements are met,
6+
HAXM can be installed and executed properly. These wiki pages (installation
7+
instructions on [Windows][install-on-windows] and [macOS][install-on-macos])
8+
describe the configuration methods of HAXM installation prerequisites.
9+
10+
This utility is a command line tool for system checking for HAXM. It is used to
11+
help user to check the status of each condition in the current system
12+
environment, so as to determine whether the hardware configuration meets the
13+
requirements or which system settings need to be changed. This software
14+
currently supports running on Windows and macOS.
15+
16+
## Downloads
17+
18+
The latest release of HAXM **Check Tool** for Windows and macOS hosts are
19+
available [here][checktool-release].
20+
21+
## Windows
22+
23+
### Usage
24+
25+
1. `cd X:\path\to\CheckTool`
26+
1. `checktool.exe --verbose`
27+
28+
The output will be as below.
29+
30+
CPU vendor * GenuineIntel
31+
Intel64 supported * Yes
32+
VMX supported * Yes
33+
VMX enabled * Yes
34+
EPT supported * Yes
35+
NX supported * Yes
36+
NX enabled * Yes
37+
Hyper-V disabled - No
38+
OS version * Windows 10.0.18363
39+
OS architecture * x86_64
40+
Guest unoccupied * Yes. 0 guest(s)
41+
42+
"*" represents the item is passed, while "-" represents the item is failed.
43+
44+
### Build
45+
46+
#### Prerequisites
47+
48+
[Visual Studio][visualstudio] 2017 or later
49+
50+
Install the following components: **Desktop development with C++** (**C++ CMake
51+
tools for Windows** is included)
52+
53+
#### Build steps
54+
55+
**Option A (Visual Studio)**
56+
57+
1. Open _CheckTool_ project in Visual Studio.
58+
59+
**File** > **Open** > **Folder...** > **Select Folder** "CheckTool"
60+
(containing _CMakeLists.txt_)
61+
1. Select proper configuration, e.g., "x86-Debug".
62+
1. Build project.
63+
64+
**Build** > **Build All**
65+
66+
The executable program (_checktool.exe_) will be generated in
67+
_X:\path\to\CheckTool\build\x86-Debug\\_. The 32-bit executable can run on both
68+
32-bit and 64-bit Windows, while the 64-bit executable can run on 64-bit Windows
69+
only.
70+
71+
**Option B (CMake)**
72+
73+
1. `set PATH=C:\Program Files (x86)\Microsoft Visual `
74+
`Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;%PATH%`
75+
1. `cd X:\path\to\CheckTool`
76+
1. `mkdir build && cd build && cmake .. && cmake --build .`
77+
78+
The executable program (_checktool.exe_) will be generated in
79+
_X:\path\to\CheckTool\build\Debug\\_. It is easy to clean the build just by
80+
removing the _build_ folder manually.
81+
82+
The full matrix for building 32-bit/64-bit Windows with Debug/Release
83+
configuration can be referred as below.
84+
85+
| | 32-bit Build | 64-bit Build
86+
----------- | -------------------------------------------- | ------------------------------------------
87+
| | `cmake -A Win32 -B build\Win32` | `cmake -A x64 -B build\x64`
88+
**Debug** | `cmake --build build\Win32 --config Debug` | `cmake --build build\x64 --config Debug`
89+
**Release** | `cmake --build build\Win32 --config Release` | `cmake --build build\x64 --config Release`
90+
91+
The path in the first step is the CMake default extension path installed in
92+
Visual Studio 2019. If [CMake][cmake] (3.17 or later) has been installed
93+
independently and added to the system path, the first step of setting path can
94+
be omitted.
95+
96+
## macOS
97+
98+
### Usage
99+
100+
1. `cd /path/to/CheckTool`
101+
1. `./checktool --verbose`
102+
103+
### Build
104+
105+
#### Prerequisites
106+
107+
* [Xcode][xcode] 7.2.1 or later
108+
* [CMake][cmake] 3.17 or later
109+
110+
#### Build steps
111+
112+
1. `cd /path/to/CheckTool`
113+
1. `mkdir build && cd build && cmake .. && make`
114+
115+
The binary (_checktool_) will be generated in _/path/to/CheckTool/build/_. It is
116+
easy to clean the build just by removing the _build_ folder manually.
117+
118+
The full list for building Debug/Release configuration can be referred as
119+
below.
120+
121+
| Debug
122+
| :--------------------------------------------------
123+
| `cmake -DCMAKE_BUILD_TYPE=Debug -B build/Debug`
124+
| `make -C build/Debug`
125+
| **Release**
126+
| `cmake -DCMAKE_BUILD_TYPE=Release -B build/Release`
127+
| `make -C build/Release`
128+
129+
[checktool-release]: https://github.com/intel/haxm/releases/tag/checktool-v1.0.0
130+
[cmake]: https://cmake.org/download/
131+
[install-on-macos]:
132+
https://github.com/intel/haxm/wiki/Installation-Instructions-on-macOS
133+
[install-on-windows]:
134+
https://github.com/intel/haxm/wiki/Installation-Instructions-on-Windows
135+
[visualstudio]: https://www.visualstudio.com/downloads/
136+
[xcode]: https://developer.apple.com/xcode/

CheckTool/arg_parser.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2020 Intel Corporation
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* 3. Neither the name of the copyright holder nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include "arg_parser.h"
32+
33+
namespace haxm {
34+
namespace check_util {
35+
36+
ArgParser::ArgParser(int &argc, char *argv[],
37+
const std::vector<std::string> &valid_options) {
38+
valid_options_ = valid_options;
39+
40+
for (int i = 1; i < argc; ++i) {
41+
args_.push_back(std::string(argv[i]));
42+
}
43+
}
44+
45+
bool ArgParser::Verify() {
46+
for (std::vector<std::string>::const_iterator it = args_.begin();
47+
it != args_.end(); ++it) {
48+
if (std::find(valid_options_.begin(), valid_options_.end(), *it)
49+
== valid_options_.end()) {
50+
error_ = *it;
51+
return false;
52+
}
53+
}
54+
return true;
55+
}
56+
57+
bool ArgParser::Test(const std::string &option) const {
58+
return std::find(args_.begin(), args_.end(), option) != args_.end();
59+
}
60+
61+
std::string ArgParser::error() const {
62+
return error_;
63+
}
64+
65+
} // namespace check_util
66+
} // namespace haxm

0 commit comments

Comments
 (0)