+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
+ * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
+ * Contact: Roman Marchenko <r.marchenko@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#include "tc_tdm.h"
+
+/* LCOV_EXCL_START */
+
+#define HWC_WIN_NUM 5
+
+class TDMHwc : public TDMOutput
+{
+public:
+ TDMHwc();
+ void SetUp(void);
+ void TearDown(void);
+
+ tdm_error error;
+};
+
+TDMHwc::TDMHwc()
+{
+ error = TDM_ERROR_NONE;
+}
+
+void TDMHwc::SetUp(void)
+{
+ TDMOutput::SetUp();
+}
+
+void TDMHwc::TearDown(void)
+{
+ TDMOutput::TearDown();
+}
+
+static void
+_tc_tdm_hwc_commit_cb(tdm_hwc *hwc, unsigned int sequence,
+ unsigned int tv_sec, unsigned int tv_usec,
+ void *user_data)
+{
+ bool *done = (bool*)user_data;
+ if (done)
+ *done = true;
+}
+
+/* tdm_hwc_window * tdm_hwc_create_window(tdm_output *output, tdm_error *error); */
+TEST_P(TDMHwc, CreateWindowFailNull)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ ASSERT_EQ(NULL, tdm_hwc_create_window(NULL, &error));
+ ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_P(TDMHwc, CreateWindowSuccessful)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error;
+ tdm_hwc_window * hw = NULL;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ hw = tdm_hwc_create_window(hwc, &error);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ tdm_hwc_window_destroy(hw);
+ } else {
+ ASSERT_EQ(NULL, tdm_hwc_create_window(hwc, &error));
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+/* tdm_hwc_get_supported_formats() */
+TEST_P(TDMHwc, GetSupportedFormatsFailNull)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_error error;
+
+ error = tdm_hwc_get_supported_formats(NULL, NULL, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_P(TDMHwc, GetSupportedFormatsSuccessful)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ const tbm_format *formats;
+ int count;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ error = tdm_hwc_get_supported_formats(hwc, &formats, &count);
+ if (error != TDM_ERROR_NOT_IMPLEMENTED) {
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ if (count > 0)
+ ASSERT_NE(NULL, formats);
+ }
+ } else {
+ error = tdm_hwc_get_supported_formats(hwc, &formats, &count);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+/* tdm_hwc_get_available_properties() */
+TEST_P(TDMHwc, GetAvailablePropertiesFailNullWin)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ const tdm_prop *props;
+ int count;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ error = tdm_hwc_get_available_properties(NULL, &props, &count);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+
+ error = tdm_hwc_get_available_properties(hwc, NULL, &count);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+
+ error = tdm_hwc_get_available_properties(hwc, &props, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ } else {
+ error = tdm_hwc_get_available_properties(hwc, &props, &count);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+TEST_P(TDMHwc, GetAvailablePropertiesSuccess)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ const tdm_prop *props;
+ int count;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ error = tdm_hwc_get_available_properties(hwc, &props, &count);
+ ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
+ } else {
+ error = tdm_hwc_get_available_properties(hwc, &props, &count);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+
+}
+
+/* tdm_hwc_get_client_target_buffer_queue() */
+TEST_P(TDMHwc, GetClientTargetBufferQueueFailNullObject)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ tbm_surface_queue_h queue = NULL;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ queue = tdm_hwc_get_client_target_buffer_queue(NULL, &error);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ ASSERT_EQ(NULL, queue);
+
+ queue = tdm_hwc_get_client_target_buffer_queue(NULL, NULL);
+ ASSERT_EQ(NULL, queue);
+ } else {
+ ASSERT_EQ(NULL, queue);
+ }
+ }
+}
+
+TEST_P(TDMHwc, GetClientTargetBufferQueueFainNoHwc)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ tbm_surface_queue_h queue = NULL;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ ASSERT_NE(NULL, queue);
+ } else {
+ queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ ASSERT_EQ(NULL, queue);
+ }
+ }
+}
+
+TEST_P(TDMHwc, GetClientTargetBufferQueueSuccessful)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ tbm_surface_queue_h queue = NULL;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
+ tbm_surface_queue_destroy(queue);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ ASSERT_NE(NULL, queue);
+
+ queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
+ tbm_surface_queue_destroy(queue);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ ASSERT_NE(NULL, queue);
+ } else {
+ queue = tdm_hwc_get_client_target_buffer_queue(hwc, &error);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ ASSERT_EQ(NULL, queue);
+
+ queue = tdm_hwc_get_client_target_buffer_queue(hwc, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ ASSERT_EQ(NULL, queue);
+ }
+ }
+}
+
+/* tdm_hwc_set_client_target_buffer() */
+TEST_P(TDMHwc, SetClientTargetBufferFailNullOutput)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_region damage = {.num_rects = 0, .rects = NULL};
+ tbm_surface_h target_buff = NULL;
+
+ target_buff = tbm_surface_internal_create_with_flags(720, 1024,
+ TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
+ ASSERT_NE(NULL, target_buff);
+
+ error = tdm_hwc_set_client_target_buffer(NULL, target_buff, damage);
+ tbm_surface_internal_destroy(target_buff);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_P(TDMHwc, SetClientTargetBufferSuccessfulSetBuff)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_region damage = {.num_rects = 0, .rects = NULL};
+ const tdm_output_mode *mode = NULL;
+ tbm_surface_h target_buff = NULL;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ ASSERT_EQ(tdm_output_get_mode(outputs[o], &mode), TDM_ERROR_NONE);
+ target_buff = tbm_surface_internal_create_with_flags(mode->hdisplay, mode->vdisplay,
+ TBM_FORMAT_ARGB8888, TBM_BO_DEFAULT);
+ ASSERT_NE(NULL, target_buff);
+
+ error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
+ tbm_surface_internal_destroy(target_buff);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ } else {
+ error = tdm_hwc_set_client_target_buffer(hwc, target_buff, damage);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+TEST_P(TDMHwc, SetClientTargetBufferSuccessfulResetBuff)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_region damage = {.num_rects = 0, .rects = NULL};
+ tbm_surface_h target_buff = NULL;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
+ tbm_surface_internal_destroy(target_buff);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ } else {
+ error = tdm_hwc_set_client_target_buffer(hwc, NULL, damage);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+/* tdm_hwc_validate() */
+TEST_P(TDMHwc, ValidateFailNull)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ uint32_t num_types;
+
+ error = tdm_hwc_validate(NULL, NULL, 0, &num_types);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ error = tdm_hwc_validate(hwc, NULL, 0, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ } else {
+ error = tdm_hwc_validate(hwc, NULL, 0, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+/* tdm_hwc_get_changed_composition_types() */
+TEST_P(TDMHwc, GetChangedCompositionTypesFailNull)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ uint32_t num_elements;
+
+ error = tdm_hwc_get_changed_composition_types(NULL, &num_elements, NULL, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ } else {
+ error = tdm_hwc_get_changed_composition_types(hwc, NULL, NULL, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+/* tdm_error tdm_hwc_accept_changes() */
+TEST_P(TDMHwc, AcceptChangesFailNull)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ error = tdm_hwc_accept_changes(NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_P(TDMHwc, AcceptChangesFailNoHwc)
+{
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ error = tdm_hwc_accept_changes(hwc);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ } else {
+ error = tdm_hwc_accept_changes(hwc);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+TEST_P(TDMHwc, AcceptChangesSuccessful)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
+ tdm_hwc_window **changed_hwc_window = NULL;
+ tdm_hwc_window_composition *composition_types = NULL;
+ uint32_t num_types;
+ uint32_t get_num = 0;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ for (int w = 0; w < HWC_WIN_NUM; w++) {
+ hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_COMPOSITION_DEVICE);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ }
+
+ error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+
+ if (num_types > 0) {
+ changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
+ composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
+
+ error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ ASSERT_EQ(get_num, num_types);
+
+ error = tdm_hwc_accept_changes(hwc);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+
+ free(composition_types);
+ free(changed_hwc_window);
+ }
+
+ for (int w = 0; w < HWC_WIN_NUM; w++)
+ tdm_hwc_window_destroy(hwc_wnds[w]);
+
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+/* tdm_error tdm_hwc_commit() */
+TEST_P(TDMHwc, CommitFailNull)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ error = tdm_hwc_commit(NULL, 1, NULL, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_P(TDMHwc, CommitSuccessful)
+{
+ TDM_UT_SKIP_FLAG(has_outputs);
+
+ tdm_hwc *hwc = NULL;
+ tdm_error error = TDM_ERROR_NONE;
+ tdm_hwc_window *hwc_wnds[HWC_WIN_NUM];
+ tdm_hwc_window **changed_hwc_window = NULL;
+ tdm_hwc_window_composition *composition_types = NULL;
+ uint32_t num_types;
+ uint32_t get_num = 0;
+
+ for (int o = 0; o < output_count; o++) {
+ hwc = tdm_output_get_hwc(outputs[o], &error);
+ if (hwc) {
+ for (int w = 0; w < HWC_WIN_NUM; w++) {
+ hwc_wnds[w] = tdm_hwc_create_window(hwc, &error);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ error = tdm_hwc_window_set_composition_type(hwc_wnds[w], TDM_COMPOSITION_DEVICE);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ }
+
+ error = tdm_hwc_validate(hwc, hwc_wnds, HWC_WIN_NUM, &num_types);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+
+ if (num_types > 0) {
+ changed_hwc_window = (tdm_hwc_window **)calloc(num_types, sizeof(tdm_hwc_window *));
+ composition_types = (tdm_hwc_window_composition *)calloc(num_types, sizeof(tdm_hwc_window_composition));
+
+ error = tdm_hwc_get_changed_composition_types(hwc, &get_num, changed_hwc_window, composition_types);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ ASSERT_EQ(get_num, num_types);
+
+ error = tdm_hwc_accept_changes(hwc);
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+
+ free(composition_types);
+ free(changed_hwc_window);
+ }
+
+ error = tdm_hwc_commit(hwc, 0, _tc_tdm_hwc_commit_cb, NULL);
+ ASSERT_NE(TDM_ERROR_NONE, error);
+
+ for (int w = 0; w < HWC_WIN_NUM; w++)
+ tdm_hwc_window_destroy(hwc_wnds[w]);
+
+ ASSERT_EQ(TDM_ERROR_NONE, error);
+ }
+ }
+}
+
+#ifdef TDM_UT_TEST_WITH_PARAMS
+INSTANTIATE_TEST_CASE_P(TDMHwcParams,
+ TDMHwc,
+ Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
+#else
+INSTANTIATE_TEST_CASE_P(TDMHwcParams,
+ TDMHwc,
+ Values(TDM_DEFAULT_MODULE));
+#endif
+
+/* LCOV_EXCL_END */
\ No newline at end of file