Test dynamic output shape in GeneratedTests.

Enable VTS unit test for dynamic output shape deduction.

Only test dynamic output shape for V1_2::IDevice with V1_2::Model.

Bug: 73506513
Test: VtsHalNeuralnetworksV1_xTargetTest with 1.2 sample driver
Change-Id: I4134e1ec54a15554eb8533134897279651b57da3
diff --git a/neuralnetworks/1.2/vts/functional/Android.bp b/neuralnetworks/1.2/vts/functional/Android.bp
index 5b119ee..0cb9e16 100644
--- a/neuralnetworks/1.2/vts/functional/Android.bp
+++ b/neuralnetworks/1.2/vts/functional/Android.bp
@@ -21,6 +21,9 @@
     srcs: [
         "GeneratedTestsV1_0.cpp",
     ],
+    cflags: [
+        "-DNN_TEST_DYNAMIC_OUTPUT_SHAPE"
+    ],
     test_suites: ["general-tests"],
 }
 
@@ -31,6 +34,9 @@
     srcs: [
         "GeneratedTestsV1_1.cpp",
     ],
+    cflags: [
+        "-DNN_TEST_DYNAMIC_OUTPUT_SHAPE"
+    ],
     test_suites: ["general-tests"],
 }
 
@@ -42,5 +48,8 @@
         "BasicTests.cpp",
         "GeneratedTests.cpp",
     ],
+    cflags: [
+        "-DNN_TEST_DYNAMIC_OUTPUT_SHAPE"
+    ],
     test_suites: ["general-tests"],
 }
diff --git a/neuralnetworks/1.2/vts/functional/GeneratedTests.cpp b/neuralnetworks/1.2/vts/functional/GeneratedTests.cpp
index 9bff09c..4bc891f 100644
--- a/neuralnetworks/1.2/vts/functional/GeneratedTests.cpp
+++ b/neuralnetworks/1.2/vts/functional/GeneratedTests.cpp
@@ -33,7 +33,8 @@
 namespace generated_tests {
 using ::test_helper::MixedTypedExample;
 extern void Execute(const sp<V1_2::IDevice>&, std::function<V1_2::Model(void)>,
-                    std::function<bool(int)>, const std::vector<MixedTypedExample>&);
+                    std::function<bool(int)>, const std::vector<MixedTypedExample>&,
+                    bool testDynamicOutputShape = false);
 }  // namespace generated_tests
 
 namespace V1_2 {
diff --git a/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_0.cpp b/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_0.cpp
index 56a61d4..956926a 100644
--- a/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_0.cpp
+++ b/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_0.cpp
@@ -33,7 +33,8 @@
 namespace generated_tests {
 using ::test_helper::MixedTypedExample;
 extern void Execute(const sp<V1_2::IDevice>&, std::function<V1_2::Model(void)>,
-                    std::function<bool(int)>, const std::vector<MixedTypedExample>&);
+                    std::function<bool(int)>, const std::vector<MixedTypedExample>&,
+                    bool testDynamicOutputShape = false);
 }  // namespace generated_tests
 
 namespace V1_2 {
diff --git a/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_1.cpp b/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_1.cpp
index 1c781ec..425690f 100644
--- a/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_1.cpp
+++ b/neuralnetworks/1.2/vts/functional/GeneratedTestsV1_1.cpp
@@ -33,7 +33,8 @@
 namespace generated_tests {
 using ::test_helper::MixedTypedExample;
 extern void Execute(const sp<V1_2::IDevice>&, std::function<V1_2::Model(void)>,
-                    std::function<bool(int)>, const std::vector<MixedTypedExample>&);
+                    std::function<bool(int)>, const std::vector<MixedTypedExample>&,
+                    bool testDynamicOutputShape = false);
 }  // namespace generated_tests
 
 namespace V1_2 {
diff --git a/neuralnetworks/1.2/vts/functional/ValidateModel.cpp b/neuralnetworks/1.2/vts/functional/ValidateModel.cpp
index b1a0e53..1f9c99d 100644
--- a/neuralnetworks/1.2/vts/functional/ValidateModel.cpp
+++ b/neuralnetworks/1.2/vts/functional/ValidateModel.cpp
@@ -172,6 +172,9 @@
 static void mutateOperandRankTest(const sp<IDevice>& device, const Model& model) {
     for (size_t operand = 0; operand < model.operands.size(); ++operand) {
         const uint32_t invalidRank = getInvalidRank(model.operands[operand].type);
+        if (invalidRank == 0) {
+            continue;
+        }
         const std::string message = "mutateOperandRankTest: operand " + std::to_string(operand) +
                                     " has rank of " + std::to_string(invalidRank);
         validate(device, message, model, [operand, invalidRank](Model* model) {
diff --git a/neuralnetworks/1.2/vts/functional/VtsHalNeuralnetworks.h b/neuralnetworks/1.2/vts/functional/VtsHalNeuralnetworks.h
index dedab8d..c0c21bd 100644
--- a/neuralnetworks/1.2/vts/functional/VtsHalNeuralnetworks.h
+++ b/neuralnetworks/1.2/vts/functional/VtsHalNeuralnetworks.h
@@ -79,6 +79,9 @@
 // Tag for the generated tests
 class GeneratedTest : public NeuralnetworksHidlTest {};
 
+// Tag for the dynamic output shape tests
+class DynamicOutputShapeTest : public NeuralnetworksHidlTest {};
+
 // Utility function to get PreparedModel from callback and downcast to V1_2.
 sp<IPreparedModel> getPreparedModel_1_2(
     const sp<V1_2::implementation::PreparedModelCallback>& callback);