Skip to content

Use ASAN when running unit tests in CI#56

Open
JoukoVirtanen wants to merge 3 commits into
mainfrom
jv-use-asan
Open

Use ASAN when running unit tests in CI#56
JoukoVirtanen wants to merge 3 commits into
mainfrom
jv-use-asan

Conversation

@JoukoVirtanen

@JoukoVirtanen JoukoVirtanen commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Adds CI unit test jobs with and without ASAN.

The ASAN tests found a failure https://github.com/stackrox/berserker/actions/runs/24287041420/job/70918030561?pr=56 when the target branch was #55

@JoukoVirtanen JoukoVirtanen changed the base branch from main to feature/new-script-worker March 26, 2026 02:57
@JoukoVirtanen JoukoVirtanen marked this pull request as draft March 26, 2026 05:29
Comment thread .github/workflows/main.yml Outdated
Comment thread .github/workflows/main.yml Outdated
@JoukoVirtanen JoukoVirtanen marked this pull request as ready for review March 26, 2026 21:22
@JoukoVirtanen JoukoVirtanen requested a review from erthalion March 26, 2026 21:22
Comment thread .github/workflows/main.yml Outdated
source "${HOME}"/.cargo/env &&
rustup component add rust-src --toolchain nightly &&
TARGET=$(rustc --version --verbose | grep host | cut -d" " -f2) &&
RUSTFLAGS="-Z sanitizer=address" cargo +nightly test -Z build-std --target "$TARGET"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are invoked from the image itself nowadays:
https://github.com/stackrox/berserker/blob/main/Dockerfile.build#L32

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now invoke the ASAN unit tests from the image itself.

@erthalion erthalion force-pushed the feature/new-script-worker branch from 881dc23 to d030a12 Compare March 31, 2026 16:35
@erthalion erthalion force-pushed the feature/new-script-worker branch from d030a12 to c135bad Compare April 8, 2026 15:13
@JoukoVirtanen JoukoVirtanen requested a review from erthalion April 11, 2026 17:21
@JoukoVirtanen JoukoVirtanen changed the base branch from feature/new-script-worker to main April 12, 2026 17:47
@erthalion erthalion force-pushed the jv-use-asan branch 2 times, most recently from ebc47a6 to bcef02e Compare May 8, 2026 12:27
@erthalion erthalion mentioned this pull request Jul 2, 2026
JoukoVirtanen and others added 2 commits July 7, 2026 17:02
Co-authored-by: Dmitrii Dolgov <9erthalion6@gmail.com>
To prevent memory leaks from allocations in helper functions, remember
references to allocated objects. For now we assume only CString is
reference.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: c627ac88-9ee6-403c-b0bc-00fba7a5a8ed

📥 Commits

Reviewing files that changed from the base of the PR and between 2fab6d0 and 1b0246c.

📒 Files selected for processing (1)
  • src/worker/script.rs
💤 Files with no reviewable changes (1)
  • src/worker/script.rs

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added an optional nightly build mode, including nightly toolchain configuration and nightly-aware test execution.
  • Bug Fixes

    • Improved runtime cleanup for generated script path resources to help prevent resource leaks during script/JIT execution.
  • Build & Maintenance

    • Updated build tooling to pass the selected Rust toolchain version into the containerized build/test flow.
    • Added a configurable Cargo feature flag for nightly mode.

Walkthrough

Adds a Cargo nightly feature and nightly-only sanitizer test wiring in the container build. It also updates script JIT execution to track and free allocated C-string pointers, and reformats several comments and docs.

Changes

Nightly toolchain and script cleanup

Layer / File(s) Summary
Cargo nightly feature and crate attribute
Cargo.toml, src/lib.rs
Adds default/nightly Cargo features and a crate-level cfg_attr enabling the unstable sanitize feature under nightly.
Containerfile and Makefile nightly build/test flow
Containerfile, Makefile
Parameterizes Rust toolchain via ARG RUST_VERSION, conditionally installs rust-src, runs address-sanitizer-enabled nightly tests, and passes --build-arg=RUST_VERSION=nightly.
Script runtime pointer tracking and cleanup
src/worker/script.rs
Replaces single cached path storage with tracked raw pointers, adds a runtime cleanup function, and updates the JIT runtime lookup to use &CStr.
JIT call sites and final cleanup emission
src/worker/script.rs
Passes C-string literals into jit_instruction and emits a final cleanup call during JIT module generation.
Documentation and comment formatting
src/lib.rs, src/main.rs, src/worker/syscalls/ioctl.rs, src/worker/script.rs
Reformats doc and inline comments without changing behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: running unit tests with ASAN in CI.
Description check ✅ Passed The description is directly related to the changeset and mentions ASAN test jobs and a found failure.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jv-use-asan

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Containerfile`:
- Line 1: Fix the Dockerfile lint issues by updating the stage alias in the
top-level FROM instruction to use matching uppercase AS, and change the
ENTRYPOINT in the Containerfile to JSON/exec form instead of shell form. Use the
FROM and ENTRYPOINT instructions in this file as the targets for the cleanup.
- Around line 45-50: The nightly ASAN test branch in the Containerfile is
missing the crate’s `nightly` Cargo feature, so the `sanitize` feature gate in
`src/lib.rs` never turns on. Update the `cargo +nightly test` invocation in this
RUN block to include the crate’s `nightly` feature alongside the existing `-Z
build-std` and `RUSTFLAGS="-Z sanitizer=address"` settings, so the ASAN path
actually exercises the intended nightly-only code.

In `@Makefile`:
- Around line 9-10: The Makefile’s two docker build steps currently reuse the
same berserker tag, so the nightly build overwrites the stable image. Update the
second docker build invocation to use a distinct tag for the nightly variant
while keeping the first build as the default berserker image, so later steps
consume the intended stable image; make this change in the build commands near
the two docker build lines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: af1e2ced-f111-4070-bda9-21101f6c0352

📥 Commits

Reviewing files that changed from the base of the PR and between c4c211b and 2fab6d0.

📒 Files selected for processing (7)
  • Cargo.toml
  • Containerfile
  • Makefile
  • src/lib.rs
  • src/main.rs
  • src/worker/script.rs
  • src/worker/syscalls/ioctl.rs

Comment thread Containerfile
@@ -1,10 +1,8 @@
FROM registry.fedoraproject.org/fedora:43 as builder

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Minor Dockerfile lint fixes flagged by pipeline.

as should match FROM casing (AS) on line 1, and ENTRYPOINT should use JSON/exec form on line 62.

🧹 Proposed fix
-FROM registry.fedoraproject.org/fedora:43 as builder
+FROM registry.fedoraproject.org/fedora:43 AS builder
-ENTRYPOINT berserker
+ENTRYPOINT ["berserker"]

Also applies to: 62-62

🧰 Tools
🪛 GitHub Actions: Main berserker CI / 0_build-and-push.txt

[warning] 1-1: Dockerfile lint warning: FromAsCasing - 'as' and 'FROM' keywords' casing do not match.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Containerfile` at line 1, Fix the Dockerfile lint issues by updating the
stage alias in the top-level FROM instruction to use matching uppercase AS, and
change the ENTRYPOINT in the Containerfile to JSON/exec form instead of shell
form. Use the FROM and ENTRYPOINT instructions in this file as the targets for
the cleanup.

Source: Pipeline failures

Comment thread Containerfile
Comment on lines +45 to +50
RUN if [ "${RUST_VERSION}" == "nightly" ]; then \
TARGET=$(rustc --version --verbose | grep host | cut -d" " -f2) && \
RUSTFLAGS="-Z sanitizer=address" cargo +nightly test -Z build-std --target "$TARGET"; \
else \
cargo test; \
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Nightly ASAN run never enables the crate's nightly Cargo feature.

This branch runs cargo +nightly test -Z build-std ... but doesn't pass --features nightly, so #![cfg_attr(feature = "nightly", feature(sanitize))] in src/lib.rs stays disabled during the ASAN run, defeating the purpose of the new feature gate.

🔧 Proposed fix
 RUN if [ "${RUST_VERSION}" == "nightly" ]; then \
         TARGET=$(rustc --version --verbose | grep host | cut -d" " -f2) && \
-        RUSTFLAGS="-Z sanitizer=address" cargo +nightly test -Z build-std --target "$TARGET"; \
+        RUSTFLAGS="-Z sanitizer=address" cargo +nightly test --features nightly -Z build-std --target "$TARGET"; \
     else \
         cargo test; \
     fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RUN if [ "${RUST_VERSION}" == "nightly" ]; then \
TARGET=$(rustc --version --verbose | grep host | cut -d" " -f2) && \
RUSTFLAGS="-Z sanitizer=address" cargo +nightly test -Z build-std --target "$TARGET"; \
else \
cargo test; \
fi
RUN if [ "${RUST_VERSION}" == "nightly" ]; then \
TARGET=$(rustc --version --verbose | grep host | cut -d" " -f2) && \
RUSTFLAGS="-Z sanitizer=address" cargo +nightly test --features nightly -Z build-std --target "$TARGET"; \
else \
cargo test; \
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Containerfile` around lines 45 - 50, The nightly ASAN test branch in the
Containerfile is missing the crate’s `nightly` Cargo feature, so the `sanitize`
feature gate in `src/lib.rs` never turns on. Update the `cargo +nightly test`
invocation in this RUN block to include the crate’s `nightly` feature alongside
the existing `-Z build-std` and `RUSTFLAGS="-Z sanitizer=address"` settings, so
the ASAN path actually exercises the intended nightly-only code.

Comment thread Makefile
Comment on lines 9 to +10
docker build -t berserker -f Containerfile .
docker build -t berserker -f Containerfile --build-arg=RUST_VERSION=nightly .

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== Files ==\n'
git ls-files | rg '(^|/)(Makefile|Containerfile|Dockerfile|README.md)$'

printf '\n== Makefile (mapped) ==\n'
ast-grep outline Makefile --view expanded || true

printf '\n== Makefile with line numbers ==\n'
cat -n Makefile | sed -n '1,120p'

printf '\n== Containerfile with line numbers ==\n'
cat -n Containerfile | sed -n '1,220p'

printf '\n== Search for berserker tag usage ==\n'
rg -n 'berserker|RUST_VERSION=nightly|build-and-push|docker build' -S .

Repository: stackrox/berserker

Length of output: 8595


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== README build / image references ==\n'
rg -n 'make |docker build|docker run|latest|BERSERKER_TAG|tag:' README.md Makefile Containerfile Containerfile.test scripts -S

printf '\n== README excerpt around usage ==\n'
cat -n README.md | sed -n '1,140p'

Repository: stackrox/berserker

Length of output: 5722


Makefile:9-10 — Use a separate tag for the nightly build. The second docker build -t berserker ... --build-arg=RUST_VERSION=nightly overwrites the first image, so berserker:latest ends up pointing at the nightly build. That means the later test/network images consume the nightly toolchain image, and the stable build is never used.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 9 - 10, The Makefile’s two docker build steps
currently reuse the same berserker tag, so the nightly build overwrites the
stable image. Update the second docker build invocation to use a distinct tag
for the nightly variant while keeping the first build as the default berserker
image, so later steps consume the intended stable image; make this change in the
build commands near the two docker build lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants