| 1 | /* |
| 2 | * Copyright (c) 2017, Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included |
| 12 | * in all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include "cm_test.h" |
| 24 | |
| 25 | struct CM_PLATFORM_INFO |
| 26 | { |
| 27 | uint32_t value0; |
| 28 | uint32_t value1; |
| 29 | uint32_t value2; |
| 30 | uint32_t value3; |
| 31 | uint32_t value4; |
| 32 | }; |
| 33 | |
| 34 | class DeviceTest: public CmTest |
| 35 | { |
| 36 | public: |
| 37 | DeviceTest() {} |
| 38 | ~DeviceTest() {} |
| 39 | |
| 40 | int32_t Destroy(CmDevice *device) |
| 41 | { return m_mockDevice.ReleaseNewDevice(device); } |
| 42 | |
| 43 | int32_t CreateWithOptions(uint32_t additional_options) |
| 44 | { |
| 45 | CmDevice *new_device = m_mockDevice.CreateNewDevice(additional_options); |
| 46 | if (nullptr == new_device) |
| 47 | { |
| 48 | return CM_FAILURE; |
| 49 | } |
| 50 | return m_mockDevice.ReleaseNewDevice(new_device); |
| 51 | }//================================================== |
| 52 | |
| 53 | int32_t CheckIsStreamLeaked() |
| 54 | { |
| 55 | int32_t initStreams, releaseStreams; |
| 56 | initStreams = m_mockDevice.CheckAvaliableStream(); |
| 57 | CmDevice *new_device = m_mockDevice.CreateNewDevice(); |
| 58 | if (nullptr == new_device) |
| 59 | { |
| 60 | return CM_FAILURE; |
| 61 | } |
| 62 | int32_t result = m_mockDevice.ReleaseNewDevice(new_device); |
| 63 | releaseStreams =m_mockDevice.CheckAvaliableStream(); |
| 64 | EXPECT_EQ(initStreams, releaseStreams); |
| 65 | return result; |
| 66 | } //================================================== |
| 67 | |
| 68 | template<typename T> |
| 69 | int32_t GetCaps(CM_DEVICE_CAP_NAME cap_name, T *cap_value) |
| 70 | { |
| 71 | uint32_t value_size = static_cast<uint32_t>(sizeof(T)); |
| 72 | return m_mockDevice->GetCaps(cap_name, value_size, cap_value); |
| 73 | } |
| 74 | |
| 75 | template<typename T> |
| 76 | int32_t SetCaps(CM_DEVICE_CAP_NAME cap_name, T *cap_value) |
| 77 | { |
| 78 | uint32_t value_size = static_cast<uint32_t>(sizeof(T)); |
| 79 | return m_mockDevice->SetCaps(cap_name, value_size, cap_value); |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | TEST_F(DeviceTest, Destroy) |
| 84 | { |
| 85 | RunEach<int32_t>(CM_SUCCESS, |
| 86 | [this]() { return Destroy(nullptr); }); |
| 87 | return; |
| 88 | }//======== |
| 89 | |
| 90 | TEST_F(DeviceTest, NoScratchSpace) |
| 91 | { |
| 92 | uint32_t option = CM_DEVICE_CREATE_OPTION_SCRATCH_SPACE_DISABLE; |
| 93 | RunEach<int32_t>(CM_SUCCESS, |
| 94 | [this, option]() { return CreateWithOptions(option); }); |
| 95 | return; |
| 96 | }//======== |
| 97 | |
| 98 | TEST_F(DeviceTest, CheckStreamLeak) |
| 99 | { |
| 100 | RunEach<int32_t>(CM_SUCCESS, |
| 101 | [this]() { return CheckIsStreamLeaked(); }); |
| 102 | return; |
| 103 | } //======== |
| 104 | |
| 105 | TEST_F(DeviceTest, QueryGpuPlatform) |
| 106 | { |
| 107 | auto QueryGpuPlatform = [this]() { |
| 108 | uint32_t gpu_platform = 0; |
| 109 | GetCaps(CAP_GPU_PLATFORM, &gpu_platform); |
| 110 | return gpu_platform != PLATFORM_INTEL_UNKNOWN; |
| 111 | }; |
| 112 | RunEach<bool>(true, QueryGpuPlatform); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | TEST_F(DeviceTest, QueryThreadCount) |
| 117 | { |
| 118 | auto QueryThreadCount = [this]() { |
| 119 | uint32_t per_walker_count = 0, per_group_count = 0; |
| 120 | GetCaps(CAP_USER_DEFINED_THREAD_COUNT_PER_MEDIA_WALKER, |
| 121 | &per_walker_count); |
| 122 | GetCaps(CAP_USER_DEFINED_THREAD_COUNT_PER_THREAD_GROUP, |
| 123 | &per_group_count); |
| 124 | return per_walker_count > 0 && per_group_count > 0; |
| 125 | }; |
| 126 | RunEach<bool>(true, QueryThreadCount); |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | TEST_F(DeviceTest, QueryFrequency) |
| 131 | { |
| 132 | auto QueryFrequency = [this]() { |
| 133 | uint32_t min_frequency = 0, max_frequency = 0, current_frequency = 0; |
| 134 | GetCaps(CAP_MIN_FREQUENCY, &min_frequency); |
| 135 | GetCaps(CAP_MAX_FREQUENCY, &max_frequency); |
| 136 | GetCaps(CAP_GPU_CURRENT_FREQUENCY, ¤t_frequency); |
| 137 | return current_frequency >= min_frequency |
| 138 | && max_frequency >= current_frequency; |
| 139 | }; |
| 140 | RunEach<bool>(true, QueryFrequency); |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | TEST_F(DeviceTest, QueryPlatformInformation) |
| 145 | { |
| 146 | auto QueryPlatformInformation = [this]() { |
| 147 | CM_PLATFORM_INFO platform_info; |
| 148 | GetCaps(CAP_PLATFORM_INFO, &platform_info); |
| 149 | return platform_info.value0 > 0 && platform_info.value1 > 0 |
| 150 | && platform_info.value2 > 0 && platform_info.value3 > 0; |
| 151 | }; |
| 152 | RunEach<bool>(true, QueryPlatformInformation); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | TEST_F(DeviceTest, SetThreadCount) |
| 157 | { |
| 158 | auto SetThreadCount = [this]() { |
| 159 | uint32_t thread_count = 0; |
| 160 | GetCaps(CAP_HW_THREAD_COUNT, &thread_count); |
| 161 | thread_count /= 2; |
| 162 | return SetCaps(CAP_HW_THREAD_COUNT, &thread_count); |
| 163 | }; |
| 164 | RunEach<int32_t>(CM_SUCCESS, SetThreadCount); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | TEST_F(DeviceTest, GetInvalidCap) |
| 169 | { |
| 170 | auto GetInvalidCap = [this]() { |
| 171 | CM_DEVICE_CAP_NAME cap_name = (CM_DEVICE_CAP_NAME)-99; |
| 172 | uint32_t value = 0; |
| 173 | return GetCaps(cap_name, &value); |
| 174 | }; |
| 175 | RunEach<int32_t>(CM_FAILURE, GetInvalidCap); |
| 176 | return; |
| 177 | } |