1 /*
2 * Copyright (c) 2018, 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 #include <cctype>
23 #include <string>
24 #include <stdio.h>
25 #include "devconfig.h"
26 #include "gtest/gtest.h"
27
28 using namespace std;
29
30 const char* g_driverPath;
31 vector<Platform_t> g_platform;
32
33 static bool ParseCmd(int argc, char *argv[]);
34
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37 testing::InitGoogleTest(&argc, argv);
38
39 if (ParseCmd(argc, argv) == false)
40 {
41 return -1;
42 }
43
44 return RUN_ALL_TESTS();
45 }
46
47 static bool ParsePlatform(const char *str);
48 static bool ParseDriverPath(const char *str);
49
ParseCmd(int argc,char * argv[])50 static bool ParseCmd(int argc, char *argv[])
51 {
52 g_driverPath = nullptr;
53 g_platform.clear();
54
55 for (int i = 1; i < argc; i++)
56 {
57 if (ParseDriverPath(argv[i]) == false && ParsePlatform(argv[i]) == false)
58 {
59 printf("ERROR\n Bad command line parameter!\n\n");
60 printf("USAGE\n devult [driver_path] [platform_name...]\n\n");
61 printf("DESCRIPTION\n [driver_path] : Use default driver relative path if not specify driver_path.\n"
62 " [platform_name...]: Select zero or more items from {SKL, BXT, BDW}.\n\n");
63 printf("EXAMPLE\n devult\n"
64 " devult ./build/media_driver/iHD_drv_video.so\n"
65 " devult skl\n"
66 " devult ./build/media_driver/iHD_drv_video.so skl\n"
67 " devult ./build/media_driver/iHD_drv_video.so skl\n\n");
68 return false;
69 }
70 }
71
72 return true;
73 }
74
ParsePlatform(const char * str)75 static bool ParsePlatform(const char *str)
76 {
77 string tmpStr(str);
78
79 for (auto i = tmpStr.begin(); i != tmpStr.end(); i++)
80 {
81 *i = toupper(*i);
82 }
83
84 for (int i = 0; i < (int)igfx_MAX; i++)
85 {
86 if (tmpStr.compare(g_platformName[i]) == 0)
87 {
88 g_platform.push_back((Platform_t)i);
89 return true;
90 }
91 }
92
93 return false;
94 }
95
ParseDriverPath(const char * str)96 static bool ParseDriverPath(const char *str)
97 {
98 if (g_driverPath == nullptr && strstr(str, "iHD_drv_video.so") != nullptr)
99 {
100 g_driverPath = str;
101 return true;
102 }
103
104 return false;
105 }
106