Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI workflows for test workspace #5575

Merged
merged 7 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/android-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- '!graphics/**'
- '!gui/**'
- '!ios/**'
- '!test/**'
- '!scripts/**'
- '!windows/**'
- '!**/**.md'
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/testframework-clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Run `clippy` on the `test` workspace
---
name: DES Testframework - Clippy
on:
pull_request:
paths:
- 'test/**/*.rs'
- .github/workflows/clippy-test.yml
- clippy.toml
workflow_dispatch:
jobs:
clippy-check-test:
name: Clippy linting of test workspace
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions-rs/[email protected]
with:
toolchain: stable
components: clippy
override: true

- name: Install build dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libdbus-1-dev

- name: Clippy check
working-directory: test
shell: bash
env:
RUSTFLAGS: --deny warnings
run: |
time cargo clippy --locked -- -W clippy::unused_async

clippy-check-test-windows:
name: Clippy linting of test workspace (Windows)
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- uses: actions-rs/[email protected]
with:
toolchain: stable
components: clippy
override: true

- name: Clippy check
working-directory: test
shell: bash
env:
RUSTFLAGS: --deny warnings
run: |
# Exclude checking test-manager on Windows, since it is not a supported compilation target.
time cargo clippy --workspace --exclude test-manager --locked -- -W clippy::unused_async
29 changes: 29 additions & 0 deletions .github/workflows/testframework-rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Run `cargo fmt --check` on the `test` workspace
---
name: DES Testframework - Check formatting
on:

Check warning on line 4 in .github/workflows/testframework-rustfmt.yml

View workflow job for this annotation

GitHub Actions / check-formatting

4:1 [truthy] truthy value should be one of [false, true]
pull_request:
paths:
- 'test/**/*.rs'
- .github/workflows/rustfmt-test.yml
- rustfmt.toml
workflow_dispatch:
jobs:
check-formatting-test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/[email protected]
with:
toolchain: stable
components: rustfmt
default: true

- name: Check formatting
working-directory: test
run: |-
rustfmt --version
cargo fmt -- --check
111 changes: 111 additions & 0 deletions .github/workflows/testframework.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Compile the test framework
---
name: DES Testframework - Build
on:

Check warning on line 4 in .github/workflows/testframework.yml

View workflow job for this annotation

GitHub Actions / check-formatting

4:1 [truthy] truthy value should be one of [false, true]
pull_request:
paths:
- '**'
- '!**/**.md'
- '!.github/workflows/**'
- '.github/workflows/daemon.yml'
- '!android/**'
- '!audits/**'
- '!build-apk.sh'
- '!build.sh'
- '!clippy.toml'
- '!deny.toml'
- '!docs/**'
- '!graphics/**'
- '!gui/**'
- '!ios/**'
- '!scripts/**'
- '!.*ignore'
- '!prepare-release.sh'
- '!rustfmt.toml'
- '!.yamllint'
workflow_dispatch:
jobs:
prepare-build-test-framework-linux:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use custom container image if specified
if: ${{ github.event.inputs.override_container_image != '' }}
run: echo "inner_container_image=${{ github.event.inputs.override_container_image }}"
>> $GITHUB_ENV

- name: Use default container image and resolve digest
if: ${{ github.event.inputs.override_container_image == '' }}
run: |
echo "inner_container_image=$(cat ./building/linux-container-image.txt)" >> $GITHUB_ENV

outputs:
container_image: ${{ env.inner_container_image }}

# Build the test runner + test manager at once.
build-test-framework-linux:
needs: prepare-build-test-framework-linux
runs-on: ubuntu-latest
container:
image: ${{ needs.prepare-build-test-framework-linux.outputs.container_image }}

steps:
# Fix for HOME path overridden by GH runners when building in containers, see:
# https://github.com/actions/runner/issues/863
- name: Fix HOME path
run: echo "HOME=/root" >> $GITHUB_ENV

- name: Install system dependencies # Needed to build test-manager, and is not included in the app container.

Check warning on line 60 in .github/workflows/testframework.yml

View workflow job for this annotation

GitHub Actions / check-formatting

60:43 [comments] too few spaces before comment
run: apt update && apt install -y pkg-config libssl-dev libpcap-dev

- name: Checkout repository
uses: actions/checkout@v3

- name: Build test framework
working-directory: test
run: cargo build --release

# Build the test runner + test manager at once.
build-test-framework-macos:
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Rust
uses: actions-rs/[email protected]
with:
toolchain: stable
default: true

- name: Build test runner
working-directory: test
run: cargo build

# Build only the test-runner binary on Windows. Windows is not a supported host for test-manager.
build-test-runner-windows:
# Cross-compile the test runner for Windows from Linux.
needs: prepare-build-test-framework-linux
runs-on: ubuntu-latest
container:
image: ${{ needs.prepare-build-test-framework-linux.outputs.container_image }}
continue-on-error: true
steps:
# Fix for HOME path overridden by GH runners when building in containers, see:
# https://github.com/actions/runner/issues/863
- name: Fix HOME path
run: echo "HOME=/root" >> $GITHUB_ENV

- name: Checkout repository
uses: actions/checkout@v3

- name: Build test runner
working-directory: test
run: cargo build --release -p test-runner --target x86_64-pc-windows-gnu
3 changes: 3 additions & 0 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ARG IMAGE=ghcr.io/mullvad/mullvadvpn-app-build:latest
FROM $IMAGE

RUN apt-get update && apt-get install -y \
pkg-config libssl-dev libpcap-dev
2 changes: 1 addition & 1 deletion test/test-manager/src/mullvad_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl RpcClientProvider {
}
}

pub async fn new_rpc_client(
pub fn new_rpc_client(
connection_handle: ConnectionHandle,
mullvad_daemon_transport: GrpcForwarder,
) -> RpcClientProvider {
Expand Down
4 changes: 2 additions & 2 deletions test/test-manager/src/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn run(
let serial_stream =
tokio_serial::SerialStream::open(&tokio_serial::new(pty_path, BAUD)).unwrap();
let (runner_transport, mullvad_daemon_transport, mut connection_handle, completion_handle) =
test_rpc::transport::create_client_transports(serial_stream).await?;
test_rpc::transport::create_client_transports(serial_stream)?;

if !skip_wait {
connection_handle.wait_for_server().await?;
Expand All @@ -45,7 +45,7 @@ pub async fn run(

let client = ServiceClient::new(connection_handle.clone(), runner_transport);
let mullvad_client =
mullvad_daemon::new_rpc_client(connection_handle, mullvad_daemon_transport).await;
mullvad_daemon::new_rpc_client(connection_handle, mullvad_daemon_transport);

let mut tests: Vec<_> = inventory::iter::<tests::TestMetadata>().collect();
tests.sort_by_key(|test| test.priority.unwrap_or(0));
Expand Down
35 changes: 18 additions & 17 deletions test/test-rpc/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,18 @@ impl ConnectionHandle {
}
}

pub fn create_server_transports(
serial_stream: impl AsyncRead + AsyncWrite + Unpin + Send + 'static,
) -> (
type ServerTransports = (
tarpc::transport::channel::UnboundedChannel<
ClientMessage<ServiceRequest>,
Response<ServiceResponse>,
>,
GrpcForwarder,
CompletionHandle,
) {
);

pub fn create_server_transports(
serial_stream: impl AsyncRead + AsyncWrite + Unpin + Send + 'static,
) -> ServerTransports {
let (runner_forwarder_1, runner_forwarder_2) = tarpc::transport::channel::unbounded();

let (daemon_rx, mullvad_daemon_forwarder) = tokio::io::duplex(DAEMON_CHANNEL_BUF_SIZE);
Expand Down Expand Up @@ -162,20 +164,9 @@ pub fn create_server_transports(
(runner_forwarder_1, daemon_rx, completion_handle)
}

pub async fn create_client_transports(
pub fn create_client_transports(
serial_stream: impl AsyncRead + AsyncWrite + Unpin + Send + 'static,
) -> Result<
(
tarpc::transport::channel::UnboundedChannel<
Response<ServiceResponse>,
ClientMessage<ServiceRequest>,
>,
GrpcForwarder,
ConnectionHandle,
CompletionHandle,
),
Error,
> {
) -> Result<ClientTransports, Error> {
let (runner_forwarder_1, runner_forwarder_2) = tarpc::transport::channel::unbounded();

let (daemon_rx, mullvad_daemon_forwarder) = tokio::io::duplex(DAEMON_CHANNEL_BUF_SIZE);
Expand Down Expand Up @@ -216,6 +207,16 @@ pub async fn create_client_transports(
))
}

type ClientTransports = (
tarpc::transport::channel::UnboundedChannel<
Response<ServiceResponse>,
ClientMessage<ServiceRequest>,
>,
GrpcForwarder,
ConnectionHandle,
CompletionHandle,
);

#[derive(err_derive::Error, Debug)]
#[error(no_from)]
enum ForwardError {
Expand Down
2 changes: 1 addition & 1 deletion test/test-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Service for TestServer {
_: context::Context,
interface: String,
) -> Result<IpAddr, test_rpc::Error> {
net::get_interface_ip(&interface).await
net::get_interface_ip(&interface)
}

async fn get_default_interface(self, _: context::Context) -> Result<String, test_rpc::Error> {
Expand Down
4 changes: 2 additions & 2 deletions test/test-runner/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub async fn send_ping(
}

#[cfg(unix)]
pub async fn get_interface_ip(interface: &str) -> Result<IpAddr, test_rpc::Error> {
pub fn get_interface_ip(interface: &str) -> Result<IpAddr, test_rpc::Error> {
// TODO: IPv6
use std::net::Ipv4Addr;

Expand All @@ -225,7 +225,7 @@ pub async fn get_interface_ip(interface: &str) -> Result<IpAddr, test_rpc::Error
}

#[cfg(target_os = "windows")]
pub async fn get_interface_ip(interface: &str) -> Result<IpAddr, test_rpc::Error> {
pub fn get_interface_ip(interface: &str) -> Result<IpAddr, test_rpc::Error> {
// TODO: IPv6

get_interface_ip_for_family(interface, talpid_windows::net::AddressFamily::Ipv4)
Expand Down
1 change: 1 addition & 0 deletions test/test-runner/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ pub async fn set_daemon_log_level(verbosity_level: Verbosity) -> Result<(), test
}

#[cfg(target_os = "macos")]
#[allow(clippy::unused_async)]
pub async fn set_daemon_log_level(_verbosity_level: Verbosity) -> Result<(), test_rpc::Error> {
// TODO: Not implemented
log::warn!("Setting log level is not implemented on macOS");
Expand Down
Loading