-
-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit-test and fix the Belkin/Liebert HID UPS exponents math #2371
Unit-test and fix the Belkin/Liebert HID UPS exponents math #2371
Conversation
…-up] Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
…methods [networkupstools#2370] Signed-off-by: Jim Klimov <[email protected]>
…its build differently [networkupstools#2371] Signed-off-by: Jim Klimov <[email protected]>
…point with == or != is unsafe [-Werror,-Wfloat-equal]" [networkupstools#2371] Signed-off-by: Jim Klimov <[email protected]>
…became quite specific to that subdriver source Still, can serve as an example/blueprint for other drivers' tests. Signed-off-by: Jim Klimov <[email protected]>
…texponenttest-belkin-hid Suffices that we #include it in the test source, and drivers/ are among include dirs Signed-off-by: Jim Klimov <[email protected]>
❌ Build nut 2.8.1.1610-master failed (commit 028478361a by @jimklimov) |
…un() and friends Signed-off-by: Jim Klimov <[email protected]>
I think I've picked my way through that The original logic seems to have been like "check if we have a value 0..199: subtract 100, and if resulting module is within 100 - pick corresponding multiplier". Actually the old original (with Fixing this into "subtract 100, and if resulting module is within 300 - pick corresponding multiplier" should match practical voltages from 0 to 380 (three-pole) with the same order of magnitudes in question. Any objections? :) |
… (over 200V) Signed-off-by: Jim Klimov <[email protected]>
…0..500V range (cover 3-pole while we are at it) Not touching liebert_config_voltage_fun() at the moment as have no non-integer examples under hand to test against. Signed-off-by: Jim Klimov <[email protected]>
Fix in driver proposed, testing on HW would be very welcome :) |
✅ Build nut 2.8.1.1613-master completed (commit cc082b5ca9 by @jimklimov) |
…ert_psi5_line_voltage_fun() into common liebert_line_voltage_fun() Hopefully should help more devices than those which serve this or that HID subtree only. Follows up from PR networkupstools#2369 Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
Cheers, any chance for practical testing, to merge the PR this weekend? <3 :) |
I can try it out tomorrow |
Gentle bump, itching to release this fix :) |
…stools#2371] Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
As raised on the mailing list at https://alioth-lists.debian.net/pipermail/nut-upsuser/2024-March/013626.html as well as in discussions for #2271, #2369 and #2370, there is some mess in exponents calculation of
drivers/belkin-hid.c
, where the driver tries to adjust for what seems wrongly encoded voltage readings in USB HID reports, which may be off by some orders of magnitude (3, 7...) depending on reading type and HW/FW model.As detailed in #2370 (comment) : The original logic which purported to fix this was broken, but by coincidence seems to have taken the right code path for the majority of devices up till NUT v2.7.4. This was fixed in NUT v2.8.0 to correct logic, but the order of magnitude estimation results no longer fit the devices' outputs, so the scaling was not applied and this caused various voltages to be reported as zeroes - causing a practical regression.
As suggested in recent discussions on the matter, this PR adds a (rather ugly, but functional) way to test the helper conversion methods "in-vivo" - in the practically unmodified sub-driver code, mocking the methods and variables it refers to elsewhere. Maybe this can be done even without the currently posted change to no longer mark
static
the variables and methods we need for a test, either by#include
of the driver source into a test program, or by shipping test methods as part of a driver/program source and/or custom-built binary (ZeroMQ style) - something to refine later. UPDATE: Went for including at the moment, was not hard after the other mock preparations.At the moment the test is functional in terms of calling one of the 3 methods currently provided by the driver source (1 added in #2369) and finding that the original method fixed in 2.8.0 (to check those clauses as floating-point numbers and not zeroed out rounded integers) indeed failed to work for the typical values it expected to process.
From this point, some TDD can be done to adjust the implementations... and I suppose the
liebert_psi5_line_voltage_mult()
checks can be merged withliebert_line_voltage_mult()
as was originally intended in PoC code posted in issue #2271 - there's little left to break in the original one, it seems.(CC @jrjparks @clepple @aquette @digitlman @electroflame)