提交 4e70fd5d 编写于 作者: F FondMemoryVVV

Modified Toolchain Codecheck

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