From 6445511313395109be689d9649965c2e183c4747 Mon Sep 17 00:00:00 2001 From: Xusong Wang Date: Thu, 30 Jul 2020 15:45:36 -0700 Subject: Fix mixed-build CTS failures. The tests are newly added in R and should not be enforced for devices with only a system upgrade. Bug: 162195407 Bug: 162395335 Test: CTS with a mixed build of R + P Test: CTS with a mixed build of R + Q Change-Id: Ia0761b0b0ed9c663c262388f4ad36bdc0c2f40d1 Merged-In: Ia0761b0b0ed9c663c262388f4ad36bdc0c2f40d1 (cherry picked from commit 34ca86b85dbe2fa954f1412b3f4f81dcf2797b5b) --- nn/runtime/test/GeneratedTestUtils.h | 2 ++ nn/runtime/test/TestGenerated.cpp | 36 +++++++++++++++++++++++++++++ nn/runtime/test/fuzzing/TestRandomGraph.cpp | 10 +++++++- 3 files changed, 47 insertions(+), 1 deletion(-) (limited to 'nn') diff --git a/nn/runtime/test/GeneratedTestUtils.h b/nn/runtime/test/GeneratedTestUtils.h index 3ac5cba03..1354f6749 100644 --- a/nn/runtime/test/GeneratedTestUtils.h +++ b/nn/runtime/test/GeneratedTestUtils.h @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -31,6 +32,7 @@ namespace android::nn::generated_tests { class GeneratedTestBase : public ::testing::TestWithParam { protected: + const std::string& kTestName = GetParam().first; const test_helper::TestModel& testModel = *GetParam().second; }; diff --git a/nn/runtime/test/TestGenerated.cpp b/nn/runtime/test/TestGenerated.cpp index a76aecd92..70b0e6f72 100644 --- a/nn/runtime/test/TestGenerated.cpp +++ b/nn/runtime/test/TestGenerated.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +62,8 @@ class GeneratedTests : public GeneratedTestBase { void SetUp() override; void TearDown() override; + bool shouldSkipTest(); + std::optional compileModel(const Model& model); void executeWithCompilation(const Compilation& compilation, const TestModel& testModel); void executeOnce(const Model& model, const TestModel& testModel); @@ -68,6 +72,9 @@ class GeneratedTests : public GeneratedTestBase { // Test driver for those generated from ml/nn/runtime/test/spec void execute(const TestModel& testModel); + // VNDK version of the device under test. + static int mVndkVersion; + std::string mCacheDir; std::vector mToken; bool mTestCompilationCaching = false; @@ -77,6 +84,8 @@ class GeneratedTests : public GeneratedTestBase { bool mTestDeviceMemory = false; }; +int GeneratedTests::mVndkVersion = __ANDROID_API_FUTURE__; + // Tag for the dynamic output shape tests class DynamicOutputShapeTest : public GeneratedTests { protected: @@ -328,8 +337,35 @@ void GeneratedTests::execute(const TestModel& testModel) { } } +bool GeneratedTests::shouldSkipTest() { + // A map of {min VNDK version -> tests that should be skipped with earlier VNDK versions}. + // The listed tests are added in a later release, but exercising old APIs. They should be + // skipped if the device has a mixed build of system and vendor partitions. + static const std::map> kMapOfMinVndkVersionToTests = { + { + __ANDROID_API_R__, + { + "add_broadcast_quant8_all_inputs_as_internal", + }, + }, + }; + for (const auto& [minVersion, names] : kMapOfMinVndkVersionToTests) { + if (mVndkVersion < minVersion && names.count(kTestName) > 0) { + return true; + } + } + return false; +} + void GeneratedTests::SetUp() { GeneratedTestBase::SetUp(); + + mVndkVersion = ::android::base::GetIntProperty("ro.vndk.version", __ANDROID_API_FUTURE__); + if (shouldSkipTest()) { + GTEST_SKIP(); + return; + } + char cacheDirTemp[] = "/data/local/tmp/TestCompilationCachingXXXXXX"; char* cacheDir = mkdtemp(cacheDirTemp); ASSERT_NE(cacheDir, nullptr); diff --git a/nn/runtime/test/fuzzing/TestRandomGraph.cpp b/nn/runtime/test/fuzzing/TestRandomGraph.cpp index 2c8024a22..fc73bc2a3 100644 --- a/nn/runtime/test/fuzzing/TestRandomGraph.cpp +++ b/nn/runtime/test/fuzzing/TestRandomGraph.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include @@ -31,7 +32,6 @@ #include "fuzzing/RandomGraphGeneratorUtils.h" #ifndef NNTEST_CTS -#include #include #include @@ -152,6 +152,7 @@ class RandomGraphTest : public ::testing::TestWithParam { mSyntheticDevices.push_back(makeTestDevice()); mSyntheticDevices.push_back(makeTestDevice()); #endif + mVndkVersion = ::android::base::GetIntProperty("ro.vndk.version", __ANDROID_API_FUTURE__); // Get all the devices and device names. mStandardDevicesFeatureLevel = __ANDROID_API_FUTURE__; @@ -225,6 +226,11 @@ class RandomGraphTest : public ::testing::TestWithParam { featureLevel <= __ANDROID_API_Q__) { return true; } + // Skip the following operations when the VNDK version is earlier than R. + if (mVndkVersion < __ANDROID_API_R__ && + op.type == TestOperationType::HEATMAP_MAX_KEYPOINT) { + return true; + } } return false; } @@ -433,6 +439,7 @@ class RandomGraphTest : public ::testing::TestWithParam { // A vector of {name, output_results}. std::vector>> mResults; + static int mVndkVersion; static int64_t mStandardDevicesFeatureLevel; // minimum across all devices #ifndef NNTEST_CTS static std::vector> mStandardDevices; @@ -445,6 +452,7 @@ bool RandomGraphTest::mDumpSpec = false; bool RandomGraphTest::mDetectMemoryLeak = false; std::map RandomGraphTest::mDevices; +int RandomGraphTest::mVndkVersion = __ANDROID_API_FUTURE__; int64_t RandomGraphTest::mStandardDevicesFeatureLevel; #ifndef NNTEST_CTS std::vector> RandomGraphTest::mStandardDevices; -- cgit v1.2.3