forked from rcore-os/zCore
Add auto-test and Change some code in zCore/rboot.conf zircon-loader/src/lib.rs zircon-syscall/src/channel.rs
This commit is contained in:
parent
cc4c928d27
commit
cf4eab5668
|
@ -0,0 +1,54 @@
|
|||
# Easy work with test
|
||||
|
||||
简单 测试
|
||||
|
||||
## Require Environment
|
||||
|
||||
- 继承zCore的运行环境
|
||||
- python3.8 [yes 3.8]
|
||||
- pip3
|
||||
|
||||
## Install Environment
|
||||
|
||||
下载 所需的pexpect
|
||||
```
|
||||
pip3 install pexpect
|
||||
```
|
||||
|
||||
## How to use
|
||||
|
||||
### Step1 开启测试所需
|
||||
|
||||
当你第一次 clone 下来 zcore后、[设:环境ok]
|
||||
|
||||
1. 配置你的core-tests在那里
|
||||
2. 修改 zCore文件目录下 rboot.conf 里 被注释的第23行、解注释、22行、注释
|
||||
3. 进入 zircon-syscall/src/channel.rs 中 修改第12行 false 改为 true 开启测试[默认关闭、因为不知道会不会与别的造成影响]
|
||||
4. 编译程序
|
||||
```
|
||||
make build zbi_file=core-tests
|
||||
```
|
||||
如果一切都 ok 进入下一步、不ok 就是上述 有条件不满足、玄学问题请致电微信群zcore
|
||||
|
||||
### Step2 开始测试
|
||||
|
||||
1. 在auto-test目录下 打开 console 输入
|
||||
|
||||
```
|
||||
sh local_start.sh
|
||||
```
|
||||
|
||||
观察 控制台 应有提示
|
||||
```
|
||||
等待执行测试....
|
||||
在 auto-test/result/result.txt 可实时查看结果
|
||||
```
|
||||
|
||||
2. 看result文件
|
||||
|
||||
### Step3 自己配置要测试的测试用例
|
||||
|
||||
在 auto-test/work/ 目录下 修改temp-test.json 里的内容、应该一看就懂
|
||||
|
||||
core-tests.json 为了写出所有测例的名字 [未完成]
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
import pexpect
|
||||
import json
|
||||
import fileinput
|
||||
|
||||
#===============Must Config========================
|
||||
|
||||
BaseFile = "../"
|
||||
|
||||
BIOS_UEFI = BaseFile + "rboot/OVMF.fd"
|
||||
|
||||
EFI_System_Partition = BaseFile + "zCore/target/x86_64/debug/esp"
|
||||
|
||||
QEMU_DISK = BaseFile + "zCore/target/x86_64/debug/disk.qcow2"
|
||||
|
||||
LogFile = BaseFile + "auto-test/result/logfile.txt"
|
||||
|
||||
Result = BaseFile + "auto-test/result/result.txt"
|
||||
|
||||
Config = BaseFile + "auto-test/work/temp-test.json"
|
||||
|
||||
rbootconf = BaseFile + "zCore/target/x86_64/debug/esp/EFI/boot/rboot.conf"
|
||||
|
||||
#==============================================
|
||||
|
||||
# qeme 的 参数
|
||||
|
||||
# args=["-smp","cores=4","-bios",BIOS_UEFI,"-enable-kvm","-drive","format=raw,file=fat:rw:"+ EFI_System_Partition,
|
||||
# "-serial","mon:stdio","-m","4G",
|
||||
# "-device","isa-debug-exit","-drive","format=qcow2,file="+FileSystem+",media=disk,cache=writeback,id=sfsimg,if=none",
|
||||
# "-device","ahci,id=ahci0","-device","ide-drive,drive=sfsimg,bus=ahci0.0","-nographic"]
|
||||
|
||||
|
||||
args=["-smp","cores=1",
|
||||
"-machine","q35",
|
||||
"-cpu","Haswell,+smap,-check,-fsgsbase",
|
||||
"-bios",BIOS_UEFI,
|
||||
"-serial","mon:stdio","-m","4G","-nic","none",
|
||||
"-drive","format=raw,file=fat:rw:"+ EFI_System_Partition,
|
||||
"-drive","format=qcow2,file="+QEMU_DISK+",id=disk,if=none",
|
||||
"-device","ich9-ahci,id=ahci",
|
||||
"-device","ide-drive,drive=disk,bus=ahci.0",
|
||||
"-device","isa-debug-exit,iobase=0xf4,iosize=0x04",
|
||||
"-accel","kvm","-cpu","host,migratable=no,+invtsc"]
|
||||
|
||||
def run():
|
||||
|
||||
return
|
||||
|
||||
def main():
|
||||
print("等待执行测试....\n在 auto-test/result/result.txt 可实时查看结果")
|
||||
|
||||
with open(Config, "r") as f:
|
||||
jsondata = f.read()
|
||||
data = json.loads(jsondata)
|
||||
|
||||
logfile = open(LogFile,"wb")
|
||||
with open(Result,"w",encoding='utf-8',errors='ignore'):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
for o in data["CoreTests"]:
|
||||
name = o["TestCaseName"]
|
||||
array = o["TestArray"]
|
||||
for i in array:
|
||||
for line in fileinput.input(rbootconf,inplace=1):
|
||||
if "#" in line:
|
||||
continue
|
||||
if " " in line:
|
||||
continue
|
||||
if line.startswith("cmdline"):
|
||||
l = line.split(":")
|
||||
index = len(l)-2
|
||||
l[index] = name+"."+i
|
||||
l.pop()
|
||||
for s in l:
|
||||
print(s,end=":")
|
||||
continue
|
||||
print(line,end="")
|
||||
fileinput.close()
|
||||
|
||||
child = pexpect.spawn("qemu-system-x86_64",args,timeout=10)
|
||||
child.logfile = logfile
|
||||
|
||||
index = child.expect(["finished!",pexpect.EOF,pexpect.TIMEOUT])
|
||||
if index == 0:
|
||||
with open(Result,"a",encoding='utf-8',errors='ignore') as f:
|
||||
f.writelines(name+"."+i+": successed\n")
|
||||
elif index == 1:
|
||||
with open(Result,"a",encoding='utf-8',errors='ignore') as f:
|
||||
f.writelines(name+"."+i+": EOF\n")
|
||||
elif index == 2:
|
||||
with open(Result,"a",encoding='utf-8',errors='ignore') as f:
|
||||
f.writelines(name+"."+i+": TIMEOUT\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
python3.8 local_core-test.py
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"CoreTests":[
|
||||
{
|
||||
"TestCaseName":"BadAccessTest",
|
||||
"TestArray": [
|
||||
"InvalidMappedAddressFails",
|
||||
"KernelMappedAddressChannelWriteFails",
|
||||
"NormalMappedAddressChannelWriteSucceeds",
|
||||
"SyscallNumTest",
|
||||
"PciCfgPioRw",
|
||||
"ChannelReadHandle"
|
||||
]
|
||||
},
|
||||
{
|
||||
"TestCaseName":"Bti",
|
||||
"TestArray": [
|
||||
"Create",
|
||||
"Pin",
|
||||
"PinContiguous",
|
||||
"PinContigFlag",
|
||||
"Resize",
|
||||
"Clone",
|
||||
"GetInfoTest",
|
||||
"NoDelayedUnpin",
|
||||
"DecommitRace"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"CoreTests":[
|
||||
{
|
||||
"TestCaseName":"BadAccessTest",
|
||||
"TestArray": [
|
||||
"InvalidMappedAddressFails",
|
||||
"KernelMappedAddressChannelWriteFails"
|
||||
]
|
||||
},
|
||||
{
|
||||
"TestCaseName":"FutexTest",
|
||||
"TestArray": [
|
||||
"WaitValueMismatch",
|
||||
"WaitTimeout",
|
||||
"WaitTimeoutElapsed",
|
||||
"WaitBadAddress",
|
||||
"Wakeup",
|
||||
"WakeupLimit",
|
||||
"WakeupAddress",
|
||||
"RequeueValueMismatch"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -19,5 +19,5 @@ resolution=1024x768
|
|||
|
||||
initramfs=\EFI\zCore\fuchsia.zbi
|
||||
|
||||
cmdline=LOG=error
|
||||
# cmdline=LOG=warn:userboot=test/core/standalone-test:kernel.enable-debugging-syscalls-true:userboot.shutdown
|
||||
cmdline=LOG=error:console.shell=true:virtcon.disable=true:
|
||||
# cmdline=LOG=warn:userboot=test/core/standalone-test:kernel.enable-debugging-syscalls-true:userboot.shutdown:console.shell=true:virtcon.disable=true:test:-f:*.*:
|
||||
|
|
|
@ -172,7 +172,7 @@ pub fn run_userboot(images: &Images<impl AsRef<[u8]>>, cmdline: &str) -> Arc<Pro
|
|||
// check: handle to root proc should be only
|
||||
|
||||
let data =
|
||||
Vec::from(cmdline.replace(':', "\0") + "\0console.shell=true\0virtcon.disable=true\0");
|
||||
Vec::from(cmdline.replace(':', "\0")); // 目前看来都要追加在cmdline、就直接写在conf文件里了、
|
||||
let msg = MessagePacket { data, handles };
|
||||
kernel_channel.write(msg).unwrap();
|
||||
|
||||
|
|
|
@ -8,9 +8,12 @@ use {
|
|||
},
|
||||
};
|
||||
|
||||
static mut GLOBALTEST: Vec<u8> = Vec::new(); // mutex 需要 引入 spin 而整个库就这一处 static 好像 有些不划算 觉得 可以 不用?
|
||||
static mut OPEN:bool = false; // 这个在 不走 测试 时 要置false
|
||||
impl Syscall<'_> {
|
||||
/// Read a message from a channel.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(unsafe_code)]
|
||||
pub fn sys_channel_read(
|
||||
&self,
|
||||
handle_value: HandleValue,
|
||||
|
@ -33,14 +36,15 @@ impl Syscall<'_> {
|
|||
let never_discard = options & MAY_DISCARD == 0;
|
||||
|
||||
// let test_args = "test\0-f\0VmoClone2TestCase.ContiguousVmoPartialClone\0";
|
||||
let test_args = "";
|
||||
// let test_args = "";
|
||||
|
||||
let mut msg = if never_discard {
|
||||
channel.check_and_read(|front_msg| {
|
||||
if num_bytes < front_msg.data.len() as u32
|
||||
|| num_handles < front_msg.handles.len() as u32
|
||||
{
|
||||
let bytes = front_msg.data.len() + test_args.len();
|
||||
let mut bytes = front_msg.data.len();
|
||||
unsafe{bytes = bytes + GLOBALTEST.len();}
|
||||
actual_bytes.write_if_not_null(bytes as u32)?;
|
||||
actual_handles.write_if_not_null(front_msg.handles.len() as u32)?;
|
||||
Err(ZxError::BUFFER_TOO_SMALL)
|
||||
|
@ -52,11 +56,35 @@ impl Syscall<'_> {
|
|||
channel.read()?
|
||||
};
|
||||
|
||||
unsafe {
|
||||
// 固定的逻辑 基本 没有什么自由度
|
||||
if GLOBALTEST.is_empty() && OPEN {
|
||||
let mut num = 3; // dummy number 指的是
|
||||
let mut temp_rev:Vec<u8> = Vec::new();
|
||||
let mut temp:Vec<u8> = Vec::new();
|
||||
for &b in msg.data.iter().rev() {
|
||||
if b==0
|
||||
{
|
||||
if num==0
|
||||
{
|
||||
break;
|
||||
}
|
||||
num-=1;
|
||||
}
|
||||
temp_rev.push(b);
|
||||
}
|
||||
for &b in temp_rev.iter().rev() {
|
||||
temp.push(b);
|
||||
}
|
||||
GLOBALTEST.extend_from_slice(temp.as_slice());
|
||||
}
|
||||
}
|
||||
|
||||
// HACK: pass arguments to standalone-test
|
||||
#[allow(clippy::naive_bytecount)]
|
||||
if handle_value == 3 && self.thread.proc().name() == "test/core/standalone-test" {
|
||||
let len = msg.data.len();
|
||||
msg.data.extend(test_args.bytes());
|
||||
unsafe{msg.data.extend(GLOBALTEST.clone());}
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
struct ProcArgs {
|
||||
|
@ -72,8 +100,9 @@ impl Syscall<'_> {
|
|||
#[allow(clippy::cast_ptr_alignment)]
|
||||
let header = unsafe { &mut *(msg.data.as_mut_ptr() as *mut ProcArgs) };
|
||||
header.args_off = len as u32;
|
||||
header.args_num = test_args.as_bytes().iter().filter(|&&b| b == 0).count() as u32;
|
||||
warn!("HACKED: test args = {:?}", test_args);
|
||||
header.args_num = 3; // 因为 根据 目前 使用 方式 这里 总是 3、就直接 写死了
|
||||
// 每次 调用 GLOBALTEST 都需要 unsafe 能省则省 就不打印了
|
||||
//warn!("HACKED: test args = {:?}", test_args);
|
||||
}
|
||||
|
||||
actual_bytes.write_if_not_null(msg.data.len() as u32)?;
|
||||
|
|
Loading…
Reference in New Issue