From 1dae430fe8a5df7421966dbf8f8d12be884df366 Mon Sep 17 00:00:00 2001 From: "nibha.sharma" Date: Fri, 28 Apr 2017 14:54:19 +0530 Subject: [PATCH] [ITC][ACR-917][usbhost][Added new module of usb host] Change-Id: Ie07616975341336275ab9a85d230692729af0f6a Signed-off-by: nibha.sharma --- packaging/itc/native-usbhost-itc.spec | 78 +++++++++++ packaging/itc/native-usbhost-itc.xml | 14 ++ src/itc/usbhost/CMakeLists.txt | 42 ++++++ src/itc/usbhost/ITs-usbhost-common.c | 56 ++++++++ src/itc/usbhost/ITs-usbhost-common.h | 37 +++++ src/itc/usbhost/ITs-usbhost.c | 110 +++++++++++++++ src/itc/usbhost/tct-usbhost-native.c | 143 ++++++++++++++++++++ src/itc/usbhost/tct-usbhost-native_mobile.h | 32 +++++ 8 files changed, 512 insertions(+) create mode 100755 packaging/itc/native-usbhost-itc.spec create mode 100755 packaging/itc/native-usbhost-itc.xml create mode 100755 src/itc/usbhost/CMakeLists.txt create mode 100755 src/itc/usbhost/ITs-usbhost-common.c create mode 100755 src/itc/usbhost/ITs-usbhost-common.h create mode 100755 src/itc/usbhost/ITs-usbhost.c create mode 100755 src/itc/usbhost/tct-usbhost-native.c create mode 100755 src/itc/usbhost/tct-usbhost-native_mobile.h diff --git a/packaging/itc/native-usbhost-itc.spec b/packaging/itc/native-usbhost-itc.spec new file mode 100755 index 000000000..89a6657ed --- /dev/null +++ b/packaging/itc/native-usbhost-itc.spec @@ -0,0 +1,78 @@ +%define MODULE_NAME usbhost +%define MODULE_LIBNAME usbhost +Name: native-%{MODULE_NAME}-itc +Summary: Native API Integration TC (%{name}) +Version: 0.1 +Release: 0 +Group: Development/Tools +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: pkgconfig(%{MODULE_LIBNAME}) +BuildRequires: pkgconfig(capi-appfw-application) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: cmake +BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(elementary) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-system-info) + +%description +Native API Integration TC (%{name}) + +%prep +%setup -q + +%build + +%define PREFIX "%{_libdir}/%{name}" + +export LDFLAGS+="-Wl,--rpath=%{PREFIX} -Wl,--as-needed" + +%if %{?ASAN_BUILD:1}0 + %if %{?DEVICE_BUILD_TYPE_MOBILE:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="mobile" -DASANBUILD="true" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif + %if %{?DEVICE_BUILD_TYPE_WEARABLE:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="wearable" -DASANBUILD="true" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif + %if %{?DEVICE_BUILD_TYPE_TV:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="tv" -DASANBUILD="true" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif + %if %{?DEVICE_BUILD_TYPE_COMMON_IOT:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="common_iot" -DASANBUILD="true" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif +%else + %if %{?DEVICE_BUILD_TYPE_MOBILE:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="mobile" -DASANBUILD="false" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif + %if %{?DEVICE_BUILD_TYPE_WEARABLE:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="wearable" -DASANBUILD="false" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif + %if %{?DEVICE_BUILD_TYPE_TV:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="tv" -DASANBUILD="false" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif + %if %{?DEVICE_BUILD_TYPE_COMMON_IOT:1}0 + cmake . -DMODULE="%{MODULE_NAME}" -DBUILDTCTYPE="itc" -DDEVICE_BUILD_TYPE="common_iot" -DASANBUILD="false" -DCMAKE_INSTALL_PREFIX=%{_prefix} + %endif +%endif + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install +mkdir -p %{buildroot}/usr/share/license +cp LICENSE %{buildroot}/usr/share/license/%{name} + +mkdir -p %{buildroot}/usr/share/packages/ +cp packaging/itc/native-%{MODULE_NAME}-itc.xml %{buildroot}/usr/share/packages/ +mkdir -p %{buildroot}%{APP_PATH}%{name}/bin +%post + +%postun + + +%files +%{APP_PATH}%{name}/* +/usr/share/packages/native-%{MODULE_NAME}-itc.xml +/usr/share/license/%{name} diff --git a/packaging/itc/native-usbhost-itc.xml b/packaging/itc/native-usbhost-itc.xml new file mode 100755 index 000000000..d9b2d1530 --- /dev/null +++ b/packaging/itc/native-usbhost-itc.xml @@ -0,0 +1,14 @@ + + + + test + Native API test Application + + + + + + + + + diff --git a/src/itc/usbhost/CMakeLists.txt b/src/itc/usbhost/CMakeLists.txt new file mode 100755 index 000000000..62c97fcf9 --- /dev/null +++ b/src/itc/usbhost/CMakeLists.txt @@ -0,0 +1,42 @@ +SET(PKG_NAME "usbhost") + +SET(EXEC_NAME "tct-${PKG_NAME}-native") +SET(RPM_NAME "native-${PKG_NAME}-itc") + +SET(CAPI_LIB "usbhost") +SET(TC_SOURCES + ITs-usbhost-common.c + ITs-usbhost.c +) + +PKG_CHECK_MODULES(${CAPI_LIB} REQUIRED + ${CAPI_LIB} + capi-appfw-application + glib-2.0 + bundle + capi-system-info + dlog + elementary +) + +INCLUDE_DIRECTORIES( + ${${CAPI_LIB}_INCLUDE_DIRS} +) + +ADD_EXECUTABLE(${EXEC_NAME} ${EXEC_NAME}.c ${TC_SOURCES} ${COMMON_FILE}) +TARGET_LINK_LIBRARIES(${EXEC_NAME} + ${${CAPI_LIB}_LIBRARIES} + bundle +) + +INSTALL(PROGRAMS ${EXEC_NAME} + DESTINATION ${BIN_DIR}/${RPM_NAME}/bin +) + +IF( DEFINED ASAN ) +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -pie -g -fsanitize=address -fsanitize-recover=address -U_FORTIFY_SOURCE -fno-omit-frame-pointer") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib -Wl,-fsanitize=address") +ELSE() +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fPIE -Wall") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib -pie") +ENDIF() diff --git a/src/itc/usbhost/ITs-usbhost-common.c b/src/itc/usbhost/ITs-usbhost-common.c new file mode 100755 index 000000000..2a5cb610b --- /dev/null +++ b/src/itc/usbhost/ITs-usbhost-common.c @@ -0,0 +1,56 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// 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. +// +#include "ITs-usbhost-common.h" + +/** @addtogroup itc-usbhost +* @ingroup itc +* @{ +*/ + +//Add helper function definitions here + +/** +* @function UsbHostGetError +* @description Maps usb_host_error_e enums +* @parameter error : error level +* @return error string +*/ +char* UsbHostGetError(usb_host_error_e error) +{ + char *szErrorVal = NULL; + switch ( error ) + { + case USB_HOST_ERROR_NONE: szErrorVal = "USB_HOST_ERROR_NONE"; break; + case USB_HOST_ERROR_IO_ERROR: szErrorVal = "USB_HOST_ERROR_IO_ERROR"; break; + case USB_HOST_ERROR_INVALID_PARAMETER: szErrorVal = "USB_HOST_ERROR_INVALID_PARAMETER"; break; + case USB_HOST_ERROR_PERMISSION_DENIED: szErrorVal = "USB_HOST_ERROR_PERMISSION_DENIED"; break; + case USB_HOST_ERROR_NO_SUCH_DEVICE: szErrorVal = "USB_HOST_ERROR_NO_SUCH_DEVICE"; break; + case USB_HOST_ERROR_NOT_FOUND: szErrorVal = "USB_HOST_ERROR_NOT_FOUND"; break; + case USB_HOST_ERROR_RESOURCE_BUSY: szErrorVal = "USB_HOST_ERROR_RESOURCE_BUSY"; break; + case USB_HOST_ERROR_TIMED_OUT: szErrorVal = "USB_HOST_ERROR_TIMED_OUT"; break; + case USB_HOST_ERROR_OVERFLOW: szErrorVal = "USB_HOST_ERROR_OVERFLOW"; break; + case USB_HOST_ERROR_DEVICE_NOT_OPENED: szErrorVal = "USB_HOST_ERROR_DEVICE_NOT_OPENED"; break; + case USB_HOST_ERROR_BROKEN_PIPE: szErrorVal = "USB_HOST_ERROR_BROKEN_PIPE"; break; + case USB_HOST_ERROR_INTERRUPTED_SYS_CALL: szErrorVal = "USB_HOST_ERROR_INTERRUPTED_SYS_CALL"; break; + case USB_HOST_ERROR_OUT_OF_MEMORY: szErrorVal = "USB_HOST_ERROR_OUT_OF_MEMORY"; break; + case USB_HOST_ERROR_NOT_SUPPORTED: szErrorVal = "USB_HOST_ERROR_NOT_SUPPORTED"; break; + default: szErrorVal = "Unknown Error"; break; + } + + return szErrorVal; +} + +/** @} */ \ No newline at end of file diff --git a/src/itc/usbhost/ITs-usbhost-common.h b/src/itc/usbhost/ITs-usbhost-common.h new file mode 100755 index 000000000..8eeecb547 --- /dev/null +++ b/src/itc/usbhost/ITs-usbhost-common.h @@ -0,0 +1,37 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// 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. +// +#ifndef _ITS_USBHOST_COMMON_H_ +#define _ITS_USBHOST_COMMON_H_ + +//Add test package related includes here +#include "tct_common.h" +#include "usb_host.h" +/** @addtogroup itc-%{MODULE_NAME} +* @ingroup itc +* @{ +*/ + +//Add helper function declarations here + +#define API_NAMESPACE "USBHOST_ITC" + +#define START_TEST {\ + FPRINTF("[Line : %d][%s] Starting test : %s\\n", __LINE__, API_NAMESPACE, __FUNCTION__);\ +} + +char* UsbHostGetError(usb_host_error_e error); +/** @} */ +#endif //_ITS_USBHOST_COMMON_H_ diff --git a/src/itc/usbhost/ITs-usbhost.c b/src/itc/usbhost/ITs-usbhost.c new file mode 100755 index 000000000..657a3668e --- /dev/null +++ b/src/itc/usbhost/ITs-usbhost.c @@ -0,0 +1,110 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// 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. +// +#include "ITs-usbhost-common.h" + +//& set: Usbhost + +/** @addtogroup itc-usbhost +* @ingroup itc +* @{ +*/ + +/** + * @function ITs_usbhost_startup + * @description Called before each test + * @parameter NA + * @return NA + */ +void ITs_usbhost_startup(void) +{ + struct stat stBuff; + if ( stat(ERR_LOG, &stBuff) == 0 ) + { + remove(ERR_LOG); + } + + return; +} + + +/** + * @function ITs_usbhost_cleanup + * @description Called after each test + * @parameter NA + * @return NA + */ +void ITs_usbhost_cleanup(void) +{ + return; +} + +/** +* @function UsbHostHotplugCB +* @description To Call when usb hotplug connect or disconnect +* @return NA +*/ +void UsbHostHotplugCB(usb_host_device_h dev, void *user_data) +{ +#if DEBUG + FPRINTF("[Line : %d][%s] UsbHostHotplugCB is called\\n", __LINE__, API_NAMESPACE); +#endif +} + +//& purpose: Registers and Unregisters the hotplug callback +//& type: auto +/** +* @testcase ITc_usb_host_set_unset_hotplug_cb_p +* @since_tizen 4.0 +* @author SRID(nibha.sharma) +* @reviewer SRID(shobhit.v) +* @type auto +* @description Registers and Unregisters the hotplug callback +* @scenario Registers and Unregisters the hotplug callback +* @apicovered usb_host_set_hotplug_cb, usb_host_unset_hotplug_cb +* @passcase If target API gets pass +* @failcase If target API fails or any precondition API fails +* @precondition None +* @postcondition None +*/ +int ITc_usb_host_set_unset_hotplug_cb_p(void) +{ + START_TEST; + + usb_host_context_h hCtxHandle; + usb_host_hotplug_h hHandle; + + int nRet = usb_host_create(&hCtxHandle); + PRINT_RESULT(USB_HOST_ERROR_NONE, nRet, "usb_host_create", UsbHostGetError(nRet)); + if(hCtxHandle == NULL) + { + FPRINTF("[Line : %d][%s] hCtxHandle is NULL %s\\n", __LINE__, API_NAMESPACE); + return 1; + } + + //Callback is NULL as it require usb attach and detach event manually + nRet = usb_host_set_hotplug_cb(hCtxHandle, UsbHostHotplugCB, USB_HOST_HOTPLUG_EVENT_ANY, NULL, &hHandle); + PRINT_RESULT(USB_HOST_ERROR_NONE, nRet, "usb_host_set_hotplug_cb", UsbHostGetError(nRet)); + if(hHandle != NULL) + { + nRet = usb_host_unset_hotplug_cb(hHandle); + PRINT_RESULT(USB_HOST_ERROR_NONE, nRet, "usb_host_unset_hotplug_cb", UsbHostGetError(nRet)); + } + + return 0; +} + +/** @} */ +/** @} */ diff --git a/src/itc/usbhost/tct-usbhost-native.c b/src/itc/usbhost/tct-usbhost-native.c new file mode 100755 index 000000000..292ceaf90 --- /dev/null +++ b/src/itc/usbhost/tct-usbhost-native.c @@ -0,0 +1,143 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// 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. +// +#include "tct_common.h" + +#ifdef MOBILE //Starts MOBILE +#include "tct-usbhost-native_mobile.h" +#endif //MOBILE //End MOBILE + +#ifdef WEARABLE //Starts WEARABLE +#include "tct-usbhost-native_wearable.h" +#endif //WEARABLE //End WEARABLE + +#ifdef TV //Starts TV +#include "tct-usbhost-native_tv.h" +#endif //TV //End TV + +#ifdef COMMON_IOT //Starts COMMON_IOT +#include "tct-usbhost-native_common_iot.h" +#endif //COMMON_IOT //End COMMON_IOT + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +typedef struct appdata { + Evas_Object *win; + Evas_Object *conform; + Evas_Object *label; +} appdata_s; + +static bool app_create(void *data) +{ + return true; +} + +static void app_control(app_control_h app_control, void *data) +{ + char* pszGetTCName = NULL; + int i=0, result=0, nRet=0; + nRet = app_control_get_extra_data(app_control, "testcase_name", &pszGetTCName); + if(nRet != APP_CONTROL_ERROR_NONE) + { + dlog_print(DLOG_ERROR, "NativeTCT", "[%s:%d] app_control_get_extra_data returns error = %d", __FUNCTION__, __LINE__, nRet); + PRINT_UTC_LOG("\\n[%s][Line : %d]Unable to fetch test case name: app_control_get_extra_data API call fails\\n", __FILE__, __LINE__); + PRINT_TC_RESULT("%d",1); + FREE_MEMORY_TC(pszGetTCName); + return; + } + + dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Executing TC Name = %s", __FUNCTION__, __LINE__, pszGetTCName); + for ( i = 0; tc_array[i].name; i++ ) + { + if ( 0 == strncmp(pszGetTCName, tc_array[i].name, strlen(pszGetTCName)) ) + { + if ( tc_array[i].startup ) + { + dlog_print(DLOG_INFO, "NativeTCT", "%s : Start up", pszGetTCName); + tc_array[i].startup(); + } + + dlog_print(DLOG_INFO, "NativeTCT", "%s : Body", pszGetTCName); + result = tc_array[i].function(); + dlog_print(DLOG_INFO, "NativeTCT", "%s returns value = %d", pszGetTCName, result); + + if ( tc_array[i].cleanup ) + { + dlog_print(DLOG_INFO, "NativeTCT", "%s : Clean up", pszGetTCName); + tc_array[i].cleanup(); + } + + PRINT_TC_RESULT("%d",result); + FREE_MEMORY_TC(pszGetTCName); + return; + } + } + + dlog_print(DLOG_ERROR, "NativeTCT", "[%s:%d] Unable to execute %s : Unknown Test Case Name", __FUNCTION__, __LINE__, pszGetTCName); + PRINT_UTC_LOG("\\n[%s][Line : %d]Unable to execute %s : Unknown Test Case Name\\n", __FILE__, __LINE__, pszGetTCName); + PRINT_TC_RESULT("%d",1); + FREE_MEMORY_TC(pszGetTCName); + return; +} + +static void app_terminate(void *data) +{ + dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Application Package is now Terminating", __FUNCTION__, __LINE__); +} + +int main(int argc, char *argv[]) +{ + int ret = 0; + appdata_s ad = {0,}; + + ui_app_lifecycle_callback_s event_callback = {0,}; + event_callback.create = app_create; + event_callback.terminate = app_terminate; + event_callback.app_control = app_control; + + //setting gcda file location for coverage + setenv("GCOV_PREFIX","/tmp",1); + dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Coverage *.gcda File location set to /tmp/home/abuild/rpmbuild/BUILD/ ", __FUNCTION__, __LINE__); + + dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Application Main Function is Invoked", __FUNCTION__, __LINE__); + ret = ui_app_main(argc, argv, &event_callback, &ad); + if (ret != APP_ERROR_NONE) + { + dlog_print(DLOG_ERROR, "NativeTCT", "Application ui_app_main call gets failed. err = %d", ret); + PRINT_UTC_LOG("\\n[%s][Line : %d]Application ui_app_main call gets failed. err = %d\\n", __FILE__, __LINE__, ret); + PRINT_TC_RESULT("%d",1); + return ret; + } + + dlog_print(DLOG_INFO, "NativeTCT", "[%s:%d] Application Package is Terminated", __FUNCTION__, __LINE__); + return ret; +} diff --git a/src/itc/usbhost/tct-usbhost-native_mobile.h b/src/itc/usbhost/tct-usbhost-native_mobile.h new file mode 100755 index 000000000..3c38e428b --- /dev/null +++ b/src/itc/usbhost/tct-usbhost-native_mobile.h @@ -0,0 +1,32 @@ +// +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// 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. +// +#ifndef __TCT_USBHOST_NATIVE_H__ +#define __TCT_USBHOST_NATIVE_H__ + +#include "testcase.h" +#include "tct_common.h" + +extern void ITs_usbhost_startup(void); +extern void ITs_usbhost_cleanup(void); + +extern int ITc_usb_host_set_unset_hotplug_cb_p(void); + +testcase tc_array[] = { + {"ITc_usb_host_set_unset_hotplug_cb_p", ITc_usb_host_set_unset_hotplug_cb_p, ITs_usbhost_startup, ITs_usbhost_cleanup}, + {NULL, NULL} +}; + +#endif // __TCT_USBHOST_NATIVE_H__ -- 2.34.1