diff --git a/commonlibrary/toolchain/libc-test/include/getfiles.cpp b/commonlibrary/toolchain/libc-test/include/getfiles.cpp index 0e2d4ea2ea6fa9c4a2ef9bcc216bd79aedcc7393..5ce697e1bc11a73bd32d6bb080c558f643e2a6bd 100644 --- a/commonlibrary/toolchain/libc-test/include/getfiles.cpp +++ b/commonlibrary/toolchain/libc-test/include/getfiles.cpp @@ -1,5 +1,4 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. +/* Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,19 +22,19 @@ namespace OHOS { using namespace std; -static vector filenames; -std::vector runtest::GetFileNames(std::string path) +static vector g_filenames; +std::vector Runtest::GetFileNames(std::string path) { vector tempName; GetTestNames(path, tempName); for (size_t i = 0; i < tempName.size(); i++) { - if ((tempName[i].find("stat", path.length()-1) != -1) || - (tempName[i].find("sem_close-unmap", path.length()-1) != -1) || - (tempName[i].find("runtest", path.length()-1) != -1)) { + if ((tempName[i].find("stat", path.length() - 1) != -1) || + (tempName[i].find("sem_close-unmap", path.length() - 1) != -1) || + (tempName[i].find("runtest", path.length() - 1) != -1)) { continue; } - filenames.push_back(tempName[i]); + g_filenames.push_back(tempName[i]); } - return filenames; + return g_filenames; } } // namespace OHOS \ No newline at end of file diff --git a/commonlibrary/toolchain/libc-test/include/gettestfiles.cpp b/commonlibrary/toolchain/libc-test/include/gettestfiles.cpp index 23b3c2013386af383a144fde942ae4c11c23f2c3..c78100f8a16fc1e7bfd74f65b3fbf4890908df12 100644 --- a/commonlibrary/toolchain/libc-test/include/gettestfiles.cpp +++ b/commonlibrary/toolchain/libc-test/include/gettestfiles.cpp @@ -1,5 +1,4 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. +/* Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/commonlibrary/toolchain/libc-test/include/runtest.h b/commonlibrary/toolchain/libc-test/include/runtest.h index c9554b38b601599d0006cd9ba21f935b0ca75cd4..d65a62e40d3442068cc821130fa93e271eba77ea 100644 --- a/commonlibrary/toolchain/libc-test/include/runtest.h +++ b/commonlibrary/toolchain/libc-test/include/runtest.h @@ -1,5 +1,4 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. +/* Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,9 +18,9 @@ #include #include namespace OHOS { -class runtest { +class Runtest { public: - static int t_setrlim(int r, long lim); + static int TSetrlim(int r, long lim); static std::vector GetFileNames(std::string path); }; } // namespace OHOS diff --git a/commonlibrary/toolchain/libc-test/include/setrlim.cpp b/commonlibrary/toolchain/libc-test/include/setrlim.cpp index cb89e5198288c2c84a91e29b4ca0b8eda43854d5..8bfe58c20f32d881cfa777a316175134f2ad1641 100644 --- a/commonlibrary/toolchain/libc-test/include/setrlim.cpp +++ b/commonlibrary/toolchain/libc-test/include/setrlim.cpp @@ -1,5 +1,4 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. +/* Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,11 +18,11 @@ #include "runtest.h" namespace OHOS { -int runtest::t_setrlim(int r, long lim) +int Runtest::TSetrlim(int r, long lim) { struct rlimit rl; - //Gets the current stack size - if (getrlimit(r, &rl)) { + // Gets the current stack size + if (getrlimit(r, &rl) != 0) { printf("getrlimit %d: %s\n", r, strerror(errno)); return -1; } @@ -35,7 +34,7 @@ int runtest::t_setrlim(int r, long lim) } rl.rlim_max = lim; rl.rlim_cur = lim; - if (setrlimit(r, &rl)) { + if (setrlimit(r, &rl) != 0) { printf("setrlimit(%d, %ld): %s\n", r, lim, strerror(errno)); return -1; } diff --git a/commonlibrary/toolchain/libc-test/src/toolchaintest.cpp b/commonlibrary/toolchain/libc-test/src/toolchaintest.cpp index cd82b3db719f37ec4aa90274a6ec298b144bc290..56dcf037cacdd05028079521564e06e377a2cb9b 100644 --- a/commonlibrary/toolchain/libc-test/src/toolchaintest.cpp +++ b/commonlibrary/toolchain/libc-test/src/toolchaintest.cpp @@ -1,5 +1,4 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. +/* Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,26 +33,26 @@ using namespace std; using namespace testing::ext; using namespace testing; namespace OHOS { -class toolchaintest : public ::testing::TestWithParam {}; +class Toolchaintest : public ::testing::TestWithParam {}; -static string filepath = "/data/local/tmp/libc-test"; -static vector temp = runtest::GetFileNames(filepath); +static string g_filepath = "/data/local/tmp/libc-test"; +static vector temp = Runtest::GetFileNames(g_filepath); -volatile int t_status = 0; +volatile int g_tStatus = 0; -static void handler(int sig) +static void Handler(int sig) { } -static int start(const char *argvs) +static int Start(const char *argvs) { - int pid, space_size = 100*1024; - //Create a child process - //Set the process stack space + int pid, spaceSize = 100 * 1024; + // Create a child process + // Set the process stack space pid = fork(); if (pid == 0) { - runtest::t_setrlim(RLIMIT_STACK, space_size); - //Overloading the subprocess space + Runtest::TSetrlim(RLIMIT_STACK, spaceSize); + // Overloading the subprocess space int exe = execl(argvs, "strptime", nullptr); printf("exe:%d %s exec failed: %s\n", exe, argvs, strerror(errno)); exit(1); @@ -61,33 +60,33 @@ static int start(const char *argvs) return pid; } -static int runTests(const char *argvs) +static int RunTests(const char *argvs) { int timeoutsec = 5, timeout = 0; int status, pid; sigset_t set; void (*retfunc)(int); - //signal set + // signal set sigemptyset(&set); sigaddset(&set, SIGCHLD); sigprocmask(SIG_BLOCK, &set, nullptr); - retfunc = signal(SIGCHLD, handler); + retfunc = signal(SIGCHLD, Handler); if (retfunc == SIG_ERR) { printf("signal triggering failed:%s\n", strerror(errno)); } - pid = start(argvs); - //The function system call failed + pid = Start(argvs); + // The function system call failed if (pid == -1) { printf("%s fork failed: %s\n", argvs, strerror(errno)); printf("FAIL %s [internal]\n", argvs); return -1; } struct timespec tp; - //Maximum blocking time + // Maximum blocking time tp.tv_sec = timeoutsec; tp.tv_nsec = 0; if (sigtimedwait(&set, nullptr, &tp) == -1) { - //Call it again + // Call it again if (errno == EAGAIN) { timeout = 1; } else { @@ -97,16 +96,16 @@ static int runTests(const char *argvs) printf("%s kill failed: %s\n", argvs, strerror(errno)); } } - //Waiting for the process to stop + // Waiting for the process to stop if (waitpid(pid, &status, 0) != pid) { printf("%s waitpid failed: %s\n", argvs, strerror(errno)); printf("FAIL %s [internal]\n", argvs); return -1; } - //Process state - if (WIFEXITED(status)) { //The right exit - if (WEXITSTATUS(status) == 0) { //operate successfully - return t_status; + // Process state + if (WIFEXITED(status)) { // The right exit + if (WEXITSTATUS(status) == 0) { // operate successfully + return g_tStatus; } printf("FAIL %s [status %d]\n", argvs, WEXITSTATUS(status)); } else if (timeout) { @@ -121,15 +120,15 @@ static int runTests(const char *argvs) /** - * @tc.name : toolchaintest.LibcTest + * @tc.name : Toolchaintest.LibcTest * @tc.desc : start test * @tc.level : Level 3 */ -HWTEST_P(toolchaintest, LibcTest, Function | MediumTest | Level3) +HWTEST_P(Toolchaintest, LibcTest, Function | MediumTest | Level3) { int ret; string testName = GetParam(); - ret = runTests(testName.c_str()); + ret = RunTests(testName.c_str()); if (ret == 0) { EXPECT_EQ(0, ret) << "test " << testName << " succeed" << endl; } else { @@ -137,5 +136,5 @@ HWTEST_P(toolchaintest, LibcTest, Function | MediumTest | Level3) EXPECT_EQ(-1, ret) << "test " << testName << " failed" << endl; } } -INSTANTIATE_TEST_SUITE_P(libcTest, toolchaintest, testing::ValuesIn(temp.begin(), temp.end())); +INSTANTIATE_TEST_SUITE_P(libcTest, Toolchaintest, testing::ValuesIn(temp.begin(), temp.end())); } // namespace OHOS \ No newline at end of file diff --git a/commonlibrary/toolchain/libc-test/tar_files.py b/commonlibrary/toolchain/libc-test/tar_files.py index 1d745e6ebde81d5cf6df0be7c828ca0e9f9719f8..acdf44cad189f7af052284ade2ae6e881027277c 100755 --- a/commonlibrary/toolchain/libc-test/tar_files.py +++ b/commonlibrary/toolchain/libc-test/tar_files.py @@ -20,33 +20,38 @@ import argparse import tarfile import shutil -copyFileCounts = 0 - -def copyFiles(sourceDir, targetDir): - global copyFileCounts - for f in os.listdir(sourceDir): - sourceF = os.path.join(sourceDir, f) - targetF = os.path.join(targetDir, f) - if not os.path.isfile(sourceF): - if os.path.isdir(sourceF): - copyFiles(sourceF, targetF) - elif os.path.isfile(sourceF): +copy_file_counts = 0 + + +def copy_files(sourcedir, targetDir): + global copy_file_counts + for f in os.listdir(sourcedir): + source_f = os.path.join(sourcedir, f) + target_f = os.path.join(targetDir, f) + if not os.path.isfile(source_f): + if os.path.isdir(source_f): + copy_files(source_f, target_f) + elif os.path.isfile(source_f): if os.path.exists(targetDir): - copyFileCounts += 1 - open(targetF, "wb").write(open(sourceF, "rb").read()) + copy_file_counts += 1 + with open(target_f, "wb") as fp: + fp.write(open(source_f, "rb").read()) elif not os.path.exists(targetDir): os.makedirs(targetDir) - copyFileCounts += 1 - open(targetF, "wb").write(open(sourceF, "rb").read()) + copy_file_counts += 1 + with open(target_f, "wb") as fp: + fp.write(open(source_f, "rb").read()) + def make_targz_one_by_one(output_filename, source_dir): - tar = tarfile.open(output_filename,"w") - for root,dir,files in os.walk(source_dir): - for file in files: - pathfile = os.path.join(root, file) - tar.add(pathfile) + tar = tarfile.open(output_filename, "w") + for root, dirs, files in os.walk(source_dir): + for file in files: + pathfile = os.path.join(root, file) + tar.add(pathfile) tar.close() + if __name__ == "__main__": parser = argparse.ArgumentParser(description='manual to this script') parser.add_argument("--input_path", type=str, default="0") @@ -57,7 +62,7 @@ if __name__ == "__main__": print(args.output_path) print(args.temp_path) - copyFiles(args.input_path, args.temp_path) + copy_files(args.input_path, args.temp_path) make_targz_one_by_one(args.output_path, args.temp_path) - shutil.rmtree(args.temp_path) #delete middle files \ No newline at end of file + shutil.rmtree(args.temp_path) # delete middle files \ No newline at end of file