Unit tests updated. Version and HW compatiblity tests added;

Tegra3, neon, sseX, x64 support uncomment and guarded by ifdefs.
This commit is contained in:
Alexander Smorkalov 2012-07-11 13:30:41 +00:00
parent 994f8710f3
commit ed0a158cc1
7 changed files with 185 additions and 96 deletions

View File

@ -156,6 +156,7 @@ int GetProcessorCount()
int DetectKnownPlatforms()
{
#ifdef __SUPPORT_TEGRA3
int tegra_status = DetectTegra();
if (3 == tegra_status)
@ -166,6 +167,9 @@ int DetectKnownPlatforms()
{
return PLATFORM_UNKNOWN;
}
#else
return PLATFORM_UNKNOWN;
#endif
// NOTE: Uncomment when all Tegras will be supported
/*if (tegra_status > 0)

View File

@ -106,7 +106,7 @@ String16 OpenCVEngine::GetLibPathByVersion(android::String16 version)
}
else
{
LOGE("OpenCV version \"%s\" is not supported", norm_version.c_str());
LOGE("OpenCV version \"%s\" (%s) is not supported", String8(version).string(), norm_version.c_str());
}
return String16(path.c_str());

View File

@ -179,8 +179,8 @@ inline int SplitPlatfrom(const vector<string>& features)
* First part is base namespace.
* Second part is version. Version starts from "v" symbol. After "v" symbol version nomber without dot symbol added.
* If platform is known third part is platform name
* If platform is unknown it is defined by hardware capabilities using pattern: <arch>_<fpu features>_<vectorisation features>_<other features>
* Example: armv7_vfpv3_neon, armv7_vfpv3d16_neon
* If platform is unknown it is defined by hardware capabilities using pattern: <arch>_<floating point and vectorization features>_<other features>
* Example: armv7_neon, armv5_vfpv3
*/
PackageInfo::PackageInfo(const string& version, int platform, int cpu_id):
Version(version),
@ -188,9 +188,13 @@ PackageInfo::PackageInfo(const string& version, int platform, int cpu_id):
CpuID(cpu_id),
InstallPath("")
{
#ifndef __SUPPORT_TEGRA3
Platform = PLATFORM_UNKNOWN;
#endif
FullName = BasePackageName + "_v" + Version.substr(0, Version.size()-1);
if (PLATFORM_UNKNOWN != Platform)
{
LOGD("Try to use known platform !!!");
FullName += string("_") + JoinPlatform(platform);
}
else
@ -201,72 +205,98 @@ PackageInfo::PackageInfo(const string& version, int platform, int cpu_id):
{
LOGD("Found processor with x86 arch");
FullName += string("_") + ARCH_X86_NAME;
// NOTE: Intel features temporary are not supported
//string features = JoinIntelFeatures(CpuID);
#ifdef __SUPPORT_INTEL_FEATURES
string features = JoinIntelFeatures(CpuID);
#else
string features;
#endif
if (!features.empty())
{
FullName += string("_") + features;
}
}
if (ARCH_X64 & CpuID)
else if (ARCH_X64 & CpuID)
{
LOGD("Found processor with x64 arch");
// NOTE: Intel features temporary are not supported
//FullName += string("_") + ARCH_X64_NAME;
//string features = JoinIntelFeatures(CpuID);
#ifdef __SUPPORT_INTEL_x64
FullName += string("_") + ARCH_X64_NAME;
#else
FullName += string("_") + ARCH_X86_NAME;
#endif
#ifdef __SUPPORT_INTEL_FEATURES
string features = JoinIntelFeatures(CpuID);
#else
string features;
#endif
if (!features.empty())
{
FullName += string("_") + features;
}
}
if (ARCH_ARMv5 & CpuID)
else if (ARCH_ARMv5 & CpuID)
{
LOGD("Found processor with ARMv5 arch");
FullName += string("_") + ARCH_ARMv5_NAME;
#ifdef __SUPPORT_ARMEABI_FEATURES
string features = JoinARMFeatures(CpuID);
#else
string features;
#endif
if (!features.empty())
{
FullName += string("_") + features;
}
}
if (ARCH_ARMv6 & CpuID)
else if (ARCH_ARMv6 & CpuID)
{
LOGD("Found processor with ARMv6 arch");
// NOTE: ARM v6 used instead ARM v6
// NOTE: ARM v5 used instead ARM v6
//FullName += string("_") + ARCH_ARMv6_NAME;
FullName += string("_") + ARCH_ARMv5_NAME;
// NOTE: ARM features temporary are not supported
//string features = JoinARMFeatures(CpuID);
#ifdef __SUPPORT_ARMEABI_FEATURES
string features = JoinARMFeatures(CpuID);
#else
string features;
#endif
if (!features.empty())
{
FullName += string("_") + features;
}
}
if (ARCH_ARMv7 & CpuID)
else if (ARCH_ARMv7 & CpuID)
{
LOGD("Found processor with ARMv7 arch");
FullName += string("_") + ARCH_ARMv7_NAME;
// NOTE: ARM features temporary are not supported
//string features = JoinARMFeatures(CpuID);
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
string features = JoinARMFeatures(CpuID);
#else
string features;
#endif
if (!features.empty())
{
FullName += string("_") + features;
}
}
if (ARCH_ARMv8 & CpuID)
else if (ARCH_ARMv8 & CpuID)
{
LOGD("Found processor with ARMv8 arch");
#ifdef __SUPPORT_ARMEABI_V8
FullName += string("_") + ARCH_ARMv8_NAME;
string features = JoinARMFeatures(CpuID);
if (!features.empty())
{
FullName += string("_") + features;
}
#else
FullName += string("_") + ARCH_ARMv7_NAME;
#endif
//string features = JoinARMFeatures(CpuID);
//if (!features.empty())
//{
// FullName += string("_") + features;
//}
}
else
{
LOGD("Found processor with unknown arch");
Version.clear();
CpuID = ARCH_UNKNOWN;
Platform = PLATFORM_UNKNOWN;
}
}
else

View File

@ -20,10 +20,7 @@ class ServiceStarter
public:
ServiceStarter()
{
PackageManager = new PackageManagerStub();
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7);
PackageManager->InstalledPackages.push_back(info);
PackageManager = new PackageManagerStub();
Engine = new OpenCVEngine(PackageManager);
defaultServiceManager()->addService(IOpenCVEngine::descriptor, Engine);
@ -34,7 +31,7 @@ public:
{
delete PackageManager;
}
private:
PackageManagerStub* PackageManager;
sp<IBinder> Engine;
};
@ -67,20 +64,50 @@ TEST(OpenCVEngineTest, GetVersion)
EXPECT_EQ(OPEN_CV_ENGINE_VERSION, Version);
}
TEST(OpenCVEngineTest, InstallVersion)
TEST(OpenCVEngineTest, GetPathForExecHWExistVersion)
{
sp<IOpenCVEngine> Engine = InitConnect();
Starter.PackageManager->InstalledPackages.clear();
Starter.PackageManager->InstallVersion("240", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON);
EXPECT_FALSE(NULL == Engine.get());
bool result = Engine->InstallVersion(String16("2.4"));
EXPECT_EQ(true, result);
String16 result = Engine->GetLibPathByVersion(String16("2.4"));
#ifdef __SUPPORT_TEGRA3
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string());
#else
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string());
#else
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
#endif
#endif
}
TEST(OpenCVEngineTest, GetPathForExistVersion)
TEST(OpenCVEngineTest, GetPathForExecHWOldVersion)
{
sp<IOpenCVEngine> Engine = InitConnect();
Starter.PackageManager->InstalledPackages.clear();
Starter.PackageManager->InstallVersion("242", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON);
EXPECT_FALSE(NULL == Engine.get());
String16 result = Engine->GetLibPathByVersion(String16("2.3"));
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7/lib",String8(result).string());
String16 result = Engine->GetLibPathByVersion(String16("2.4.1"));
#ifdef __SUPPORT_TEGRA3
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string());
#else
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string());
#else
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
#endif
#endif
}
TEST(OpenCVEngineTest, GetPathForExecHWNewVersion)
{
sp<IOpenCVEngine> Engine = InitConnect();
Starter.PackageManager->InstalledPackages.clear();
Starter.PackageManager->InstallVersion("242", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON);
EXPECT_FALSE(NULL == Engine.get());
String16 result = Engine->GetLibPathByVersion(String16("2.4.3"));
EXPECT_EQ(0, result.size());
}
TEST(OpenCVEngineTest, GetPathForUnExistVersion)
@ -95,7 +122,15 @@ TEST(OpenCVEngineTest, InstallAndGetVersion)
{
sp<IOpenCVEngine> Engine = InitConnect();
EXPECT_FALSE(NULL == Engine.get());
EXPECT_TRUE(Engine->InstallVersion(String16("2.5")));
String16 result = Engine->GetLibPathByVersion(String16("2.5"));
EXPECT_STREQ("/data/data/org.opencv.lib_v25_tegra3/lib", String8(result).string());
EXPECT_TRUE(Engine->InstallVersion(String16("2.4")));
String16 result = Engine->GetLibPathByVersion(String16("2.4"));
#ifdef __SUPPORT_TEGRA3
EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra3/lib", String8(result).string());
#else
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a_neon/lib", String8(result).string());
#else
EXPECT_STREQ("/data/data/org.opencv.lib_v24_armv7a/lib", String8(result).string());
#endif
#endif
}

View File

@ -13,50 +13,55 @@ TEST(PackageInfo, FullNameArmv7)
{
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7);
string name = info.GetFullName();
EXPECT_STREQ("org.opencv.lib_v23_armv7", name.c_str());
EXPECT_STREQ("org.opencv.lib_v23_armv7a", name.c_str());
}
TEST(PackageInfo, FullNameArmv7Neon)
{
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON);
string name = info.GetFullName();
EXPECT_STREQ("org.opencv.lib_v23_armv7", name.c_str());
// TODO: Replace if seporate package will be exists
//EXPECT_STREQ("org.opencv.lib_v23_armv7_neon", name.c_str());
#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
}
TEST(PackageInfo, FullNameArmv7VFPv3)
{
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_VFPv3);
string name = info.GetFullName();
EXPECT_STREQ("org.opencv.lib_v23_armv7", name.c_str());
// TODO: Replace if seporate package will be exists
//EXPECT_STREQ("org.opencv.lib_v23_armv7_vfpv3", name.c_str());
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();
EXPECT_STREQ("org.opencv.lib_v23_armv7", name.c_str());
// TODO: Replace if seporate package will be exists
//EXPECT_STREQ("org.opencv.lib_v23_armv7_neon", name.c_str());
#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
}
TEST(PackageInfo, FullNameX86SSE2)
{
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2);
string name = info.GetFullName();
#ifdef __SUPPORT_INTEL_FEATURES
EXPECT_STREQ("org.opencv.lib_v23_x86_sse2", name.c_str());
#else
EXPECT_STREQ("org.opencv.lib_v23_x86", name.c_str());
// TODO: Replace if seporate package will be exists
//EXPECT_STREQ("org.opencv.lib_v23_x86_sse2", name.c_str());
#endif
}
TEST(PackageInfo, Armv7VFPv3NeonFromFullName)
TEST(PackageInfo, Armv7NeonFromFullName)
{
PackageInfo info("org.opencv.lib_v23_armv7_vfpv3_neon", "/data/data/org.opencv.lib_v23_armv7_vfpv3_neon");
PackageInfo info("org.opencv.lib_v23_armv7a_neon", "/data/data/org.opencv.lib_v23_armv7_neon");
EXPECT_EQ("230", info.GetVersion());
EXPECT_EQ(ARCH_ARMv7 | FEATURES_HAS_VFPv3 | FEATURES_HAS_NEON, info.GetCpuID());
EXPECT_EQ(ARCH_ARMv7 | FEATURES_HAS_NEON, info.GetCpuID());
}
TEST(PackageInfo, X86SSE2FromFullName)
@ -83,11 +88,17 @@ TEST(PackageInfo, Tegra3FromFullName)
TEST(PackageInfo, FullNameTegra3)
{
PackageInfo info("230", PLATFORM_TEGRA3, 0);
EXPECT_TRUE(!info.IsValid());
// TODO: Replace if seporate package will be exists
//string name = info.GetFullName();
//EXPECT_STREQ("org.opencv.lib_v23_tegra3", name.c_str());
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)
@ -110,18 +121,19 @@ TEST(PackageInfo, Comparator1)
TEST(PackageInfo, Comparator2)
{
PackageInfo info1("240", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON | FEATURES_HAS_VFPv3);
PackageInfo info2("org.opencv.lib_v24_armv7", "/data/data/org.opencv.lib_v24_armv7");
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");
EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str());
EXPECT_EQ(info1, info2);
}
// TODO: Enable test if seporate package will be exists
// TEST(PackageInfo, Comparator3)
// {
// PackageInfo info1("230", PLATFORM_TEGRA2, 0);
// PackageInfo info2("org.opencv.lib_v23_tegra2", "/data/data/org.opencv.lib_v23_tegra2");
// EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str());
// EXPECT_EQ(info1, info2);
// }
#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");
EXPECT_STREQ(info1.GetFullName().c_str(), info2.GetFullName().c_str());
EXPECT_EQ(info1, info2);
}
#endif

View File

@ -4,7 +4,7 @@ using namespace std;
bool PackageManagerStub::InstallPackage(const PackageInfo& package)
{
InstalledPackages.push_back(PackageInfo(package.GetFullName(), "/data/data/" + package.GetFullName()));
InstalledPackages.push_back(PackageInfo(package.GetFullName(), "/data/data/" + package.GetFullName() + "/lib"));
return true;
}

View File

@ -24,47 +24,45 @@ TEST(PackageManager, InstalledVersions)
TEST(PackageManager, CheckVersionInstalled)
{
PackageManagerStub pm;
PackageInfo info("230", PLATFORM_TEGRA3, 0);
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7);
pm.InstalledPackages.push_back(info);
EXPECT_TRUE(pm.CheckVersionInstalled("230", PLATFORM_TEGRA3, 0));
EXPECT_TRUE(pm.CheckVersionInstalled("230", PLATFORM_UNKNOWN, ARCH_ARMv7));
}
TEST(PackageManager, InstallVersion)
{
PackageManagerStub pm;
PackageInfo info("230", PLATFORM_TEGRA3, 0);
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv5);
pm.InstalledPackages.push_back(info);
EXPECT_TRUE(pm.InstallVersion("240", PLATFORM_TEGRA3, 0));
EXPECT_TRUE(pm.InstallVersion("240", PLATFORM_UNKNOWN, ARCH_ARMv5));
EXPECT_EQ(2, pm.InstalledPackages.size());
EXPECT_TRUE(pm.CheckVersionInstalled("240", PLATFORM_TEGRA3, 0));
EXPECT_TRUE(pm.CheckVersionInstalled("240", PLATFORM_UNKNOWN, ARCH_ARMv5));
}
TEST(PackageManager, GetPackagePathForArmv7)
{
PackageManagerStub pm;
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7);
pm.InstalledPackages.push_back(info);
EXPECT_TRUE(pm.InstallVersion("230", PLATFORM_UNKNOWN, ARCH_ARMv7));
string path = pm.GetPackagePathByVersion("230", PLATFORM_UNKNOWN, ARCH_ARMv7);
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7/lib", path.c_str());
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a/lib", path.c_str());
}
TEST(PackageManager, GetPackagePathForArmv7Neon)
{
PackageManagerStub pm;
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON);
pm.InstalledPackages.push_back(info);
EXPECT_TRUE(pm.InstallVersion("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON));
string path = pm.GetPackagePathByVersion("230", PLATFORM_UNKNOWN, ARCH_ARMv7 | FEATURES_HAS_NEON);
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7/lib", path.c_str());
// TODO: Replace if seporate package will be exists
//EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7_neon/lib", path.c_str());
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a_neon/lib", path.c_str());
#else
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a/lib", path.c_str());
#endif
}
TEST(PackageManager, GetPackagePathForX86)
{
PackageManagerStub pm;
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_X86);
pm.InstalledPackages.push_back(info);
EXPECT_TRUE(pm.InstallVersion("230", PLATFORM_UNKNOWN, ARCH_X86));
string path = pm.GetPackagePathByVersion("230", PLATFORM_UNKNOWN, ARCH_X86);
EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86/lib", path.c_str());
}
@ -72,12 +70,29 @@ TEST(PackageManager, GetPackagePathForX86)
TEST(PackageManager, GetPackagePathForX86SSE2)
{
PackageManagerStub pm;
PackageInfo info("230", PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2);
pm.InstalledPackages.push_back(info);
EXPECT_TRUE(pm.InstallVersion("230", PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2));
string path = pm.GetPackagePathByVersion("230", PLATFORM_UNKNOWN, ARCH_X86 | FEATURES_HAS_SSE2);
#ifdef __SUPPORT_INTEL_FEATURES
EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86_sse2/lib", path.c_str());
#else
EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86/lib", path.c_str());
// TODO: Replace if seporate package will be exists
//EXPECT_STREQ("/data/data/org.opencv.lib_v23_x86_sse2/lib", path.c_str());
#endif
}
TEST(PackageManager, GetPackagePathForTegra3)
{
PackageManagerStub pm;
EXPECT_TRUE(pm.InstallVersion("230", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON));
string path = pm.GetPackagePathByVersion("230", PLATFORM_TEGRA3, ARCH_ARMv7 | FEATURES_HAS_NEON);
#ifdef __SUPPORT_TEGRA3
EXPECT_STREQ("/data/data/org.opencv.lib_v23_tegra3/lib", path.c_str());
#else
#ifdef __SUPPORT_ARMEABI_V7A_FEATURES
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a_neon/lib", path.c_str());
#else
EXPECT_STREQ("/data/data/org.opencv.lib_v23_armv7a/lib", path.c_str());
#endif
#endif
}
// TODO: Enable tests if seporate package will be exists
@ -89,12 +104,5 @@ TEST(PackageManager, GetPackagePathForX86SSE2)
// string path = pm.GetPackagePathByVersion("240", PLATFORM_TEGRA2, 0);
// EXPECT_STREQ("/data/data/org.opencv.lib_v24_tegra2/lib", path.c_str());
// }
//
// TEST(PackageManager, GetPackagePathForTegra3)
// {
// PackageManagerStub pm;
// PackageInfo info("230", PLATFORM_TEGRA3, 0);
// pm.InstalledPackages.push_back(info);
// string path = pm.GetPackagePathByVersion("230", PLATFORM_TEGRA3, 0);
// EXPECT_STREQ("/data/data/org.opencv.lib_v23_tegra3/lib", path.c_str());
// }