Skip to content

Commit

Permalink
feat: update behavior tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zjregee committed Aug 24, 2024
1 parent 44dce4a commit 738e439
Show file tree
Hide file tree
Showing 9 changed files with 523 additions and 543 deletions.
11 changes: 10 additions & 1 deletion .github/scripts/behavior_test_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@
print(errors)
sys.exit(1)

test_command = "python3 /mnt/behavior_test.py"
test_command = "python3 /mnt/file_behavior_test.py"
stdin, stdout, stderr = ssh.exec_command(test_command)
output = stdout.read().decode('utf-8')
errors = stderr.read().decode('utf-8')
exit_status = stdout.channel.recv_exit_status()
if exit_status != 0:
print(errors)
sys.exit(1)

test_command = "python3 /mnt/path_behavior_test.py"
stdin, stdout, stderr = ssh.exec_command(test_command)
output = stdout.read().decode('utf-8')
errors = stderr.read().decode('utf-8')
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions .github/scripts/path_behavior_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os

TEST_POINT = "/mnt"
TEST_PRESET_PATHS = [
("./behavior_test_judge.py", True),
("./build_and_run_ovfs.sh", True),
("./file_behavior_test.py", True),
("./image.img", True),
("./install_and_run_vm.sh", True),
("./meta-data", True),
("./path_behavior_test.py", True),
("./seed.iso", True),
("./ubuntu-20.04.6-live-server-amd64.iso", True),
("./user-data", True),
]

def list_paths():
walked_entries = []
for dirpath, dirnames, filenames in os.walk(TEST_POINT):
rel_dir = os.path.relpath(dirpath, TEST_POINT)
for dirname in dirnames:
walked_entries.append((os.path.join(rel_dir, dirname), False))
for filename in filenames:
walked_entries.append((os.path.join(rel_dir, filename), True))
return walked_entries

def test_path():
paths = list_paths()
paths.sort()
TEST_PRESET_PATHS.sort()
assert paths == TEST_PRESET_PATHS

if __name__ == "__main__":
test_path()
2 changes: 1 addition & 1 deletion .github/workflows/behavior_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:
nohup ./build_and_run_ovfs.sh &
nohup ./install_and_run_vm.sh &
pip install paramiko
python behavior_test.py
python behavior_test_judge.py
working-directory: .github/scripts
20 changes: 20 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: OVFS Format Check

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Format Check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run Format Check
run: cargo fmt -- --check
36 changes: 36 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::ffi::CStr;
use std::io;

use anyhow::Error as AnyError;
use log::debug;
use opendal::ErrorKind;
use snafu::prelude::Snafu;

#[derive(Debug, Snafu)]
Expand All @@ -20,6 +23,39 @@ pub enum Error {
},
}

impl From<opendal::Error> for Error {
fn from(error: opendal::Error) -> Error {
debug!("opendal error occurred: {:?}", error);
match error.kind() {
ErrorKind::Unsupported => Error::from(libc::EOPNOTSUPP),
ErrorKind::IsADirectory => Error::from(libc::EISDIR),
ErrorKind::NotFound => Error::from(libc::ENOENT),
ErrorKind::PermissionDenied => Error::from(libc::EACCES),
ErrorKind::AlreadyExists => Error::from(libc::EEXIST),
ErrorKind::NotADirectory => Error::from(libc::ENOTDIR),
ErrorKind::RangeNotSatisfied => Error::from(libc::EINVAL),
ErrorKind::RateLimited => Error::from(libc::EBUSY),
_ => Error::from(libc::ENOENT),
}
}
}

impl From<libc::c_int> for Error {
fn from(errno: libc::c_int) -> Error {
let err_str = unsafe { libc::strerror(errno) };
let message = if err_str.is_null() {
format!("errno: {}", errno)
} else {
let c_str = unsafe { CStr::from_ptr(err_str) };
c_str.to_string_lossy().into_owned()
};
Error::VhostUserFsError {
message,
source: None,
}
}
}

impl From<Error> for io::Error {
fn from(error: Error) -> io::Error {
match error {
Expand Down
Loading

0 comments on commit 738e439

Please sign in to comment.