提交 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");
* 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<std::string> filenames;
std::vector<std::string> runtest::GetFileNames(std::string path)
static vector<std::string> g_filenames;
std::vector<std::string> Runtest::GetFileNames(std::string path)
{
vector<string> 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
/*
* 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
......
/*
* 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 <string>
#include <vector>
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<std::string> GetFileNames(std::string path);
};
} // 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");
* 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;
}
......
/*
* 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<string> {};
class Toolchaintest : public ::testing::TestWithParam<string> {};
static string filepath = "/data/local/tmp/libc-test";
static vector<std::string> temp = runtest::GetFileNames(filepath);
static string g_filepath = "/data/local/tmp/libc-test";
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;
//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
......@@ -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):
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册