Skip to content
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

Open
wants to merge 6 commits into
base: r/ics3a/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

##################### Build camera-vhal #######################

LOCAL_MODULE := camera.$(TARGET_PRODUCT)
Expand All @@ -37,6 +36,7 @@ camera_vhal_src := \
src/Exif.cpp \
src/Thumbnail.cpp \
src/ClientCommunicator.cpp \
src/CapabilitiesHelper.cpp \
src/ConnectionsListener.cpp \
src/CameraSocketCommand.cpp \
src/onevpl-video-decode/MfxDecoder.cpp \
Expand Down Expand Up @@ -137,4 +137,4 @@ LOCAL_MODULE := camera.$(TARGET_PRODUCT).jpeg
include $(BUILD_SHARED_LIBRARY)

######################################################

include $(LOCAL_PATH)/Gtest/Android.mk
36 changes: 36 additions & 0 deletions Gtest/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_LDLIBS += -landroid -llog
LOCAL_CFLAGS += -fexceptions
LOCAL_MODULE_TAGS:= optional

LOCAL_SRC_FILES := main.cpp CameraFixture.cpp CameraClient.cpp
LOCAL_SHARED_LIBRARIES += liblog libcutils libutils camera.$(TARGET_PRODUCT) libvhal-client
LOCAL_MULTILIB := 64
LOCAL_VENDOR_MODULE := true
LOCAL_STATIC_LIBRARIES += libgtest_main libgtest libgmock [email protected] [email protected]


LOCAL_CPPFLAGS := $(LOG_FLAGS) $(WARNING_LEVEL) $(DEBUG_FLAGS) $(VERSION_FLAGS)

LOCAL_C_INCLUDES += \
$(LOCAL_PATH) \
$(LOCAL_PATH)/../../libvhal-client \
$(LOCAL_PATH)/../include \
external/libjpeg-turbo \
external/libexif \
external/libyuv/files/include \
frameworks/native/include/media/hardware \
hardware/intel/libva \
hardware/intel/onevpl/api/vpl \
hardware/libhardware/modules/gralloc \
$(LOCAL_PATH)/include \
$(call include-path-for, camera) \
external/gtest/include \
external/gtest \
bionic

LOCAL_MODULE:= CameraFixtureTest

include $(BUILD_EXECUTABLE)
123 changes: 123 additions & 0 deletions Gtest/CameraClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#define LOG_TAG "CameraClient"
#include "CameraClient.h"
#include <log/log.h>

using namespace std::chrono_literals;
using namespace vhal::client;
using namespace std;
int CameraClient::startDummyStreamer()
{
is_running = true;
string socket_path("/ipc");
UnixConnectionInfo conn_info = { socket_path, instance_id };
try {
video_sink = make_shared<VideoSink>(conn_info,
[&](const VideoSink::camera_config_cmd_t& ctrl_msg) {
switch (ctrl_msg.cmd) {
case VideoSink::camera_cmd_t::CMD_OPEN: {
ALOGI("%s: Received Open command from Camera VHal", __FUNCTION__);
break;
}
case VideoSink::camera_cmd_t::CMD_CLOSE:
ALOGI("%s: Received Close command from Camera VHal", __FUNCTION__);
exit(0);
default:
ALOGI("%s: Unknown Command received, exiting with failure", __FUNCTION__);
exit(1);
}
});

} catch (const std::exception& ex) {
ALOGI("%s: VideoSink creation error : %s", __FUNCTION__,ex.what());
exit(1);
}

ALOGI("%s: Waiting Camera Open callback..", __FUNCTION__);

while (!video_sink->IsConnected())
this_thread::sleep_for(100ms);

// we need to be alive :)
while (is_running) {
this_thread::sleep_for(100ms);
}
return 0;
}

bool CameraClient::IsConnected() {
return video_sink->IsConnected();
}

void CameraClient::RequestCameraCapability() {
if(IsConnected()) {
ALOGI("%s: Calling GetCameraCapabilty..", __FUNCTION__);
video_sink->GetCameraCapabilty();
}
}

void CameraClient::sendOneCameraConfig() {
int noOfCameras = 1;
std::vector<VideoSink::camera_info_t> camera_info(noOfCameras);
for (int i = 0; i < noOfCameras; i++) {
camera_info[i].cameraId = i;
camera_info[i].codec_type = VideoSink::VideoCodecType::kH264;
camera_info[i].resolution = VideoSink::FrameResolution::k1080p;
camera_info[i].sensorOrientation = VideoSink::SensorOrientation::ORIENTATION_0;
camera_info[i].facing = VideoSink::CameraFacing::BACK_FACING;
}

ALOGI("%s: Calling SetCameraCapabilty..", __FUNCTION__);
video_sink->SetCameraCapabilty(camera_info);
}

void CameraClient::sendTwoCameraConfig() {
int noOfCameras = 2;
std::vector<VideoSink::camera_info_t> camera_info(noOfCameras);
for (int i = 0; i < noOfCameras; i++) {
camera_info[i].cameraId = i;
camera_info[i].codec_type = VideoSink::VideoCodecType::kH264;
camera_info[i].resolution = (i==0) ? VideoSink::FrameResolution::k1080p : VideoSink::FrameResolution::k720p;
camera_info[i].sensorOrientation = VideoSink::SensorOrientation::ORIENTATION_0;
camera_info[i].facing = (i == 0) ? VideoSink::CameraFacing::BACK_FACING : VideoSink::CameraFacing::FRONT_FACING;
}

ALOGI("%s: Calling SetCameraCapabilty..", __FUNCTION__);
video_sink->SetCameraCapabilty(camera_info);
}

void CameraClient::sendMultipleCameraConfig() {
int noOfCameras = 4;
std::vector<VideoSink::camera_info_t> camera_info(noOfCameras);
for (int i = 0; i < noOfCameras; i++) {
camera_info[i].cameraId = i;
camera_info[i].codec_type = VideoSink::VideoCodecType::kH264;
camera_info[i].resolution = (i==0) ? VideoSink::FrameResolution::k1080p : VideoSink::FrameResolution::k720p;
camera_info[i].sensorOrientation = VideoSink::SensorOrientation::ORIENTATION_0;
camera_info[i].facing = (i == 0) ? VideoSink::CameraFacing::BACK_FACING : VideoSink::CameraFacing::FRONT_FACING;
}

ALOGI("%s: Calling SetCameraCapabilty..", __FUNCTION__);
video_sink->SetCameraCapabilty(camera_info);
}

void CameraClient::stopDummyStreamer() {
is_running = false;
}
48 changes: 48 additions & 0 deletions Gtest/CameraClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <iostream>
#include "video_sink.h"
#include <array>
#include <atomic>
#include <chrono>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <vector>

using namespace vhal::client;
using namespace std;

class CameraClient {
private:
bool is_running;
public :
int startDummyStreamer();
void stopDummyStreamer();
void RequestCameraCapability();
void sendTwoCameraConfig();
void sendOneCameraConfig();
bool IsConnected();
void sendMultipleCameraConfig();

int instance_id = 10000;
shared_ptr<VideoSink> video_sink;
};
126 changes: 126 additions & 0 deletions Gtest/CameraFixture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <string>
#include <list>
#include <thread>
#include <chrono>
#include "CameraFixture.h"
#include "CameraSocketCommand.h"

using namespace std;
using namespace android;
using namespace std::chrono_literals;

void CameraFixture::runStreamer(){
mCameraClient.startDummyStreamer();
}

CameraFixture::CameraFixture()
{
SetCallback();
}

void CameraFixture::SetUp()
{
t1 = new thread(&CameraFixture::runStreamer, this);
this_thread::sleep_for(1500ms);
}

void CameraFixture::TearDown()
{
Sapna1-singh marked this conversation as resolved.
Show resolved Hide resolved
mCameraClient.stopDummyStreamer();
t1->join();
delete t1;
t1 = nullptr;
}

CameraFixture::~CameraFixture()
{
DestroyCallbacks();
}

TEST_F(CameraFixture, ClientWithOneCamera)
{
ASSERT_EQ(NO_CAMERA_PRESENT, gVirtualCameraFactory.get_number_of_cameras());
mCameraClient.RequestCameraCapability();
mCameraClient.sendOneCameraConfig();
this_thread::sleep_for(500ms);
ASSERT_EQ(ONE_CAMERA_CLIENT, gVirtualCameraFactory.get_number_of_cameras());
gVirtualCameraFactory.clearCameraInfo(client_id);
}

TEST_F(CameraFixture, ClientWithTwoCamera)
{
mCameraClient.RequestCameraCapability();
mCameraClient.sendTwoCameraConfig();
this_thread::sleep_for(500ms);
ASSERT_EQ(TWO_CAMERA_CLIENT, gVirtualCameraFactory.get_number_of_cameras());
gVirtualCameraFactory.clearCameraInfo(client_id);
}

TEST_F(CameraFixture, ClientWithMultiCamera)
{
mCameraClient.RequestCameraCapability();
mCameraClient.sendMultipleCameraConfig();
this_thread::sleep_for(500ms);
ASSERT_EQ(MULTI_CAMERA_CLIENT, gVirtualCameraFactory.get_number_of_cameras());
gVirtualCameraFactory.clearCameraInfo(client_id);
}

TEST_F(CameraFixture, CheckForCodecType)
{
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsCodecTypeValid((uint32_t)android::socket::VideoCodecType::kH264));
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsCodecTypeValid((uint32_t)android::socket::VideoCodecType::kH265));
ASSERT_EQ(INVALID_TYPE, mCapabilitiesHelper.IsCodecTypeValid((uint32_t)INVALID_WAV));
}

TEST_F(CameraFixture, CheckForFacing)
{
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsCameraFacingValid((uint32_t)android::socket::CameraFacing::BACK_FACING));
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsCameraFacingValid((uint32_t)android::socket::CameraFacing::FRONT_FACING));
ASSERT_EQ(INVALID_TYPE, mCapabilitiesHelper.IsCameraFacingValid((uint32_t)FRONT_FACING_SECOND));
}

TEST_F(CameraFixture, CheckForOrientation)
{
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsSensorOrientationValid((uint32_t)android::socket::SensorOrientation::ORIENTATION_90));
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsSensorOrientationValid((uint32_t)android::socket::SensorOrientation::ORIENTATION_270));
ASSERT_EQ(INVALID_TYPE, mCapabilitiesHelper.IsSensorOrientationValid((uint32_t)INVALID_ORIENTATION_360));
}

TEST_F(CameraFixture, CheckForResolution)
{
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsResolutionValid((uint32_t)android::socket::FrameResolution::k720p));
ASSERT_EQ(VALID_TYPE, mCapabilitiesHelper.IsResolutionValid((uint32_t)android::socket::FrameResolution::k1080p));
ASSERT_EQ(INVALID_TYPE, mCapabilitiesHelper.IsResolutionValid((uint32_t)INVALID_k2160p));
}

TEST_F(CameraFixture, MultipleCameraCapReq)
{
mCameraClient.RequestCameraCapability();
mCameraClient.RequestCameraCapability();
mCameraClient.RequestCameraCapability();
mCameraClient.sendMultipleCameraConfig();
this_thread::sleep_for(500ms);
ASSERT_EQ(MULTI_CAMERA_CLIENT, gVirtualCameraFactory.get_number_of_cameras());
gVirtualCameraFactory.clearCameraInfo(client_id);
this_thread::sleep_for(200ms);
gVirtualCameraFactory.destroy(client_id);
}

Loading