1. add int, double reading in JsonProcessor
This commit is contained in:
@@ -6,6 +6,9 @@
|
|||||||
"test_set_micron_MT29F16G08AJADAWP.json",
|
"test_set_micron_MT29F16G08AJADAWP.json",
|
||||||
"test_readSnapshot_HK.json",
|
"test_readSnapshot_HK.json",
|
||||||
"test_get_badBlockMap_fromNAND.json",
|
"test_get_badBlockMap_fromNAND.json",
|
||||||
|
"test_readSnapshot_HK.json",
|
||||||
|
"test_erase_all.json",
|
||||||
|
"test_abort.json",
|
||||||
"test_readSnapshot_HK.json"
|
"test_readSnapshot_HK.json"
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|||||||
@@ -138,6 +138,22 @@ void JsonProcessor::jsonGetStrValue(QJsonObject obj, QString paramName, QString
|
|||||||
{ paramValue = val; }
|
{ paramValue = val; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int JsonProcessor::jsonGetIntValue(QJsonObject obj, QString paramName, QString jsonObjName)
|
||||||
|
{
|
||||||
|
QJsonValue val = obj[paramName];
|
||||||
|
if (val == QJsonValue::Null)
|
||||||
|
{ throw(ErrInJsonSet(jsonPath, jsonObjName, paramName, "parameter is missing")); }
|
||||||
|
return val.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
double JsonProcessor::jsonGetDoubleValue(QJsonObject obj, QString paramName, QString jsonObjName)
|
||||||
|
{
|
||||||
|
QJsonValue val = obj[paramName];
|
||||||
|
if (val == QJsonValue::Null)
|
||||||
|
{ throw(ErrInJsonSet(jsonPath, jsonObjName, paramName, "parameter is missing")); }
|
||||||
|
return val.toDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void JsonProcessor::jsonSetComPortSettings(QString jsonObjName, QJsonObject obj, comSettings_t &com)
|
void JsonProcessor::jsonSetComPortSettings(QString jsonObjName, QJsonObject obj, comSettings_t &com)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public:
|
|||||||
virtual void jsonSaveComPortSettings(QJsonObject &obj, comSettings_t &com);
|
virtual void jsonSaveComPortSettings(QJsonObject &obj, comSettings_t &com);
|
||||||
|
|
||||||
virtual void jsonGetStrValue(QJsonObject obj, QString paramName, QString ¶mValue, QString jsonObjName);
|
virtual void jsonGetStrValue(QJsonObject obj, QString paramName, QString ¶mValue, QString jsonObjName);
|
||||||
|
virtual int jsonGetIntValue(QJsonObject obj, QString paramName, QString jsonObjName);
|
||||||
|
virtual double jsonGetDoubleValue(QJsonObject obj, QString paramName, QString jsonObjName);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -237,16 +237,13 @@ bool UARTFixture::validateTextResponse(const QByteArray& rx,
|
|||||||
return passed;
|
return passed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UARTFixture::runTextCase(const QJsonObject& cfg, QString caseFile)
|
bool UARTFixture::runTextCase(const QJsonObject& cfg, QString caseFile, QString jsonObjName)
|
||||||
{
|
{
|
||||||
QByteArray tx;
|
QByteArray tx;
|
||||||
QString binaryFname = cfg["binary"].toString();
|
QString binaryFname;
|
||||||
|
JsonProcessor json;
|
||||||
if (binaryFname.isEmpty())
|
json.setJsonFile(caseFile);
|
||||||
{
|
json.jsonGetStrValue(cfg, "binary", binaryFname, jsonObjName);
|
||||||
writeToLog(QString("'binary' field not found in %1").arg(caseFile), false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!loadBinaryFile(binaryFname, tx)) { return false; }
|
if (!loadBinaryFile(binaryFname, tx)) { return false; }
|
||||||
if (!sendCommand(tx)) { return false; }
|
if (!sendCommand(tx)) { return false; }
|
||||||
@@ -294,35 +291,26 @@ bool UARTFixture::prepareBinaryCommand(const QJsonObject& cfg, QByteArray& data)
|
|||||||
bool UARTFixture::validateStructField(const QByteArray& rxData,
|
bool UARTFixture::validateStructField(const QByteArray& rxData,
|
||||||
const QJsonObject& fieldCfg,
|
const QJsonObject& fieldCfg,
|
||||||
const QJsonObject& structJson,
|
const QJsonObject& structJson,
|
||||||
|
QString& structJsonFname,
|
||||||
QString& errMsg,
|
QString& errMsg,
|
||||||
QString& errMsgMismatch,
|
QString& errMsgMismatch,
|
||||||
QString caseFile)
|
QString caseFile,
|
||||||
|
QString jsonObjName)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
QJsonObject fieldInfo;
|
QJsonObject fieldInfo;
|
||||||
QString fieldName, fieldType, op;
|
QString fieldName, fieldType, op;
|
||||||
bool isArray = false;
|
bool isArray = false;
|
||||||
QJsonArray fields;
|
QJsonArray fields;
|
||||||
|
JsonProcessor json;
|
||||||
|
json.setJsonFile(caseFile);
|
||||||
|
|
||||||
fieldName = fieldCfg["field"].toString();
|
json.jsonGetStrValue(fieldCfg, "field", fieldName, jsonObjName);
|
||||||
if (fieldName.isEmpty())
|
json.jsonGetStrValue(fieldCfg, "type", fieldType, jsonObjName);
|
||||||
{
|
json.jsonGetStrValue(fieldCfg, "op", op, jsonObjName);
|
||||||
writeToLog(QString("'field' field not found or incorrect in %1").arg(caseFile), false);
|
double expectValue = json.jsonGetDoubleValue(fieldCfg, "expect", jsonObjName);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
fieldType = fieldCfg["type"].toString();
|
|
||||||
if (fieldType.isEmpty())
|
|
||||||
{
|
|
||||||
writeToLog(QString("'type' field not found or incorrect in %1").arg(caseFile), false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
op = fieldCfg["op"].toString("==");
|
|
||||||
if (op.isEmpty())
|
|
||||||
{
|
|
||||||
writeToLog(QString("'op' field not found or incorrect in %1").arg(caseFile), false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// !!! array field is not necessary so not nececarry using JsonProcessor
|
||||||
isArray = fieldCfg["array"].toBool(false);
|
isArray = fieldCfg["array"].toBool(false);
|
||||||
fields = structJson["fields"].toArray();
|
fields = structJson["fields"].toArray();
|
||||||
|
|
||||||
@@ -345,8 +333,10 @@ bool UARTFixture::validateStructField(const QByteArray& rxData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// offset and size from ELF JSON
|
// offset and size from ELF JSON
|
||||||
int offset = fieldInfo["offset"].toInt();
|
json.setJsonFile(structJsonFname);
|
||||||
int size = fieldInfo["size"].toInt();
|
int offset = json.jsonGetIntValue(fieldInfo, "offset", "");
|
||||||
|
int size = json.jsonGetIntValue(fieldInfo, "size", "");
|
||||||
|
json.setJsonFile(caseFile);
|
||||||
|
|
||||||
if ((offset + size) > rxData.size())
|
if ((offset + size) > rxData.size())
|
||||||
{
|
{
|
||||||
@@ -380,9 +370,6 @@ bool UARTFixture::validateStructField(const QByteArray& rxData,
|
|||||||
|
|
||||||
int arrayCount = size / elemSize;
|
int arrayCount = size / elemSize;
|
||||||
|
|
||||||
// expected value
|
|
||||||
double expectValue = fieldCfg["expect"].toDouble();
|
|
||||||
|
|
||||||
// iterate array
|
// iterate array
|
||||||
for (int i = 0; i < arrayCount; i++)
|
for (int i = 0; i < arrayCount; i++)
|
||||||
{
|
{
|
||||||
@@ -447,8 +434,6 @@ bool UARTFixture::validateStructField(const QByteArray& rxData,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
double expectValue = fieldCfg["expect"].toDouble();
|
|
||||||
|
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (op == "==") { ok = (actual == expectValue); }
|
if (op == "==") { ok = (actual == expectValue); }
|
||||||
else if (op == "!=") { ok = (actual != expectValue); }
|
else if (op == "!=") { ok = (actual != expectValue); }
|
||||||
@@ -467,9 +452,11 @@ bool UARTFixture::validateStructField(const QByteArray& rxData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool UARTFixture::validateBinaryResponse(const QByteArray& rx, const QJsonObject& cfg,
|
bool UARTFixture::validateBinaryResponse(const QByteArray& rx, const QJsonObject& cfg,
|
||||||
const QJsonObject& structJson, QString caseFile)
|
const QJsonObject& structJson, QString &structJsonFname,
|
||||||
|
QString caseFile)
|
||||||
{
|
{
|
||||||
QJsonArray checks = cfg["struct_check"].toArray();
|
QString json_checks_field = "struct_check";
|
||||||
|
QJsonArray checks = cfg[json_checks_field].toArray();
|
||||||
QString err, errMsgMismatch;
|
QString err, errMsgMismatch;
|
||||||
bool passed;
|
bool passed;
|
||||||
|
|
||||||
@@ -481,8 +468,9 @@ bool UARTFixture::validateBinaryResponse(const QByteArray& rx, const QJsonObject
|
|||||||
|
|
||||||
for (const QJsonValue& v: qAsConst(checks))
|
for (const QJsonValue& v: qAsConst(checks))
|
||||||
{
|
{
|
||||||
passed = validateStructField(rx, v.toObject(), structJson,
|
passed = validateStructField(rx, v.toObject(), structJson, structJsonFname,
|
||||||
err, errMsgMismatch, caseFile);
|
err, errMsgMismatch, caseFile,
|
||||||
|
json_checks_field);
|
||||||
if (!passed) { writeToLog(QString("%1\n%2").arg(err, errMsgMismatch) , false); break; }
|
if (!passed) { writeToLog(QString("%1\n%2").arg(err, errMsgMismatch) , false); break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,26 +484,21 @@ bool UARTFixture::runBinaryCase(const QJsonObject& cfg, const QJsonObject& meta,
|
|||||||
QByteArray tx;
|
QByteArray tx;
|
||||||
QString struct_name, struct_type, structJsonFileName;
|
QString struct_name, struct_type, structJsonFileName;
|
||||||
QJsonObject param, structJson;
|
QJsonObject param, structJson;
|
||||||
|
JsonProcessor json;
|
||||||
|
json.setJsonFile(caseFile);
|
||||||
|
|
||||||
// find struct_name from test_case
|
// find struct_name from test_case
|
||||||
param = meta["parameters"].toObject();
|
QString parameters = "parameters";
|
||||||
|
param = meta[parameters].toObject();
|
||||||
if (param.isEmpty())
|
if (param.isEmpty())
|
||||||
{
|
{
|
||||||
writeToLog(QString("'parameters' field not found in %1").arg(caseFile), false);
|
writeToLog(QString("'parameters' field not found in %1").arg(caseFile), false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct_name = param["struct_name"].toString();
|
|
||||||
if (struct_name.isEmpty())
|
json.jsonGetStrValue(param, "struct_name", struct_name, parameters);
|
||||||
{
|
json.jsonGetStrValue(param, "struct_type", struct_type, parameters);
|
||||||
writeToLog(QString("'struct_name' field incorrect or not found in %1").arg(caseFile), false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
struct_type = param["struct_type"].toString();
|
|
||||||
if (struct_type.isEmpty())
|
|
||||||
{
|
|
||||||
writeToLog(QString("'struct_type' field incorrect or not found in %1").arg(caseFile), false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
structJsonFileName = QString("%1%2.json").arg(path.iar_json_out, struct_type);
|
structJsonFileName = QString("%1%2.json").arg(path.iar_json_out, struct_type);
|
||||||
|
|
||||||
// extract from elf about struct info
|
// extract from elf about struct info
|
||||||
@@ -541,20 +524,25 @@ bool UARTFixture::runBinaryCase(const QJsonObject& cfg, const QJsonObject& meta,
|
|||||||
if (!sendCommand(tx)) { return false; }
|
if (!sendCommand(tx)) { return false; }
|
||||||
|
|
||||||
QByteArray rx = receiveResponse(cfg);
|
QByteArray rx = receiveResponse(cfg);
|
||||||
return validateBinaryResponse(rx, cfg, structJson, caseFile);
|
return validateBinaryResponse(rx, cfg, structJson, structJsonFileName, caseFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UARTFixture::runCase(const QString& caseFile)
|
void UARTFixture::runCase(const QString& caseFile)
|
||||||
{
|
{
|
||||||
QJsonObject cfg, meta;
|
QJsonObject cfg, meta;
|
||||||
bool passed = false;
|
bool passed = false;
|
||||||
|
QString rx_data_type;
|
||||||
|
JsonProcessor json;
|
||||||
|
json.setJsonFile(caseFile);
|
||||||
|
|
||||||
if (!loadTestCase(caseFile, cfg, meta)) { return; }
|
if (!loadTestCase(caseFile, cfg, meta)) { return; }
|
||||||
|
|
||||||
QString rx_data_type = meta["input_data_type"].toString();
|
try
|
||||||
|
{
|
||||||
|
json.jsonGetStrValue(meta, "input_data_type", rx_data_type, "meta");
|
||||||
|
|
||||||
if (rx_data_type == "text")
|
if (rx_data_type == "text")
|
||||||
{ passed = runTextCase(cfg, caseFile); }
|
{ passed = runTextCase(cfg, caseFile, "meta"); }
|
||||||
else if (rx_data_type == "binary")
|
else if (rx_data_type == "binary")
|
||||||
{ passed = runBinaryCase(cfg, meta, caseFile); }
|
{ passed = runBinaryCase(cfg, meta, caseFile); }
|
||||||
else
|
else
|
||||||
@@ -571,6 +559,14 @@ void UARTFixture::runCase(const QString& caseFile)
|
|||||||
if (g_options.delayMs > 0)
|
if (g_options.delayMs > 0)
|
||||||
{ QThread::msleep(g_options.delayMs); }
|
{ QThread::msleep(g_options.delayMs); }
|
||||||
}
|
}
|
||||||
|
catch (ErrInJsonSet &jsonSet)
|
||||||
|
{
|
||||||
|
QString msg = QString("%1. %2: \nJSON parameter: %3\nJSON object: %4.\nfile: %5")
|
||||||
|
.arg(jsonSet.getIntro(), jsonSet.getErrMsg(), jsonSet.getParam(),
|
||||||
|
jsonSet.getJsonObj(), jsonSet.getFname());
|
||||||
|
writeToLog(msg, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UARTFixture::serializeCmdDataBuf(void *dataStruct, int countBytes)
|
void UARTFixture::serializeCmdDataBuf(void *dataStruct, int countBytes)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -100,17 +100,17 @@ protected:
|
|||||||
|
|
||||||
bool validateTextResponse(const QByteArray& rx,
|
bool validateTextResponse(const QByteArray& rx,
|
||||||
const QJsonObject& cfg, QString caseFile);
|
const QJsonObject& cfg, QString caseFile);
|
||||||
bool runTextCase(const QJsonObject& cfg, QString caseFile);
|
bool runTextCase(const QJsonObject& cfg, QString caseFile, QString jsonObjName);
|
||||||
|
|
||||||
bool prepareBinaryCommand(const QJsonObject& cfg, QByteArray& data);
|
bool prepareBinaryCommand(const QJsonObject& cfg, QByteArray& data);
|
||||||
|
|
||||||
bool validateStructField(const QByteArray& rxData,
|
bool validateStructField(const QByteArray& rxData,
|
||||||
const QJsonObject& fieldCfg,
|
const QJsonObject& fieldCfg,
|
||||||
const QJsonObject& structJson,
|
const QJsonObject& structJson, QString &structJsonFname,
|
||||||
QString& errMsg,
|
QString& errMsg,
|
||||||
QString &errMsgMismatch, QString caseFile);
|
QString &errMsgMismatch, QString caseFile, QString jsonObjName);
|
||||||
bool validateBinaryResponse(const QByteArray& rx, const QJsonObject& cfg,
|
bool validateBinaryResponse(const QByteArray& rx, const QJsonObject& cfg,
|
||||||
const QJsonObject &structJson, QString caseFile);
|
const QJsonObject &structJson, QString &structJsonFname,
|
||||||
|
QString caseFile);
|
||||||
bool runBinaryCase(const QJsonObject& cfg, const QJsonObject &meta,
|
bool runBinaryCase(const QJsonObject& cfg, const QJsonObject &meta,
|
||||||
QString caseFile);
|
QString caseFile);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user