code format

Signed-off-by: f00829171 <chris.feng@huawei.com>
This commit is contained in:
f00829171 2024-04-18 20:33:27 +08:00
parent 473509b995
commit 378ca151f4
9 changed files with 120 additions and 123 deletions

View File

@ -24,6 +24,7 @@ import distutils.file_util as file_util
import json
import subprocess
def get_modulename_by_buildtarget(module_list_file, build_target):
if not os.path.exists(module_list_file):
return ""
@ -32,15 +33,16 @@ def get_modulename_by_buildtarget(module_list_file, build_target):
module_info_data = json.load(module_file)
for module in module_info_data:
if module in [build_target, f'{build_target}_override']:
return module_info_data[module];
return module_info_data[module]
return ""
if __name__ == '__main__':
global_parts_info = sys.argv[1]
tmp_subsystem_part = sys.argv[2]
method = sys.argv[3]
if method == "judgePart":
res = get_modulename_by_buildtarget(global_parts_info,tmp_subsystem_part)
sys.stdout.write(str(res))
res = get_modulename_by_buildtarget(global_parts_info, tmp_subsystem_part)
sys.stdout.write(str(res))
else:
sys.stdout.write("test")
sys.stdout.write("test")

View File

@ -41,9 +41,9 @@ def _get_xts_rootpath(project_path):
def _get_subsystem_name(project_path):
if '/hits/' in project_path:
if '/hits/' in project_path:
index0 = project_path.find('/hits/') + len('/hits/')
elif '/acts/' in project_path:
elif '/acts/' in project_path:
index0 = project_path.find('/acts/') + len('/acts/')
else:
raise ValueError('Illegal xts project path ' + project_path)
@ -222,7 +222,7 @@ class SuiteModuleWithTestbundleBuilder:
dest_file = os.path.join(
_testcases_dir, "{}.hap".format(_testsuite_name))
self._copy_file(args.buildgen_testfile, dest_file)
os.chmod(dest_file, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)
os.chmod(dest_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
return
if args.project_type == "pythontest":
self._generate_json_by_template(_test_xml.replace(".xml", ".json"),
@ -240,7 +240,8 @@ class SuiteModuleWithTestbundleBuilder:
_testcases_dir)
self._record_testpart_info(args.build_target_name,
_testsuite_name,
_testcases_dir,args.subsystem_name,args.part_name)
_testcases_dir,
args.subsystem_name,args.part_name)
if _test_xml and os.path.exists(_test_xml):
self._copy_file(_test_xml, _config_file)
elif _test_xml.replace(".xml", ".json") and \

View File

@ -28,89 +28,88 @@ extern "C" {
#endif
#endif
#define CONST_EMPTY_STRING ""
#define CONST_STRING_SPACE " "
#define CONST_DOT_STRING ","
#define CONST_EMPTY_STRING ""
#define CONST_STRING_SPACE " "
#define CONST_DOT_STRING ","
#define TEST_INIT(func) LAYER_INITCALL_DEF(func, test, "test")
#define TEST_INIT_PRI(func, priority) LAYER_INITCALL(func, test, "test", priority)
typedef struct TestSuiteManager {
/**
* @brief get the test suite by suite name
* @param the test suite name
* @return the TestSuite point
* */
CTestSuite* (*GetTestSuite)(const char *test_suite);
* @brief get the test suite by suite name
* @param the test suite name
* @return the TestSuite point
* */
CTestSuite *(*GetTestSuite)(const char *test_suite);
BOOL (*RegisterTestSuite)(CTestSuite *testSuite);
/**
* @brief remove the test suite.
* @param the test case addr.
* @return TRUE success
* */
* @brief remove the test suite.
* @param the test case addr.
* @return TRUE success
* */
BOOL (*RemoveTestSuite)(CTestSuite *testSuite);
/**
* @brief remove the test suite.
* @param the test case addr.
* @return TRUE success
* */
* @brief remove the test suite.
* @param the test case addr.
* @return TRUE success
* */
void (*AddTestCase)(CTestCase *testCase);
/**
* @brief remove special test suite.
* @param caseName
*/
void (*RunSpecialTestSuite)(const char *subSystemName,
const char *moduleName,
const char *suiteName,
const char *caseName,
int caseLevel);
void (*RunSpecialTestSuite)(
const char *subSystemName, const char *moduleName, const char *suiteName, const char *caseName, int caseLevel);
void (*RunTestSuite)(const char* suite_name);
void (*RunTestSuite)(const char *suite_name);
Vector test_suites;
}TestSuiteManager;
} TestSuiteManager;
TestSuiteManager *GetTestMgrInstance(void);
#define LITE_TEST_SUIT(subsystem, module, test_suite) \
static CTestSuite suite_object##test_suite;\
static void initSuite##test_suite(void) {\
suite_object##test_suite.subsystem_name = #subsystem;\
suite_object##test_suite.module_name = #module;\
suite_object##test_suite.suite_name = #test_suite;\
suite_object##test_suite.file = __FILE__;\
suite_object##test_suite.times = HCTEST_REPEAT_TIMES;\
suite_object##test_suite.test_cases = VECTOR_Make(NULL, NULL);\
TestSuiteManager* testMgr = GetTestMgrInstance();\
testMgr->RegisterTestSuite(&(suite_object##test_suite));\
}\
SYS_SERVICE_INIT(initSuite##test_suite);
#define LITE_TEST_SUIT(subsystem, module, test_suite) \
static CTestSuite suite_object##test_suite; \
static void initSuite##test_suite(void) \
{ \
suite_object##test_suite.subsystem_name = #subsystem; \
suite_object##test_suite.module_name = #module; \
suite_object##test_suite.suite_name = #test_suite; \
suite_object##test_suite.file = __FILE__; \
suite_object##test_suite.times = HCTEST_REPEAT_TIMES; \
suite_object##test_suite.test_cases = VECTOR_Make(NULL, NULL); \
TestSuiteManager *testMgr = GetTestMgrInstance(); \
testMgr->RegisterTestSuite(&(suite_object##test_suite)); \
} \
SYS_SERVICE_INIT(initSuite##test_suite);
#define LITE_TEST_CASE(test_suite, case_object, test_flag) \
static void case_object##_runTest(void);\
static CTestCase create##case_object;\
static void initCase##case_object(void) {\
create##case_object.suite_name = #test_suite;\
create##case_object.case_name = #case_object;\
create##case_object.flag = test_flag; \
create##case_object.line_num = __LINE__; \
create##case_object.lite_setup = test_suite##SetUp; \
create##case_object.lite_teardown = test_suite##TearDown;\
create##case_object.execute_func = case_object##_runTest;\
TestSuiteManager* testMgr = GetTestMgrInstance();\
testMgr->AddTestCase(&(create##case_object));\
}\
SYS_RUN(initCase##case_object);\
static void case_object##_runTest(void)
#define LITE_TEST_CASE(test_suite, case_object, test_flag) \
static void case_object##_runTest(void); \
static CTestCase create##case_object; \
static void initCase##case_object(void) \
{ \
create##case_object.suite_name = #test_suite; \
create##case_object.case_name = #case_object; \
create##case_object.flag = test_flag; \
create##case_object.line_num = __LINE__; \
create##case_object.lite_setup = test_suite##SetUp; \
create##case_object.lite_teardown = test_suite##TearDown; \
create##case_object.execute_func = case_object##_runTest; \
TestSuiteManager *testMgr = GetTestMgrInstance(); \
testMgr->AddTestCase(&(create##case_object)); \
} \
SYS_RUN(initCase##case_object); \
static void case_object##_runTest(void)
#define RUN_TEST_SUITE(test_suite) \
static void runSuite##test_suite(void) {\
TestSuiteManager* testMgr = GetTestMgrInstance(); \
testMgr->RunTestSuite(#test_suite); \
}\
TEST_INIT(runSuite##test_suite);
#define RUN_TEST_SUITE(test_suite) \
static void runSuite##test_suite(void) \
{ \
TestSuiteManager *testMgr = GetTestMgrInstance(); \
testMgr->RunTestSuite(#test_suite); \
} \
TEST_INIT(runSuite##test_suite);
void LiteTestPrint(const char *fmt, ...);

View File

@ -20,8 +20,7 @@
#define UNITY_EXCLUDE_LIMITS_H
#define UNITY_EXCLUDE_STDINT_H
#define UNITY_OUTPUT_CHAR(a) printf("%c",(a))
#define UNITY_OUTPUT_CHAR(a) printf("%c", (a))
#define UNITY_EXCLUDE_SETJMP_H
#define UNITY_EXCLUDE_MATH_H

View File

@ -30,19 +30,23 @@
#define UDIDSIZE_LEN 64
void setUp(void) {}
void tearDown(void) {}
void suiteSetUp(void) { }
int suiteTearDown(int num_failures) { return num_failures; }
void setUp(void)
{}
void tearDown(void)
{}
void suiteSetUp(void)
{}
int suiteTearDown(int num_failures)
{
return num_failures;
}
static TestSuiteManager g_testSuiteManager;
static BOOL CompareInputType(const char *source, const char *input);
static void RunSingleTestCase(CTestCase* cTestCase,
const char *caseName, const int32 flag);
static void RunSingleTestCase(CTestCase *cTestCase, const char *caseName, const int32 flag);
static int16 g_totalSuitesNum = 0;
static int16 g_doneSuitesNum = 0;
static void RunSingleTestSuite(CTestSuite* testSuite)
static void RunSingleTestSuite(CTestSuite *testSuite)
{
if (testSuite == NULL) {
return;
@ -70,17 +74,17 @@ static void RunSingleTestSuite(CTestSuite* testSuite)
UnityEnd();
}
static CTestSuite* GetTestSuite(const char *test_suite)
static CTestSuite *GetTestSuite(const char *test_suite)
{
CTestSuite* suite = NULL;
TestSuiteManager* testMgr = GetTestMgrInstance();
CTestSuite *suite = NULL;
TestSuiteManager *testMgr = GetTestMgrInstance();
if (testMgr == NULL || test_suite == NULL) {
return suite;
}
int16 size = VECTOR_Size(&(testMgr->test_suites));
int16 i;
for (i = 0; i < size; i++) {
CTestSuite* curSuite = (CTestSuite *)(VECTOR_At(&(testMgr->test_suites), i));
CTestSuite *curSuite = (CTestSuite *)(VECTOR_At(&(testMgr->test_suites), i));
if (strcmp(curSuite->suite_name, test_suite) == 0) {
suite = curSuite;
break;
@ -99,9 +103,8 @@ static BOOL RegisterTestSuite(CTestSuite *testSuite)
static BOOL RemoveTestSuite(CTestSuite *testSuite)
{
VECTOR_Swap(&(g_testSuiteManager.test_suites),
VECTOR_Find(&(g_testSuiteManager.test_suites), testSuite),
testSuite);
VECTOR_Swap(
&(g_testSuiteManager.test_suites), VECTOR_Find(&(g_testSuiteManager.test_suites), testSuite), testSuite);
return TRUE;
}
@ -110,7 +113,7 @@ static void AddTestCase(CTestCase *testCase)
if (testCase == NULL) {
return;
}
CTestSuite* suite = GetTestSuite(testCase->suite_name);
CTestSuite *suite = GetTestSuite(testCase->suite_name);
if (suite == NULL) {
CTestSuite suite_object;
suite_object.subsystem_name = NULL;
@ -133,12 +136,10 @@ static BOOL CompareInputType(const char *source, const char *input)
}
static BOOL g_isBreak = FALSE;
static void RunSingleTestCase(CTestCase* cTestCase,
const char *caseName, const int32 flag)
static void RunSingleTestCase(CTestCase *cTestCase, const char *caseName, const int32 flag)
{
if (cTestCase != NULL) {
if (CompareInputType(cTestCase->case_name, caseName)
|| (cTestCase->flag != flag)) {
if (CompareInputType(cTestCase->case_name, caseName) || (cTestCase->flag != flag)) {
g_isBreak = TRUE;
return;
}
@ -146,11 +147,8 @@ static void RunSingleTestCase(CTestCase* cTestCase,
}
}
static void RunSpecialTestSuite(const char *subSystemName,
const char *moduleName,
const char *suiteName,
const char *caseName,
int caseLevel)
static void RunSpecialTestSuite(
const char *subSystemName, const char *moduleName, const char *suiteName, const char *caseName, int caseLevel)
{
int16 i;
int16 j;
@ -160,16 +158,15 @@ static void RunSpecialTestSuite(const char *subSystemName,
if (g_isBreak) {
break;
}
CTestSuite* curSuite = (CTestSuite *)(VECTOR_At(&(g_testSuiteManager.test_suites), i));
CTestSuite *curSuite = (CTestSuite *)(VECTOR_At(&(g_testSuiteManager.test_suites), i));
if (curSuite != NULL) {
if (CompareInputType(curSuite->subsystem_name, subSystemName)
|| CompareInputType(curSuite->module_name, moduleName)
|| CompareInputType(curSuite->suite_name, suiteName)) {
if (CompareInputType(curSuite->subsystem_name, subSystemName) ||
CompareInputType(curSuite->module_name, moduleName) ||
CompareInputType(curSuite->suite_name, suiteName)) {
continue;
}
for (j = 0; j < VECTOR_Size(&(curSuite->test_cases)); j++) {
CTestCase* cTestCase = (CTestCase *)(VECTOR_At(
&(curSuite->test_cases), j));
CTestCase *cTestCase = (CTestCase *)(VECTOR_At(&(curSuite->test_cases), j));
RunSingleTestCase(cTestCase, caseName, caseLevel);
}
}
@ -177,17 +174,17 @@ static void RunSpecialTestSuite(const char *subSystemName,
UNITY_END();
}
static void RunTestSuite(const char* suite_name)
static void RunTestSuite(const char *suite_name)
{
printf("Start to run test suite:%s\n", suite_name);
CTestSuite* curSuite = GetTestSuite(suite_name);
CTestSuite *curSuite = GetTestSuite(suite_name);
if (curSuite != NULL) {
g_doneSuitesNum++;
int16 times = curSuite->times;
int16 i;
for (i = 0; i < times; i++) {
sleep(1);
printf("Run test suite %d times\n", i+1);
printf("Run test suite %d times\n", i + 1);
RunSingleTestSuite(curSuite);
}
if (g_totalSuitesNum == g_doneSuitesNum) {
@ -250,20 +247,19 @@ void ObtainProductParams(void)
if (abiList != NULL) {
printf("AbiList = %s\n", abiList);
}
}
#ifdef INTER_ATTEST_MINI_MODULE
void ObtainAttestResultParams(void)
{
AttestResultInfo attestResultInfo = { 0 };
AttestResultInfo attestResultInfo = {0};
attestResultInfo.ticket = NULL;
int32_t retStatus = GetAttestStatus(&attestResultInfo);
if (retStatus != DEVATTEST_SUCCESS) {
printf("[CLIENT MAIN] wrong. retStatus:%d\n", retStatus);
}
printf("authResult = %d\n",attestResultInfo.authResult);
printf("softwareResult = %d\n",attestResultInfo.softwareResult);
printf("authResult = %d\n", attestResultInfo.authResult);
printf("softwareResult = %d\n", attestResultInfo.softwareResult);
}
#endif
@ -299,7 +295,7 @@ void ObtainSystemParams(void)
ObtainAttestResultParams();
#endif
char udid[UDIDSIZE_LEN + 1] = { 0 };
char udid[UDIDSIZE_LEN + 1] = {0};
int retUdid = GetDevUdid(udid, UDIDSIZE_LEN + 1);
if (retUdid == 0) {
printf("DevUdid = %s\n", udid);
@ -351,7 +347,7 @@ void ObtainSystemParams(void)
}
ObtainProductParams();
printf("******To Obtain Product Params End ******\n");
return;
}
@ -365,11 +361,11 @@ static void InitTestSuiteMgr(void)
g_testSuiteManager.RemoveTestSuite = RemoveTestSuite;
g_testSuiteManager.RunSpecialTestSuite = RunSpecialTestSuite;
g_testSuiteManager.RunTestSuite = RunTestSuite;
printf("[%10s] HCTest Framework inited.\n", "HCtest Service");
printf("[%10s] HCTest Framework inited.\n", "HCtest Service");
ObtainSystemParams();
}
CORE_INIT(InitTestSuiteMgr);
TestSuiteManager* GetTestMgrInstance(void)
TestSuiteManager *GetTestMgrInstance(void)
{
return &g_testSuiteManager;
}

View File

@ -41,7 +41,7 @@ static void Init(void)
testService.flag = FALSE;
SAMGR_GetInstance()->RegisterService((Service *)&testService);
}
SYSEX_SERVICE_INIT_PRI(Init,4);
SYSEX_SERVICE_INIT_PRI(Init, 4);
static const char *GetName(Service *service)
{
(void)service;

View File

@ -98,16 +98,16 @@ int main()
printf("VersionID = %s\n", versionId);
}
AttestResultInfo attestResultInfo = { 0 };
AttestResultInfo attestResultInfo = {0};
attestResultInfo.ticket = NULL;
int32_t retStatus = GetAttestStatus(&attestResultInfo);
if (retStatus != DEVATTEST_SUESS) {
printf("[CLIENT MAIN] wrong. retStatus:%d\n", retStatus);
}
printf("authResult = %d\n",attestResultInfo.authResult);
printf("softwareResult = %d\n",attestResultInfo.softwareResult);
printf("authResult = %d\n", attestResultInfo.authResult);
printf("softwareResult = %d\n", attestResultInfo.softwareResult);
char udid[UDIDSIZE_LEN + 1] = { 0 };
char udid[UDIDSIZE_LEN + 1] = {0};
int retUdid = GetDevUdid(udid, UDIDSIZE_LEN + 1);
if (retUdid == 0) {
printf("DevUdid = %s\n", udid);
@ -158,7 +158,7 @@ int main()
printf("marketName = %s\n", marketName);
}
ObtainProductParms();
ObtainProductParms();
printf("******To Obtain Product Params End ******\n");
return 0;

View File

@ -103,10 +103,10 @@ int main()
AttestResultInfo attestResultInfo;
(void)DelayedSingleton<DevAttestClient>::GetInstance()->GetAttestStatus(attestResultInfo);
printf("authResult = %d\n",attestResultInfo.authResult_);
printf("softwareResult = %d\n",attestResultInfo.softwareResult_);
printf("authResult = %d\n", attestResultInfo.authResult_);
printf("softwareResult = %d\n", attestResultInfo.softwareResult_);
char udid[UDIDSIZE_LEN + 1] = { 0 };
char udid[UDIDSIZE_LEN + 1] = {0};
int ret = GetDevUdid(udid, UDIDSIZE_LEN + 1);
if (ret == 0) {
printf("DevUdid = %s\n", udid);
@ -151,13 +151,13 @@ int main()
if (buildRootHash != nullptr) {
printf("BuildRootHash = %s\n", buildRootHash);
}
const char *marketName = GetMarketName();
if (marketName != nullptr) {
printf("marketName = %s\n", marketName);
}
ObtainProductParms();
ObtainProductParms();
printf("******To Obtain Product Params End ******\n");
return 0;

View File

@ -28,5 +28,5 @@ with os.fdopen(file_descriptor, 'r+') as file:
data = json.load(file)
data[OPEN_HARMONY_KEY] = OPEN_HARMONY_VALUE
file.seek(0)
json.dump(data, file, indent = 4)
json.dump(data, file, indent=4)
file.truncate()