beltex / SMCKit

Apple SMC library & tool
https://beltex.github.io/SMCKit
MIT License
473 stars 55 forks source link

Unit tests via XCTest #1

Closed beltex closed 9 years ago

beltex commented 10 years ago

Test:

beltex commented 9 years ago

Progress on this front. Bounds checks (min/max temperature), fail cases, and cross checks through I/O Kit or other (like DiscRecording framework for ODD). Though keep in mind, as mentioned in the test class, no matter what were limited, we can't validate actual temperature, fan RPM, etc.

beltex commented 9 years ago

I think the issue can be closed now, though of course, we still have the limitations mentioned before. Will continue to add and improve tests.

Also, came across two interesting things that could come in handy for this one way or another, still in the process of exploring them, will report back soon.

beltex commented 9 years ago

So the first of two, is Apple’s own powermetrics tool. In 10.10, it added an SMC sampler. This is awesome because as far as I know, it is the first publicly available tool from Apple that directly displays readings from the SMC, besides of course the Apple Hardware Test (AHT), but thats a bit different (have to boot from it, not practical to use). So we finally have an official reference. It's not open source at the moment, though not surprising given all that it does (check out the manual page, its a treat to read, lots of great info).

Here's a snippet of sample output from it

# Requires sudo by default unfortunately
$ sudo powermetrics -s smc -n 1

...

**** SMC sensors ****

CPU Thermal level: 0
IO Thermal level: 0
Fan: 1301 rpm
CPU die temperature: 58.16 C
Number of prochots: 0

So how does this help? Two things:

  1. Wanted to see what SMC keys it was using. Put together a DTrace script to get them. See Gist
  2. We can use it to validate some values by cross-checking with it. Put together a test that does this, see powermetricsTests dir.
beltex commented 9 years ago

The second thing that I came across was the Intel Power Gadget API. Pretty cool, has a nifty GUI app to go with it as well. It can get CPU temperature, which we could use to cross-check with. Problem is, requires installing a driver (kext) + framework. The need for a kext seems to be due to the rdmsr instruction, which can only be executed in kernel-space (temperature seems to be stored in a Model Specific Register - MSR). Could bundle it with SMCKit possibly to make that easier. Second, only works on second generation Intel Core 2 Duo chips and on.