Skip to content

Commit 52e7f33

Browse files
committed
fixed --brand-list and windows ci/cd tests
1 parent 6886678 commit 52e7f33

3 files changed

Lines changed: 126 additions & 129 deletions

File tree

.github/workflows/cross-platform-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ jobs:
352352
shell: pwsh
353353
run: |
354354
$bin = Get-ChildItem build -Filter "*.exe" | Select-Object -First 1 -ExpandProperty FullName
355-
pwsh auxiliary/test_cli.ps1 -BIN $bin
355+
pwsh auxiliary/test_cli.ps1 -BIN $bin -TIMEOUT_SECS 10
356356
357357
platform-builds:
358358
needs: [linux, macos, windows]

auxiliary/test_cli.ps1

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,24 @@ function Fail-Test([string]$desc) { Write-Host " FAIL $desc"; $script:fail++ }
1919

2020
# Runs the binary with $binArgs. Returns ([string] output, [int] exitCode).
2121
# exitCode is -99 on timeout. $captureStderr controls whether stderr is merged.
22+
# Uses Start-Job + & operator so the process inherits a proper console context,
23+
# matching how the "Full CLI output" step runs the binary directly.
2224
function invoke_bin([string[]]$binArgs, [bool]$captureStderr = $true) {
23-
$tmpOut = New-TemporaryFile
24-
$tmpErr = New-TemporaryFile
25-
try {
26-
$proc = Start-Process `
27-
-FilePath $script:BIN `
28-
-ArgumentList $binArgs `
29-
-NoNewWindow `
30-
-PassThru `
31-
-RedirectStandardOutput $tmpOut.FullName `
32-
-RedirectStandardError $tmpErr.FullName
33-
34-
$finished = $proc.WaitForExit($script:TIMEOUT_SECS * 1000)
35-
if (-not $finished) {
36-
$proc.Kill()
37-
return $null, -99
38-
}
39-
40-
$out = (Get-Content $tmpOut.FullName -Raw) ?? ""
41-
if ($captureStderr) {
42-
$out += (Get-Content $tmpErr.FullName -Raw) ?? ""
43-
}
44-
return $out.TrimEnd(), $proc.ExitCode
45-
} finally {
46-
Remove-Item $tmpOut.FullName, $tmpErr.FullName -Force -ErrorAction SilentlyContinue
25+
$job = Start-Job -ScriptBlock {
26+
param($bin, $args, $captureErr)
27+
$out = if ($captureErr) { & $bin @args 2>&1 } else { & $bin @args }
28+
[PSCustomObject]@{ Output = ($out -join "`n"); ExitCode = $LASTEXITCODE }
29+
} -ArgumentList $script:BIN, $binArgs, $captureStderr
30+
31+
if ($job | Wait-Job -Timeout $script:TIMEOUT_SECS) {
32+
$result = Receive-Job $job
33+
Remove-Job $job -Force
34+
return ($result?.Output ?? ""), ($result?.ExitCode ?? 0)
4735
}
36+
37+
Stop-Job $job
38+
Remove-Job $job -Force
39+
return $null, -99
4840
}
4941

5042
function check([string]$desc, [string[]]$binArgs) {
@@ -83,50 +75,55 @@ function range_out([string]$desc, [int]$lo, [int]$hi, [string[]]$binArgs) {
8375
Write-Host "=== vmaware CLI tests ==="
8476
Write-Host ""
8577

86-
# --- exit codes ---
78+
# exit codes (cheap flags only — no full detection scan)
8779
Write-Host "exit codes"
8880
check "--help exits 0" @("--help")
8981
check "--version exits 0" @("--version")
9082
check "--brand-list exits 0" @("--brand-list")
91-
check "--detect exits 0" @("--detect")
92-
check "--percent exits 0" @("--percent")
93-
check "--brand exits 0" @("--brand")
94-
check "--type exits 0" @("--type")
95-
check "--conclusion exits 0" @("--conclusion")
9683
check "--number exits 0" @("--number")
97-
98-
$out, $code = invoke_bin @("--stdout")
99-
if ($code -eq -99) { Fail-Test "--stdout exits 0 or 1 (timeout after ${TIMEOUT_SECS}s)" }
100-
elseif ($code -le 1) { ok "--stdout exits 0 or 1" }
101-
else { Fail-Test "--stdout exits 0 or 1" }
102-
10384
check_fails "unknown arg exits non-zero" @("--this-arg-does-not-exist")
10485

105-
# --- short-flag aliases ---
86+
# short-flag aliases (cheap flags only)
10687
Write-Host ""
10788
Write-Host "short flag aliases"
10889
check "-h exits 0" @("-h")
10990
check "-v exits 0" @("-v")
110-
check "-a exits 0" @("-a", "--detect")
111-
check "-d exits 0" @("-d")
112-
check "-b exits 0" @("-b")
113-
check "-p exits 0" @("-p")
114-
check "-c exits 0" @("-c")
11591
check "-n exits 0" @("-n")
116-
check "-t exits 0" @("-t")
11792
check "-l exits 0" @("-l")
11893

119-
# --- output format ---
94+
# output format + exit codes for full-scan flags (one scan per flag)
12095
Write-Host ""
12196
Write-Host "output format"
12297
match_out "--detect outputs 0 or 1" '^[01]$' @("--detect")
12398
range_out "--percent outputs 0-100" 0 100 @("--percent")
12499
match_out "--number outputs a positive int" '^[1-9][0-9]*$' @("--number")
100+
101+
$out, $code = invoke_bin @("--stdout")
102+
if ($code -eq -99) { Fail-Test "--stdout exits 0 or 1 (timeout after ${TIMEOUT_SECS}s)" }
103+
elseif ($code -le 1) { ok "--stdout exits 0 or 1" }
104+
else { Fail-Test "--stdout exits 0 or 1" }
105+
125106
match_out "--brand outputs a non-empty line" '.' @("--brand")
126107
match_out "--type outputs a non-empty line" '.' @("--type")
127108
match_out "--conclusion outputs a sentence" '.' @("--conclusion")
128109

129-
# --- no-ansi strips escape codes ---
110+
# short-flag aliases for full-scan flags (reuse match_out to avoid duplicate scans)
111+
Write-Host ""
112+
Write-Host "short flag aliases (full-scan)"
113+
match_out "-d outputs 0 or 1" '^[01]$' @("-d")
114+
match_out "-b outputs a non-empty line" '.' @("-b")
115+
match_out "-p outputs 0-100" '^[0-9]+$' @("-p")
116+
match_out "-c outputs a sentence" '.' @("-c")
117+
match_out "-t outputs a non-empty line" '.' @("-t")
118+
119+
$out, $code = invoke_bin @("-s")
120+
if ($code -eq -99) { Fail-Test "-s exits 0 or 1 (timeout after ${TIMEOUT_SECS}s)" }
121+
elseif ($code -le 1) { ok "-s exits 0 or 1" }
122+
else { Fail-Test "-s exits 0 or 1" }
123+
124+
check "-a exits 0" @("-a", "--detect")
125+
126+
# no-ansi strips escape codes
130127
Write-Host ""
131128
Write-Host "no-ansi"
132129
$ansiOut, $_ = invoke_bin @("--no-ansi")
@@ -136,7 +133,7 @@ if ($ansiOut -match '\x1B\[') {
136133
ok "--no-ansi output contains no ANSI escape codes"
137134
}
138135

139-
# --- technique count ---
136+
# technique count
140137
Write-Host ""
141138
Write-Host "technique count"
142139
$nOut, $_ = invoke_bin @("--number") $false
@@ -147,14 +144,14 @@ if ($n -match '^\d+$' -and [int]$n -gt 10) {
147144
Fail-Test "--number returned unexpected value: $n"
148145
}
149146

150-
# --- mutual exclusion ---
147+
# mutual exclusion
151148
Write-Host ""
152149
Write-Host "mutual exclusion"
153150
check_fails "--detect + --brand rejected" @("--detect", "--brand")
154151
check_fails "--percent + --brand rejected" @("--percent", "--brand")
155152
check_fails "--stdout + --detect rejected" @("--stdout", "--detect")
156153

157-
# --- --disable: valid names ---
154+
# --disable: valid names
158155
Write-Host ""
159156
Write-Host "--disable (valid names)"
160157
check "--disable single name works" @("--disable", "HYPERVISOR_BIT", "--detect")
@@ -168,13 +165,13 @@ check "--disable HYPERVISOR_HOOK works" @("--disable", "HYPERVISOR_HOO
168165
check "--disable SINGLE_STEP works" @("--disable", "SINGLE_STEP", "--detect")
169166
check "--disable DBVM works" @("--disable", "DBVM", "--detect")
170167

171-
# --- --disable: invalid names ---
168+
# --disable: invalid names
172169
Write-Host ""
173170
Write-Host "--disable (invalid names)"
174171
check_fails "--disable bogus name fails" @("--disable", "NOT_A_REAL_TECHNIQUE", "--detect")
175172
check_fails "--disable MULTIPLE (setting) fails" @("--disable", "MULTIPLE", "--detect")
176173

177-
# --- --disable reflected in general output ---
174+
# --disable reflected in general output
178175
Write-Host ""
179176
Write-Host "--disable reflected in general output"
180177
$disOut, $_ = invoke_bin @("--no-ansi", "--disable", "HYPERVISOR_BIT")
@@ -184,7 +181,7 @@ if ($disOut -match "Skipped CPUID hypervisor bit") {
184181
Fail-Test "--disable HYPERVISOR_BIT not reflected in general output"
185182
}
186183

187-
# --- --high-threshold ---
184+
# --high-threshold
188185
Write-Host ""
189186
Write-Host "--high-threshold"
190187
$pNOut, $_ = invoke_bin @("--percent") $false
@@ -197,18 +194,18 @@ if ($pN -ge $pH) {
197194
Fail-Test "--high-threshold produced higher percentage ($pN -> $pH)"
198195
}
199196

200-
# --- --all ---
197+
# --all
201198
Write-Host ""
202199
Write-Host "--all"
203200
check "--all --detect exits 0" @("--all", "--detect")
204201
check "--all --percent exits 0" @("--all", "--percent")
205202

206-
# --- --dynamic ---
203+
# --dynamic
207204
Write-Host ""
208205
Write-Host "--dynamic"
209206
check "--dynamic --conclusion exits 0" @("--dynamic", "--conclusion")
210207

211-
# --- --json ---
208+
# --json
212209
Write-Host ""
213210
Write-Host "--json"
214211
$tmpJson = [System.IO.Path]::GetTempFileName() + ".json"
@@ -234,7 +231,7 @@ try {
234231
if (Test-Path $tmpJson) { Remove-Item $tmpJson -Force }
235232
}
236233

237-
# --- --brand-list ---
234+
# --brand-list
238235
Write-Host ""
239236
Write-Host "--brand-list"
240237
$blOut, $_ = invoke_bin @("--brand-list") $false
@@ -246,7 +243,7 @@ if ($count -gt 5) {
246243
Fail-Test "--brand-list returned too few entries ($count lines)"
247244
}
248245

249-
# --- summary ---
246+
# summary
250247
Write-Host ""
251248
Write-Host "==========================="
252249
Write-Host " Passed: $($script:pass)"

src/cli/main.cpp

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -93,78 +93,78 @@ R"(Usage:
9393

9494
[[noreturn]] static void brand_list() {
9595
std::cout <<
96-
R"(VirtualBox
97-
VMware
98-
VMware Express
99-
VMware ESX
100-
VMware GSX
101-
VMware Workstation
102-
VMware Fusion
103-
bhyve
104-
QEMU
105-
KVM
106-
KVM Hyper-V Enlightenment
107-
QEMU+KVM Hyper-V Enlightenment
108-
QEMU+KVM
109-
Virtual PC
110-
Microsoft Hyper-V
111-
Microsoft Virtual PC/Hyper-V
112-
Parallels
113-
Xen HVM
114-
ACRN
115-
QNX hypervisor
116-
Hybrid Analysis
117-
Sandboxie
118-
Docker
119-
Wine
120-
Anubis
121-
JoeBox
122-
ThreatExpert
123-
CWSandbox
124-
Comodo
125-
Bochs
126-
Lockheed Martin LMHS
127-
NVMM
128-
OpenBSD VMM
129-
Intel HAXM
130-
Unisys s-Par
131-
Cuckoo
132-
BlueStacks
133-
Jailhouse
134-
Apple VZ
135-
Intel KGT (Trusty)
136-
Microsoft Azure Hyper-V
137-
Xbox NanoVisor (Hyper-V)
138-
SimpleVisor
139-
Hyper-V artifact (host with Hyper-V enabled)
140-
User-mode Linux
141-
IBM PowerVM
142-
Google Compute Engine (KVM)
143-
OpenStack (KVM)
144-
KubeVirt (KVM)
145-
AWS Nitro System (KVM-based)
146-
Podman
147-
WSL
148-
OpenVZ
149-
ANY.RUN
150-
Barevisor
151-
HyperPlatform
152-
MiniVisor
153-
Intel TDX
154-
LKVM
155-
AMD SEV
156-
AMD SEV-ES
157-
AMD SEV-SNP
158-
Neko Project II
159-
NoirVisor
160-
Qihoo 360 Sandbox
161-
DBVM
162-
UTM
163-
Compaq FX!32
164-
Insignia RealPC
165-
Connectix Virtual PC
166-
Containerd
167-
)";
96+
R"(VirtualBox
97+
VMware
98+
VMware Express
99+
VMware ESX
100+
VMware GSX
101+
VMware Workstation
102+
VMware Fusion
103+
bhyve
104+
QEMU
105+
KVM
106+
KVM Hyper-V Enlightenment
107+
QEMU+KVM Hyper-V Enlightenment
108+
QEMU+KVM
109+
Virtual PC
110+
Microsoft Hyper-V
111+
Microsoft Virtual PC/Hyper-V
112+
Parallels
113+
Xen HVM
114+
ACRN
115+
QNX hypervisor
116+
Hybrid Analysis
117+
Sandboxie
118+
Docker
119+
Wine
120+
Anubis
121+
JoeBox
122+
ThreatExpert
123+
CWSandbox
124+
Comodo
125+
Bochs
126+
Lockheed Martin LMHS
127+
NVMM
128+
OpenBSD VMM
129+
Intel HAXM
130+
Unisys s-Par
131+
Cuckoo
132+
BlueStacks
133+
Jailhouse
134+
Apple VZ
135+
Intel KGT (Trusty)
136+
Microsoft Azure Hyper-V
137+
Xbox NanoVisor (Hyper-V)
138+
SimpleVisor
139+
Hyper-V artifact (host with Hyper-V enabled)
140+
User-mode Linux
141+
IBM PowerVM
142+
Google Compute Engine (KVM)
143+
OpenStack (KVM)
144+
KubeVirt (KVM)
145+
AWS Nitro System (KVM-based)
146+
Podman
147+
WSL
148+
OpenVZ
149+
ANY.RUN
150+
Barevisor
151+
HyperPlatform
152+
MiniVisor
153+
Intel TDX
154+
LKVM
155+
AMD SEV
156+
AMD SEV-ES
157+
AMD SEV-SNP
158+
Neko Project II
159+
NoirVisor
160+
Qihoo 360 Sandbox
161+
DBVM
162+
UTM
163+
Compaq FX!32
164+
Insignia RealPC
165+
Connectix Virtual PC
166+
Containerd
167+
)";
168168
std::exit(0);
169169
}
170170

0 commit comments

Comments
 (0)