未验证 提交 fb27e84a 编写于 作者: O openharmony_ci 提交者: Gitee

!6505 增加libuv测试套件

Merge pull request !6505 from 胡瑞涛/monthly_20221018
......@@ -33,5 +33,7 @@ group("arkui") {
"ace_napi_test:ActsAceNapiEtsTest",
"ace_standard:ActsAceStandardTest",
"ace_standard_video:ActsAceStandardVideoTest",
"libuv:ActsLibuvTestSuite",
"libuv:libuvTest",
]
}
# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
import("//test/xts/acts/arkui/libuv/comm.gni")
ohos_static_library("libuvTestStatic") {
include_dirs = [
"//third_party/libuv/include",
"//third_party/libuv/src",
"//third_party/libuv/src/unix",
]
sources = [
"//third_party/libuv/test/blackhole-server.c",
"//third_party/libuv/test/echo-server.c",
"//third_party/libuv/test/runner-unix.c",
"//third_party/libuv/test/runner.c",
"//third_party/libuv/test/test-active.c",
"//third_party/libuv/test/test-async-null-cb.c",
"//third_party/libuv/test/test-async.c",
"//third_party/libuv/test/test-barrier.c",
"//third_party/libuv/test/test-callback-order.c",
"//third_party/libuv/test/test-callback-stack.c",
"//third_party/libuv/test/test-close-fd.c",
"//third_party/libuv/test/test-close-order.c",
"//third_party/libuv/test/test-condvar.c",
"//third_party/libuv/test/test-connect-unspecified.c",
"//third_party/libuv/test/test-connection-fail.c",
"//third_party/libuv/test/test-cwd-and-chdir.c",
"//third_party/libuv/test/test-default-loop-close.c",
"//third_party/libuv/test/test-delayed-accept.c",
"//third_party/libuv/test/test-dlerror.c",
"//third_party/libuv/test/test-eintr-handling.c",
"//third_party/libuv/test/test-embed.c",
"//third_party/libuv/test/test-emfile.c",
"//third_party/libuv/test/test-env-vars.c",
"//third_party/libuv/test/test-error.c",
"//third_party/libuv/test/test-fail-always.c",
"//third_party/libuv/test/test-fork.c",
"//third_party/libuv/test/test-fs-copyfile.c",
"//third_party/libuv/test/test-fs-event.c",
"//third_party/libuv/test/test-fs-fd-hash.c",
"//third_party/libuv/test/test-fs-open-flags.c",
"//third_party/libuv/test/test-fs-poll.c",
"//third_party/libuv/test/test-fs-readdir.c",
"//third_party/libuv/test/test-fs.c",
"//third_party/libuv/test/test-get-currentexe.c",
"//third_party/libuv/test/test-get-loadavg.c",
"//third_party/libuv/test/test-get-memory.c",
"//third_party/libuv/test/test-get-passwd.c",
"//third_party/libuv/test/test-getaddrinfo.c",
"//third_party/libuv/test/test-gethostname.c",
"//third_party/libuv/test/test-getnameinfo.c",
"//third_party/libuv/test/test-getsockname.c",
"//third_party/libuv/test/test-getters-setters.c",
"//third_party/libuv/test/test-gettimeofday.c",
"//third_party/libuv/test/test-handle-fileno.c",
"//third_party/libuv/test/test-homedir.c",
"//third_party/libuv/test/test-hrtime.c",
"//third_party/libuv/test/test-idle.c",
"//third_party/libuv/test/test-idna.c",
"//third_party/libuv/test/test-ip-name.c",
"//third_party/libuv/test/test-ip4-addr.c",
"//third_party/libuv/test/test-ip6-addr.c",
"//third_party/libuv/test/test-ipc-heavy-traffic-deadlock-bug.c",
"//third_party/libuv/test/test-ipc-send-recv.c",
"//third_party/libuv/test/test-ipc.c",
"//third_party/libuv/test/test-loop-alive.c",
"//third_party/libuv/test/test-loop-close.c",
"//third_party/libuv/test/test-loop-configure.c",
"//third_party/libuv/test/test-loop-handles.c",
"//third_party/libuv/test/test-loop-stop.c",
"//third_party/libuv/test/test-loop-time.c",
"//third_party/libuv/test/test-metrics.c",
"//third_party/libuv/test/test-multiple-listen.c",
"//third_party/libuv/test/test-mutexes.c",
"//third_party/libuv/test/test-not-readable-nor-writable-on-read-error.c",
"//third_party/libuv/test/test-not-writable-after-shutdown.c",
"//third_party/libuv/test/test-osx-select.c",
"//third_party/libuv/test/test-pass-always.c",
"//third_party/libuv/test/test-ping-pong.c",
"//third_party/libuv/test/test-pipe-bind-error.c",
"//third_party/libuv/test/test-pipe-close-stdout-read-stdin.c",
"//third_party/libuv/test/test-pipe-connect-error.c",
"//third_party/libuv/test/test-pipe-connect-multiple.c",
"//third_party/libuv/test/test-pipe-connect-prepare.c",
"//third_party/libuv/test/test-pipe-getsockname.c",
"//third_party/libuv/test/test-pipe-pending-instances.c",
"//third_party/libuv/test/test-pipe-sendmsg.c",
"//third_party/libuv/test/test-pipe-server-close.c",
"//third_party/libuv/test/test-pipe-set-fchmod.c",
"//third_party/libuv/test/test-pipe-set-non-blocking.c",
"//third_party/libuv/test/test-platform-output.c",
"//third_party/libuv/test/test-poll-close-doesnt-corrupt-stack.c",
"//third_party/libuv/test/test-poll-close.c",
"//third_party/libuv/test/test-poll-closesocket.c",
"//third_party/libuv/test/test-poll-multiple-handles.c",
"//third_party/libuv/test/test-poll-oob.c",
"//third_party/libuv/test/test-poll.c",
"//third_party/libuv/test/test-process-priority.c",
"//third_party/libuv/test/test-process-title-threadsafe.c",
"//third_party/libuv/test/test-process-title.c",
"//third_party/libuv/test/test-queue-foreach-delete.c",
"//third_party/libuv/test/test-random.c",
"//third_party/libuv/test/test-readable-on-eof.c",
"//third_party/libuv/test/test-ref.c",
"//third_party/libuv/test/test-run-nowait.c",
"//third_party/libuv/test/test-run-once.c",
"//third_party/libuv/test/test-semaphore.c",
"//third_party/libuv/test/test-shutdown-close.c",
"//third_party/libuv/test/test-shutdown-eof.c",
"//third_party/libuv/test/test-shutdown-simultaneous.c",
"//third_party/libuv/test/test-shutdown-twice.c",
"//third_party/libuv/test/test-signal-multiple-loops.c",
"//third_party/libuv/test/test-signal-pending-on-close.c",
"//third_party/libuv/test/test-signal.c",
"//third_party/libuv/test/test-socket-buffer-size.c",
"//third_party/libuv/test/test-spawn.c",
"//third_party/libuv/test/test-stdio-over-pipes.c",
"//third_party/libuv/test/test-strscpy.c",
"//third_party/libuv/test/test-tcp-alloc-cb-fail.c",
"//third_party/libuv/test/test-tcp-bind-error.c",
"//third_party/libuv/test/test-tcp-bind6-error.c",
"//third_party/libuv/test/test-tcp-close-accept.c",
"//third_party/libuv/test/test-tcp-close-reset.c",
"//third_party/libuv/test/test-tcp-close-while-connecting.c",
"//third_party/libuv/test/test-tcp-close.c",
"//third_party/libuv/test/test-tcp-connect-error-after-write.c",
"//third_party/libuv/test/test-tcp-connect-error.c",
"//third_party/libuv/test/test-tcp-connect-timeout.c",
"//third_party/libuv/test/test-tcp-connect6-error.c",
"//third_party/libuv/test/test-tcp-create-socket-early.c",
"//third_party/libuv/test/test-tcp-flags.c",
"//third_party/libuv/test/test-tcp-oob.c",
"//third_party/libuv/test/test-tcp-open.c",
# "//third_party/libuv/test/test-metrics-idle-time.c",
# "//third_party/libuv/test/test-metrics-idle-time-thread.c",
# "//third_party/libuv/test/test-metrics-idle-time-zero.c",
"//third_party/libuv/test/test-tcp-read-stop-start.c",
"//third_party/libuv/test/test-tcp-read-stop.c",
"//third_party/libuv/test/test-tcp-shutdown-after-write.c",
"//third_party/libuv/test/test-tcp-try-write-error.c",
"//third_party/libuv/test/test-tcp-try-write.c",
"//third_party/libuv/test/test-tcp-unexpected-read.c",
"//third_party/libuv/test/test-tcp-write-after-connect.c",
"//third_party/libuv/test/test-tcp-write-fail.c",
"//third_party/libuv/test/test-tcp-write-queue-order.c",
"//third_party/libuv/test/test-tcp-write-to-half-open-connection.c",
"//third_party/libuv/test/test-tcp-writealot.c",
"//third_party/libuv/test/test-test-macros.c",
"//third_party/libuv/test/test-thread-equal.c",
"//third_party/libuv/test/test-thread.c",
"//third_party/libuv/test/test-threadpool-cancel.c",
"//third_party/libuv/test/test-threadpool.c",
"//third_party/libuv/test/test-timer-again.c",
"//third_party/libuv/test/test-timer-from-check.c",
"//third_party/libuv/test/test-timer.c",
"//third_party/libuv/test/test-tmpdir.c",
"//third_party/libuv/test/test-tty-duplicate-key.c",
"//third_party/libuv/test/test-tty-escape-sequence-processing.c",
"//third_party/libuv/test/test-tty.c",
"//third_party/libuv/test/test-udp-alloc-cb-fail.c",
"//third_party/libuv/test/test-udp-bind.c",
"//third_party/libuv/test/test-udp-connect.c",
"//third_party/libuv/test/test-udp-connect6.c",
"//third_party/libuv/test/test-udp-create-socket-early.c",
"//third_party/libuv/test/test-udp-dgram-too-big.c",
"//third_party/libuv/test/test-udp-ipv6.c",
"//third_party/libuv/test/test-udp-mmsg.c",
"//third_party/libuv/test/test-udp-multicast-interface.c",
"//third_party/libuv/test/test-udp-multicast-interface6.c",
"//third_party/libuv/test/test-udp-multicast-join.c",
"//third_party/libuv/test/test-udp-multicast-join6.c",
"//third_party/libuv/test/test-udp-multicast-ttl.c",
"//third_party/libuv/test/test-udp-open.c",
"//third_party/libuv/test/test-udp-options.c",
"//third_party/libuv/test/test-udp-send-and-recv.c",
"//third_party/libuv/test/test-udp-send-hang-loop.c",
"//third_party/libuv/test/test-udp-send-immediate.c",
"//third_party/libuv/test/test-udp-send-unreachable.c",
"//third_party/libuv/test/test-udp-sendmmsg-error.c",
"//third_party/libuv/test/test-udp-try-send.c",
"//third_party/libuv/test/test-uname.c",
"//third_party/libuv/test/test-walk-handles.c",
"//third_party/libuv/test/test-watcher-cross-stop.c",
]
deps = [ "//third_party/libuv:uv_static" ]
}
ohos_executable("libuvruntest") {
include_dirs = [
"//third_party/libuv/include",
"//third_party/libuv/src",
"//third_party/libuv/src/unix",
]
sources = [ "//third_party/libuv/test/run-tests.c" ]
deps = [ ":libuvTestStatic" ]
}
ohos_moduletest_suite("ActsLibuvTestSuite") {
sources = [ "src/ActsLibuvTestSuite.cpp" ]
include_dirs = [
"//test/xts/acts/arkui/libuv/src",
"//third_party/libuv/test",
"//third_party/libuv/include",
"//third_party/libuv/src",
"//third_party/libuv/src/unix",
]
deps = [ ":libuvTestStatic" ]
cflags = [ "-Wno-error" ]
}
action("cpLibuv") {
testonly = true
script = "cplibuv.sh"
outputs = [ "${target_out_dir}/cplibuv.log" ]
deps = [
":ActsLibuvTestSuite",
":libuvruntest",
]
}
group("libuvTest") {
testonly = true
if (is_standard_system) {
deps = [
":ActsLibuvTestSuite",
":cpLibuv",
":libuvruntest",
]
}
}
# Libuv测试套件说明
- [介绍](#section_Libuv_001)
- [使用说明](#section_Libuv_002)
## 介绍<a name="section_Libuv_001"></a>
Libuv测试套件使用Libuv三方库内原有的unittest,通过acts测试套件框架在运行时调用运行,具体目录结构如下:
```bash
.
├── BUILD.gn
├── comm.gni
├── cplibuv.sh
├── genlocal.py
├── src
│ ├── ActsLibuvTestSuite.cpp
│ └── ActsLibuvTestSuite.h
└── Test.json
```
* BUILD.gn:编译脚本,编译acts测试套件,编译Libuv三方库测试代码,执行actions事件在acts测试套件对应的testcases目录下建立libuvdata目录,然后将运行测试需要的Libuv测试进程,解析运行日志所需的Python脚本拷贝到libuvdata目录。
* comm.gni:通用编译配置。
* cplibuv.sh:编译后actions事件执行的脚本。
* genlocal.py:libuv的test程序运行后结果会保存在task_log.log文件内,分析运行日志后会存储结果在summary_report.xml文件内,然后根据xdevice流程生成summary_report。
* src:测试套件的实现,内部直接调用libuv的unittest进程。
* Test.json:运行测试需要json脚本,包括拷贝内容到开发板。
## 使用说明<a name="section_Libuv_002"></a>
* 编译运行
```bash
./build.sh --product-name rk3568 --gn-args build_xts=true --build-target "acts" --gn-args is_standard_system=true
```
* 测试运行:进入suites/acts目录,执行python -m xdevice,然后在命令框里输入一下命令
```bash
run -l ActsLibuvTestSuite
```
\ No newline at end of file
{
"description": "Config for ActsLibuvTestSuite test cases",
"driver": {
"module-name": "ActsLibuvTestSuite",
"native-test-timeout": "120000",
"native-test-device-path": "/data/local/tmp",
"runtime-hint": "100s",
"type": "CppTest"
},
"kits": [
{
"pre-push" : [
],
"post-push" : [
"chmod -R 777 /data/local/tmp/*"
],
"push": [
"ActsLibuvTestSuite->/data/local/tmp/ActsLibuvTestSuite",
"libuvdata/libuvruntest->/data/local/tmp/libuvruntest "
],
"type": "PushKit"
},
{
"type": "ShellKit",
"run-command": [
"remount",
"mkdir /data/test",
"cd /data/local/tmp"
],
"teardown-localcommand": [
"python testcases/libuvdata/genlocal.py"
]
}
]
}
\ No newline at end of file
# Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
common_include = [ "//test/xts/acts/graphic/libuv/src" ]
common_depends = [ "//third_party/libuv:uv_static" ]
#!/bin/bash
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
mkdir -p "suites/acts/testcases/libuvdata"
cp -rf "../../test/xts/acts/arkui/libuv/genlocal.py" "suites/acts/testcases/libuvdata"
cp -rf "common/common/libuvruntest" "suites/acts/testcases/libuvdata"
from ast import Return
import os
import sys
from unittest import suite
G_SUITE = ""
G_MAXCASECNT = 5
G_MUSTPASSPATH = "mustpass/"
G_MUSTPASSFILE = ".txt"
G_TMPPATH = "template/"
G_TMPDIRPATH = G_TMPPATH + "ace_ets_template"
G_HAPDIRPATH = "../act_etc_component_"
G_IMPORTTEST = "import {}Jsunit from \'./{}.test.ets\';"
G_IMPORTTESTCASE = "{}Jsunit()"
G_PATHDIRPATH = "/entry/src/main/ets/MainAbility/pages/"
G_PAGETEMPPATH = "/pagetemplate.ets"
G_PAGEATTRTEMPPATH = "/pageattrtemplate.ets"
G_TESTDIRPATH = "/entry/src/main/ets/test/"
G_TESTCASETEMPPATH = "/testcasetemplate.ets"
G_TESTTEMPPATH = "/List.test.ets"
G_LISTTESTETSPATH = "/entry/src/main/ets/test/List.test.ets"
G_PAGENAMEPATTERN = "##PAGENAME"
G_ATTRNAMEPATTERN = "##ATTRNAME"
G_LOWATTRNAMEPATTERN = "##LOWATTRNAME"
G_PAGENAMETESETPATTERN = "##PAGENAMETEST"
G_PAGEFILENAMEPATTERN = "##PAGEFILENAME"
G_SUITENAMEPATTERN = "##SUITENAME"
G_PAGENAMETESTPATTERN = "##PAGENAMETEXT"
G_CONFIGJSONPATH = "/entry/src/main/config.json"
G_BUILDGNPATH = "/BUILD.gn"
G_TESTJSONPATH = "/Test.json"
G_INDEXETSPATH = "/entry/src/main/ets/MainAbility/pages/index.ets"
def writemultestcase():
print("writemultestcase")
writemultestcasecpp()
print("writemulbuildgn")
writemulbuildgn()
def writemulbuildgn():
#生成buildgn
for suiteitem in G_SUITE:
subcasecnt = 0
subattcnt = 0
subgncnt = 0
suiteitemcap = "".join(suiteitem[:1].upper() + suiteitem[1:])
print("suite:", suiteitem, "----------------------")
#创建一个hap目录
hapdirpath = G_HAPDIRPATH + suiteitem.lower()
if os.path.exists(hapdirpath):
os.system(r"rm -rf {}".format(hapdirpath))
os.system(r"cp {} {} -r".format(G_TMPDIRPATH, hapdirpath))
else:
os.system(r"cp {} {} -r".format(G_TMPDIRPATH, hapdirpath))
mustpass = G_MUSTPASSPATH + suiteitem + G_MUSTPASSFILE
with open(mustpass) as mastpassfile:
compdict = {"":1}
importtestheads = []
importtests = []
for line in mastpassfile:
if line[0] == "#":
continue
line = line.replace("\n", "")
linelist = line.split(",")
suitename = linelist[0]
casename = linelist[1]
if suitename in compdict:
#同文件里加属性
ind = compdict[suitename]
subattcnt += 1
#在page文件里追加attr内容
suitenamecap = "".join(suitename[:1].upper() + suitename[1:])
casenamecap = "".join(casename[:1].upper() + casename[1:])
pagename = suitenamecap + casenamecap
pagenametext = suitename + "-" + casenamecap
pagefilename = hapdirpath + G_PATHDIRPATH + suitename + ".ets"
attrtmp = G_TMPPATH + G_PAGEATTRTEMPPATH
#print("addattr:", subattcnt, pagename, attrtmp)
with open(attrtmp, encoding="utf-8", mode="r") as attrtmpfile:
for attrtempline in attrtmpfile:
attrtempline = attrtempline.replace(" ", "\ ")
attrtempline = attrtempline.replace(G_PAGENAMETESTPATTERN, pagenametext)
attrtempline = attrtempline.replace(G_ATTRNAMEPATTERN, casename)
os.system(r"sed -i '{}a {}' {}".format(ind, attrtempline, pagefilename))
ind += 1
compdict[suitename] = ind
else:
#创建不同页面
subgncnt += 1
subattcnt = 1
ind = 29
compdict[suitename] = ind
postfix = '%04d' % subgncnt
dirpath = suitename + postfix
temppagefilename = G_TMPPATH + G_PAGETEMPPATH
suitenamecap = "".join(suitename[:1].upper() + suitename[1:])
casenamecap = "".join(casename[:1].upper() + casename[1:])
pagename = suitename + casenamecap
capagename = suitenamecap + casenamecap
testname = pagename
pagefilename = hapdirpath + G_PATHDIRPATH + suitename + ".ets"
os.system(r"cp {} {}".format(temppagefilename, pagefilename))
#替换page里的名称
os.system(r"sed -i 's/{}/{}/g' {}".format(G_PAGENAMEPATTERN, capagename, pagefilename))
#追加page里的attr
pagenametext = suitename + "-" + casenamecap
attrtmp = G_TMPPATH + G_PAGEATTRTEMPPATH
#print("addattr:", subattcnt, pagename, attrtmp)
with open(attrtmp, encoding="utf-8", mode="r") as attrtmpfile:
for attrtempline in attrtmpfile:
attrtempline = attrtempline.replace(" ", "\ ")
attrtempline = attrtempline.replace(G_PAGENAMETESTPATTERN, pagenametext)
attrtempline = attrtempline.replace(G_ATTRNAMEPATTERN, casename)
os.system(r"sed -i '{}a {}' {}".format(ind, attrtempline, pagefilename))
ind += 1
compdict[suitename] = ind
temptestfilename = G_TMPPATH + G_TESTCASETEMPPATH
testfilename = hapdirpath + G_TESTDIRPATH + suitename + ".test.ets"
#print("createpage:", subgncnt, dirpath, pagefilename, testfilename)
os.system(r"cp {} {}".format(temptestfilename, testfilename))
#替换test里的名称
os.system(r"sed -i 's/{}/{}/g' {}".format(G_ATTRNAMEPATTERN, testname, testfilename))
os.system(r"sed -i 's/{}/{}/g' {}".format(G_PAGENAMETESETPATTERN, testname+"Test", testfilename))
os.system(r"sed -i 's/{}/{}/g' {}".format(G_PAGEFILENAMEPATTERN, pagename, testfilename))
os.system(r"sed -i 's/{}/{}/g' {}".format(G_LOWATTRNAMEPATTERN, casename, testfilename))
#替换config.json里的名称
configjsonname = hapdirpath + G_CONFIGJSONPATH
os.system(r"sed -i 's/{}/{}/g' {}".format(G_SUITENAMEPATTERN, suiteitemcap, configjsonname))
os.system(r"sed -i 's/{}/{}/g' {}".format(G_PAGEFILENAMEPATTERN, casenamecap, configjsonname))
#替换BUILD.gn里的名称
buildgnname = hapdirpath + G_BUILDGNPATH
os.system(r"sed -i 's/{}/{}/g' {}".format(G_SUITENAMEPATTERN, suiteitemcap, buildgnname))
# formate gn
#print("Formate: dirpath:",buildgnname)
formatcmd = "cat "+buildgnname+" | ~/workspace/oh31/prebuilts/build-tools/linux-x86/bin/gn format --stdin > FORMAT_RESULT.gn;cp -f FORMAT_RESULT.gn "+buildgnname+";rm FORMAT_RESULT.gn"
os.system(formatcmd)
#替换index.ets里的名称
indexetsname = hapdirpath + G_INDEXETSPATH
os.system(r"sed -i 's/{}/{}/g' {}".format(G_SUITENAMEPATTERN, suiteitemcap, indexetsname))
#替换Test.json里的名称
testjsonname = hapdirpath + G_TESTJSONPATH
os.system(r"sed -i 's/{}/{}/g' {}".format(G_SUITENAMEPATTERN, suiteitemcap, testjsonname))
#G_IMPORTTEST = "import {} from './{}Jsunit.test';\n"
importtestheads.append(G_IMPORTTEST.format(testname, suitename))
importtests.append(G_IMPORTTESTCASE.format(testname))
subcasecnt += 1
#print("importtestheads:", importtestheads)
#print("importtests:", importtests)
#插入List.test.ets,装载多个testcase
ind = 16
for importtestsline in importtests:
os.system(r"sed -i '{}a \ \ {}' {}".format(ind, importtestsline, hapdirpath + G_LISTTESTETSPATH))
ind += 1
ind = 14
for importtestheadsline in importtestheads:
os.system(r"sed -i '{}a {}' {}".format(ind, importtestheadsline, hapdirpath + G_LISTTESTETSPATH))
ind += 1
def writemultestcasecpp():
#生成testcase
for suiteitem in G_SUITE:
print("suite:", suiteitem)
def removedir(rootdir):
for root,dirs,files in os.walk(rootdir, topdown=False):
for name in files:
os.remove(os.path.join(rootdir,name))
for name in dirs:
os.rmdir(os.path.join(rootdir,name))
os.rmdir(rootdir)
def printhelp():
print("Need testsuite and codepattern:\n")
print("For example\n")
print("python3 .\GenerateTestCase.py apilack\n")
print("codepattern contains: apilack, attrlack\n")
def new_report(bakdir, str):
files = os.listdir(bakdir)
lists = [] #列出目录的下所有文件和文件夹保存到lists
for f in files:
# if f.startswith(str):
if "latest" in f:
continue
lists.append(f)
lists.sort(key=lambda fn:os.path.getmtime(bakdir + "/" + fn)) # 按时间排序
file_new = os.path.join(bakdir,lists[-1]) # 获取最新的文件保存到file_new
print("latest file:", file_new)
return file_new
if __name__ == '__main__':
latestpath = new_report("reports", "")
tmpfile = "tmptestsuite.xml"
putfile = "/result/ActsLibuvTestSuite.xml"
tasklogfile = "/log/task_log.log"
putdir = latestpath+putfile
tasklogpath = latestpath+tasklogfile
timelist = latestpath.split("/")
curtime = timelist[1].replace("\n", "")
testcaselist = []
total = 0
passcnt = 0
failcnt = 0
suitename = ""
#读取最近的tasklog文件
with open(tasklogpath) as tasklogbuf:
#从tasklog文件中获取运行的testcase的信息
for tasklogline in tasklogbuf:
if "[Start test suite [" in tasklogline:
suitelist = tasklogline.split("[Start test suite [")
suiteitem = suitelist[1].split("]")
suitename = suiteitem[0]
if "[ok " in tasklogline:
freslist = tasklogline.split("ok")
numcase = freslist[1]
numcase = numcase.replace(" ","")
numcase = numcase.replace("]","")
caseline = numcase.split("-")
total +=1
passcnt += 1
testcaselist.append(caseline[1]+"-true")
if "[not ok " in tasklogline:
freslist = tasklogline.split("not ok")
numcase = freslist[1]
numcase = numcase.replace(" ","")
numcase = numcase.replace("]","")
caseline = numcase.split("-")
total +=1
failcnt += 1
testcaselist.append(caseline[1]+"-false")
#print("tasklogfile line:", caseline[0], caseline[1])
#将testcase信息生成文件
xmlfile = open(tmpfile, mode='w+')
xmlfile.write("<?xml version='1.0' encoding='UTF-8'?>\n")
xmlfile.write("<testsuites name=\"{}\" timestamp=\"{}\" time=\"0.0\" errors=\"0\" disabled=\"0\" failures=\"{}\" tests=\"{}\" ignored=\"0\" unavailable=\"0\" productinfo=\"{}\">\n".format(suitename, curtime, failcnt, total, "{}"))
xmlfile.write(" <testsuite name=\"{}\" time=\"0.0\" errors=\"0\" disabled=\"0\" failures=\"{}\" ignored=\"0\" tests=\"{}\" message=\"\">\n".format(suitename, failcnt, total))
for casename in testcaselist:
casename = casename.replace("\n","")
loccasename = casename.split("-")
recasename = loccasename[0]
casestate = loccasename[1]
xmlfile.write(" <testcase name=\"{}\" status=\"run\" time=\"0.0\" classname=\"{}\" result=\"{}\" level=\"1\" message=\"\" />\n".format(recasename, suitename, casestate))
xmlfile.write(" </testsuite>\n")
xmlfile.write("</testsuites>\n")
xmlfile.close()
#将tmp文件替换xts框架的result
os.system(r"cp {} {}".format(tmpfile, putdir))
\ No newline at end of file
/*
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <stdlib.h>
#include "ActsLibuvTestSuite.h"
extern "C"{
#include "runner.h"
}
namespace OHOS {
using namespace std;
using namespace testing::ext;
// Preset action of the test suite, which is executed before the first test case
void ActsLibuvTestSuite::SetUpTestCase(void)
{
}
// Test suite cleanup action, which is executed after the last test case
void ActsLibuvTestSuite::TearDownTestCase(void)
{
}
// Preset action of the test case
void ActsLibuvTestSuite::SetUp()
{
}
// Cleanup action of the test case
void ActsLibuvTestSuite::TearDown()
{
}
HWTEST_F(ActsLibuvTestSuite, TestLibuvTestCase001, Function | MediumTest | Level2)
{
printf("------start ActsLibuvTestSuite------\n");
system("/data/local/tmp/libuvruntest");
EXPECT_TRUE(true);
printf("------end ActsLibuvTestSuite------\n");
}
}
/*
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LIBUV_TESTCASE_H
#define LIBUV_TESTCASE_H
#include <gtest/gtest.h>
namespace OHOS {
class ActsLibuvTestSuite : public testing::Test {
public:
protected:
// Preset action of the test suite, which is executed before the first test case
static void SetUpTestCase(void);
// Test suite cleanup action, which is executed after the last test case
static void TearDownTestCase(void);
// Preset action of the test case
virtual void SetUp();
// Cleanup action of the test case
virtual void TearDown();
};
} // namespace OHOS
#endif // LIBUV_TESTCASE_H
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册