1 /*
2  * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved.
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 in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * 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 
24 #ifndef __GOOGLETEST_EXTENSION__H__
25 #define __GOOGLETEST_EXTENSION__H__
26 
27 #include <gtest/gtest.h>
28 #include "hsakmt.h"
29 #include "KFDTestFlags.hpp"
30 
31 enum LOGTYPE {
32     LOGTYPE_INFO,            // msg header in green
33     LOGTYPE_WARNING    // msg header in yellow
34 };
35 
36 class KFDLog{};
37 std::ostream& operator << (KFDLog log ,LOGTYPE level);
38 
39 // @brief  log additional details, to be displayed in the same format as other google test outputs
40 // currently not supported by google test
41 // should be used like cout: LOG() << "message" << value << std::endl;
42 #define LOG()      KFDLog() << LOGTYPE_INFO
43 #define WARN()     KFDLog() << LOGTYPE_WARNING
44 
45 // all test MUST be in a try catch since google test flag to throw exception on any fatal fail is on
46 #define TEST_START(testProfile)   if (Ok2Run(testProfile)) try {
47 #define TEST_END       } catch (...) {}
48 
49 // used to wrape setup and teardown functions, anything that is build-in gtest  and is not a test
50 #define ROUTINE_START   try {
51 #define ROUTINE_END       }catch(...) {}
52 
53 #define TEST_REQUIRE_ENV_CAPABILITIES(envCaps)          if (!TestReqEnvCaps(envCaps))  return;
54 #define TEST_REQUIRE_NO_ENV_CAPABILITIES(envCaps)  if (!TestReqNoEnvCaps(envCaps))  return;
55 
56 #define ASSERT_SUCCESS(_val) ASSERT_EQ(HSAKMT_STATUS_SUCCESS, (_val))
57 #define EXPECT_SUCCESS(_val) EXPECT_EQ(HSAKMT_STATUS_SUCCESS, (_val))
58 
59 #define ASSERT_NOTNULL(_val) ASSERT_NE((void *)NULL, _val)
60 #define EXPECT_NOTNULL(_val) EXPECT_NE((void *)NULL, _val)
61 
62 // @brief  determines if its ok to run a test given input flags
63 bool Ok2Run(unsigned int testProfile);
64 
65 // @brief  checks if all HW capabilities needed for a test to run exist
66 bool TestReqEnvCaps(unsigned int hwCaps);
67 
68 // @brief  checks if all HW capabilities that prevents a test from running are non existing
69 bool TestReqNoEnvCaps(unsigned int hwCaps);
70 
71 #endif
72