From 44aeff04ae56acae53dac58902c31bcfa9a195b4 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 12 Jul 2012 08:02:41 +0000 Subject: [PATCH] Package name logic improved; Aditional tests added; Some bug fixes with different __SUPPORT_XXX defines. --- android/service/engine/jni/Android.mk | 8 +- .../engine/jni/NativeService/PackageInfo.cpp | 22 +++-- .../engine/jni/Tests/OpenCVEngineTest.cpp | 5 +- .../engine/jni/Tests/PackageInfoTest.cpp | 97 ++++++++++++------- .../engine/jni/Tests/PackageManagerStub.cpp | 2 +- android/service/engine/jni/Tests/Tests.mk | 6 +- 6 files changed, 90 insertions(+), 50 deletions(-) diff --git a/android/service/engine/jni/Android.mk b/android/service/engine/jni/Android.mk index 4ba317603..ded931f57 100644 --- a/android/service/engine/jni/Android.mk +++ b/android/service/engine/jni/Android.mk @@ -24,8 +24,8 @@ LOCAL_C_INCLUDES := \ $(TOP)/system/core/include LOCAL_CFLAGS += -DPLATFORM_ANDROID -LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES -LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +#LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +#LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES LOCAL_PRELINK_MODULE := false @@ -65,8 +65,8 @@ LOCAL_C_INCLUDES := \ LOCAL_PRELINK_MODULE := false LOCAL_CFLAGS += -DPLATFORM_ANDROID -LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES -LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +#LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +#LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES LOCAL_MODULE := libOpenCVEngine_jni diff --git a/android/service/engine/jni/NativeService/PackageInfo.cpp b/android/service/engine/jni/NativeService/PackageInfo.cpp index ae4b34b4d..fc6e43df0 100644 --- a/android/service/engine/jni/NativeService/PackageInfo.cpp +++ b/android/service/engine/jni/NativeService/PackageInfo.cpp @@ -30,19 +30,23 @@ inline string JoinARMFeatures(int cpu_id) if (FEATURES_HAS_NEON2 & cpu_id) { - result = string(FEATURES_HAS_NEON2_NAME); + if (!((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id) ||(ARCH_ARMv7 & cpu_id))) + result = string(FEATURES_HAS_NEON2_NAME); } else if (FEATURES_HAS_NEON & cpu_id) { - result = string(FEATURES_HAS_NEON_NAME); + if (!((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id))) + result = string(FEATURES_HAS_NEON_NAME); } else if (FEATURES_HAS_VFPv3 & cpu_id) { - result = string(FEATURES_HAS_VFPv3_NAME); + if ((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id)) + result = string(FEATURES_HAS_VFPv3_NAME); } else if (FEATURES_HAS_VFPv3d16 & cpu_id) { - result = string(FEATURES_HAS_VFPv3d16_NAME); + if ((ARCH_ARMv5 & cpu_id) || (ARCH_ARMv6 & cpu_id)) + result = string(FEATURES_HAS_VFPv3d16_NAME); } return result; @@ -182,7 +186,7 @@ inline int SplitPlatfrom(const vector& features) * If platform is unknown it is defined by hardware capabilities using pattern: __ * Example: armv7_neon, armv5_vfpv3 */ -PackageInfo::PackageInfo(const string& version, int platform, int cpu_id): +PackageInfo::PackageInfo(const string& version, int platform, int cpu_id, std::string install_path): Version(version), Platform(platform), CpuID(cpu_id), @@ -194,7 +198,6 @@ PackageInfo::PackageInfo(const string& version, int platform, int cpu_id): FullName = BasePackageName + "_v" + Version.substr(0, Version.size()-1); if (PLATFORM_UNKNOWN != Platform) { - LOGD("Try to use known platform !!!"); FullName += string("_") + JoinPlatform(platform); } else @@ -307,13 +310,18 @@ PackageInfo::PackageInfo(const string& version, int platform, int cpu_id): Platform = PLATFORM_UNKNOWN; } } + + if (!FullName.empty()) + { + InstallPath = install_path + FullName + "/lib"; + } } PackageInfo::PackageInfo(const string& fullname, const string& install_path, const string& package_version): FullName(fullname), InstallPath(install_path) { - LOGD("PackageInfo::PackageInfo(\"%s\", \"%s\")", fullname.c_str(), install_path.c_str()); + LOGD("PackageInfo::PackageInfo(\"%s\", \"%s\", \"%s\")", fullname.c_str(), install_path.c_str(), package_version.c_str()); assert(!fullname.empty()); assert(!install_path.empty()); diff --git a/android/service/engine/jni/Tests/OpenCVEngineTest.cpp b/android/service/engine/jni/Tests/OpenCVEngineTest.cpp index 1b4b6b227..a198a474a 100644 --- a/android/service/engine/jni/Tests/OpenCVEngineTest.cpp +++ b/android/service/engine/jni/Tests/OpenCVEngineTest.cpp @@ -104,9 +104,9 @@ TEST(OpenCVEngineTest, GetPathForExecHWNewVersion) { sp Engine = InitConnect(); Starter.PackageManager->InstalledPackages.clear(); - Starter.PackageManager->InstallVersion("242", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); + Starter.PackageManager->InstallVersion("241", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); EXPECT_FALSE(NULL == Engine.get()); - String16 result = Engine->GetLibPathByVersion(String16("2.4.3")); + String16 result = Engine->GetLibPathByVersion(String16("2.4.2")); EXPECT_EQ(0, result.size()); } @@ -121,6 +121,7 @@ TEST(OpenCVEngineTest, GetPathForUnExistVersion) TEST(OpenCVEngineTest, InstallAndGetVersion) { sp Engine = InitConnect(); + Starter.PackageManager->InstalledPackages.clear(); EXPECT_FALSE(NULL == Engine.get()); EXPECT_TRUE(Engine->InstallVersion(String16("2.4"))); String16 result = Engine->GetLibPathByVersion(String16("2.4")); diff --git a/android/service/engine/jni/Tests/PackageInfoTest.cpp b/android/service/engine/jni/Tests/PackageInfoTest.cpp index 14e347c6e..c8f6c7ced 100644 --- a/android/service/engine/jni/Tests/PackageInfoTest.cpp +++ b/android/service/engine/jni/Tests/PackageInfoTest.cpp @@ -18,25 +18,24 @@ TEST(PackageInfo, FullNameArmv7) TEST(PackageInfo, FullNameArmv7Neon) { - PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON); + PackageInfo info("241", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON); string name = info.GetFullName(); #ifdef __SUPPORT_ARMEABI_V7A_FEATURES - EXPECT_STREQ("org.opencv.lib_v23_armv7a_neon", name.c_str()); + EXPECT_STREQ("org.opencv.lib_v24_armv7a_neon", name.c_str()); #else - EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str()); + EXPECT_STREQ("org.opencv.lib_v24_armv7a", name.c_str()); #endif } TEST(PackageInfo, FullNameArmv7VFPv3) { - PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3); + PackageInfo info("233", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3); string name = info.GetFullName(); EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str()); } TEST(PackageInfo, FullNameArmv7VFPv3Neon) { - PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON); string name = info.GetFullName(); #ifdef __SUPPORT_ARMEABI_V7A_FEATURES @@ -46,6 +45,46 @@ TEST(PackageInfo, FullNameArmv7VFPv3Neon) #endif } +TEST(PackageInfo, FullNameArmv5) +{ + PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv5); + string name = info.GetFullName(); + EXPECT_STREQ("org.opencv.lib_v23_armv5", name.c_str()); +} + +TEST(PackageInfo, FullNameArmv6) +{ + PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv6); + string name = info.GetFullName(); + EXPECT_STREQ("org.opencv.lib_v23_armv5", name.c_str()); +} + +TEST(PackageInfo, FullNameArmv6VFPv3) +{ + PackageInfo info("232", PLATFORM_UNKNOWN, ARCH_ARMv6 | FEATURES_HAS_VFPv3); + string name = info.GetFullName(); +#ifdef __SUPPORT_ARMEABI_FEATURES + EXPECT_STREQ("org.opencv.lib_v23_armv5_vfpv3", name.c_str()); +#else + EXPECT_STREQ("org.opencv.lib_v23_armv5", name.c_str()); +#endif +} + +TEST(PackageInfo, FullNameTegra3) +{ + PackageInfo info("230", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); + string name = info.GetFullName(); + #ifdef __SUPPORT_TEGRA3 + EXPECT_STREQ("org.opencv.lib_v23_tegra3", name.c_str()); + #else + #ifdef __SUPPORT_ARMEABI_V7A_FEATURES + EXPECT_STREQ("org.opencv.lib_v23_armv7a_neon", name.c_str()); + #else + EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str()); + #endif + #endif +} + TEST(PackageInfo, FullNameX86SSE2) { PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2); @@ -64,6 +103,20 @@ TEST(PackageInfo, Armv7NeonFromFullName) EXPECT_EQ(ARCH_ARMv7 | FEATURES_HAS_NEON, info.GetCpuID()); } +TEST(PackageInfo, Armv5FromFullName) +{ + PackageInfo info("org.opencv.lib_v23_armv5", "/data/data/org.opencv.lib_v23_armv5"); + EXPECT_EQ("230", info.GetVersion()); + EXPECT_EQ(ARCH_ARMv5, info.GetCpuID()); +} + +TEST(PackageInfo, Armv5VFPv3FromFullName) +{ + PackageInfo info("org.opencv.lib_v23_armv5_vfpv3", "/data/data/org.opencv.lib_v23_armv5_vfpv3"); + EXPECT_EQ("230", info.GetVersion()); + EXPECT_EQ(ARCH_ARMv5 | FEATURES_HAS_VFPv3, info.GetCpuID()); +} + TEST(PackageInfo, X86SSE2FromFullName) { PackageInfo info("org.opencv.lib_v24_x86_sse2", "/data/data/org.opencv.lib_v24_x86_sse2"); @@ -86,30 +139,6 @@ TEST(PackageInfo, Tegra3FromFullName) EXPECT_EQ(PLATFORM_TEGRA3, info.GetPlatform()); } -TEST(PackageInfo, FullNameTegra3) -{ - PackageInfo info("230", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON); - string name = info.GetFullName(); -#ifdef __SUPPORT_TEGRA3 - EXPECT_STREQ("org.opencv.lib_v23_tegra3", name.c_str()); -#else -#ifdef __SUPPORT_ARMEABI_V7A_FEATURES - EXPECT_STREQ("org.opencv.lib_v23_armv7a_neon", name.c_str()); -#else - EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str()); -#endif -#endif -} - -TEST(PackageInfo, FullNameTegra2) -{ - PackageInfo info("230", PLATFORM_TEGRA2, 0); - EXPECT_TRUE(!info.IsValid()); - // TODO: Replace if seporate package will be exists - //string name = info.GetFullName(); - //EXPECT_STREQ("org.opencv.lib_v23_tegra2", name.c_str()); -} - TEST(PackageInfo, Comparator1) { PackageInfo info1("240", PLATFORM_UNKNOWN, ARCH_X86); @@ -121,9 +150,11 @@ TEST(PackageInfo, Comparator1) TEST(PackageInfo, Comparator2) { PackageInfo info1("240", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON | FEATURES_HAS_VFPv3); +#ifdef __SUPPORT_ARMEABI_V7A_FEATURES + PackageInfo info2("org.opencv.lib_v24_armv7a_neon", "/data/data/org.opencv.lib_v24_armv7a_neon"); +#else PackageInfo info2("org.opencv.lib_v24_armv7a", "/data/data/org.opencv.lib_v24_armv7a"); - // TODO: Replace if seporate package will be exists - //PackageInfo info2("org.opencv.lib_v24_armv7_vfpv3_neon", "/data/data/org.opencv.lib_v24_armv7_vfpv3_neon"); +#endif EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str()); EXPECT_EQ(info1, info2); } @@ -131,8 +162,8 @@ TEST(PackageInfo, Comparator2) #ifdef __SUPPORT_TEGRA3 TEST(PackageInfo, Comparator3) { - PackageInfo info1("230", PLATFORM_TEGRA2, 0); - PackageInfo info2("org.opencv.lib_v23_tegra2", "/data/data/org.opencv.lib_v23_tegra2"); + PackageInfo info1("230", PLATFORM_TEGRA3, 0); + PackageInfo info2("org.opencv.lib_v23_tegra3", "/data/data/org.opencv.lib_v23_tegra3"); EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str()); EXPECT_EQ(info1, info2); } diff --git a/android/service/engine/jni/Tests/PackageManagerStub.cpp b/android/service/engine/jni/Tests/PackageManagerStub.cpp index b39524b0d..20be63a9b 100644 --- a/android/service/engine/jni/Tests/PackageManagerStub.cpp +++ b/android/service/engine/jni/Tests/PackageManagerStub.cpp @@ -4,7 +4,7 @@ using namespace std; bool PackageManagerStub::InstallPackage(const PackageInfo& package) { - InstalledPackages.push_back(PackageInfo(package.GetFullName(), "/data/data/" + package.GetFullName() + "/lib")); + InstalledPackages.push_back(package); return true; } diff --git a/android/service/engine/jni/Tests/Tests.mk b/android/service/engine/jni/Tests/Tests.mk index 9027e15fb..4fe111184 100644 --- a/android/service/engine/jni/Tests/Tests.mk +++ b/android/service/engine/jni/Tests/Tests.mk @@ -17,7 +17,7 @@ LOCAL_SRC_FILES := \ Tests/PackageManagmentTest.cpp \ Tests/PackageInfoTest.cpp \ Tests/OpenCVEngineTest.cpp \ - Tests/TestMain.cpp + Tests/TestMain.cpp # Tests/HardwareDetectionTest.cpp \ LOCAL_C_INCLUDES := \ @@ -31,8 +31,8 @@ LOCAL_C_INCLUDES := \ $(TOP)/system/core/include LOCAL_CFLAGS += -O0 -DGTEST_HAS_CLONE=0 -DGTEST_OS_LINUX_ANDROID=1 -DGTEST_HAS_TR1_TUPLE=0 -LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES -LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +#LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 +#LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_V7A_FEATURES #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES LOCAL_LDFLAGS = -Wl,-allow-shlib-undefined