Skip to content

Commit 0ef5017

Browse files
authored
ci: add github actions for lint and format (#156)
1 parent 179ec0e commit 0ef5017

File tree

13 files changed

+127
-30
lines changed

13 files changed

+127
-30
lines changed

.cirrus.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ build: &BUILD
1313
- df -T /tmp
1414
- target/release/pjdfstest -c $CFG -p /tmp
1515
- su $SU_ARGS "target/release/pjdfstest -c $CFG -p /tmp"
16-
- rustup component add clippy
17-
- cargo clippy --all-targets
16+
1817

1918
task:
2019
name: FreeBSD

.github/workflows/book.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ jobs:
3030
with:
3131
crate: mdbook-cmdrun
3232

33-
- uses: dtolnay/rust-toolchain@stable
3433
- name: Build the suite to retrieve its features
35-
run: cd rust && cargo build
34+
working-directory: rust
35+
run: cargo build
3636

37-
- run: cd book && ./build.sh
37+
- working-directory: book
38+
run: ./build.sh
3839

3940
- name: Deploy
4041
uses: peaceiris/actions-gh-pages@v4

.github/workflows/ci.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
on:
2+
push:
3+
4+
jobs:
5+
format_lint_check:
6+
runs-on: ubuntu-latest
7+
env:
8+
RUSTFLAGS: -D warnings
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Check formatting
13+
working-directory: rust
14+
run: cargo fmt --all --check
15+
16+
- name: Check clippy for Linux
17+
working-directory: rust
18+
run: cargo clippy --all-targets --all-features
19+
20+
- name: Install FreeBSD target
21+
run: rustup target add x86_64-unknown-freebsd
22+
23+
- name: Check clippy for FreeBSD
24+
working-directory: rust
25+
run: cargo clippy --all-targets --all-features --target x86_64-unknown-freebsd
26+
27+
- name: Check doc
28+
working-directory: rust
29+
run: cargo doc --no-deps --all-features

README.md

+67-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
# pjdfstest - Rust rewrite
1+
# pjdfstest.rs - Rust rewrite
22

3-
pjdfstest is a test suite that helps exercise POSIX system calls.
3+
pjdfstest is a file system test suite to assess the correctness of file system implementations in terms of POSIX compliance.
4+
The test suite has been rewritten in Rust as part of the Google Summer of Code 2022 program.
45

56
## Build
67

8+
### Requirements
9+
10+
The following dependencies are required to build the project:
11+
12+
#### Common
13+
14+
- Rust (1.72.1 or later)
15+
16+
#### Linux
17+
18+
- libacl1-dev (Debian/Ubuntu), libacl-devel (Fedora), acl (Arch)
19+
- acl
20+
721
```bash
822
cd rust
923
cargo run
@@ -13,6 +27,51 @@ cargo run
1327

1428
The documentation is available at <https://saidsay-so.github.io/pjdfstest/>.
1529

30+
## Configuration file
31+
32+
A TOML configuration file can be used to specify parameters for the test suite.
33+
A default configuration file is provided in the repository, which can be used as a template.
34+
35+
```toml
36+
# Configuration for the pjdfstest runner
37+
38+
# This section allows enabling file system specific features.
39+
# Please see the book for more details.
40+
# A list of these features is provided when executing the runner with `-l`.
41+
[features]
42+
# File flags can be specified for OS which supports them.
43+
# file_flags = ["UF_IMMUTABLE"]
44+
45+
# Here is an example with the `posix_fallocate` syscall.
46+
posix_fallocate = {}
47+
48+
# Might use the key notation as well.
49+
# [features.posix_fallocate]
50+
51+
[settings]
52+
# naptime is the duration of various short sleeps. It should be greater than
53+
# the timestamp granularity of the file system under test.
54+
naptime = 0.001
55+
# Allow to run the EROFS tests, which require to remount the file system on which
56+
# pjdsfstest is run as read-only.
57+
allow_remount = false
58+
59+
# This section allows to modify the mechanism for switching users, which is required by some tests.
60+
# [dummy_auth]
61+
# An entry is the name of a user and its associated group.
62+
# For now, the array requires exactly 3 entries.
63+
# Please see the book for more details.
64+
# entries = [
65+
# ["nobody", "nobody"],
66+
# nogroup instead for some Linux distros
67+
# ["nobody", "nogroup"],
68+
# ["tests", "tests"],
69+
# ["pjdfstest", "pjdfstest"],
70+
# ]
71+
```
72+
73+
Please refer to the [documentation](https://saidsay-so.github.io/pjdfstest/configuration-file.html) for more details.
74+
1675
## Command-line interface
1776

1877
_`pjdfstest [OPTIONS] [--] TEST_PATTERNS`_
@@ -70,3 +129,9 @@ tests:x:::Dummy User for pjdfstest:/:/usr/bin/nologin
70129
pjdfstest:x:::Dummy User for pjdfstest:/:/usr/bin/nologin
71130
EOF
72131
```
132+
133+
## Contributing
134+
135+
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for submitting pull requests to us
136+
and the process for adding new tests.
137+
Also, read the [documentation](https://saidsay-so.github.io/pjdfstest/test-declaration.html) on how to declare tests.

book/src/introduction.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ primarily for FreeBSD file systems.
55
It was originally written to validate the ZFS port to FreeBSD,
66
but it now supports multiple operating systems and file systems.
77

8-
This is a complete rewrite of the original test suite in Rust.
8+
This is a complete rewrite of the original test suite in Rust,
9+
as part of the Google Summer of Code 2022 program
10+
(<https://summerofcode.withgoogle.com/archive/2022/projects/6XPYWLzJ>).
911

1012
**NOTE: The documentation is still a work-in-progress**
1113

book/src/test-declaration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn update_ctime(ctx: &mut TestContext, f_type: FileType) {
2525

2626
All the structures and functions needed are documented in the `pjdfstest` crate,
2727
which you can obtain by running `cargo doc --open` in the `rust` directory
28-
or by visiting the [documentation](/doc/pjdfstest).
28+
or by visiting the [documentation](doc/pjdfstest/).
2929

3030
## Test context
3131

rust/src/config/auth.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::error::Error;
2-
use std::{borrow::Cow, fmt::Display};
32
use std::process::exit;
3+
use std::{borrow::Cow, fmt::Display};
44

55
use nix::unistd::{Group, User};
66
use serde::{de::Visitor, ser::SerializeTuple, Deserialize, Serialize};
@@ -145,11 +145,11 @@ impl Default for DummyAuthConfig {
145145
},
146146
DummyAuthEntry {
147147
user: upjdfstest,
148-
group: gpjdfstest
148+
group: gpjdfstest,
149149
},
150150
DummyAuthEntry {
151151
user: utests,
152-
group: gtests
152+
group: gtests,
153153
},
154154
],
155155
}

rust/src/features.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize};
2121
#[serde(rename_all = "snake_case")]
2222
#[strum(serialize_all = "snake_case")]
2323
pub enum FileSystemFeature {
24-
/// The [`chflags`](https://man.freebsd.org/cgi/man.cgi?chflags(1)) command is available
24+
/// The [`chflags`](https://man.freebsd.org/cgi/man.cgi?chflags(1)) syscall is available
2525
Chflags,
2626
/// NFSv4 style Access Control Lists are available
2727
Nfsv4Acls,

rust/src/flags.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use serde::{Deserialize, Serialize};
44

5+
/// Define a set of flags for a given enum and implement `From` for `nix::sys::stat::FileFlag`.
56
macro_rules! flags {
67
( $( #[$enum_attrs: meta] )* pub enum $enum: ident { $(#[cfg($cfg: meta)] $(#[$attr: meta])* $flag: ident ),* $(,)?} ) => {
78
$(#[$enum_attrs])*

rust/src/macros.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! Macros for defining test cases.
2-
//!
3-
//! The `test_case` macro is used to define test cases for a test suite.
2+
//!
3+
//! The `test_case` macro is used to define test cases for a test suite.
44
55
/// Macro for defining test cases, which are automatically registered with the test suite.
6-
///
6+
///
77
/// A test case can be serialized or non-serialized, require root privileges, and be run on specific file types.
88
/// It can also require specific features to be enabled, and have guards which are run before the test case is executed to determine if conditions are met.
9-
///
9+
///
1010
/// The macro supports mutiple parameters which can be combined in a specific order,
1111
/// for example:
12-
///
12+
///
1313
/// ```rust
1414
/// // Non-serialized test case
1515
/// test_case! {
@@ -18,7 +18,7 @@
1818
/// }
1919
/// fn basic(_: &mut crate::test::TestContext) {}
2020
/// ```
21-
///
21+
///
2222
/// ```rust
2323
/// // Non-serialized test case with required features, guards, and root privileges
2424
/// test_case! {
@@ -27,7 +27,7 @@
2727
/// }
2828
/// fn features(_: &mut crate::test::TestContext) {}
2929
/// ```
30-
///
30+
///
3131
/// ```rust
3232
/// // Serialized test case with root privileges
3333
/// test_case! {
@@ -36,7 +36,7 @@
3636
/// }
3737
/// fn serialized(_: &mut crate::test::SerializedTestContext) {}
3838
/// ```
39-
///
39+
///
4040
/// ```rust
4141
/// // Serialized test case with required features
4242
/// test_case! {
@@ -45,12 +45,12 @@
4545
/// }
4646
/// fn serialized_features(_: &mut crate::test::SerializedTestContext) {}
4747
/// ```
48-
///
48+
///
4949
/// ```rust
5050
/// // Serialized test case with required features, guards, root privileges, and file types
5151
/// test_case! {
5252
/// /// description
53-
/// serialized_types, serialized, FileSystemFeature::Chflags, FileSystemFeature::PosixFallocate; guard_example, root => [Regular, Fifo]
53+
/// serialized_types, serialized, root, FileSystemFeature::Chflags, FileSystemFeature::PosixFallocate; guard_example, root => [Regular, Fifo]
5454
/// }
5555
/// fn serialized_types(_: &mut crate::test::SerializedTestContext, _: crate::context::FileType) {}
5656
/// ```

rust/src/tests/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Where the tests are defined.
2-
//!
2+
//!
33
//! This module contains the tests for the file system test suite. The tests are defined as functions
44
//! which are then registered with the test suite.
5-
//!
5+
//!
66
//! The tests are defined using the `test_case!` macro, which is used to define a test case for the test suite.
7-
//!
7+
//!
88
//! It also contains some helper functions and macros which are used to define the tests.
99
1010
use std::fs::symlink_metadata;

rust/src/tests/rmdir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ fn has_mount_cap(_: &Config, _: &Path) -> anyhow::Result<()> {
105105
if !Uid::effective().is_root() && ctl.value()? == CtlValue::Int(0) {
106106
anyhow::bail!("process doesn't have the rights to mount the dummy file system")
107107
}
108-
if !Uid::effective().is_root() &&
109-
!OsStr::from_bytes(&Command::new("lsvfs").output().unwrap().stdout)
108+
if !Uid::effective().is_root()
109+
&& !OsStr::from_bytes(&Command::new("lsvfs").output().unwrap().stdout)
110110
.to_string_lossy()
111111
.contains("nullfs")
112112
{

rust/src/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Utility functions for filesystem operations.
2-
//!
2+
//!
33
//! This module provides utility functions for filesystem operations which are not available in the standard library.
44
55
use std::{
@@ -95,7 +95,7 @@ pub fn lchflags<P: ?Sized + nix::NixPath>(
9595

9696
/// Wrapper for open which returns [`Ownedfd`] instead of [`RawFd`].
9797
pub fn open<P: ?Sized + nix::NixPath>(path: &P, oflag: OFlag, mode: Mode) -> nix::Result<OwnedFd> {
98-
// SAFETY: The file descriptor was initialized only by open and isn't used anywhere else,
98+
// SAFETY: The file descriptor was initialized only by open and isn't used anywhere else,
9999
// leaving the ownership to the caller.
100100
nix::fcntl::open(path, oflag, mode).map(|fd| unsafe { OwnedFd::from_raw_fd(fd) })
101101
}

0 commit comments

Comments
 (0)