Fix a resource clean-up routine
When a test case is being terminated, VTS framework calls TearDown() to
clean up all resources. VtsHalEvsV1_1TargetTest stores weak references
to opened hardware cameras for this and tries to close them explicitly
when it can promote them. However, it was observed that VirtualCamera's
destructor is not called yet even it fails to promote.
Therefore, this change modifies a container to hold a strong pointer and
explictly removes it after a test case calls closeCamera().
Also, this change corrects a bug in checking setExtendedInfo_1_1()
results.
Bug: 150893461
Test: vts-trafed VtsHalEvsV1_1_TargetTest
Change-Id: I23b55b2f2282834fb5a9d364f4eb176060027de1
diff --git a/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp b/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp
index b31795b..368a6d4 100644
--- a/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp
+++ b/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp
@@ -97,18 +97,19 @@
std::string service_name = GetParam();
pEnumerator = IEvsEnumerator::getService(service_name);
ASSERT_NE(pEnumerator.get(), nullptr);
+ LOG(INFO) << "Test target service: " << service_name;
mIsHwModule = pEnumerator->isHardware();
}
virtual void TearDown() override {
// Attempt to close any active camera
- for (auto &&c : activeCameras) {
- sp<IEvsCamera_1_1> cam = c.promote();
+ for (auto &&cam : activeCameras) {
if (cam != nullptr) {
pEnumerator->closeCamera(cam);
}
}
+ activeCameras.clear();
}
protected:
@@ -235,7 +236,7 @@
std::vector<CameraDesc> cameraInfo; // Empty unless/until loadCameraList() is called
bool mIsHwModule; // boolean to tell current module under testing
// is HW module implementation.
- std::deque<wp<IEvsCamera_1_1>> activeCameras; // A list of active camera handles that are
+ std::deque<sp<IEvsCamera_1_1>> activeCameras; // A list of active camera handles that are
// needed to be cleaned up.
std::vector<UltrasonicsArrayDesc>
ultrasonicsArraysInfo; // Empty unless/until
@@ -273,10 +274,7 @@
}
for (int pass = 0; pass < 2; pass++) {
- activeCameras.clear();
- sp<IEvsCamera_1_1> pCam =
- IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
- .withDefault(nullptr);
+ sp<IEvsCamera_1_1> pCam = pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg);
ASSERT_NE(pCam, nullptr);
for (auto&& devName : devices) {
@@ -302,15 +300,16 @@
const auto id = 0xFFFFFFFF; // meaningless id
hidl_vec<uint8_t> values;
auto err = pCam->setExtendedInfo_1_1(id, values);
- ASSERT_EQ(EvsResult::INVALID_ARG, err);
+ ASSERT_NE(EvsResult::INVALID_ARG, err);
pCam->getExtendedInfo_1_1(id, [](const auto& result, const auto& data) {
- ASSERT_EQ(EvsResult::INVALID_ARG, result);
+ ASSERT_NE(EvsResult::INVALID_ARG, result);
ASSERT_EQ(0, data.size());
});
// Explicitly close the camera so resources are released right away
pEnumerator->closeCamera(pCam);
+ activeCameras.clear();
}
}
}
@@ -378,6 +377,7 @@
// Close the superceded camera
pEnumerator->closeCamera(pCam);
+ activeCameras.pop_front();
// Verify that the second camera instance self-identifies correctly
pCam2->getCameraInfo_1_1([&cam](CameraDesc desc) {
@@ -388,6 +388,7 @@
// Close the second camera instance
pEnumerator->closeCamera(pCam2);
+ activeCameras.pop_front();
}
// Sleep here to ensure the destructor cleanup has time to run so we don't break follow on tests
@@ -418,7 +419,6 @@
continue;
}
- activeCameras.clear();
sp<IEvsCamera_1_1> pCam =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
.withDefault(nullptr);
@@ -484,6 +484,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam);
+ activeCameras.clear();
}
}
@@ -515,7 +516,6 @@
continue;
}
- activeCameras.clear();
sp<IEvsCamera_1_1> pCam =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
.withDefault(nullptr);
@@ -568,6 +568,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam);
+ activeCameras.clear();
}
}
@@ -622,7 +623,6 @@
continue;
}
- activeCameras.clear();
sp<IEvsCamera_1_1> pCam =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
.withDefault(nullptr);
@@ -665,6 +665,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam);
+ activeCameras.clear();
}
// Explicitly release the display
@@ -694,7 +695,6 @@
// Test each reported camera
for (auto&& cam: cameraInfo) {
- activeCameras.clear();
// Create two camera clients.
sp<IEvsCamera_1_1> pCam0 =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
@@ -773,6 +773,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam0);
pEnumerator->closeCamera(pCam1);
+ activeCameras.clear();
// TODO(b/145459970, b/145457727): below sleep() is added to ensure the
// destruction of active camera objects; this may be related with two
@@ -808,7 +809,6 @@
continue;
}
- activeCameras.clear();
// Create a camera client
sp<IEvsCamera_1_1> pCam =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
@@ -921,6 +921,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam);
+ activeCameras.clear();
}
}
@@ -956,7 +957,6 @@
continue;
}
- activeCameras.clear();
// Create two camera clients.
sp<IEvsCamera_1_1> pCamMaster =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
@@ -1102,6 +1102,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCamMaster);
pEnumerator->closeCamera(pCamNonMaster);
+ activeCameras.clear();
}
}
@@ -1137,7 +1138,6 @@
continue;
}
- activeCameras.clear();
// Create two camera clients.
sp<IEvsCamera_1_1> pCamMaster =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
@@ -1575,6 +1575,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCamMaster);
pEnumerator->closeCamera(pCamNonMaster);
+ activeCameras.clear();
}
}
@@ -1605,8 +1606,6 @@
// Test each reported camera
for (auto&& cam: cameraInfo) {
- activeCameras.clear();
-
// Create two clients
sp<IEvsCamera_1_1> pCam0 =
IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
@@ -1944,6 +1943,8 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam0);
pEnumerator->closeCamera(pCam1);
+ activeCameras.clear();
+
}
// Explicitly release the display
@@ -1969,7 +1970,6 @@
// Test each reported camera
for (auto&& cam: cameraInfo) {
- activeCameras.clear();
// choose a configuration that has a frame rate faster than minReqFps.
Stream targetCfg = {};
const int32_t minReqFps = 15;
@@ -2049,6 +2049,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam);
+ activeCameras.clear();
}
// Explicitly release the display
@@ -2074,7 +2075,6 @@
// Test each reported camera
for (auto&& cam: cameraInfo) {
- activeCameras.clear();
// choose a configuration that has a frame rate faster than minReqFps.
Stream targetCfg = {};
const int32_t minReqFps = 15;
@@ -2201,6 +2201,7 @@
// Explicitly release the camera
pEnumerator->closeCamera(pCam0);
pEnumerator->closeCamera(pCam1);
+ activeCameras.clear();
}
}