247fa9f1e0
For following test cases:
- KFDQMTest.QueueLatency
- KFDQMTest.BasicCuMaskingLinear
- KFDQMTest.BasicCuMaskingEven
- KFDMemoryTest.MMBandWidth
- KFDMemoryTest.MMapLarge
- KFDMemoryTest.MMBench
v2: xml element cannot start with a number, so change the key name of
MMBandWidth and MMBench accordingly
xml element cannot contain whitespaces, so trim whitespaces in "VRAM "
v3: introduce KFDLog-like way to use KFDRecord
Change-Id: Ifc3ed5657621252a7b39dccf1ef4f50a92593f77
Signed-off-by: Xiaojie Yuan <xiaojie.yuan@amd.com>
93 строки
3.5 KiB
C++
93 строки
3.5 KiB
C++
/*
|
|
* Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
*/
|
|
|
|
#ifndef __GOOGLETEST_EXTENSION__H__
|
|
#define __GOOGLETEST_EXTENSION__H__
|
|
|
|
#include <gtest/gtest.h>
|
|
#include "hsakmt.h"
|
|
#include "KFDTestFlags.hpp"
|
|
|
|
enum LOGTYPE {
|
|
LOGTYPE_INFO, // msg header in green
|
|
LOGTYPE_WARNING // msg header in yellow
|
|
};
|
|
|
|
class KFDLog{};
|
|
std::ostream& operator << (KFDLog log, LOGTYPE level);
|
|
|
|
// @brief Log additional details, to be displayed in the same format as other google test outputs
|
|
// Currently not supported by gtest
|
|
// Should be used like cout: LOG() << "message" << value << std::endl;
|
|
#define LOG() KFDLog() << LOGTYPE_INFO
|
|
#define WARN() KFDLog() << LOGTYPE_WARNING
|
|
|
|
class KFDRecord: public testing::Test {
|
|
public:
|
|
KFDRecord(const char *val): m_val(val) {}
|
|
KFDRecord(std::string &val): m_val(val) {}
|
|
KFDRecord(HSAint64 val): m_val(std::to_string(val)) {}
|
|
KFDRecord(HSAuint64 val): m_val(std::to_string(val)) {}
|
|
KFDRecord(double val): m_val(std::to_string(val)) {}
|
|
~KFDRecord() {
|
|
RecordProperty(m_key.str().c_str(), m_val.c_str());
|
|
}
|
|
std::stringstream &get_key_stream() {
|
|
return m_key;
|
|
}
|
|
virtual void TestBody() {};
|
|
private:
|
|
std::string m_val;
|
|
std::stringstream m_key;
|
|
};
|
|
|
|
#define RECORD(val) (KFDRecord(val).get_key_stream())
|
|
|
|
// All tests MUST be in a try catch since the gtest flag to throw an exception on any fatal failure is enabled
|
|
#define TEST_START(testProfile) if (Ok2Run(testProfile)) try {
|
|
#define TEST_END } catch (...) {}
|
|
|
|
// Used to wrap setup and teardown functions, anything that is built-in gtest and is not a test
|
|
#define ROUTINE_START try {
|
|
#define ROUTINE_END }catch(...) {}
|
|
|
|
#define TEST_REQUIRE_ENV_CAPABILITIES(envCaps) if (!TestReqEnvCaps(envCaps)) return;
|
|
#define TEST_REQUIRE_NO_ENV_CAPABILITIES(envCaps) if (!TestReqNoEnvCaps(envCaps)) return;
|
|
|
|
#define ASSERT_SUCCESS(_val) ASSERT_EQ(HSAKMT_STATUS_SUCCESS, (_val))
|
|
#define EXPECT_SUCCESS(_val) EXPECT_EQ(HSAKMT_STATUS_SUCCESS, (_val))
|
|
|
|
#define ASSERT_NOTNULL(_val) ASSERT_NE((void *)NULL, _val)
|
|
#define EXPECT_NOTNULL(_val) EXPECT_NE((void *)NULL, _val)
|
|
|
|
// @brief Determines if it is ok to run a test given input flags
|
|
bool Ok2Run(unsigned int testProfile);
|
|
|
|
// @brief Checks if all HW capabilities needed for a test to run exist
|
|
bool TestReqEnvCaps(unsigned int hwCaps);
|
|
|
|
// @brief Checks if all HW capabilities that prevents a test from running are absent
|
|
bool TestReqNoEnvCaps(unsigned int hwCaps);
|
|
|
|
#endif
|