-
Notifications
You must be signed in to change notification settings - Fork 7
Add Gtest support to test Camera-vhal API's #11
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
Open
Sapna1-singh
wants to merge
6
commits into
projectceladon:r/ics3a/main
Choose a base branch
from
Sapna1-singh:ww07_Gtest
base: r/ics3a/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13e8a83
Modularize code and add a helper class for camera info validation
Sapna1-singh c47f2c2
Add Gtest support to test Camera-vhal API's
Sapna1-singh 71a970b
Fix crash seen in deleting VirtualCameraFactory object
Sapna1-singh c670149
Fix the clean up issue observed while running gtest for camera-vhal
Sapna1-singh 4406922
Merge branch 'r/ics3a/main' into ww07_Gtest
Sapna1-singh 56be12d
Update ClientCommunicator.cpp
Sapna1-singh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 android.hardware.camera.common@1.0-helper android.hardware.graphics.mapper@2.0 | ||
|
|
||
|
|
||
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| { | ||
| 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); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.