Skip to content

Commit

Permalink
Merge pull request rcore-os#151 from rcore-os/libc-test-for-ci
Browse files Browse the repository at this point in the history
Add libc-test to CI
  • Loading branch information
wangrunji0408 authored Aug 15, 2020
2 parents a6741dd + c40da39 commit 3dcf7d6
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 17 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,27 @@ jobs:
pip3 install pexpect
python3 core-tests.py
libc-test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Pull prebuilt images
run: git lfs pull -I prebuilt/linux/libc-libos.so
- name: Install musl toolchain
run: sudo apt-get install musl-tools musl-dev -y
- name: Prepare rootfs and libc-test
run: make rootfs && make libc-test
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release -p linux-loader
- name: Run libc-tests
run: |
cd scripts
python3 libc-tests.py
cat linux/test-result.txt
doc:
runs-on: ubuntu-20.04
steps:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ rootfs: prebuilt/linux/$(ROOTFS_TAR)
rm -rf rootfs && mkdir -p rootfs
tar xf $< -C rootfs
cp prebuilt/linux/libc-libos.so rootfs/lib/ld-musl-x86_64.so.1
@for VAR in $(BASENAMES); do gcc $(TEST_DIR)$$VAR.c -o $(DEST_DIR)$$VAR $(CFLAG); done
@for VAR in $(BASENAMES); do gcc $(TEST_DIR)$$VAR.c -o $(DEST_DIR)$$VAR $(CFLAG); done

libc-test:
cd rootfs && git clone git://repo.or.cz/libc-test --depth 1
cd rootfs/libc-test && cp config.mak.def config.mak && echo 'CC := musl-gcc' >> config.mak && make -j
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,17 @@ Run all (non-panicked) core-tests for CI:
```sh
pip3 install pexpect
cd script && python3 core-tests.py
# Check `zircon/test-result.txt` for results.
```

Check `test-result.txt` for results.

Run Linux musl libc-tests for CI:

```sh
make rootfs && make libc-test
cd script && python3 libc-tests.py
# Check `linux/test-result.txt` for results.
```

## Components

Expand Down
15 changes: 4 additions & 11 deletions linux-loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use linux_loader::*;
use linux_object::fs::STDIN;
use rcore_fs_hostfs::HostFS;
use std::io::Write;
use std::sync::Arc;
use zircon_object::object::*;

/// main entry
#[async_std::main]
Expand All @@ -33,8 +31,9 @@ async fn main() {
let envs = vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-alpine-linux-musl/bin".into()];

let hostfs = HostFS::new("rootfs");
let proc: Arc<dyn KernelObject> = run(args, envs, hostfs);
proc.wait_signal(Signal::PROCESS_TERMINATED).await;
let proc = run(args, envs, hostfs);
let code = proc.wait_for_exit().await;
std::process::exit(code as i32);
}

/// init the env_logger
Expand Down Expand Up @@ -63,7 +62,6 @@ fn init_logger() {
mod tests {
use super::*;
use std::fs;
use zircon_object::object::task::*;

/// test with cmd line
async fn test(cmdline: &str) -> i64 {
Expand All @@ -74,12 +72,7 @@ mod tests {
vec!["PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-alpine-linux-musl/bin".into()]; // TODO
let hostfs = HostFS::new("../rootfs");
let proc = run(args, envs, hostfs);
let procobj: Arc<dyn KernelObject> = proc.clone();
procobj.wait_signal(Signal::PROCESS_TERMINATED).await;
if let Status::Exited(code) = proc.status() {
return code;
}
-1
proc.wait_for_exit().await
}

// test using busybox
Expand Down
9 changes: 5 additions & 4 deletions scripts/core-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

TIMEOUT = 300
ZCORE_PATH = '../zCore'
OUTPUT_FILE = 'test-output.txt'
RESULT_FILE = 'test-result.txt'
CHECK_FILE = 'test-check-passed.txt'
TEST_CASE_FILE = 'testcases.txt'
BASE = 'zircon/'
OUTPUT_FILE = BASE + 'test-output.txt'
RESULT_FILE = BASE + 'test-result.txt'
CHECK_FILE = BASE + 'test-check-passed.txt'
TEST_CASE_FILE = BASE + 'testcases.txt'


class Tee:
Expand Down
57 changes: 57 additions & 0 deletions scripts/libc-tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import glob
import subprocess

# ===============Must Config========================

TIMEOUT = 5 # seconds
ZCORE_PATH = '../zCore'
BASE = 'linux/'
OUTPUT_FILE = BASE + 'test-output.txt'
RESULT_FILE = BASE + 'test-result.txt'
CHECK_FILE = BASE + 'test-allow-failed.txt'

# ==============================================

passed = set()
failed = set()
timeout = set()

for path in glob.glob("../rootfs/libc-test/src/*/*.exe"):
path = path[len('../rootfs'):]
# ignore static linked tests
if path.endswith('-static.exe'):
continue
try:
subprocess.run("cd .. && cargo run --release -p linux-loader " + path,
shell=True, timeout=TIMEOUT, check=True)
passed.add(path)
except subprocess.CalledProcessError:
failed.add(path)
except subprocess.TimeoutExpired:
timeout.add(path)

with open(RESULT_FILE, "w") as f:
print('PASSED:', file=f)
for case in passed:
print(case, file=f)
print('FAILED:', file=f)
for case in failed:
print(case, file=f)
print('TIMEOUT:', file=f)
for case in timeout:
print(case, file=f)

with open(CHECK_FILE, 'r') as f:
allow_failed = set([case.strip() for case in f.readlines()])

check_failed = (failed | timeout) - allow_failed
if check_failed:
print('=== Failed cases ===')
for case in check_failed:
print(case)
exit(1)
else:
print('All checked case passed!')

os.system('killall linux-loader')
46 changes: 46 additions & 0 deletions scripts/linux/test-allow-failed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/libc-test/src/common/runtest.exe
/libc-test/src/regression/getpwnam_r-errno.exe
/libc-test/src/regression/pthread_atfork-errno-clobber.exe
/libc-test/src/regression/sigreturn.exe
/libc-test/src/regression/pthread-robust-detach.exe
/libc-test/src/regression/fflush-exit.exe
/libc-test/src/regression/daemon-failure.exe
/libc-test/src/regression/rewind-clear-error.exe
/libc-test/src/regression/statvfs.exe
/libc-test/src/regression/pthread_exit-dtor.exe
/libc-test/src/regression/rlimit-open-files.exe
/libc-test/src/regression/getpwnam_r-crash.exe
/libc-test/src/functional/strptime.exe
/libc-test/src/functional/pthread_cancel-points.exe
/libc-test/src/functional/tls_align_dlopen.exe
/libc-test/src/functional/sem_open.exe
/libc-test/src/functional/tls_init_dlopen.exe
/libc-test/src/functional/ipc_shm.exe
/libc-test/src/functional/vfork.exe
/libc-test/src/functional/strtod_long.exe
/libc-test/src/functional/utime.exe
/libc-test/src/functional/setjmp.exe
/libc-test/src/functional/ipc_sem.exe
/libc-test/src/functional/fcntl.exe
/libc-test/src/functional/ipc_msg.exe
/libc-test/src/functional/socket.exe
/libc-test/src/functional/tls_align.exe
/libc-test/src/functional/pthread_robust.exe
/libc-test/src/math/powf.exe
/libc-test/src/math/fmal.exe
/libc-test/src/regression/pthread_cond_wait-cancel_ignored.exe
/libc-test/src/regression/raise-race.exe
/libc-test/src/regression/pthread_once-deadlock.exe
/libc-test/src/regression/pthread_cond-smasher.exe
/libc-test/src/regression/pthread_condattr_setclock.exe
/libc-test/src/functional/pthread_mutex_pi.exe
/libc-test/src/functional/pthread_cancel.exe
/libc-test/src/functional/pthread_mutex.exe
/libc-test/src/functional/spawn.exe
/libc-test/src/functional/popen.exe
/libc-test/src/regression/execle-env.exe
/libc-test/src/regression/malloc-oom.exe
/libc-test/src/regression/pthread_create-oom.exe
/libc-test/src/regression/setenv-oom.exe
/libc-test/src/regression/flockfile-list.exe
/libc-test/src/regression/malloc-brk-fail.exe
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions zircon-object/src/task/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,17 @@ impl Process {
pub fn thread_ids(&self) -> Vec<KoID> {
self.inner.lock().threads.iter().map(|t| t.id()).collect()
}

/// Wait for process exit and get return code.
pub async fn wait_for_exit(self: &Arc<Self>) -> i64 {
let object: Arc<dyn KernelObject> = self.clone();
object.wait_signal(Signal::PROCESS_TERMINATED).await;
if let Status::Exited(code) = self.status() {
code
} else {
unreachable!();
}
}
}

impl Task for Process {
Expand Down

0 comments on commit 3dcf7d6

Please sign in to comment.