Skip to content

Commit

Permalink
Add support for exec_test
Browse files Browse the repository at this point in the history
  • Loading branch information
liqinggd committed Feb 20, 2024
1 parent e2e48c3 commit 09deddb
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 7 deletions.
19 changes: 14 additions & 5 deletions regression/syscall_test/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# SPDX-License-Identifier: MPL-2.0

TESTS ?= chmod_test fsync_test getdents_test link_test lseek_test mkdir_test \
open_create_test open_test pty_test read_test rename_test stat_test \
statfs_test symlink_test sync_test truncate_test uidgid_test unlink_test \
vdso_clock_gettime_test write_test
TESTS ?= chmod_test exec_test fsync_test getdents_test link_test lseek_test mkdir_test \
open_create_test open_test pty_test read_test rename_test stat_test statfs_test \
symlink_test sync_test uidgid_test unlink_test vdso_clock_gettime_test write_test


TEST_ATTACHMENTS := exec_assert_closed_workload exec_basic_workload exec_proc_exe_workload \
exec_state_workload exit_script priority_execve sigaltstack_check

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
Expand All @@ -21,11 +24,14 @@ BLOCK_LIST := $(CUR_DIR)/blocklists

.PHONY: all clean

all: $(TESTS)
all: $(TESTS) $(TEST_ATTACHMENTS)

$(TESTS): $(BIN_DIR) $(TARGET_DIR)
@cp -f $</$@ $(TARGET_DIR)/tests

$(TEST_ATTACHMENTS): $(BIN_DIR) $(TARGET_DIR)
@cp -f $</$@ $(TARGET_DIR)/tests

ifndef ASTER_PREBUILT_SYSCALL_TEST
$(BIN_DIR): $(SRC_DIR)
@if ! type bazel > /dev/null; then \
Expand All @@ -35,6 +41,9 @@ $(BIN_DIR): $(SRC_DIR)
@rm -rf $@ && mkdir -p $@
@cd $(SRC_DIR) && bazel build --test_tag_filters=native //test/syscalls/...
@cp $(SRC_DIR)/bazel-bin/test/syscalls/linux/*_test $@
@for file in $(TEST_ATTACHMENTS); do \
cp -f $(SRC_DIR)/bazel-bin/test/syscalls/linux/$$file $@; \
done

$(SRC_DIR):
@rm -rf $@ && mkdir -p $@
Expand Down
20 changes: 20 additions & 0 deletions regression/syscall_test/blocklists/exec_test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ExecTest.EmptyPath
ExecTest.ExecFn
ExecTest.ExecNameScript
ExecTest.InterpreterScript*
ExecTest.WithSiblingThread
ExecTest.FromSiblingThread
ExecTest.SymlinkLimitRefreshedForInterpreter
ExecTest.CloexecEventfd
ExecStateTest.ItimerPreserved
ExecveatTest.AbsolutePath
ExecveatTest.AbsolutePathWithEmptyPathFlag
ExecveatTest.EmptyPathWithDirFD
ExecveatTest.EmptyPathWithoutEmptyPathFlag
ExecveatTest.SymlinkNoFollowAndEmptyPath
ExecveatTest.SymlinkNoFollowIgnoreSymlinkAncestor
ExecveatTest.SymlinkNoFollowWithNormalFile
ExecveatTest.InterpreterScript*
ExecveatTest.InvalidFlags
ExecveatTest.UnshareFiles
GetpriorityTest.ExecveMaintainsPriority
2 changes: 1 addition & 1 deletion regression/syscall_test/run_syscall_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ run_one_test(){
if [ -f $TEST_BIN_DIR/$1 ]; then
rm -rf $TEST_TMP_DIR/*
get_blocklist_subtests $1
$TEST_BIN_DIR/$1 --gtest_filter=-$BLOCK
cd $TEST_BIN_DIR && ./$1 --gtest_filter=-$BLOCK
ret=$?
else
echo -e "Warning: $1 test does not exit"
Expand Down
31 changes: 31 additions & 0 deletions services/aster-nix/src/fs/procfs/pid/cmdline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use super::*;

/// Represents the inode at `/proc/[pid]/cmdline`.
pub struct CmdlineFileOps(Arc<Process>);

impl CmdlineFileOps {
pub fn new_inode(process_ref: Arc<Process>, parent: Weak<dyn Inode>) -> Arc<dyn Inode> {
ProcFileBuilder::new(Self(process_ref))
.parent(parent)
.build()
.unwrap()
}
}

impl FileOps for CmdlineFileOps {
fn data(&self) -> Result<Vec<u8>> {
let cmdline_output = if self.0.is_zombie() {
// Returns 0 characters for zombie process.
Vec::new()
} else {
let Ok(argv_cstrs) = self.0.vm().argv() else {
return Ok(Vec::new());
};
argv_cstrs
.into_iter()
.flat_map(|c_str| c_str.into_bytes_with_nul().into_iter())
.collect()
};
Ok(cmdline_output)
}
}
8 changes: 7 additions & 1 deletion services/aster-nix/src/fs/procfs/pid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use crate::fs::utils::{DirEntryVecExt, Inode};
use crate::prelude::*;
use crate::process::Process;

use self::cmdline::CmdlineFileOps;
use self::comm::CommFileOps;
use self::exe::ExeSymOps;
use self::fd::FdDirOps;
use super::template::{
DirOps, FileOps, ProcDir, ProcDirBuilder, ProcFileBuilder, ProcSymBuilder, SymOps,
};

mod cmdline;
mod comm;
mod exe;
mod fd;
Expand Down Expand Up @@ -50,6 +52,7 @@ impl DirOps for PidDirOps {
"exe" => ExeSymOps::new_inode(self.0.clone(), this_ptr.clone()),
"comm" => CommFileOps::new_inode(self.0.clone(), this_ptr.clone()),
"fd" => FdDirOps::new_inode(self.0.clone(), this_ptr.clone()),
"cmdline" => CmdlineFileOps::new_inode(self.0.clone(), this_ptr.clone()),
_ => return_errno!(Errno::ENOENT),
};
Ok(inode)
Expand All @@ -69,6 +72,9 @@ impl DirOps for PidDirOps {
});
cached_children.put_entry_if_not_found("fd", || {
FdDirOps::new_inode(self.0.clone(), this_ptr.clone())
})
});
cached_children.put_entry_if_not_found("cmdline", || {
CmdlineFileOps::new_inode(self.0.clone(), this_ptr.clone())
});
}
}
4 changes: 4 additions & 0 deletions services/aster-nix/src/syscall/execve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ fn read_cstring_vec(
max_string_number: usize,
max_string_len: usize,
) -> Result<Vec<CString>> {
if array_ptr == 0 {
return Ok(Vec::new());
}

let mut res = Vec::new();
let mut read_addr = array_ptr;
let mut find_null = false;
Expand Down

0 comments on commit 09deddb

Please sign in to comment.