From 14e7b3118e1995970145ef37dbd9866442da5019 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Fri, 1 Sep 2023 15:54:43 +0900 Subject: [PATCH] device: Add lcov exception code Add line coverage exception to below cases. 1. Internal API and functions used only in internal functions. 2. Profile specific functions that are not common profile.(ex - mobile, wearable...) 3. Error handling code section. 4. Not supported feature functions in the line coverage test environment.(ex - battery, haptic, ir, led...) - Above features are false by default in the line coverage test environment. Change-Id: I4e3a1c939aa26305a1b4c376bae6e905e2325e58 Signed-off-by: Yunhee Seo --- src/battery.c | 39 +++++++++++++++++++++------------------ src/board-internal.c | 2 ++ src/callback.c | 12 ++++++++++++ src/common.c | 14 ++++++++------ src/display.c | 8 ++++++++ src/haptic.c | 12 ++---------- src/input-internal.c | 4 +++- src/ir.c | 15 ++++----------- src/led.c | 10 ++++++++++ src/power-internal.c | 4 +++- 10 files changed, 73 insertions(+), 47 deletions(-) diff --git a/src/battery.c b/src/battery.c index e3f2370..a80693b 100644 --- a/src/battery.c +++ b/src/battery.c @@ -33,6 +33,7 @@ #define BATTERY_FEATURE "http://tizen.org/feature/battery" +//LCOV_EXCL_START static int is_battery_supported(void) { int ret_val; @@ -40,20 +41,17 @@ static int is_battery_supported(void) ret_val = system_info_get_platform_bool(BATTERY_FEATURE, &battery_avail); if (ret_val < 0) { -//LCOV_EXCL_START System Error _E("Failed to get value of battery feature"); return false; -//LCOV_EXCL_STOP } else if (ret_val == 0 && !battery_avail) { -//LCOV_EXCL_START System Error _D("Battery is not supported"); return false; -//LCOV_EXCL_STOP } else return true; } +//LCOV_EXCL_STOP - +//LCOV_EXCL_START int device_battery_get_percent(int *percent) { struct device_battery_info info; @@ -64,7 +62,7 @@ int device_battery_get_percent(int *percent) ret_val = is_battery_supported(); if (!ret_val) - return DEVICE_ERROR_NOT_SUPPORTED; + return DEVICE_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE ret_val = device_battery_get_info_direct(&info); if (ret_val < 0) @@ -73,7 +71,9 @@ int device_battery_get_percent(int *percent) *percent = info.capacity; return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_battery_is_charging(bool *charging) { int ret_val, val; @@ -95,7 +95,9 @@ int device_battery_is_charging(bool *charging) *charging = val; return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_battery_get_level_status(device_battery_level_e *status) { int val, ret_val; @@ -121,17 +123,17 @@ int device_battery_get_level_status(device_battery_level_e *status) *status = DEVICE_BATTERY_LEVEL_HIGH; else if (val == VCONFKEY_SYSMAN_BAT_LEVEL_FULL) *status = DEVICE_BATTERY_LEVEL_FULL; -//LCOV_EXCL_START System Error /* regard not supported as disconnected */ else if (val == -ENOTSUP) *status = DEVICE_BATTERY_LEVEL_EMPTY; -//LCOV_EXCL_STOP else return DEVICE_ERROR_OPERATION_FAILED; return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START static void battery_get_info(struct battery_info *info, void *data) { struct device_battery_info *bat = data; @@ -151,7 +153,9 @@ static void battery_get_info(struct battery_info *info, void *data) bat->voltage_now = info->voltage_now; bat->voltage_average = info->voltage_average; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Internal function int device_battery_get_info_direct(struct device_battery_info *info) { int ret_val; @@ -165,15 +169,15 @@ int device_battery_get_info_direct(struct device_battery_info *info) ret_val = hal_device_battery_get_current_state(battery_get_info, info); if (ret_val < 0) { -//LCOV_EXCL_START System Error _E("Failed to get battery info: %d", ret_val); return DEVICE_ERROR_OPERATION_FAILED; -//LCOV_EXCL_STOP } return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_battery_get_health(device_battery_health_e *health) { struct device_battery_info info; @@ -189,10 +193,8 @@ int device_battery_get_health(device_battery_health_e *health) ret = device_battery_get_info_direct(&info); if (ret != DEVICE_ERROR_NONE) { -//LCOV_EXCL_START System Error _E("Failed to get battery info (%d)", ret); return ret; -//LCOV_EXCL_STOP } len = strlen(info.health); @@ -211,7 +213,9 @@ int device_battery_get_health(device_battery_health_e *health) return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_battery_get_power_source(device_battery_power_source_e *source) { struct device_battery_info info; @@ -227,10 +231,8 @@ int device_battery_get_power_source(device_battery_power_source_e *source) ret = device_battery_get_info_direct(&info); if (ret != DEVICE_ERROR_NONE) { -//LCOV_EXCL_START System Error _E("Failed to get battery info (%d)", ret); return ret; -//LCOV_EXCL_STOP } len = strlen(info.power_source); @@ -245,7 +247,9 @@ int device_battery_get_power_source(device_battery_power_source_e *source) return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_battery_get_property(device_battery_property_e property, int *val) { struct device_battery_info info = {0, }; @@ -260,10 +264,8 @@ int device_battery_get_property(device_battery_property_e property, int *val) ret = device_battery_get_info_direct(&info); if (ret != DEVICE_ERROR_NONE) { -//LCOV_EXCL_START System Error _E("Failed to get battery info (%d)", ret); return ret; -//LCOV_EXCL_STOP } switch (property) { @@ -292,7 +294,9 @@ int device_battery_get_property(device_battery_property_e property, int *val) return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_battery_get_status(device_battery_status_e *status) { struct device_battery_info info; @@ -308,10 +312,8 @@ int device_battery_get_status(device_battery_status_e *status) ret = device_battery_get_info_direct(&info); if (ret != DEVICE_ERROR_NONE) { -//LCOV_EXCL_START System Error _E("Failed to get battery info (%d)", ret); return ret; -//LCOV_EXCL_STOP } len = strlen(info.status); @@ -328,6 +330,7 @@ int device_battery_get_status(device_battery_status_e *status) return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP void __attribute__ ((destructor)) battery_finalize(void) { diff --git a/src/board-internal.c b/src/board-internal.c index 01686b0..cda6c07 100644 --- a/src/board-internal.c +++ b/src/board-internal.c @@ -16,6 +16,7 @@ #include +//LCOV_EXCL_START Internal function int device_board_get_serial_number(char *buffer, const int max_len) { int ret; @@ -59,3 +60,4 @@ int device_board_set_partition_status(char partition_ab, const char *status) { return hal_device_board_set_partition_status(partition_ab, status); } +//LCOV_EXCL_STOP \ No newline at end of file diff --git a/src/callback.c b/src/callback.c index 9f448c4..98c805a 100644 --- a/src/callback.c +++ b/src/callback.c @@ -266,6 +266,7 @@ static int unregister_signal(int *sig_id) static int register_request(int type) { switch (type) { + //LCOV_EXCL_START case DEVICE_CALLBACK_BATTERY_CAPACITY: return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_capacity_cb, NULL); @@ -275,9 +276,11 @@ static int register_request(int type) case DEVICE_CALLBACK_BATTERY_CHARGING: return vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery_charging_cb, NULL); + //LCOV_EXCL_STOP case DEVICE_CALLBACK_DISPLAY_STATE: return vconf_notify_key_changed(VCONFKEY_PM_STATE, display_changed_cb, NULL); + //LCOV_EXCL_START case DEVICE_CALLBACK_FLASH_BRIGHTNESS: /* sig_id begins with 1. */ if (flash_sigid) @@ -286,6 +289,7 @@ static int register_request(int type) DEVICED_PATH_LED, DEVICED_INTERFACE_LED, SIGNAL_FLASH_STATE, flash_state_cb, &flash_sigid); + //LCOV_EXCL_STOP default: if (event_sigid) return -EEXIST; @@ -302,6 +306,7 @@ static int register_request(int type) static int release_request(int type) { switch (type) { + //LCOV_EXCL_START case DEVICE_CALLBACK_BATTERY_CAPACITY: return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, battery_capacity_cb); @@ -311,13 +316,16 @@ static int release_request(int type) case DEVICE_CALLBACK_BATTERY_CHARGING: return vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery_charging_cb); + //LCOV_EXCL_STOP case DEVICE_CALLBACK_DISPLAY_STATE: return vconf_ignore_key_changed(VCONFKEY_PM_STATE, display_changed_cb); + //LCOV_EXCL_START case DEVICE_CALLBACK_FLASH_BRIGHTNESS: if (!flash_sigid) return -ENOENT; return unregister_signal(&flash_sigid); + //LCOV_EXCL_STOP default: if (!event_sigid) return -ENOENT; @@ -338,6 +346,7 @@ static int device_callback_check_feature_supported(int type) bool supported; switch (type) { + //LCOV_EXCL_START case DEVICE_CALLBACK_BATTERY_CAPACITY: case DEVICE_CALLBACK_BATTERY_LEVEL: case DEVICE_CALLBACK_BATTERY_CHARGING: @@ -350,6 +359,7 @@ static int device_callback_check_feature_supported(int type) f_battery = true; return 0; + //LCOV_EXCL_STOP case DEVICE_CALLBACK_DISPLAY_STATE: if (f_display) return 0; @@ -360,6 +370,7 @@ static int device_callback_check_feature_supported(int type) f_display = true; return 0; + //LCOV_EXCL_START case DEVICE_CALLBACK_FLASH_BRIGHTNESS: if (f_flash) return 0; @@ -370,6 +381,7 @@ static int device_callback_check_feature_supported(int type) f_flash = true; return 0; + //LCOV_EXCL_STOP default: return 0; } diff --git a/src/common.c b/src/common.c index 7a8ea3d..581748e 100644 --- a/src/common.c +++ b/src/common.c @@ -34,22 +34,24 @@ tizen_profile_t _get_tizen_profile() char *profileName; system_info_get_platform_string("http://tizen.org/feature/profile", &profileName); switch (*profileName) { + //LCOV_EXCL_START case 'm': case 'M': profile = TIZEN_PROFILE_MOBILE; break; case 'w': case 'W': - profile = TIZEN_PROFILE_WEARABLE; //LCOV_EXCL_LINE - break; //LCOV_EXCL_LINE + profile = TIZEN_PROFILE_WEARABLE; + break; case 't': case 'T': - profile = TIZEN_PROFILE_TV; //LCOV_EXCL_LINE - break; //LCOV_EXCL_LINE + profile = TIZEN_PROFILE_TV; + break; case 'i': case 'I': - profile = TIZEN_PROFILE_IVI; //LCOV_EXCL_LINE - break; //LCOV_EXCL_LINE + profile = TIZEN_PROFILE_IVI; + break; + //LCOV_EXCL_STOP default: // common or unknown ==> ALL ARE COMMON. profile = TIZEN_PROFILE_COMMON; //LCOV_EXCL_LINE } diff --git a/src/display.c b/src/display.c index e467559..d964953 100644 --- a/src/display.c +++ b/src/display.c @@ -481,6 +481,7 @@ int is_feature_display_supported(void) return true; } +//LCOV_EXCL_START Internal function int device_display_get_rotation_angle(int display_index, device_display_rotation_angle_e *angle, device_display_init_direction_e *init_direction) @@ -530,7 +531,9 @@ int device_display_get_rotation_angle(int display_index, return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Internal function int device_display_set_rotation_angle(int display_index, device_display_rotation_angle_e angle, device_display_rotation_direction_e rotation_direction) @@ -584,6 +587,7 @@ int device_display_set_rotation_angle(int display_index, return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP int is_feature_display_state_supported(void) { @@ -605,6 +609,7 @@ int is_feature_display_state_supported(void) return true; } +//LCOV_EXCL_START Internal function int device_display_set_white_balance(int display_index, display_white_balance_e white_balance_type, int value) { int ret; @@ -654,7 +659,9 @@ int device_display_set_white_balance(int display_index, display_white_balance_e return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START Internal function int device_display_get_white_balance(int display_index, display_white_balance_e white_balance_type, int *value) { int ret, reply; @@ -700,3 +707,4 @@ int device_display_get_white_balance(int display_index, display_white_balance_e return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP \ No newline at end of file diff --git a/src/haptic.c b/src/haptic.c index 5f70397..ce613bc 100644 --- a/src/haptic.c +++ b/src/haptic.c @@ -56,6 +56,7 @@ struct haptic_handle { static guint haptic_id = 0; static GList *handle_list; +//LCOV_EXCL_START static int is_haptic_supported(void) { int ret_val; @@ -63,15 +64,11 @@ static int is_haptic_supported(void) ret_val = system_info_get_platform_bool(VIBRATION_FEATURE, &haptic_avail); if (ret_val < 0) { -//LCOV_EXCL_START System Error _E("Failed to get value of haptic feature"); return false; -//LCOV_EXCL_STOP } else if (ret_val == 0 && !haptic_avail) { -//LCOV_EXCL_START System Error _D("Haptic is not supported"); return false; -//LCOV_EXCL_STOP } else return true; } @@ -104,7 +101,6 @@ int device_haptic_get_count(int *device_number) return DEVICE_ERROR_NONE; } -//LCOV_EXCL_START Not called Callback static void restart_callback(void) { GList *elem, *elem_next; @@ -123,9 +119,7 @@ static void restart_callback(void) } } -//LCOV_EXCL_STOP -//LCOV_EXCL_START Not called Callback static void haptic_signal_callback(GDBusConnection *conn, const gchar *sender, const gchar *path, @@ -150,7 +144,6 @@ static void haptic_signal_callback(GDBusConnection *conn, restart_callback(); } -//LCOV_EXCL_STOP int device_haptic_open(int device_index, haptic_device_h *device_handle) { @@ -192,10 +185,8 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle) if (!found) { handle = (struct haptic_handle *)malloc(sizeof(struct haptic_handle)); if (!handle) { -//LCOV_EXCL_START System Error _E("Failed to malloc"); return DEVICE_ERROR_OPERATION_FAILED; -//LCOV_EXCL_STOP } handle->handle = val; @@ -344,3 +335,4 @@ int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_han return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP \ No newline at end of file diff --git a/src/input-internal.c b/src/input-internal.c index e4849d4..ad76e45 100644 --- a/src/input-internal.c +++ b/src/input-internal.c @@ -30,6 +30,7 @@ #define METHOD_INPUT_GET_EVENT_STATE "InputGetEventState" #define METHOD_INPUT_GET_DEVICE_NAME "InputGetDeviceName" +//LCOV_EXCL_START Internal function static bool input_is_supported_input_type(device_input_type_e input_device_type) { switch (input_device_type) { @@ -202,4 +203,5 @@ int device_input_get_device_name(int input_device_id, char **input_device_name) *input_device_name = temp_input_device_name; return DEVICE_ERROR_NONE; -} \ No newline at end of file +} +//LCOV_EXCL_STOP \ No newline at end of file diff --git a/src/ir.c b/src/ir.c index a96392b..71eea1a 100644 --- a/src/ir.c +++ b/src/ir.c @@ -25,7 +25,7 @@ #define METHOD_TRANSMIT "TransmitIR" #define IR_FEATURE "http://tizen.org/feature/consumer_ir" - +//LCOV_EXCL_START int device_ir_is_available(bool *available) { int ret_val; @@ -37,10 +37,8 @@ int device_ir_is_available(bool *available) ret_val = system_info_get_platform_bool(IR_FEATURE, &ir_avail); if (ret_val < 0) { -//LCOV_EXCL_START System Error *available = false; return DEVICE_ERROR_OPERATION_FAILED; -//LCOV_EXCL_STOP } else if (ret_val == 0 && !ir_avail) { *available = false; return DEVICE_ERROR_NOT_SUPPORTED; @@ -50,19 +48,19 @@ int device_ir_is_available(bool *available) DEVICED_INTERFACE_IR, METHOD_IS_AVAILABLE, NULL, NULL); -//LCOV_EXCL_START System Error if (ret_val == -EACCES || ret_val == -EPERM) return DEVICE_ERROR_PERMISSION_DENIED; if (!ret_val) { *available = false; return DEVICE_ERROR_OPERATION_FAILED; } -//LCOV_EXCL_STOP *available = ir_avail; return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_ir_transmit(int carrier_frequency, int *pattern, int size) { int ret_val; @@ -76,19 +74,15 @@ int device_ir_transmit(int carrier_frequency, int *pattern, int size) _E("IR is not supported or IR operation failed"); return ret_val; } -//LCOV_EXCL_START System Error _E("IR is not supported"); return DEVICE_ERROR_OPERATION_FAILED; -//LCOV_EXCL_STOP } -//LCOV_EXCL_START System Error if (!pattern) return DEVICE_ERROR_INVALID_PARAMETER; if (size <= 0) { _E("IR pattern size is invalid"); return DEVICE_ERROR_INVALID_PARAMETER; } -//LCOV_EXCL_STOP builder = g_variant_builder_new(G_VARIANT_TYPE ("ai")); g_variant_builder_add(builder, "i", carrier_frequency); @@ -100,12 +94,11 @@ int device_ir_transmit(int carrier_frequency, int *pattern, int size) g_variant_new("(ai)", builder), NULL); g_variant_builder_unref(builder); -//LCOV_EXCL_START System Error if (ret_val == -EACCES || ret_val == -EPERM) return DEVICE_ERROR_PERMISSION_DENIED; if (ret_val < 0) return DEVICE_ERROR_OPERATION_FAILED; -//LCOV_EXCL_STOP return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP diff --git a/src/led.c b/src/led.c index 3faff2c..0b38bd0 100644 --- a/src/led.c +++ b/src/led.c @@ -54,6 +54,7 @@ static void __CONSTRUCTOR__ init(void) support_camera_led = true; } +//LCOV_EXCL_START int device_flash_get_max_brightness(int *max_brightness) { int ret_dbus, val; @@ -73,7 +74,9 @@ int device_flash_get_max_brightness(int *max_brightness) *max_brightness = val; return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_flash_get_brightness(int *brightness) { int ret_dbus, val; @@ -93,7 +96,9 @@ int device_flash_get_brightness(int *brightness) *brightness = val; return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_flash_set_brightness(int brightness) { int max, ret_dbus; @@ -117,7 +122,9 @@ int device_flash_set_brightness(int brightness) return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_led_play_custom(int on, int off, unsigned int color, unsigned int flags) { int ret_dbus; @@ -138,7 +145,9 @@ int device_led_play_custom(int on, int off, unsigned int color, unsigned int fla return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP +//LCOV_EXCL_START int device_led_stop_custom(void) { int ret_dbus; @@ -156,6 +165,7 @@ int device_led_stop_custom(void) return DEVICE_ERROR_NONE; } +//LCOV_EXCL_STOP //LCOV_EXCL_START Not tested API int device_multi_led_get_number(int *num_of_leds) diff --git a/src/power-internal.c b/src/power-internal.c index 60aca42..01a9b94 100644 --- a/src/power-internal.c +++ b/src/power-internal.c @@ -73,6 +73,7 @@ struct power_lock_state_change_callback_handler { void *data; }; +//LCOV_EXCL_START Internal function static bool power_is_valid_power_lock_type(power_lock_e power_lock_type) { switch(power_lock_type) { @@ -787,4 +788,5 @@ int device_power_remove_lock_state_change_callback(power_lock_e power_lock_type, } return DEVICE_ERROR_NONE; -} \ No newline at end of file +} +//LCOV_EXCL_STOP \ No newline at end of file -- 2.7.4