提交 c5e24db6 编写于 作者: O oumeng

test framework

Signed-off-by: Noumeng <oumeng@huawei.com>
上级 b0f06550
# Compile the test case
- [Introduction]
- [Directory]
- [Constraints and Limitations]
- [illustrate]
- [Description of related issues]
## Introduction
Provides a framework based on cmake compilation, which can compile binary files for different platforms.
According to the needs of customers, compile and generate corresponding executable programs and library files. Its compilation process is:
1. Use python script to configure the parameters of cmake compilation
2. After python runs, a Makefile will be generated
3. Execute the compiled task by running cmake --build .
## Directory
```
.
├── README.en.md
├── README.md
├── ndk-test
│   ├── CMakeLists.txt # Starting point for ndk-test build via cmake
│   ├── build.py # Script to compile ndk-test
│   └── src
├── sanitize
│   ├── CMakeLists.txt # Starting point for sanitize build via cmake
│   ├── asan
│   ├── build.py # Script to compile sanitize
│   ├── cfi
│   ├── fuzz
│   ├── scudo
│   └── ubsan
├── script # Script Directory
│   ├── __pycache__
│   ├── build.py # Total Compile Script
│   ├── config_args.py # Parameters required for cmake compilation
│   ├── runtest-sanitize.sh
│   ├── runtest.sh
│   └── runtest_Windows.bat # Push the compiled files to the board
└── target # save the target file
└── README.md
```
## Constraints and Limitations
- Need to download NDK or compile and generate through openharmony
- Configuration environment, please refer to [help for wiki](https://gitee.com/openharmony/third_party_musl/wikis/Home)
## illustrate
1. Compile commands for full compilation in the general directory
```
python build.py
```
2. The corresponding compilation directory can be compiled separately
```
# subdirectory sanitize
python build.py
# subdirectory ndk-test
python build.py
```
3. Run the test case on the board
```
# Make sure the board is connected to the computer and run the script
runtest_Windows.bat
```
4. If the above steps are executed successfully, the script will generate a REPORT and REPORT-SANITIZE files to record the results of running the ndk-test and sanitize test cases respectively
## Description of related issues
**For cmake parameter CMAKE_TOOCHAIN_FILE**
- Points to the location of the toolchain file, which is important for compiling binaries for different platforms, so give the correct path
\ No newline at end of file
# 编译测试案例
- [简介]
- [目录]
- [约束与限制]
- [说明]
- [相关问题说明]
## 简介
提供了一个基于cmake编译的框架,可编译不同平台的二进制文件
根据客户的需求,编译生成对应的可执行程序和库文件。其编译流程为:
1. 使用python脚本进行配置cmake编译的参数
2. python运行后会生成Makefile文件
3. 通过运行cmake --build .来执行编译的任务
## 目录结构
```
.
├── README.en.md
├── README.md
├── ndk-test
│   ├── CMakeLists.txt # ndk-test通过cmake构建的起点
│   ├── build.py # 编译ndk-test的脚本
│   └── src
├── sanitize
│   ├── CMakeLists.txt # sanitize通过cmake构建的起点
│   ├── asan
│   ├── build.py # 编译sanitize的脚本
│   ├── cfi
│   ├── fuzz
│   ├── scudo
│   └── ubsan
├── script # 编译放置的脚本
│   ├── __pycache__
│   ├── build.py # 编译的总脚本
│   ├── config_args.py # cmake编译需要的参数
│   ├── runtest-sanitize.sh
│   ├── runtest.sh
│   └── runtest_Windows.bat # 将编译生成的文件推送到板子上
└── target # 存放目标文件
└── README.md
```
## 限制与约束
- 需要下载NDK或者通过openharmony编译生成
- 配置环境,详情请参照[gitee中的wiki文档](https://gitee.com/openharmony/third_party_musl/wikis/Home)
## 说明
1. 总目录下全量编译的编译命令
```
python build.py
```
2. 对应的编译目录可单独编译
```
# 子目录sanitize
python build.py
# 子目录ndk-test
python build.py
```
3. 在板子上运行测试案例
```
# 确定板子连接好电脑,运行脚本
runtest_Windows.bat
```
4. 若以上步骤执行成功,脚本会产生一个REPORT和REPORT-SANITIZE文件,来分别记录ndk-test和sanitize测试案例运行的结果
## 相关问题说明
**对于cmake参数CMAKE_TOOCHAIN_FILE**
- 指向的是工具链文件所在的位置,对于编译不同平台二进制文件是很重要的,所以要给定正确的路径
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
PROJECT(NDK-TEST)
ADD_SUBDIRECTORY(src/chello)
ADD_SUBDIRECTORY(src/cpphello)
ADD_SUBDIRECTORY(src/headers)
ADD_SUBDIRECTORY(src/installing)
ADD_SUBDIRECTORY(src/shared-library)
ADD_SUBDIRECTORY(src/static-library)
\ No newline at end of file
import os
import shutil
import sys
sys.path.append('../script')
from config_args import linux_args
def build_unix():
if os.path.exists('build') and os.path.isdir('build'):
shutil.rmtree('build')
while True:
if not os.path.exists('build'):
break
os.mkdir('build')
os.chdir('build')
build_string = 'cmake' + ' '+ (" ".join(linux_args)) + ' '+'..'
print(build_string)
res = os.popen(build_string)
print(res.read())
res = os.popen('cmake --build .')
print(res.read())
if __name__ == '__main__':
build_unix()
cmake_minimum_required(VERSION 3.16)
project(HELLO)
add_subdirectory(src)
add_subdirectory(include)
set(LIB_SRC hello.c)
add_library(libhello STATIC ${LIB_SRC})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
set_target_properties(libhello PROPERTIES OUTPUT_NAME "hello")
#include <stdio.h>
#include "hello.h"
void hello(const char * name)
{
printf ("Hello %s!\n",name);
}
#ifndef DBZHANG_HELLO_
#define DBZHANG_HELLO_
void hello(const char* name);
#endif //DBZHANG_HELLO_
include_directories(${PROJECT_SOURCE_DIR}/include)
#link_directories(${PROJECT_BINARY_DIR}/lib)
set(APP_SRC main.c)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
add_executable(chello ${APP_SRC})
target_link_libraries(chello libhello)
#include "hello.h"
int main()
{
hello("World");
return 0;
}
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
PROJECT(CPPHELLO)
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(src)
SET(LIB_SRC hello.cpp)
ADD_LIBRARY(hello_static STATIC ${LIB_SRC})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
SET_TARGET_PROPERTIES(hello_static PROPERTIES OUTPUT_NAME "hello")
#include "hello.h"
void hello(const char * name)
{
std::cout<< "hello" <<std::endl;
}
#ifndef DBZHANG_HELLO_
#define DBZHANG_HELLO_
#include <iostream>
void hello(const char* name);
#endif //DBZHANG_HELLO_
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
SET(APP_SRC main.cpp)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
ADD_EXECUTABLE(cpphello ${APP_SRC})
TARGET_LINK_LIBRARIES(cpphello hello_static)
#include "hello.h"
int main()
{
hello("World");
return 0;
}
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
PROJECT(HELLO)
ADD_SUBDIRECTORY(src)
#ifndef __HELLO_H__
#define __HELLO_H__
class Hello
{
public:
void print();
};
#endif
# Create a sources variable with a link to all cpp files to compile
SET(SOURCE
Hello.cpp
main.cpp
)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
# Add an executable with the above sources
ADD_EXECUTABLE(hello_headers ${SOURCE})
# Set the directories that should be included in the build command for this target
# when running g++ these will be included as -I/directory/path/
TARGET_INCLUDE_DIRECTORIES(hello_headers
PRIVATE
${PROJECT_SOURCE_DIR}/include
)
#include <iostream>
#include "Hello.h"
void Hello::print()
{
std::cout << "Hello Headers!" << std::endl;
}
#include "Hello.h"
int main(int argc, char *argv[])
{
Hello hi;
hi.print();
return 0;
}
\ No newline at end of file
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
PROJECT(ndk_examples_install)
ADD_SUBDIRECTORY(src)
#ifndef __HELLO_H__
#define __HELLO_H__
class Hello
{
public:
void print();
};
#endif
# Sample configuration file that could be installed
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
############################################################
# Create a library
############################################################
#Generate the shared library from the library sources
ADD_LIBRARY(ndk_examples_inst STATIC
Hello.cpp
)
TARGET_INCLUDE_DIRECTORIES(ndk_examples_inst
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
############################################################
# Create an executable
############################################################
# Add an executable with the above sources
ADD_EXECUTABLE(ndk_examples_inst_bin
main.cpp
)
# link the new hello_library target with the hello_binary target
TARGET_LINK_LIBRARIES(ndk_examples_inst_bin
PRIVATE
ndk_examples_inst
)
############################################################
# Install
############################################################
# Binaries
INSTALL(TARGETS ndk_examples_inst_bin
DESTINATION bin)
# Library
# Note: may not work on windows
INSTALL(TARGETS ndk_examples_inst
LIBRARY DESTINATION lib)
# Header files
INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION include)
# Config
INSTALL(FILES ndk-examples.conf
DESTINATION etc)
#include <iostream>
#include "installing/Hello.h"
void Hello::print()
{
std::cout << "Hello Install!" << std::endl;
}
#include "installing/Hello.h"
int main(int argc, char *argv[])
{
Hello hi;
hi.print();
return 0;
}
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
PROJECT(HELLO_LIBRARY)
ADD_SUBDIRECTORY(src)
#ifndef __HELLO_H__
#define __HELLO_H__
class Hello
{
public:
void print();
};
#endif
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
############################################################
# Create a library
############################################################
#Generate the shared library from the library sources
ADD_LIBRARY(hello_shared_library SHARED
Hello.cpp
)
ADD_LIBRARY(hello::library ALIAS hello_shared_library)
TARGET_INCLUDE_DIRECTORIES(hello_shared_library
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
############################################################
# Create an executable
############################################################
# Add an executable with the above sources
ADD_EXECUTABLE(hello_shared_binary
main.cpp
)
# link the new hello_library target with the hello_binary target
TARGET_LINK_LIBRARIES( hello_shared_binary
PRIVATE
hello::library
)
#include <iostream>
#include "shared/Hello.h"
void Hello::print()
{
std::cout << "Hello Shared Library!" << std::endl;
}
#include "shared/Hello.h"
int main(int argc, char *argv[])
{
Hello hi;
hi.print();
return 0;
}
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
PROJECT(HELLO_LIBRARY)
ADD_SUBDIRECTORY(src)
#ifndef __HELLO_H__
#define __HELLO_H__
class Hello
{
public:
void print();
};
#endif
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/output)
############################################################
# Create a library
############################################################
#Generate the static library from the library sources
ADD_LIBRARY(hello_static_library STATIC
Hello.cpp
)
TARGET_INCLUDE_DIRECTORIES(hello_static_library
PUBLIC
${PROJECT_SOURCE_DIR}/include
)
############################################################
# Create an executable
############################################################
# Add an executable with the above sources
ADD_EXECUTABLE(hello_static_binary
main.cpp
)
# link the new hello_library target with the hello_binary target
TARGET_LINK_LIBRARIES( hello_static_binary
PRIVATE
hello_static_library
)
#include <iostream>
#include "static/Hello.h"
void Hello::print()
{
std::cout << "Hello Static Library!" << std::endl;
}
#include "static/Hello.h"
int main(int argc, char *argv[])
{
Hello hi;
hi.print();
return 0;
}
from distutils.command.build import build
import os
import fnmatch
from pickletools import string1
import shutil
import datetime
compiler_list = [
'ndk-test',
#'sanitize',
]
# Check the output directory
def check_target_dir():
target_dir = os.path.join(os.getcwd(),os.path.pardir,'target')
print(target_dir)
if os.path.exists(target_dir) and os.path.isdir(target_dir):
# print('target directory exist')
for filename in os.listdir(target_dir):
if os.path.isdir(os.path.join(target_dir,filename)):
shutil.rmtree(os.path.join(target_dir,filename))
else:
os.mkdir(target_dir)
# Traverse the directory, find the test case that needs to be compiled and compile it
def build_compiler():
check_target_dir()
build_start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print('build_start:' + build_start)
comliler_dir = os.path.join(os.getcwd(),os.path.pardir)
# print(comliler_dir)
for name in compiler_list:
file_path = os.path.join(comliler_dir,name)
# print(file_path)
if os.path.isdir(file_path):
for f_name in os.listdir(file_path):
if fnmatch.fnmatch(f_name, 'build.py'):
os.chdir(file_path)
string_build = 'python {}'.format('build.py')
os.system(string_build)
return_dir = os.path.join(os.getcwd(),os.path.pardir,'script')
os.chdir(return_dir)
build_end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print('build_end:' + build_end)
copy_target()
del_Intermediate_file()
return 0
# Copy the compiled target product to the target directory
def copy_target():
copy_start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print('copy_target_start:' + copy_start)
find_dir = os.path.join(os.getcwd(),os.path.pardir)
check_target_dir()
for name in compiler_list:
file_path = os.path.join(find_dir,name)
for curdir, dirs, files in os.walk(file_path):
for dirname in dirs:
if dirname == 'output':
copy_tar_out = os.path.join(find_dir,'target',name,os.path.basename(curdir))
# print(copy_tar_out)
if not os.path.isdir(copy_tar_out):
os.makedirs(copy_tar_out)
tar_out = os.path.join(curdir,dirname)
# print(tar_out)
print(tar_out + '----->' + copy_tar_out)
for filename in os.listdir(tar_out):
src = os.path.join(tar_out, filename)
dst = os.path.join(copy_tar_out, filename)
print(src + '----->' + dst)
shutil.copy(src, dst)
copy_end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print('copy_target_end:' + copy_end)
return 0
# Remove intermediate files from source files
def del_Intermediate_file():
del_start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print('copy_target_start:' + del_start)
find_dir = os.path.join(os.getcwd(),os.path.pardir)
for name in compiler_list:
file_path = os.path.join(find_dir,name)
del_file_path = os.path.join(file_path)
for curdir, dirs, files in os.walk(del_file_path):
for dirname in dirs:
if dirname == 'build':
# print(os.path.join(curdir,dirname))
shutil.rmtree(os.path.join(curdir,dirname))
del_end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print('copy_target_end:' + del_end)
if __name__ == '__main__':
# check_target_dir()
build_compiler()
# copy_target()
# del_Intermediate_file()
linux_args = [
'-DOHOS_STL=c++_shared' ,
'-DOHOS_ARCH=armeabi-v7a' ,
'-DOHOS_PLATFORM=OHOS' ,
'-DCMAKE_TOOLCHAIN_FILE=~/openharmony/out/sdk/packages/ohos-sdk/linux/native/build/cmake/ohos.toolchain.cmake' ,
]
#! /bin/sh
rm REPORT-SANITIZE
touch REPORT-SANITIZE
num_s=0
num_f=0
num_skip=0
function skip {
echo skip
let num_skip=$num_skip+1
}
for case in `ls sanitize/asan`
do
echo [Runing test] : sanitize/asan/$case
if [ "$case" = "use-after-return" ]; then
ASAN_OPTIONS=detect_stack_use_after_return=1 sanitize/asan/$case 2>tmp
elif [ "$case" = "IO-a" ] | [ "$case" = "IO-b" ]; then
ASAN_OPTIONS=check_initialization_order=true sanitize/asan/$case 2>tmp
else
ASAN_OPTIONS='' sanitize/asan/$case 2>tmp
fi
# check result
if [ "$case" = "memory-leaks" ];then
grep -nr 'SUMMARY: ' tmp | grep "leaked in"
else
grep -nr 'SUMMARY: ' tmp | grep $case
fi
res=$?
# Specially
if [ res -ne 0 ] && [ "$case" = "IO-b" ];then
echo "$case succeeded."
let num_s=$num_s+1
elif [ res -ne 0 ];then
echo "[ERROR] asan/$case failed." | tee -a REPORT-SANITIZE
sanitize/asan/$case >> REPORT-SANITIZE
let num_f=$num_f+1
else
echo "$case succeeded."
let num_s=$num_s+1
fi
done
for case in `ls sanitize/scudo`
do
cat /dev/null > tmp
echo [Runing test] : sanitize/scudo/$case
if [ "$case" = "aligned-new" ];then
sanitize/scudo/$case valid 2>tmp
r1=$?
SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case invalid 2>tmp
r2=$?
SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case invalid 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r3=$?
let res=$r1+$r2+$r3
res2=$r1+$r2+$r3
elif [ "$case" = "alignment" ];then
sanitize/scudo/$case pointers 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
res=$?
elif [ "$case" = "dealloc-race" ];then
SCUDO_OPTIONS="QuarantineChunksUpToSize=0" sanitize/scudo/$case 2>tmp
res=$?
elif [ "$case" = "double-free" ];then
sanitize/scudo/$case malloc 2>tmp
grep -nr "ERROR: invalid chunk state" tmp >/dev/null
r1=$?
sanitize/scudo/$case new 2>tmp
grep -nr "ERROR: invalid chunk state" tmp >/dev/null
r2=$?
sanitize/scudo/$case newarray 2>tmp
grep -nr "ERROR: invalid chunk state" tmp >/dev/null
r3=$?
let res=$r1+$r2+$r3
res2=$r1+$r2+$r3
elif [ "$case" = "fsanitize" ];then
skip #build error
continue
elif [ "$case" = "interface" ];then
sanitize/scudo/$case ownership 2>tmp
r1=$?
sanitize/scudo/$case ownership-and-size 2>tmp
r2=$?
sanitize/scudo/$case heap-size 2>tmp
r3=$?
SCUDO_OPTIONS="allocator_may_return_null=1" sanitize/scudo/$case soft-limit 2>tmp
r4=$?
SCUDO_OPTIONS="allocator_may_return_null=1" sanitize/scudo/$case hard-limit 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r5=$?
let res=$r1+$r2+$r3+$r4+$r5
res2=$r1+$r2+$r3+$r4+$r5
elif [ "$case" = "memalign" ];then
skip
continue
# sanitize/scudo/$case valid 2>tmp
# sanitize/scudo/$case invalid 2>tmp
# scudo_opts=allocator_may_return_null=1 sanitize/scudo/$case invalid 2>tmp
# sanitize/scudo/$case double-free 2>tmp
# scudo_opts=DeallocationTypeMismatch=1 sanitize/scudo/$case realloc 2>tmp
# scudo_opts=DeallocationTypeMismatch=0 sanitize/scudo/$case realloc 2>tmp
elif [ "$case" = "mismatch" ];then
SCUDO_OPTIONS=DeallocationTypeMismatch=1 sanitize/scudo/$case mallocdel 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r1=$?
SCUDO_OPTIONS=DeallocationTypeMismatch=0 sanitize/scudo/$case mallocdel 2>tmp
r2=$?
SCUDO_OPTIONS=DeallocationTypeMismatch=1 sanitize/scudo/$case newfree 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r3=$?
SCUDO_OPTIONS=DeallocationTypeMismatch=0 sanitize/scudo/$case newfree 2>tmp
r4=$?
let res=$r1+$r2+$r3+$r4
res2=$r1+$r2+$r3+$r4
elif [ "$case" = "preinit" ];then
skip # UNSUPPORTED
continue
elif [ "$case" = "options" ];then
sanitize/scudo/$case 2>tmp
r1=$?
SCUDO_OPTIONS=DeallocationTypeMismatch=0 sanitize/scudo/$case 2>tmp
r2=$?
SCUDO_OPTIONS=DeallocationTypeMismatch=1 sanitize/scudo/$case 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r3=$?
let res=$r1+$r2+$r3
res2=$r1+$r2+$r3
elif [ "$case" = "preload" ];then
skip
continue
# env LD_PRELOAD=%shared_libscudo not %run %t 2>tmp | FileCheck %s
# env LD_PRELOAD=%shared_minlibscudo not %run %t 2>tmp | FileCheck %s
elif [ "$case" = "realloc" ];then
skip
continue
# sanitize/scudo/$case pointers 2>tmp
# sanitize/scudo/$case contents 2>tmp
# sanitize/scudo/$case usablesize 2>tmp
elif [ "$case" = "rss" ];then
sanitize/scudo/$case 2>tmp
r1=$?
SCUDO_OPTIONS="soft_rss_limit_mb=128" sanitize/scudo/$case 2>tmp
r2=$?
SCUDO_OPTIONS="hard_rss_limit_mb=128" sanitize/scudo/$case 2>tmp
r3=$?
SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=0" sanitize/scudo/$case 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r4=$? #not
SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=1" sanitize/scudo/$case 2>tmp
r5=$?
SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r6=$? #not
SCUDO_OPTIONS="soft_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
r7=$?
SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=0" sanitize/scudo/$case 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r8=$? #not
SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=1" sanitize/scudo/$case 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r9=$? #not
SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=0:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r10=$? #not
SCUDO_OPTIONS="hard_rss_limit_mb=32:allocator_may_return_null=1:can_use_proc_maps_statm=0" sanitize/scudo/$case 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r11=$? #not
let res=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9+$r10+$r11
res2=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9+$r10+$r11
elif [ "$case" = "sized-delete" ];then
SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case gooddel 2>tmp
r1=$?
SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case baddel 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r2=$?
SCUDO_OPTIONS=DeleteSizeMismatch=0 sanitize/scudo/$case baddel 2>tmp
r3=$?
SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case gooddelarr 2>tmp
r4=$?
SCUDO_OPTIONS=DeleteSizeMismatch=1 sanitize/scudo/$case baddelarr 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r5=$?
SCUDO_OPTIONS=DeleteSizeMismatch=0 sanitize/scudo/$case baddelarr 2>tmp
r6=$?
let res=$r1+$r2+$r3+$r4+$r5+$r6
res2=$r1+$r2+$r3+$r4+$r5+$r6
elif [ "$case" = "sizes" ];then
SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case malloc 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r1=$?
SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case malloc 2>tmp
r2=$?
SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case calloc 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r3=$?
SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case calloc 2>tmp
r4=$?
SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case new 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r5=$?
SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case new 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r6=$?
SCUDO_OPTIONS=allocator_may_return_null=0 sanitize/scudo/$case new-nothrow 2>tmp #not
grep -nr 'Scudo ERROR: ' tmp >/dev/null
r7=$?
SCUDO_OPTIONS=allocator_may_return_null=1 sanitize/scudo/$case new-nothrow 2>tmp
r8=$?
sanitize/scudo/$case usable 2>tmp
r9=$?
let res=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9
res2=$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9
else
sanitize/scudo/$case 2>tmp
grep -nr 'Scudo ERROR: ' tmp >/dev/null
res=$?
fi
if [ res -ne 0 ];then
# echo res
echo "[ERROR] scudo/$case failed." | tee -a REPORT-SANITIZE
let num_f=$num_f+1
continue
else
echo "scudo/$case succeeded."
let num_s=$num_s+1
continue
fi
echo
done
for case in `ls sanitize/ubsan`
do
echo [Runing test] : sanitize/ubsan/$case
sanitize/ubsan/$case 2>tmp
# check result
grep -nr 'SUMMARY: UndefinedBehaviorSanitizer' tmp
res=$?
if [ res -ne 0 ];then
echo "[ERROR] ubsan/$case failed." | tee -a REPORT-SANITIZE
sanitize/ubsan/$case >> REPORT-SANITIZE
let num_f=$num_f+1
else
echo "ubsan/$case succeeded."
let num_s=$num_s+1
fi
done
let sum_case=$num_s+$num_f+$num_skip
echo "All:$sum_case Succeeded:$num_s Failed:$num_f Skiped:$num_skip"
if [ $num_f -eq 0 ];then
echo "No test failed, REPORT-SANITIZE not create."
fi
rm tmp
#! /bin/bash
cd /data/ndk-test
rm REPORT
touch REPORT
:<<LIC-TEST
for file in ./*
do
if [ "$file" = "runtest" ] \
|| [ "$file" = "REPORT" ] \
|| [ "$file" = "libdlopen_dso.so" ] \
|| [ "$file" = "libtls_init_dso.so" ] \
|| [ "$file" = "libtls_align_dso.so" ] \
|| [ "$file" = "libtls_get_new-dtv_dso.so" ]
then
continue
else
/data/ndk-test/libc-test/common/runtest -w '' /data/ndk-test/libc-test/$file >> REPORT
fi
done
LIC-TEST
ndk_test_path="./ndk-test"
function get_result(){
dirlist=$(ls ${ndk_test_path})
for dirname in ${dirlist[*]}
do
if [ -d "${ndk_test_path}/${dirname}" ];
then
for filename in $(ls ${ndk_test_path}/${dirname})
do
# echo $filename
cd ${ndk_test_path}/${dirname}
var=${filename#*.}
#echo $var
if test $var = "so"
then
:
elif test $var = "a"
then
:
else
FILE="../../REPORT"
datetime=$(date '+%Y-%m-%d %H:%M:%S')
echo $datetime >> $FILE
RETURN=`./$var >> ../../REPORT 2>&1`
fi
cd ../..
done
fi
done
}
get_result
# call script
# ./runtest-sanitize.sh
@echo off
REM 本地路径和远程路径
@REM 本地OpenHarmony源码目录,请根据实际环境修改!!,脚本参数获取
set LOCAL=Z:\home\oumeng\third\third_party_musl\ndk-test\target
@REM 远程传输目标目录
set REMOTE=/data/ndk-test
@REM runtest脚本所在目录
set SHDIR=%LOCAL%\..\script
@REM 非必要情况下不要修改以下代码
@REM 开始时间
set /a startS=%time:~6,2%
set /a startM=%time:~3,2%
@REM 检查设备是否连接
echo HDC device checking...
for /F "usebackq delims==" %%c in (`hdc list targets`) DO (
echo Device list:
echo %%c | findstr "[Empty]" && goto noDevice || echo %%c && goto hdcStart
)
@REM 在单板创建目录,原先并不存在相应目录,也无法在传输时创建,因此需要预先创建好才能传输到相应位置。
:hdcStart
echo.
echo now mkdir...
hdc shell mkdir %REMOTE%
@REM 修改文件夹权限
@REM hdc shell mount -o rw,remount /
@REM 创建临时文件夹,用于存放用例生成的临时文件
hdc shell mkdir /tmp
hdc shell mkdir /dev/shm
echo Mkdir done.
goto hdcSend
@REM 传输文件,单板上执行runtest.sh,将结果REPORT返回到.bat所在目录 动态库传输
:hdcSend
for /d %%i in (%LOCAL%\*) do (
@REM echo %%i
@REM echo %%~ni
hdc shell mkdir %REMOTE%/%%~ni
for /d %%s in (%%i\*) do (
@REM echo %%~ns
hdc shell mkdir %REMOTE%/%%~ni/%%~ns
for %%f in (%%s\*) do (
hdc file send %%f %REMOTE%/%%~ni/%%~ns
)
hdc shell chmod +x %REMOTE%/%%~ni/%%~ns/*
)
)
echo Test cases sending finished.
echo.
goto sendSH
@REM 传输文件,单板上执行runtest.sh,将结果REPORT返回到.bat所在目录 动态库传输
:hdcSend
@REM 发送脚本并执行用例
:sendSH
echo Sending runtest.sh
hdc file send %SHDIR%\runtest.sh %REMOTE%/runtest.sh
@REM hdc file send %SHDIR%\runtest-sanitize.sh %REMOTE%/runtest-sanitize.sh
hdc shell chmod u+x %REMOTE%/runtest.sh
@REM hdc shell chmod u+x %REMOTE%/runtest-sanitize.sh
echo runtest.sh has been transported.
echo runtest-sanitize.sh has been transported.
echo.
echo hdc shell .%REMOTE%/runtest.sh
hdc shell sh %REMOTE%/runtest.sh
echo.
echo ================================
echo The test cases have been executed.
@REM 删除临时文件夹
hdc shell rm /tmp -rf
hdc shell rm /dev/shm -rf
echo.
echo hdc file recv %REMOTE%/REPORT %~dp0REPORT
hdc file recv %REMOTE%/REPORT %~dp0REPORT
@REM echo hdc file recv %REMOTE%/REPORT-SANITIZE %~dp0REPORT-SANITIZE
@REM hdc file recv %REMOTE%/REPORT-SANITIZE %~dp0REPORT-SANITIZE
goto end
@REM 提示检查设备连接。
:noDevice
echo Device not found,please check your device.
goto end
@REM 完成所用时间
:end
echo.
set /a endS=%time:~6,2%
set /a endM=%time:~3,2%
set /a diffS_=%endS%-%startS%
set /a diffM_=%endM%-%startM%
@REM REPORT文件比较
@REM start python %LOCAL%\third_party\musl\scripts\compare.py
@REM if exist "%LOCAL%\third_party\musl\scripts\\result.html" (
@REM echo Test failed,please checking result.html!
@REM ) else (
@REM echo Test successful!
@REM )
@REM echo file compareing finished
@REM echo All items finished.
@REM echo Time cost:%diffM_%m%diffS_%s .
@REM echo.
pause
exit
- Place the compilation to generate the object file
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册