11401458bSopenharmony_ci/* 21401458bSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 31401458bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41401458bSopenharmony_ci * you may not use this file except in compliance with the License. 51401458bSopenharmony_ci * You may obtain a copy of the License at 61401458bSopenharmony_ci * 71401458bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81401458bSopenharmony_ci * 91401458bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101401458bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111401458bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121401458bSopenharmony_ci * See the License for the specific language governing permissions and 131401458bSopenharmony_ci * limitations under the License. 141401458bSopenharmony_ci */ 151401458bSopenharmony_ci 161401458bSopenharmony_ci#include "hisysevent_delay_test.h" 171401458bSopenharmony_ci 181401458bSopenharmony_ci#include <gtest/gtest.h> 191401458bSopenharmony_ci 201401458bSopenharmony_ci#include <iosfwd> 211401458bSopenharmony_ci#include <string> 221401458bSopenharmony_ci#include <thread> 231401458bSopenharmony_ci#include <unistd.h> 241401458bSopenharmony_ci#include <vector> 251401458bSopenharmony_ci 261401458bSopenharmony_ci#include "gtest/gtest-message.h" 271401458bSopenharmony_ci#include "gtest/gtest-test-part.h" 281401458bSopenharmony_ci#include "gtest/hwext/gtest-ext.h" 291401458bSopenharmony_ci#include "gtest/hwext/gtest-tag.h" 301401458bSopenharmony_ci 311401458bSopenharmony_ci#include "hisysevent.h" 321401458bSopenharmony_ci#include "string_ex.h" 331401458bSopenharmony_ci#include "string_util.h" 341401458bSopenharmony_ci 351401458bSopenharmony_ciusing namespace testing::ext; 361401458bSopenharmony_ciusing namespace OHOS; 371401458bSopenharmony_ciusing namespace OHOS::HiviewDFX; 381401458bSopenharmony_ci 391401458bSopenharmony_cinamespace { 401401458bSopenharmony_ciconstexpr int WROTE_TOTAL_CNT = 30; 411401458bSopenharmony_ci 421401458bSopenharmony_civoid WriteStringWithLength(const std::string testCaseName, const std::string testCaseDescription, int cnt) 431401458bSopenharmony_ci{ 441401458bSopenharmony_ci string param; 451401458bSopenharmony_ci param.append(cnt, 'a'); 461401458bSopenharmony_ci std::vector<int> wroteRet; 471401458bSopenharmony_ci int ret = SUCCESS; 481401458bSopenharmony_ci for (int i = 0; i < WROTE_TOTAL_CNT; ++i) { 491401458bSopenharmony_ci ret = HiSysEventWrite(HiSysEvent::Domain::AAFWK, "LIFECYCLE_TIMEOUT", HiSysEvent::EventType::FAULT, "key", 501401458bSopenharmony_ci param); 511401458bSopenharmony_ci wroteRet.emplace_back(ret); 521401458bSopenharmony_ci } 531401458bSopenharmony_ci ASSERT_EQ(wroteRet.size(), WROTE_TOTAL_CNT); 541401458bSopenharmony_ci ASSERT_EQ(std::count(wroteRet.begin(), wroteRet.end(), SUCCESS), WROTE_TOTAL_CNT); 551401458bSopenharmony_ci} 561401458bSopenharmony_ci 571401458bSopenharmony_citemplate<typename T> 581401458bSopenharmony_civoid WriteSingleValue(const std::string testCaseName, const std::string testCaseDescription, T val) 591401458bSopenharmony_ci{ 601401458bSopenharmony_ci std::vector<int> wroteRet; 611401458bSopenharmony_ci int ret = SUCCESS; 621401458bSopenharmony_ci for (int i = 0; i < WROTE_TOTAL_CNT; ++i) { 631401458bSopenharmony_ci ret = HiSysEventWrite(HiSysEvent::Domain::AAFWK, "LIFECYCLE_TIMEOUT", HiSysEvent::EventType::FAULT, "key", 641401458bSopenharmony_ci val); 651401458bSopenharmony_ci wroteRet.emplace_back(ret); 661401458bSopenharmony_ci } 671401458bSopenharmony_ci ASSERT_EQ(wroteRet.size(), WROTE_TOTAL_CNT); 681401458bSopenharmony_ci ASSERT_EQ(std::count(wroteRet.begin(), wroteRet.end(), SUCCESS), WROTE_TOTAL_CNT); 691401458bSopenharmony_ci} 701401458bSopenharmony_ci} 711401458bSopenharmony_ci 721401458bSopenharmony_civoid HiSysEventDelayTest::SetUpTestCase(void) 731401458bSopenharmony_ci{ 741401458bSopenharmony_ci} 751401458bSopenharmony_ci 761401458bSopenharmony_civoid HiSysEventDelayTest::TearDownTestCase(void) 771401458bSopenharmony_ci{ 781401458bSopenharmony_ci} 791401458bSopenharmony_ci 801401458bSopenharmony_civoid HiSysEventDelayTest::SetUp(void) 811401458bSopenharmony_ci{ 821401458bSopenharmony_ci} 831401458bSopenharmony_ci 841401458bSopenharmony_civoid HiSysEventDelayTest::TearDown(void) 851401458bSopenharmony_ci{ 861401458bSopenharmony_ci} 871401458bSopenharmony_ci 881401458bSopenharmony_ci/** 891401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest001 901401458bSopenharmony_ci * @tc.desc: Write a sysevent without any parameter 911401458bSopenharmony_ci * @tc.type: FUNC 921401458bSopenharmony_ci * @tc.require: issueI76V6J 931401458bSopenharmony_ci */ 941401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest001, TestSize.Level1) 951401458bSopenharmony_ci{ 961401458bSopenharmony_ci std::vector<int> wroteRet; 971401458bSopenharmony_ci int ret = SUCCESS; 981401458bSopenharmony_ci for (int i = 0; i < WROTE_TOTAL_CNT; ++i) { 991401458bSopenharmony_ci ret = HiSysEventWrite(HiSysEvent::Domain::AAFWK, "LIFECYCLE_TIMEOUT", HiSysEvent::EventType::FAULT); 1001401458bSopenharmony_ci wroteRet.emplace_back(ret); 1011401458bSopenharmony_ci } 1021401458bSopenharmony_ci ASSERT_EQ(wroteRet.size(), WROTE_TOTAL_CNT); 1031401458bSopenharmony_ci ASSERT_EQ(std::count(wroteRet.begin(), wroteRet.end(), SUCCESS), WROTE_TOTAL_CNT); 1041401458bSopenharmony_ci} 1051401458bSopenharmony_ci 1061401458bSopenharmony_ci/** 1071401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest002 1081401458bSopenharmony_ci * @tc.desc: Write sysevent with a bool parameter 1091401458bSopenharmony_ci * @tc.type: FUNC 1101401458bSopenharmony_ci * @tc.require: issueI76V6J 1111401458bSopenharmony_ci */ 1121401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest002, TestSize.Level1) 1131401458bSopenharmony_ci{ 1141401458bSopenharmony_ci bool value = true; 1151401458bSopenharmony_ci WriteSingleValue("HiSysEventDelayTest002", "Write sysevent with a bool parameter", value); 1161401458bSopenharmony_ci} 1171401458bSopenharmony_ci 1181401458bSopenharmony_ci/** 1191401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest003 1201401458bSopenharmony_ci * @tc.desc: Write sysevent with a char parameter 1211401458bSopenharmony_ci * @tc.type: FUNC 1221401458bSopenharmony_ci * @tc.require: issueI76V6J 1231401458bSopenharmony_ci */ 1241401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest003, TestSize.Level1) 1251401458bSopenharmony_ci{ 1261401458bSopenharmony_ci char value = 'a'; 1271401458bSopenharmony_ci WriteSingleValue("HiSysEventDelayTest003", "Write sysevent with a char parameter", value); 1281401458bSopenharmony_ci} 1291401458bSopenharmony_ci 1301401458bSopenharmony_ci/** 1311401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest004 1321401458bSopenharmony_ci * @tc.desc: Write sysevent with a double parameter 1331401458bSopenharmony_ci * @tc.type: FUNC 1341401458bSopenharmony_ci * @tc.require: issueI76V6J 1351401458bSopenharmony_ci */ 1361401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest004, TestSize.Level1) 1371401458bSopenharmony_ci{ 1381401458bSopenharmony_ci double value = 30949.374; 1391401458bSopenharmony_ci WriteSingleValue("HiSysEventDelayTest004", "Write sysevent with a double parameter", value); 1401401458bSopenharmony_ci} 1411401458bSopenharmony_ci 1421401458bSopenharmony_ci/** 1431401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest005 1441401458bSopenharmony_ci * @tc.desc: Write sysevent with a float parameter 1451401458bSopenharmony_ci * @tc.type: FUNC 1461401458bSopenharmony_ci * @tc.require: issueI76V6J 1471401458bSopenharmony_ci */ 1481401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest005, TestSize.Level1) 1491401458bSopenharmony_ci{ 1501401458bSopenharmony_ci float value = 230.47; 1511401458bSopenharmony_ci WriteSingleValue("HiSysEventDelayTest005", "Write sysevent with a float parameter", value); 1521401458bSopenharmony_ci} 1531401458bSopenharmony_ci 1541401458bSopenharmony_ci/** 1551401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest006 1561401458bSopenharmony_ci * @tc.desc: Write sysevent with a integer parameter 1571401458bSopenharmony_ci * @tc.type: FUNC 1581401458bSopenharmony_ci * @tc.require: issueI76V6J 1591401458bSopenharmony_ci */ 1601401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest006, TestSize.Level1) 1611401458bSopenharmony_ci{ 1621401458bSopenharmony_ci int value = 100; 1631401458bSopenharmony_ci WriteSingleValue("HiSysEventDelayTest006", "Write sysevent with a integer parameter", value); 1641401458bSopenharmony_ci} 1651401458bSopenharmony_ci 1661401458bSopenharmony_ci/** 1671401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest007 1681401458bSopenharmony_ci * @tc.desc: Write sysevent with a long parameter 1691401458bSopenharmony_ci * @tc.type: FUNC 1701401458bSopenharmony_ci * @tc.require: issueI76V6J 1711401458bSopenharmony_ci */ 1721401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest007, TestSize.Level1) 1731401458bSopenharmony_ci{ 1741401458bSopenharmony_ci long value = 1000000; 1751401458bSopenharmony_ci WriteSingleValue("HiSysEventDelayTest007", "Write sysevent with a long parameter", value); 1761401458bSopenharmony_ci} 1771401458bSopenharmony_ci 1781401458bSopenharmony_ci/** 1791401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest008 1801401458bSopenharmony_ci * @tc.desc: Write sysevent with a short parameter 1811401458bSopenharmony_ci * @tc.type: FUNC 1821401458bSopenharmony_ci * @tc.require: issueI76V6J 1831401458bSopenharmony_ci */ 1841401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest008, TestSize.Level1) 1851401458bSopenharmony_ci{ 1861401458bSopenharmony_ci short value = 10; 1871401458bSopenharmony_ci WriteSingleValue("HiSysEventDelayTest008", "Write sysevent with a short parameter", value); 1881401458bSopenharmony_ci} 1891401458bSopenharmony_ci 1901401458bSopenharmony_ci/** 1911401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest009 1921401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 32 1931401458bSopenharmony_ci * @tc.type: FUNC 1941401458bSopenharmony_ci * @tc.require: issueI76V6J 1951401458bSopenharmony_ci */ 1961401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest009, TestSize.Level1) 1971401458bSopenharmony_ci{ 1981401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest009", "Write a sysevent with a string param whose length is 32", 1991401458bSopenharmony_ci 32); 2001401458bSopenharmony_ci} 2011401458bSopenharmony_ci 2021401458bSopenharmony_ci/** 2031401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest010 2041401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 64 2051401458bSopenharmony_ci * @tc.type: FUNC 2061401458bSopenharmony_ci * @tc.require: issueI76V6J 2071401458bSopenharmony_ci */ 2081401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest010, TestSize.Level1) 2091401458bSopenharmony_ci{ 2101401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest010", "Write a sysevent with a string param whose length is 64", 2111401458bSopenharmony_ci 64); 2121401458bSopenharmony_ci} 2131401458bSopenharmony_ci 2141401458bSopenharmony_ci/** 2151401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest011 2161401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 128 2171401458bSopenharmony_ci * @tc.type: FUNC 2181401458bSopenharmony_ci * @tc.require: issueI76V6J 2191401458bSopenharmony_ci */ 2201401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest011, TestSize.Level1) 2211401458bSopenharmony_ci{ 2221401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest011", "Write a sysevent with a string param whose length is 128", 2231401458bSopenharmony_ci 128); 2241401458bSopenharmony_ci} 2251401458bSopenharmony_ci 2261401458bSopenharmony_ci/** 2271401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest012 2281401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 256 2291401458bSopenharmony_ci * @tc.type: FUNC 2301401458bSopenharmony_ci * @tc.require: issueI76V6J 2311401458bSopenharmony_ci */ 2321401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest012, TestSize.Level1) 2331401458bSopenharmony_ci{ 2341401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest012", "Write a sysevent with a string param whose length is 256", 2351401458bSopenharmony_ci 256); 2361401458bSopenharmony_ci} 2371401458bSopenharmony_ci 2381401458bSopenharmony_ci 2391401458bSopenharmony_ci/** 2401401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest013 2411401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 512 2421401458bSopenharmony_ci * @tc.type: FUNC 2431401458bSopenharmony_ci * @tc.require: issueI76V6J 2441401458bSopenharmony_ci */ 2451401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest013, TestSize.Level1) 2461401458bSopenharmony_ci{ 2471401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest013", "Write a sysevent with a string param whose length is 512", 2481401458bSopenharmony_ci 512); 2491401458bSopenharmony_ci} 2501401458bSopenharmony_ci 2511401458bSopenharmony_ci/** 2521401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest014 2531401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 1024 2541401458bSopenharmony_ci * @tc.type: FUNC 2551401458bSopenharmony_ci * @tc.require: issueI76V6J 2561401458bSopenharmony_ci */ 2571401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest014, TestSize.Level1) 2581401458bSopenharmony_ci{ 2591401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest014", "Write a sysevent with a string param whose length is 1024", 2601401458bSopenharmony_ci 1024); 2611401458bSopenharmony_ci} 2621401458bSopenharmony_ci 2631401458bSopenharmony_ci/** 2641401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest015 2651401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 2048 2661401458bSopenharmony_ci * @tc.type: FUNC 2671401458bSopenharmony_ci * @tc.require: issueI76V6J 2681401458bSopenharmony_ci */ 2691401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest015, TestSize.Level1) 2701401458bSopenharmony_ci{ 2711401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest015", "Write a sysevent with a string param whose length is 2048", 2721401458bSopenharmony_ci 2048); 2731401458bSopenharmony_ci} 2741401458bSopenharmony_ci 2751401458bSopenharmony_ci/** 2761401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest016 2771401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 3072 2781401458bSopenharmony_ci * @tc.type: FUNC 2791401458bSopenharmony_ci * @tc.require: issueI76V6J 2801401458bSopenharmony_ci */ 2811401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest016, TestSize.Level1) 2821401458bSopenharmony_ci{ 2831401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest016", "Write a sysevent with a string param whose length is 3072", 2841401458bSopenharmony_ci 3072); 2851401458bSopenharmony_ci} 2861401458bSopenharmony_ci 2871401458bSopenharmony_ci/** 2881401458bSopenharmony_ci * @tc.name: HiSysEventDelayTest017 2891401458bSopenharmony_ci * @tc.desc: Write a sysevent with a string param whose length is 4096 2901401458bSopenharmony_ci * @tc.type: FUNC 2911401458bSopenharmony_ci * @tc.require: issueI76V6J 2921401458bSopenharmony_ci */ 2931401458bSopenharmony_ciHWTEST_F(HiSysEventDelayTest, HiSysEventDelayTest017, TestSize.Level1) 2941401458bSopenharmony_ci{ 2951401458bSopenharmony_ci WriteStringWithLength("HiSysEventDelayTest017", "Write a sysevent with a string param whose length is 4096", 2961401458bSopenharmony_ci 4096); 2971401458bSopenharmony_ci}