Skip to content

Commit

Permalink
Enable all cargo tests in CI (#151)
Browse files Browse the repository at this point in the history
## What Changed and Why?

- Renames the `cargo make` rule run in CI to `ci-tests`. Under the hood
this now runs a general `cargo test` so that all tests are run. The only
way `cargo` tests are now excluded from CI is via `ignore` instead of
having a second filter via the CI script.

  This ensures all tests are actually exercised in CI.

- Converts the `consts` module into local structs `Markers` and
`Symbols` that are initialized per-session.

This fixes an issue with stale data that can cause test cases to fail.
This is caused by `Symbol`s. A `Symbol` is an interned string, with the
interner stored in a thread-local `SESSION_GLOBALS` variable. The
"costants" we allocate in `consts` however are `lazy_static`, which
means they are shared across threads. If two compiler sessions run in
parallel, then one would initialize the values in `consts`, interning
`Symbol`s in its interner. However the indices in those symbols would
refer to different strings in the other session, which breaks the
annotation extractor. A similar scenario would also occur if the two
sessions are sequential, as the `lazy_static` would preserve the
symbols. This is why the fresh, per-session intialization is needed, and
simply changing `lazy_static` to `thread_local` would be insufficient.

- Switches the name generation for test crates in the integration tests
to using random names.

This fixes issues where the crates already existed or tests wold race
for the same name if the test code was the same.

- It disables incremental compilation in CI. 

This substantially reduces the disk space needed and stays within the
limits of disk space available in [GitHub hosted
runners](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories).

## Checklist

- [x] Above description has been filled out so that upon quash merge we
have a
  good record of what changed.
- [x] New functions, methods, types are documented. Old documentation is
updated
  if necessary
- [x] Documentation in Notion has been updated
- [x] Tests for new behaviors are provided
  - [ ] New test suites (if any) ave been added to the CI tests (in
`.github/workflows/rust.yml`) either as compiler test or integration
test.
*Or* justification for their omission from CI has been provided in this
PR
    description.
  • Loading branch information
JustusAdam authored Jul 22, 2024
1 parent f7c6562 commit 2d832e1
Show file tree
Hide file tree
Showing 17 changed files with 339 additions and 209 deletions.
149 changes: 73 additions & 76 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ name: Rust

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
# Disable incremental computation. Has no benefit in CI, as the builds are
# always fresh. Substantially reduces disk usage (17GB -> 6GB as of writing
# this)
CARGO_INCREMENTAL: false

jobs:
compiler-tests:
Expand All @@ -17,93 +21,86 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# just triggers rustup to download the toolchain
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Build
run: cargo make install
- name: Run tests
run: cargo make pdg-tests
- uses: actions/checkout@v3
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Run tests
run: cargo make ci-tests

format-check:
name: Format Control
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# just triggers rustup to download the toolchain
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Run checks
run: cargo make format-check-all
- uses: actions/checkout@v3
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Run checks
run: cargo make format-check-all

linting:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Here come the complaints
run: cargo make clippy-check-all
- uses: actions/checkout@v3
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Here come the complaints
run: cargo make clippy-check-all

documentation:
name: Documentation Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Here come the complaints
run: cargo make doc-check
- uses: actions/checkout@v3
- name: Cache Toolchain
uses: actions/cache@v3
with:
path: ~/.rustup
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('rust-toolchain.toml') }}
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-rust-deps-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo-make
run: rustup run stable cargo install --force --debug cargo-make
- name: Here come the complaints
run: cargo make doc-check
45 changes: 41 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ debug = true
[replace."rustc_utils:0.7.4-nightly-2023-08-25"]
# path = "../rustc_plugin/crates/rustc_utils"
git = "https://github.com/JustusAdam/rustc_plugin"
rev = "6cc378d254e0c4fdfdbec975f82302173bfa0586"
rev = "6dcee5d8758f8ac456209e95dfa25e03142295f1"

[replace."rustc_plugin:0.7.4-nightly-2023-08-25"]
# path = "../rustc_plugin/crates/rustc_plugin"
git = "https://github.com/JustusAdam/rustc_plugin"
rev = "6cc378d254e0c4fdfdbec975f82302173bfa0586"
rev = "6dcee5d8758f8ac456209e95dfa25e03142295f1"
42 changes: 16 additions & 26 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ default_to_workspace = false
command = "cargo"
args = ["install", "--locked", "--path", "crates/paralegal-flow"]

[tasks.pdg-tests]
description = "The suite of synthetic tests for the PDG and the policy framweork."
dependencies = ["analyzer-tests", "policy-framework-tests", "guide-project"]
[tasks.ci-tests]
description = "The suite of tests we run in CI"
dependencies = ["cargo-tests", "guide-project"]

[tasks.check-all]
description = "Perform all formatting-like checks. This is the same set that runs in the CI."
Expand All @@ -47,38 +47,28 @@ stage them and rerun the script until no more errors occur.
"""
dependencies = ["format-all", "clippy-all"]

[tasks.analyzer-tests]
args = [
"test",
"-p",
"paralegal-flow",
"--test",
"non_transitive_graph_tests",
"--test",
"call_chain_analysis_tests",
"--test",
"control_flow_tests",
"--test",
"new_alias_analysis_tests",
"--test",
"boxes",
"--test",
"async_tests",
"--no-fail-fast",
]
description = "Low-level tests for the PDG emitted by the analyzer specifically."
[tasks.cargo-tests]
command = "cargo"
args = ["test"]

[tasks.flowistry-tests]
command = "cargo"
args = ["test", "-pflowistry_pdg", "-pflowistry_pdg_construction"]

[tasks.paralegal-flow-tests]
command = "cargo"
args = ["test", "-pparalegal-flow", "-pparalegal-spdg"]

[tasks.policy-framework-tests]
description = "Tests related to the correctness of the policy framework."
[tasks.policy-tests]
command = "cargo"
args = ["test", "-p", "paralegal-policy", "--lib"]
args = ["test", "-pparalegal-policy"]

[tasks.guide-project]
description = "Build and run the policy from the guide."
cwd = "guide/deletion-policy"
command = "cargo"
args = ["run"]
dependencies = ["install"]

[tasks.doc-check]
dependencies = [
Expand Down
23 changes: 23 additions & 0 deletions crates/flowistry_pdg/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::env;
use std::path::PathBuf;

fn rustup_toolchain_path() -> PathBuf {
let rustup_home = env::var("RUSTUP_HOME").unwrap();
let rustup_tc = env::var("RUSTUP_TOOLCHAIN").unwrap();
[&rustup_home, "toolchains", &rustup_tc]
.into_iter()
.collect()
}

fn get_rustup_lib_path() -> PathBuf {
let mut rustup_lib = rustup_toolchain_path();
rustup_lib.push("lib");
rustup_lib
}

fn main() {
if cfg!(target_os = "linux") {
let rustup_lib = get_rustup_lib_path();
println!("cargo:rustc-link-search=native={}", rustup_lib.display());
}
}
23 changes: 23 additions & 0 deletions crates/flowistry_pdg_construction/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::env;
use std::path::PathBuf;

fn rustup_toolchain_path() -> PathBuf {
let rustup_home = env::var("RUSTUP_HOME").unwrap();
let rustup_tc = env::var("RUSTUP_TOOLCHAIN").unwrap();
[&rustup_home, "toolchains", &rustup_tc]
.into_iter()
.collect()
}

fn get_rustup_lib_path() -> PathBuf {
let mut rustup_lib = rustup_toolchain_path();
rustup_lib.push("lib");
rustup_lib
}

fn main() {
if cfg!(target_os = "linux") {
let rustup_lib = get_rustup_lib_path();
println!("cargo:rustc-link-search=native={}", rustup_lib.display());
}
}
Loading

0 comments on commit 2d832e1

Please sign in to comment.