| 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 | class ThreadSpaceTest: public CmTest |
| 26 | { |
| 27 | public: |
| 28 | static const uint32_t WIDTH = 64; |
| 29 | static const uint32_t HEIGHT = 64; |
| 30 | |
| 31 | ThreadSpaceTest(): m_thread_space(nullptr) {} |
| 32 | |
| 33 | ~ThreadSpaceTest() {} |
| 34 | |
| 35 | int32_t CreateDestroy(uint32_t width, uint32_t height) |
| 36 | { |
| 37 | int32_t result = m_mockDevice->CreateThreadSpace(width, height, |
| 38 | m_thread_space); |
| 39 | if (result != CM_SUCCESS) |
| 40 | { |
| 41 | return result; |
| 42 | } |
| 43 | return m_mockDevice->DestroyThreadSpace(m_thread_space); |
| 44 | }//========================================================= |
| 45 | |
| 46 | int32_t SelectDependencyPattern(CM_DEPENDENCY_PATTERN pattern) |
| 47 | { |
| 48 | int32_t result = m_mockDevice->CreateThreadSpace(WIDTH, HEIGHT, |
| 49 | m_thread_space); |
| 50 | EXPECT_EQ(CM_SUCCESS, result); |
| 51 | result = m_thread_space->SelectThreadDependencyPattern(pattern); |
| 52 | int32_t destroy_result |
| 53 | = m_mockDevice->DestroyThreadSpace(m_thread_space); |
| 54 | EXPECT_EQ(CM_SUCCESS, destroy_result); |
| 55 | return result; |
| 56 | }//=============== |
| 57 | |
| 58 | int32_t SelectMediaWalkingPattern(CM_WALKING_PATTERN pattern) |
| 59 | { |
| 60 | int32_t result = m_mockDevice->CreateThreadSpace(WIDTH, HEIGHT, |
| 61 | m_thread_space); |
| 62 | EXPECT_EQ(CM_SUCCESS, result); |
| 63 | result = m_thread_space->SelectMediaWalkingPattern(pattern); |
| 64 | int32_t destroy_result |
| 65 | = m_mockDevice->DestroyThreadSpace(m_thread_space); |
| 66 | EXPECT_EQ(CM_SUCCESS, destroy_result); |
| 67 | return result; |
| 68 | }//=============== |
| 69 | |
| 70 | private: |
| 71 | CMRT_UMD::CmThreadSpace *m_thread_space; |
| 72 | };//======================================== |
| 73 | |
| 74 | TEST_F(ThreadSpaceTest, MultipleSizes) |
| 75 | { |
| 76 | RunEach<int32_t>(CM_SUCCESS, |
| 77 | [this]() { return CreateDestroy(WIDTH, HEIGHT); }); |
| 78 | |
| 79 | auto CreateWithMaxSize |
| 80 | = [this]() |
| 81 | { return CreateDestroy(CM_MAX_THREADSPACE_WIDTH_SKLUP_FOR_MW, |
| 82 | CM_MAX_THREADSPACE_HEIGHT_SKLUP_FOR_MW); }; |
| 83 | RunEach<int32_t>(CM_SUCCESS, CreateWithMaxSize); |
| 84 | return; |
| 85 | }//======== |
| 86 | |
| 87 | TEST_F(ThreadSpaceTest, DependencyPattern) |
| 88 | { |
| 89 | CM_DEPENDENCY_PATTERN pattern = static_cast<CM_DEPENDENCY_PATTERN>(39); |
| 90 | RunEach<int32_t>( |
| 91 | CM_FAILURE, |
| 92 | [this, pattern]() { return SelectDependencyPattern(pattern); }); |
| 93 | |
| 94 | RunEach<int32_t>( |
| 95 | CM_SUCCESS, |
| 96 | [this]() { return SelectDependencyPattern(CM_NONE_DEPENDENCY); }); |
| 97 | return; |
| 98 | }//======== |
| 99 | |
| 100 | TEST_F(ThreadSpaceTest, MediaWalkingPattern) |
| 101 | { |
| 102 | CM_WALKING_PATTERN pattern = static_cast<CM_WALKING_PATTERN>(39); |
| 103 | RunEach<int32_t>( |
| 104 | CM_INVALID_MEDIA_WALKING_PATTERN, |
| 105 | [this, pattern]() { return SelectMediaWalkingPattern(pattern); }); |
| 106 | |
| 107 | RunEach<int32_t>( |
| 108 | CM_SUCCESS, |
| 109 | [this]() { return SelectMediaWalkingPattern(CM_WALK_DEFAULT); }); |
| 110 | return; |
| 111 | }//======== |