aboutsummaryrefslogtreecommitdiff
path: root/src/armnnOnnxParser/test/Addition.cpp
diff options
context:
space:
mode:
authorRyan OShea <Ryan.OShea2@arm.com>2020-02-21 12:33:17 +0000
committerRyan O'Shea <ryan.oshea2@arm.com>2020-02-21 12:37:19 +0000
commit337c17f964fd4d40fe638ef960f7f96b61b63947 (patch)
treef7e997c66d7f56dde36a7cbe8e766b00111f2e22 /src/armnnOnnxParser/test/Addition.cpp
parentd149ad03250cd8ad8bfe28cbb830ca3fcc6c4f04 (diff)
downloadarmnn-337c17f964fd4d40fe638ef960f7f96b61b63947.tar.gz
IVGCVSW-4307 Onnx Segfault Bug
* Fixed ParseConstant * Fixed Exception * Fixed 0 dimension tensor * Add unit test to check addition as tensor and scalar * Change C++ style comments to Doxygen style Signed-off-by: Ryan OShea <Ryan.OShea2@arm.com> Change-Id: Ied7cbe2e11e713c23d87106d2db39e0eb446c920
Diffstat (limited to 'src/armnnOnnxParser/test/Addition.cpp')
-rw-r--r--src/armnnOnnxParser/test/Addition.cpp110
1 files changed, 109 insertions, 1 deletions
diff --git a/src/armnnOnnxParser/test/Addition.cpp b/src/armnnOnnxParser/test/Addition.cpp
index 993a620dcc..6fc8eb1151 100644
--- a/src/armnnOnnxParser/test/Addition.cpp
+++ b/src/armnnOnnxParser/test/Addition.cpp
@@ -286,6 +286,103 @@ struct AddInvalidBroadcastFixture : public armnnUtils::ParserPrototxtFixture<arm
}
};
+struct AddScalarFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ AddScalarFixture(const std::string& dataType)
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input0"
+ type {
+ tensor_type {
+ elem_type: )" + dataType + R"(
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Input1"
+ type {
+ tensor_type {
+ elem_type: )" + dataType + R"(
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input0"
+ input: "Input1"
+ output: "Output"
+ name: "addition"
+ op_type: "Add"
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ }
+};
+
+struct AddValidScalarFixture : AddScalarFixture
+{
+ AddValidScalarFixture() : AddScalarFixture("1") {
+ Setup();
+ }
+};
+
+struct AddInvalidScalarFixture : AddScalarFixture
+{
+ AddInvalidScalarFixture() : AddScalarFixture("6") { }
+};
+
BOOST_FIXTURE_TEST_CASE(ValidAddTest, AddValidFixture)
{
RunTest<4>({{"Input0", {1.0f, 2.0f, -3.0f, -4.0f}},
@@ -308,4 +405,15 @@ BOOST_FIXTURE_TEST_CASE(ValidBroadcastAdd, AddValidBroadcastFixture)
{"Input1", {1.0f, 2.0f, 3.0, 4.0f}}}, {{"Output", {2.0, 4.0, 0, 0.0}}});
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_FIXTURE_TEST_CASE(ValidAddScalarTest, AddValidScalarFixture)
+{
+ RunTest<4>({{"Input0", {1.0f, 2.0f, -3.0f, -4.0f}},
+ {"Input1", {-8.0f}}}, {{"Output", {-7.0, -6.0, -11.0, -12.0}}});
+}
+
+BOOST_FIXTURE_TEST_CASE(IncorrectDataTypeAddScalar, AddInvalidScalarFixture)
+{
+ BOOST_CHECK_THROW(Setup(), armnn::ParseException);
+}
+
+BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file