Pseudo randomly add checks

This commit is contained in:
Bhargava Shastry 2019-07-29 16:38:24 +02:00
parent f0c6391159
commit 12f54b55a2
2 changed files with 41 additions and 25 deletions

View File

@ -353,20 +353,20 @@ void ProtoConverter::visit(ValueType const& _x)
{
switch (_x.value_type_oneof_case())
{
case ValueType::kInty:
visit(_x.inty());
break;
case ValueType::kByty:
visit(_x.byty());
break;
case ValueType::kAdty:
visit(_x.adty());
break;
case ValueType::kBoolty:
visit(_x.boolty());
break;
case ValueType::VALUE_TYPE_ONEOF_NOT_SET:
break;
case ValueType::kInty:
visit(_x.inty());
break;
case ValueType::kByty:
visit(_x.byty());
break;
case ValueType::kAdty:
visit(_x.adty());
break;
case ValueType::kBoolty:
visit(_x.boolty());
break;
case ValueType::VALUE_TYPE_ONEOF_NOT_SET:
break;
}
}
@ -500,8 +500,10 @@ unsigned ProtoConverter::resizeDimension(
addVarDef(lhs, rhs);
}
// if (c.length != l)
checkResizeOp(_param, length);
// Add checks on array length pseudo randomly
if (addCheck(getNextCounter()))
// if (c.length != l)
checkResizeOp(_param, length);
return length;
}
@ -517,12 +519,19 @@ void ProtoConverter::resizeHelper(
// (depth-first) recurse otherwise.
if (_arrInfoVec.empty())
{
// expression name is _var
// value is a value of base type
std::string value = getValueByBaseType(_x);
// add assignment and check
DataType dataType = getDataTypeByBaseType(_x);
addCheckedVarDef(dataType, _varName, _paramName, value);
// We are at the leaf node now.
// To ensure we do not create a very large test case
// especially for multidimensional dynamic arrays,
// we create a checked assignment pseudo randomly.
if (addCheck(getNextCounter()))
{
// expression name is _var
// value is a value of base type
std::string value = getValueByBaseType(_x);
// add assignment and check
DataType dataType = getDataTypeByBaseType(_x);
addCheckedVarDef(dataType, _varName, _paramName, value);
}
}
else
{

View File

@ -310,7 +310,7 @@ private:
static unsigned getIntWidth(IntegerType const& _x)
{
return 8 * ((_x.width() % 32) + 1);
return 8 * (_x.width() % 32 + 1);
}
static bool isIntSigned(IntegerType const& _x)
@ -325,12 +325,12 @@ private:
static std::string getIntTypeAsString(IntegerType const& _x)
{
return ((isIntSigned(_x) ? "int" : "uint") + std::to_string(getIntWidth(_x)));
return (isIntSigned(_x) ? "int" : "uint") + std::to_string(getIntWidth(_x));
}
static unsigned getFixedByteWidth(FixedByteType const& _x)
{
return (_x.width() % 32) + 1;
return _x.width() % 32 + 1;
}
static std::string getFixedByteTypeAsString(FixedByteType const& _x)
@ -413,6 +413,10 @@ private:
_counter,
_isHexLiteral
);
static bool addCheck(unsigned _counter)
{
return _counter % s_arrayCheckFrequency == 0;
}
/// Contains the test program
@ -434,6 +438,9 @@ private:
static unsigned constexpr s_maxArrayLength = 4;
static unsigned constexpr s_maxArrayDimensions = 4;
static unsigned constexpr s_maxDynArrayLength = 256;
/// Add check only if counter returned by getNextCounter()
/// is divisible by s_arrayCheckFrequency
static unsigned constexpr s_arrayCheckFrequency = 11;
/// Prefixes for declared and parameterized variable names
static auto constexpr s_varNamePrefix = "x_";
static auto constexpr s_paramNamePrefix = "c_";