Debian Codegraph @

media_driver/linux/ult/ult_app/cm/cm_test.h

raw
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 #ifndef MEDIADRIVER_LINUX_CODECHAL_ULT_ULTAPP_CMTEST_H_
24 #define MEDIADRIVER_LINUX_CODECHAL_ULT_ULTAPP_CMTEST_H_
25
26 #include <malloc.h>
27 #include "gtest/gtest.h"
28 #include "mock_device.h"
29 #include "../memory_leak_detector.h"
30
31 #pragma GCC diagnostic ignored "-Wnonnull"
32
33 class CmTest: public testing::Test
34 {
35 public:
36 static void* AllocateAlignedMemory(size_t size, size_t alignment)
37 { return memalign(alignment, size); }
38
39 static void FreeAlignedMemory(void *memory) { free(memory); }
40
41 CmTest(): m_currentPlatform(igfx_MAX) {}
42
43 template<typename T, class Function>
44 bool RunEach(T expected_return, Function RunTest)
45 {
46 bool result = true;
47
48 const std::vector<Platform_t> &platforms = m_driverLoader.GetPlatforms();
49 int platform_count = static_cast<int>(platforms.size());
50
51 for (int i = 0; i < platform_count; ++i)
52 {
53 CreateMockDevice(platforms[i]);
54
55 T function_return = RunTest();
56 EXPECT_EQ(function_return, expected_return);
57 result &= (function_return == expected_return);
58
59 ReleaseMockDevice();
60 }
61 return result;
62 }//===============
63
64 protected:
65 bool CreateMockDevice(const Platform_t &current_platform)
66 {
67 int va_status = m_driverLoader.InitDriver(current_platform);
68 EXPECT_EQ(VA_STATUS_SUCCESS, va_status);
69 m_currentPlatform = current_platform;
70 m_mockDevice.Create(&m_driverLoader);
71 return true;
72 }//=============
73
74 bool ReleaseMockDevice()
75 {
76 m_mockDevice.Release();
77 int va_status = m_driverLoader.CloseDriver();
78 EXPECT_EQ(VA_STATUS_SUCCESS, va_status);
79 return true;
80 }//=============
81
82 DriverDllLoader m_driverLoader;
83
84 CMRT_UMD::MockDevice m_mockDevice;
85
86 Platform_t m_currentPlatform;
87 };
88
89 #endif // #ifndef MEDIADRIVER_LINUX_CODECHAL_ULT_ULTAPP_CMTEST_H_