Skip to content

Commit 04baec1

Browse files
committed
ad9371: unit test fixes
Signed-off-by: IonutMuthi <Ionut.Muthi@analog.com>
1 parent e0768cf commit 04baec1

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

js/testAutomations/ad9371/ad9371_Basic_Unit_test.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,21 +2388,26 @@ TestFramework.runTest("UNIT.CAL.FULL_CALIBRATION_FLOW", function() {
23882388
msleep(500);
23892389

23902390
// Trigger calibration
2391-
ad9371.calibrate();
2391+
var calOk = ad9371.calibrate();
23922392
msleep(2000);
23932393

2394-
// Verify flags still set
2395-
var rxQec = ad9371.getCalibrateRxQecEn();
2396-
var txQec = ad9371.getCalibrateTxQecEn();
2397-
printToConsole(" After calibrate: rx_qec=" + rxQec + " tx_qec=" + txQec);
2398-
2399-
// Restore
2394+
// Restore before any return path
24002395
ad9371.setCalibrateRxQecEn(origRxQec);
24012396
ad9371.setCalibrateTxQecEn(origTxQec);
24022397
ad9371.setCalibrateTxLolEn(origTxLol);
24032398
ad9371.setCalibrateTxLolExtEn(origTxLolExt);
24042399
msleep(500);
24052400

2401+
if (!calOk) {
2402+
printToConsole(" FAIL: Calibration returned error from hardware");
2403+
return false;
2404+
}
2405+
2406+
// Verify flags still set after successful calibration
2407+
var rxQec = ad9371.getCalibrateRxQecEn();
2408+
var txQec = ad9371.getCalibrateTxQecEn();
2409+
printToConsole(" After calibrate: rx_qec=" + rxQec + " tx_qec=" + txQec);
2410+
24062411
return true;
24072412
} catch (e) {
24082413
printToConsole(" Error: " + e);
@@ -2888,7 +2893,7 @@ TestFramework.runTest("UNIT.BADVAL.TX_LO_FREQUENCY", function() {
28882893
printToConsole(" Wrote 0 MHz, read=" + readBack);
28892894

28902895
// Should either clamp to min or reject — value should not be 0
2891-
var passed = (parseFloat(readBack) >= 300);
2896+
var passed = (parseFloat(readBack) >= 70);
28922897
if (!passed) {
28932898
printToConsole(" FAIL: TX LO accepted invalid frequency 0 MHz");
28942899
}

packages/ad9371/plugins/ad9371plugin/include/ad9371plugin/ad9371_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class SCOPY_AD9371PLUGIN_EXPORT Ad9371_API : public ApiObject
5858
Q_INVOKABLE void setCalibrateClgcEn(const QString &val);
5959
Q_INVOKABLE QString getCalibrateVswrEn();
6060
Q_INVOKABLE void setCalibrateVswrEn(const QString &val);
61-
Q_INVOKABLE void calibrate();
61+
Q_INVOKABLE bool calibrate();
6262

6363
// --- RX Chain ---
6464
Q_INVOKABLE QString getRxRfBandwidth();

packages/ad9371/plugins/ad9371plugin/src/ad9371_api.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,25 +384,27 @@ void Ad9371_API::setCalibrateVswrEn(const QString &v)
384384
iio_device_attr_write_bool(tool->m_dev, "calibrate_vswr_en", v.toInt() != 0);
385385
}
386386

387-
void Ad9371_API::calibrate()
387+
bool Ad9371_API::calibrate()
388388
{
389389
// Direct IIO write — no widget for write-only trigger
390390
ConnectionProvider *cp = ConnectionProvider::GetInstance();
391391
Connection *conn = cp->open(m_plugin->m_param);
392392
if(!conn) {
393393
qWarning(CAT_AD9371_API) << "Failed to open connection for calibrate";
394-
return;
394+
return false;
395395
}
396396
iio_device *dev = iio_context_find_device(conn->context(), "ad9371-phy");
397397
if(!dev) {
398398
qWarning(CAT_AD9371_API) << "ad9371-phy device not found";
399-
return;
399+
return false;
400400
}
401401
int ret = iio_device_attr_write_bool(dev, "calibrate", true);
402-
if(ret < 0)
402+
if(ret < 0) {
403403
qWarning(CAT_AD9371_API) << "Calibration failed:" << ret;
404-
else
405-
qDebug(CAT_AD9371_API) << "Calibration triggered";
404+
return false;
405+
}
406+
qDebug(CAT_AD9371_API) << "Calibration triggered";
407+
return true;
406408
}
407409

408410
// --- RX Chain ---

0 commit comments

Comments
 (0)