Skip to content

Commit aaa81e4

Browse files
committed
simbatt: Provide instructions for how to test the driver
Add instructions for how to install the driver, simulate two batteries, modify battery parameters and clean up afterwards. The instructions assume that testsigning is already enabled with "bcdedit /set testsigning on" and that the driver signing certificate is trusted with "certutil.exe -addstore root simbatt.cer" and "certutil.exe -f -addstore trustedpublisher simbatt.cer".
1 parent dbfbead commit aaa81e4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

simbatt/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,39 @@ This source code is intended to demonstrate implementation of Windows battery dr
1717
This is a KMDF based sample.
1818

1919
You may use this sample as a starting point to implement a battery miniport specific to your needs.
20+
21+
22+
## How to test
23+
24+
### Driver installation
25+
```
26+
:: Install driver
27+
pnputil /add-driver simbatt.inf /install
28+
29+
:: Simulate two batteries
30+
devgen /add /instanceid 1 /hardwareid "{6B34C467-CE1F-4c0d-A3E4-F98A5718A9D6}\SimBatt"
31+
devgen /add /instanceid 2 /hardwareid "{6B34C467-CE1F-4c0d-A3E4-F98A5718A9D6}\SimBatt"
32+
```
33+
34+
### Modify battery parameters
35+
Parameters for each simulated battery can be changed through `IOCTL_SIMBATT_SET_STATUS` IOCTL calls with [`BATTERY_STATUS`](https://learn.microsoft.com/en-us/windows/win32/power/battery-status-str) input. This enables simulation of many power scenarios, such as low charge and switching between AC and DC power without physical batteries. One can in fact simulate multi-battery setups in a Virtual Machine (VM) this way.
36+
37+
Example of how to simulate 50% battery charge that is currently being discharged:
38+
```
39+
BATTERY_STATUS status = {};
40+
status.PowerState = BATTERY_DISCHARGING;
41+
status.Capacity = 50; // 50%
42+
status.Rate = BATTERY_UNKNOWN_RATE;
43+
status.Voltage = BATTERY_UNKNOWN_VOLTAGE;
44+
DeviceIoControl(battery, IOCTL_SIMBATT_SET_STATUS, &status, sizeof(status), nullptr, 0, nullptr, nullptr);
45+
```
46+
47+
### Driver uninstallation
48+
```
49+
:: Delete simulated batteries
50+
devgen /remove "SWD\DEVGEN\1"
51+
devgen /remove "SWD\DEVGEN\2"
52+
53+
:: Uninstall driver
54+
pnputil /delete-driver simbatt.inf /uninstall /force
55+
```

0 commit comments

Comments
 (0)