未验证 提交 92e608a0 编写于 作者: O openharmony_ci 提交者: Gitee

!94 Modified the codes

Merge pull request !94 from stivn/master
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _DISTRIBUTED_H_ #ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_H_
#define _DISTRIBUTED_H_ #define AW_CXX_DISTRIBUTED_DISTRIBUTED_H_
#include <iostream> #include <iostream>
#include "securec.h" #include "securec.h"
...@@ -50,4 +50,4 @@ using DistDeviceInfo = DistDevInfo; ...@@ -50,4 +50,4 @@ using DistDeviceInfo = DistDevInfo;
} // namespace DistributeSystemTest } // namespace DistributeSystemTest
} // namespace OHOS } // namespace OHOS
#endif // _DISTRIBUTED_H_ #endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_H_
...@@ -85,7 +85,11 @@ int DistributedAgent::InitAgentServer() ...@@ -85,7 +85,11 @@ int DistributedAgent::InitAgentServer()
} }
struct sockaddr_in addr; struct sockaddr_in addr;
memset_s(&addr, sizeof(addr), 0, sizeof(addr)); errno_t ret = EOK;
ret = memset_s(&addr, sizeof(addr), 0, sizeof(addr));
if (ret != EOK) {
return -1;
}
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
if (agentIpAddr_ != "") { if (agentIpAddr_ != "") {
inet_pton(AF_INET, agentIpAddr_.c_str(), &addr.sin_addr); inet_pton(AF_INET, agentIpAddr_.c_str(), &addr.sin_addr);
...@@ -203,7 +207,8 @@ int DistributedAgent::DoCmdServer(int serverSockFd) ...@@ -203,7 +207,8 @@ int DistributedAgent::DoCmdServer(int serverSockFd)
auto pclinereturn = reinterpret_cast<DistributedMsg *>(returnValue); auto pclinereturn = reinterpret_cast<DistributedMsg *>(returnValue);
pclinereturn->no = pcline->no; pclinereturn->no = pcline->no;
pclinereturn->cmdTestType = htons(DST_COMMAND_CALL); pclinereturn->cmdTestType = htons(DST_COMMAND_CALL);
sprintf_s(pclinereturn->alignmentCmd, (MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN), "%d", nresult); (void)sprintf_s(pclinereturn->alignmentCmd, (MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN),
"%d", nresult) < 0);
rlen = strlen(pclinereturn->alignmentCmd) + 1; rlen = strlen(pclinereturn->alignmentCmd) + 1;
pclinereturn->len = htons(rlen); pclinereturn->len = htons(rlen);
HiLog::Info(DistributedAgent::LABEL, "agent get message :%s .\n", HiLog::Info(DistributedAgent::LABEL, "agent get message :%s .\n",
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef DISTRIBUTED_AGENT_H #ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_AGENT_H_
#define DISTRIBUTED_AGENT_H #define AW_CXX_DISTRIBUTED_DISTRIBUTED_AGENT_H_
#include <map> #include <map>
#include <vector> #include <vector>
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
protected: protected:
virtual bool SetUp(); virtual bool SetUp();
virtual bool TearDown(); virtual bool TearDown();
virtual void OnLocalInit() {}; virtual void OnLocalInit() {}
virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen,
const std::string &strExpectValue, int expectValueLen); const std::string &strExpectValue, int expectValueLen);
virtual int OnProcessMsg(const std::string &strMsg, int msgLen, std::string &strReturnValue, int returnBufLen); virtual int OnProcessMsg(const std::string &strMsg, int msgLen, std::string &strReturnValue, int returnBufLen);
...@@ -69,4 +69,5 @@ private: ...@@ -69,4 +69,5 @@ private:
} // namespace DistributeSystemTest } // namespace DistributeSystemTest
} // namespace OHOS } // namespace OHOS
#endif // DISTRIBUTED_AGENT_H #endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_AGENT_H_
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef DISTRIBUTED_CFG_H #ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_CFG_H_
#define DISTRIBUTED_CFG_H #define AW_CXX_DISTRIBUTED_DISTRIBUTED_CFG_H_
#include <map> #include <map>
#include <iostream> #include <iostream>
...@@ -52,4 +52,5 @@ private: ...@@ -52,4 +52,5 @@ private:
}; };
} // namespace DistributeSystemTest } // namespace DistributeSystemTest
} // namespace OHOS } // namespace OHOS
#endif
\ No newline at end of file #endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_CFG_H_
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef DISTRIBUTED_MAJOR_H #ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_MAJOR_H_
#define DISTRIBUTED_MAJOR_H #define AW_CXX_DISTRIBUTED_DISTRIBUTED_MAJOR_H_
#include <vector> #include <vector>
#include <map> #include <map>
...@@ -92,7 +92,7 @@ protected: ...@@ -92,7 +92,7 @@ protected:
int GetReturnVal(); int GetReturnVal();
private: private:
void OnProcessNotify() {}; void OnProcessNotify() {}
int returnVal_; int returnVal_;
static void SetUpTestCase(void); static void SetUpTestCase(void);
...@@ -101,14 +101,14 @@ private: ...@@ -101,14 +101,14 @@ private:
// init network environment, obtain all the address of agent and connect // init network environment, obtain all the address of agent and connect
int InitEnv(std::vector<std::string> clientList); int InitEnv(std::vector<std::string> clientList);
virtual void SetUp() {}; virtual void SetUp() {}
virtual void TearDown() {}; virtual void TearDown() {}
virtual void OnNotify() {}; virtual void OnNotify() {}
virtual bool OnProcessValue(const std::string &szbuf, int len); virtual bool OnProcessValue(const std::string &szbuf, int len);
virtual bool OnMsgProc(const std::string &szbuf, int len); virtual bool OnMsgProc(const std::string &szbuf, int len);
}; };
} // namespace DistributeSystemTest } // namespace DistributeSystemTest
} // namespace OHOS } // namespace OHOS
#endif // DISTRIBUTED_MAJOR_H #endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_MAJOR_H_
\ No newline at end of file
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef UNTITLED_CSV_TO_XML_H #ifndef AW_CXX_DISTRIBUTED_UTILS_CSV_TRANSFORM_XML_H_
#define UNTITLED_CSV_TO_XML_H #define AW_CXX_DISTRIBUTED_UTILS_CSV_TRANSFORM_XML_H_
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <string> #include <string>
...@@ -35,7 +36,7 @@ class CsvTransformXml { ...@@ -35,7 +36,7 @@ class CsvTransformXml {
public: public:
CsvTransformXml(std::string targetFile) explicit CsvTransformXml(std::string targetFile)
{ {
SetFileName(targetFile); SetFileName(targetFile);
SetCvsFileName(); SetCvsFileName();
...@@ -137,4 +138,5 @@ public: ...@@ -137,4 +138,5 @@ public:
} }
}; };
#endif // UNTITLED_CVS_TO_XML_H #endif // AW_CXX_DISTRIBUTED_UTILS_CSV_TRANSFORM_XML_H_
...@@ -32,8 +32,6 @@ namespace TestAW { ...@@ -32,8 +32,6 @@ namespace TestAW {
#define ID_LARGER_IS_BETTER true #define ID_LARGER_IS_BETTER true
#define ID_SMALLER_IS_BETTER false #define ID_SMALLER_IS_BETTER false
#define _max(a,b) (((a)>=(b)) ? (a) : (b) )
#define _min(a,b) (((a)<=(b)) ? (a) : (b))
namespace { namespace {
const auto XML_TAG_ROOT = "configuration"; const auto XML_TAG_ROOT = "configuration";
...@@ -182,7 +180,7 @@ GtestPerfTestCase::GtestPerfTestCase(BaseLineManager* pManager, ...@@ -182,7 +180,7 @@ GtestPerfTestCase::GtestPerfTestCase(BaseLineManager* pManager,
// get test case name from GTEST API. // get test case name from GTEST API.
// should be use tester->XXX() instead of this. // should be use tester->XXX() instead of this.
if (tester != nullptr) { if (tester != nullptr && ::testing::UnitTest::GetInstance() != nullptr) {
m_strCaseName = string(::testing::UnitTest::GetInstance()->current_test_info()->name()); m_strCaseName = string(::testing::UnitTest::GetInstance()->current_test_info()->name());
} }
...@@ -284,11 +282,11 @@ bool GtestPerfTestCase::ExpectValue(double testValue, bool isLargerBetter) ...@@ -284,11 +282,11 @@ bool GtestPerfTestCase::ExpectValue(double testValue, bool isLargerBetter)
} else { } else {
double baseValue = -1; double baseValue = -1;
if (isLargerBetter) { if (isLargerBetter) {
baseValue = _max(m_dbLastValue, m_dbBaseLine); baseValue = (m_dbLastValue >= m_dbBaseLine) ? m_dbLastValue : m_dbBaseLine;
EXPECT_GE(testValue, (baseValue * (1.0 - m_dbFloatRange))); EXPECT_GE(testValue, (baseValue * (1.0 - m_dbFloatRange)));
m_bTestResult = (testValue >= (baseValue * (1.0 - m_dbFloatRange))) ? true : false; m_bTestResult = (testValue >= (baseValue * (1.0 - m_dbFloatRange))) ? true : false;
} else { } else {
baseValue = _min(m_dbLastValue, m_dbBaseLine); baseValue = (m_dbLastValue <= m_dbBaseLine) ? m_dbLastValue : m_dbBaseLine;
EXPECT_LE(testValue, (baseValue * (1.0 + m_dbFloatRange))); EXPECT_LE(testValue, (baseValue * (1.0 + m_dbFloatRange)));
m_bTestResult = (testValue <= (baseValue * (1.0 + m_dbFloatRange))) ? true : false; m_bTestResult = (testValue <= (baseValue * (1.0 + m_dbFloatRange))) ? true : false;
} }
...@@ -311,22 +309,22 @@ bool GtestPerfTestCase::SaveResult(double testValue) ...@@ -311,22 +309,22 @@ bool GtestPerfTestCase::SaveResult(double testValue)
INF_MSG("[ PERF ] %s: baseline:%f, test_result: %f\n", m_strCaseName.c_str(), m_dbBaseLine, testValue); INF_MSG("[ PERF ] %s: baseline:%f, test_result: %f\n", m_strCaseName.c_str(), m_dbBaseLine, testValue);
memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer));
if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", m_dbBaseLine) > 0) { if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", m_dbBaseLine) > 0) {
m_pTester->RecordProperty("baseline", buffer); m_pTester->RecordProperty("baseline", buffer);
} }
memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer));
if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%d", m_dCaseVersion) > 0) { if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%d", m_dCaseVersion) > 0) {
m_pTester->RecordProperty("tc_version", buffer); m_pTester->RecordProperty("tc_version", buffer);
} }
memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer));
if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", m_dbLastValue) > 0) { if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", m_dbLastValue) > 0) {
m_pTester->RecordProperty("lastvalue", m_bHasLastValue ? buffer : ""); m_pTester->RecordProperty("lastvalue", m_bHasLastValue ? buffer : "");
} }
memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer));
if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", testValue) > 0) { if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", testValue) > 0) {
m_pTester->RecordProperty("value", buffer); m_pTester->RecordProperty("value", buffer);
} }
...@@ -337,5 +335,5 @@ bool GtestPerfTestCase::SaveResult(double testValue) ...@@ -337,5 +335,5 @@ bool GtestPerfTestCase::SaveResult(double testValue)
return true; return true;
} }
} // TestAW } // namespace TestAW
} // OHOS } // namespace OHOS
\ No newline at end of file
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef TEST_AW_CXX_HWEXT_PERF_H #ifndef AW_CXX_HWEXT_PERF_H_
#define TEST_AW_CXX_HWEXT_PERF_H #define AW_CXX_HWEXT_PERF_H_
#include <string> #include <string>
#include <list> #include <list>
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
std::string testClassName = "", std::string testClassName = "",
std::string testInterfaceName = ""); std::string testInterfaceName = "");
~GtestPerfTestCase() {}; ~GtestPerfTestCase() {}
// expect result is larger than or equal baseline*(1.0-float_range). // expect result is larger than or equal baseline*(1.0-float_range).
bool ExpectLarger(double testValue); bool ExpectLarger(double testValue);
...@@ -164,6 +164,7 @@ private: ...@@ -164,6 +164,7 @@ private:
bool m_bTestResult; bool m_bTestResult;
double m_dbTestResult; double m_dbTestResult;
}; };
} // TestAW } // namespace TestAW
} // OHOS } // namespace OHOS
#endif // TEST_AW_CXX_HWEXT_PERF_H
\ No newline at end of file #endif // AW_CXX_HWEXT_PERF_H_
...@@ -25,6 +25,10 @@ const int FUZZ_FTH_DATA = 3; ...@@ -25,6 +25,10 @@ const int FUZZ_FTH_DATA = 3;
namespace OHOS { namespace OHOS {
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{ {
if (data == nullptr) {
return false;
}
bool result = false; bool result = false;
if (size >= FUZZ_DATA_LEN) { if (size >= FUZZ_DATA_LEN) {
result = data[FUZZ_FST_DATA] == 'F' && result = data[FUZZ_FST_DATA] == 'F' &&
...@@ -34,7 +38,7 @@ namespace OHOS { ...@@ -34,7 +38,7 @@ namespace OHOS {
} }
return result; return result;
} }
} } // namespace.OHOS
/* Fuzzer entry point */ /* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
......
...@@ -50,6 +50,9 @@ bool IsPrime(int n) ...@@ -50,6 +50,9 @@ bool IsPrime(int n)
bool FileExist(const char* fileName) bool FileExist(const char* fileName)
{ {
if (fileName == nullptr) {
return false;
}
struct stat myStat; struct stat myStat;
return (!stat(fileName, &myStat)); return (!stat(fileName, &myStat));
} }
...@@ -45,11 +45,11 @@ public: ...@@ -45,11 +45,11 @@ public:
DistributeDemo() = default; DistributeDemo() = default;
~DistributeDemo() = default; ~DistributeDemo() = default;
static void SetUpTestCase(void) {}; static void SetUpTestCase(void) {}
static void TearDownTestCase(void) {}; static void TearDownTestCase(void) {}
virtual void SetUp() {}; virtual void SetUp() {}
virtual void TearDown() {}; virtual void TearDown() {}
}; };
/** /**
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef SERVICEDEMO_CALC_MULTI_H #ifndef EXAMPLE_LITE_C_DEMO_INCLUDE_CALC_MULTI_H_
#define SERVICEDEMO_CALC_MULTI_H #define EXAMPLE_LITE_C_DEMO_INCLUDE_CALC_MULTI_H_
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
...@@ -30,4 +30,4 @@ int calc_multi(int a, int b); ...@@ -30,4 +30,4 @@ int calc_multi(int a, int b);
#endif #endif
#endif #endif
#endif // SERVICEDEMO_CALC_MULTI_H #endif // EXAMPLE_LITE_C_DEMO_INCLUDE_CALC_MULTI_H_
...@@ -24,19 +24,19 @@ using namespace OHOS::TestAW; ...@@ -24,19 +24,19 @@ using namespace OHOS::TestAW;
static BaseLineManager m_baseline(PERF_BASELINE_CONFIG_PATH); static BaseLineManager m_baseline(PERF_BASELINE_CONFIG_PATH);
class SpentTimeTest : public testing::Test { class SpentTimeTest : public testing::Test {
public: public:
static void SetUpTestCase(void) {}; static void SetUpTestCase(void) {}
static void TearDownTestCase(void) {}; static void TearDownTestCase(void) {}
void SetUp() {}; void SetUp() {}
void TearDown() {}; void TearDown() {}
}; };
static void LoopMsleep(void* pMsec) static void LoopMsleep(void* pMsec)
{ {
if (pMsec == NULL) { if (pMsec == nullptr) {
return; return;
} }
int msec = *(int*)pMsec; int msec = *reinterpret_cast<int*> (pMsec);
for (int index = 0; index < msec; index++) { for (int index = 0; index < msec; index++) {
Msleep(1); Msleep(1);
} }
......
...@@ -263,12 +263,12 @@ import("//build/test.gni") ...@@ -263,12 +263,12 @@ import("//build/test.gni")
module_output_path = "developertest/calculator" module_output_path = "developertest/calculator"
ohos_unittest("BenchmarkDemoTest") { ohos_benchmarktest("BenchmarkDemoTest") {
module_out_path = module_output_path module_out_path = module_output_path
sources = [ "benchmark_demo_test.cpp" ] sources = [ "benchmark_demo_test.cpp" ]
} }
group("unittest") { group("benchmarktest") {
testonly = true testonly = true
deps = [] deps = []
...@@ -315,9 +315,9 @@ group("unittest") { ...@@ -315,9 +315,9 @@ group("unittest") {
4. 指定测试套名称 4. 指定测试套名称
``` ```
ohos_unittest("BenchmarkDemoTest") { # benchmark测试编译模板 ohos_benchmarktest("BenchmarkDemoTest") {
module_out_path = module_output_path module_out_path = module_output_path
sources = [ "benchmark_demo_test.cpp" ] # 指定测试用例文件 sources = [ "benchmark_demo_test.cpp" ]
} }
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册