-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Gtest support to test Camera-vhal API's #11
base: r/ics3a/main
Are you sure you want to change the base?
Conversation
2ff2b56
to
51be974
Compare
Gtest/Android.mk
Outdated
LOCAL_CFLAGS += -fexceptions | ||
LOCAL_MODULE_TAGS:= optional | ||
|
||
LOCAL_SRC_FILES := main.cpp CameraFixture.cpp streamer_simulation_camera_client.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the same naming conventions for the files , Classes and functions ?
Gtest/Android.mk
Outdated
LOCAL_MODULE_TAGS:= optional | ||
|
||
LOCAL_SRC_FILES := main.cpp CameraFixture.cpp streamer_simulation_camera_client.cpp | ||
LOCAL_SHARED_LIBRARIES += liblog libcutils libutils camera.cic_cloud libvhal-client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would be better to use camera.$(TARGET_PRODUCT) instead of hardcoding.
Gtest/CameraFixture.cpp
Outdated
|
||
|
||
void CameraFixture::runStreamer(){ | ||
cc.IsRunning = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is IsRunning a static variable and not a member ?
Also, I think initializing it to true can be done from startDummyStreamer function internally.
Similarly setting to false can be done through a simple stopStreamer API. Thus it can be a private member too.
Gtest/CameraFixture.cpp
Outdated
CameraFixture::CameraFixture() | ||
{ | ||
SetCallback(); | ||
t1 = new thread(&CameraFixture::runStreamer, this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory Leak ? This object t1 is not destructed.
Gtest/CameraFixture.h
Outdated
#include "VirtualCameraFactory.h" | ||
#include "streamer_simulation_camera_client.h" | ||
|
||
#define clientId 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very common variable, and shouldn't be defined as a macro.
And, I think its better to use upper case for all macros.
[&](const VideoSink::camera_config_cmd_t& ctrl_msg) { | ||
switch (ctrl_msg.cmd) { | ||
case VideoSink::camera_cmd_t::CMD_OPEN: { | ||
cout << "Received Open command from Camera VHal\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Printing a TAG and func might be helpful for debugging.
include/VirtualCameraFactory.h
Outdated
/* | ||
* Returns the shared pointer for client Communicator | ||
*/ | ||
std::vector<std::shared_ptr<ClientCommunicator>> getClientThread() { return mClientThreads; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not pass the clientId and just return the particular ClientThread ?
src/ClientCommunicator.cpp
Outdated
val_client_cap[i].validOrientation = IsSensorOrientationValid(camera_info[i].sensorOrientation); | ||
val_client_cap[i].validCameraFacing = IsCameraFacingValid(camera_info[i].facing); | ||
|
||
/*switch (camera_info[i].codec_type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete these lines instead of commenting out.
src/ClientCommunicator.cpp
Outdated
@@ -141,6 +172,8 @@ void ClientCommunicator::configureCapabilities() { | |||
if (header.type != CAMERA_INFO) { | |||
ALOGE("%s(%d): invalid camera_packet_type: %s", __FUNCTION__, mClientId, | |||
camera_type_to_str(header.type)); | |||
if(header.type == REQUEST_CAPABILITY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is not a valid usecase, I wouldn't recommend using a goto statement here.
If we really want to support the REQUEST_CAPABILITY dynamically, we should modularize all of these socket communication code, to save the current state, and handle the state changes accordingly.
6bcebd7
to
7267fde
Compare
include/ClientCommunicatorHelper.h
Outdated
#ifndef CLIENT_COMMUNICATOR_HELPER_H | ||
#define CLIENT_COMMUNICATOR_HELPER_H | ||
|
||
#include <iostream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need these 2 headers included ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its better to keep these 2 headers to avoid redefinition of header file issue.
include/ClientCommunicatorHelper.h
Outdated
|
||
namespace android { | ||
|
||
class ClientCommunicatorHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we have some ClientCommunication specific contents to be added in this file, I think it would be better to rename this something like CapabilitiesHelper
?
src/ClientCommunicatorHelper.cpp
Outdated
#include <ClientCommunicatorHelper.h> | ||
#include "CameraSocketCommand.h" | ||
#include <log/log.h> | ||
#include <sys/socket.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again please check if all these headers are required.
@@ -297,22 +233,24 @@ void ClientCommunicator::configureCapabilities() { | |||
// Wait till complete the metadata update for a camera. | |||
{ | |||
Mutex::Autolock al(sMutex); | |||
// Dynamic client configuration is not supported when camera |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamic configuration check is not required anymore ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No its not required. Its already fixed from AIC application code.
src/ClientCommunicator.cpp
Outdated
@@ -321,16 +259,14 @@ void ClientCommunicator::configureCapabilities() { | |||
if (send(mClientFd, ack_packet, ack_packet_size, 0) < 0) { | |||
ALOGE("%s(%d): Failed to send camera capabilities, err: %s ", __FUNCTION__, mClientId, | |||
strerror(errno)); | |||
goto out; | |||
free(ack_packet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can avoid multiple free calls if you put the below logs in else block, and remove this line ?
src/ClientCommunicator.cpp
Outdated
break; | ||
case CAMERA_DATA: | ||
if (!mIsConfigurationDone) { | ||
ALOGE("%s(%d): Not Valid Type.....camera_packet_type: %s, line_num = %d ", __FUNCTION__, mClientId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention Configuration Incomplete in the logs to indicate why the packet is invalid.
eg.
ALOGE("%s(%d): Invalid camera_packet_type: %s, Configuration not completed", __FUNCTION__, mClientId,
camera_type_to_str(header.type));```
src/ClientCommunicator.cpp
Outdated
handleIncomingFrames(header.size); | ||
break; | ||
default: | ||
if (header.size > mSocketBuffer.size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this condition should be part of the default case, instead it can be checked before entering the switch case probably.
Even if its targeted only for data packets, I think it should be handled at the beginning of case CAMERA_DATA:
.
Gtest/CameraClient.h
Outdated
|
||
class CameraClient { | ||
private: | ||
bool IsRunning; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have a uniform naming convention for the variables(at least for the newly introduced source files).
Could be mIsRunning, is_running_
, but should be same across the variables used (instance_id , video_sink
etc).
Modularize all the socket communication code for handling all the incoming requests dynamically and add a helper class that facilitates validation of all the camera info metadata. Tracked-On: OAM-106780 Signed-off-by: Singh, Sapna1 <[email protected]>
Introduce a property based on which instance id is taken for socket connection for Gtest purpose. Check for this property in camera-vhal and if this set then use the instance id that is set by property for Gtest else use the default one. Newly introduced property is ro.boot.container.testid. Add Unit TestCases for Camera-vhal in Gtest. Tracked-On: OAM-105831 Signed-off-by: Singh, Sapna1 [email protected]
ConnectionsListener class was derived from Thread class which was causing issue while calling join for this thread from VirtualCameraFactory destructor. The Base class from which ConnectionsListener was derived was not the proper class. With current implementation, instead of deriving from thread class, a thread is introduced as a member of the class to do the same job and it is started during creation of ConnectionsListener object Tracked-On: OAM-106781 Signed-off-by: Singh, Sapna1 <[email protected]>
7267fde
to
3ddd23c
Compare
close the client thread after completing the execution of all testcases. An API is introduced to do cleanup and in that API, client thread exit is requested, socket server thread exit is requested and joins with the main thread after all the cleanup. Tracked-On: OAM-106783 Signed-off-by: Singh, Sapna1 <[email protected]>
3ddd23c
to
c670149
Compare
Introduce a property based on which instance id is taken for socket connection for Gtest purpose. Check for this property in camera-vhal and if this set then use the instance id that is set by property for Gtest else use the default one.
Newly introduced property is ro.boot.container.testid.
Add Unit TestCases for Camera-vhal in Gtest.
Tracked-On: OAM-105831
Signed-off-by: Singh, Sapna1 [email protected]