Skip to content

Fix: Auidit report changes#19

Merged
mrLSD merged 5 commits into
masterfrom
auido-2026-05-31
Jun 1, 2026
Merged

Fix: Auidit report changes#19
mrLSD merged 5 commits into
masterfrom
auido-2026-05-31

Conversation

@mrLSD

@mrLSD mrLSD commented May 31, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Bounded execution with a step limit to prevent non-terminating runs.
    • Correct LR/SC reservation semantics and alignment pre-checks for atomic ops.
    • ELF loading now uses program segments (PT_LOAD) for execution.
    • CLI shows dynamic version/author info.
  • Bug Fixes

    • Instruction decode and immediate/shamt extraction fixes.
    • Corrected division/remainder edge-case and word-sized AMO behavior.
  • Tests

    • Expanded unit/integration tests for CLI, decoding, execution, atomics, and ELF handling.
  • Chores

    • CI migrated to GitHub Actions with coverage upload; project version and docs updated; .gitignore expanded.

mrLSD added 4 commits May 31, 2026 02:54
      DecodeA64: .D atomics used decimal funct5 + rs2=rs1; add 0b prefix and use rs2
      DecodeI: RV64 shamt now 6-bit (inst[25:20]); ExecuteM64: DIVUW/REMUW use low-32 uint32
      Add edge-case tests for .D atomics, shamt 32/63, DIVUW/REMUW high bits
  ExecuteA/A64: LR/SC reservation so SC can fail, 32-bit AMO.W rs2, trap misaligned atomics
  Run.fs: load all PT_LOAD segments (code/data/zero-filled bss) for 32- and 64-bit ELF
  Add tests: LR/SC, AMO.W width, alignment, ELF32/64 load, runCycle integration
…test coverage

  Robustness: run-loop step-limit (StepLimit trap), ELF/run exception handling, RV32 DIV/REM overflow check, -v trace
  Fixes: CLI long-key value arg-index, immutable setRegister (Array.copy); hygiene (module rename, typo, StartsWith, doc
  comments)
  Version: <Version>0.5.0 in fsproj as single source, read from assembly + dynamic year; DecodeM tuple match -> 100% line
  coverage
@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b60a58f1-9947-406d-a6ae-a2cb37940bd6

📥 Commits

Reviewing files that changed from the base of the PR and between 9f7b46a and 9679553.

📒 Files selected for processing (2)
  • Program.fs
  • risc-v.fsproj
💤 Files with no reviewable changes (1)
  • risc-v.fsproj
🚧 Files skipped from review as they are similar to previous changes (1)
  • Program.fs

📝 Walkthrough

Walkthrough

Implements LR/SC reservation semantics and alignment checks for A-extension, fixes decoding and arithmetic bugs, switches ELF loading to PT_LOAD, adds bounded execution with a StepLimit, updates CLI/versioning and CI to collect/upload coverage, and adds extensive unit and integration tests validating these behaviors.

Changes

RISC-V Simulator Atomics and Corrections

Layer / File(s) Summary
Arch trap types and machine state reservation
Arch.fs, MachineState.fs
TrapErrors gains StepLimit. MachineState adds Reservation : int64 option, setReservation/clearReservation, and setRegister becomes non-mutating (array copy).
RV32 atomic LR.W/SC.W and AMO word operations
ExecuteA.fs
execLR_W records reservation; execSC_W conditionally stores on reservation match and returns 0/1; AMO min/max use int32/uint32 semantics; pre-dispatch 4-byte alignment trap added.
RV64 atomic LR.D/SC.D and AMO double operations
ExecuteA64.fs
execLR_D records reservation; execSC_D conditionally stores on reservation match and returns 0/1; pre-dispatch 8-byte alignment trap added.
Instruction decoding bugfixes
DecodeA64.fs, DecodeI.fs, DecodeM.fs
Fixes A64 rs2 extraction for LR_D/SC_D/AMO; corrects non-RV32 shamt slice from 24..20 to 25..20; refactors RV32M decode to (funct7,funct3) tuple matching.
Execution arithmetic and operand corrections
ExecuteM.fs, ExecuteM64.fs
RV32 DIV/REM use correct negative min (-2147483648L); RV64 DIVUW/REMUW perform operations on uint32 operands.
ELF loading and bounded execution loop
Run.fs
Switches to PT_LOAD segment-based ELF loading, adds readElfFile variant and runSteps bounded loop; runCycle delegates to runSteps 10_000_000 and yields StepLimit on exhaustion.
CLI versioning and argument parsing improvements
CLI.fs, Program.fs
version/author derived from assembly/DateTime; option token detection uses StartsWith "-"; main wrapped in try/with to print load/run errors with file context.
Project configuration and build infrastructure
.github/workflows/dotnet.yml, .travis.yml, .gitignore, risc-v.fsproj, Tests/Tests.fsproj, README.md
Replaces Travis with GitHub Actions including Codecov upload; extends .gitignore; bumps package version and adds coverlet.collector; updates README badges and supported .NET text.
ELF loader and execution integration tests
Tests/run/run.fs, Tests/rv64a/amo.fs
Adds tests validating PT_LOAD loading with .bss zero-fill, runCycle behavior (EBREAK stop and unmapped fetch trap), and non-ELF error handling; renames rv32a amo module to rv64a.
RV64A atomic instruction test coverage
Tests/rv64a/amoD.fs, Tests/rv64a/amoSem.fs
Adds comprehensive RV64A tests covering LR.D/SC.D, AMO.D variants, reservation semantics, low-32-bit operand behavior, and misalignment traps.
RV64 shift and division operand width tests
Tests/rv64i/alui.fs, Tests/rv64m/alu.fs
Adds RV64 shift-immediate tests for large shamt (32, 63) and DIVUW/REMUW low-32-bit behavior tests.
Unit tests for core simulator functionality
Tests/unit/units.fs, Tests/unit/cli.fs, Tests/unit/decode.fs, Tests/unit/execute.fs, Tests/unit/app.fs
Adds extensive unit tests for architecture parsing, int64 helpers, memory ops, CLI parsing semantics, decoder None cases, execution traps/AMO behavior, runSteps budgeting, and CLI/main behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

.NET

Poem

🐰 Atomic hops now stay reserved,
Steps counted so the loop is curbed;
Registers copied, races tamed,
LR/SC semantics rightly named.
Tests bloom bright where fixes served.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title contains a typo ('Auidit' instead of 'Audit') and is vague; it does not clearly describe the primary change in this multi-file changeset involving atomic instruction fixes, test coverage, CI/CD updates, and execution logic improvements. Clarify the title to reflect the main objectives, e.g., 'Implement atomic instruction semantics and add comprehensive test coverage' or similar, and correct the spelling of 'Audit' if intended.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch auido-2026-05-31

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@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: 4

🧹 Nitpick comments (2)
Tests/run/run.fs (1)

105-113: 💤 Low value

Consider using Assert.Throws for clearer exception testing.

The current approach works but is less idiomatic for xUnit. Using Assert.Throws<exn> would make the test intent clearer and provide better failure messages.

♻️ Suggested refactor
 [<Fact>]
 let ``readElfFile throws on a non-ELF file`` () =
-    let path = Path.GetTempFileName()
-    try
-        File.WriteAllBytes(path, [| 0uy; 1uy; 2uy; 3uy |])
-        let threw = try (Run.readElfFile path |> ignore; false) with _ -> true
-        Assert.True(threw)
-    finally
-        File.Delete path
+    withTempElf [| 0uy; 1uy; 2uy; 3uy |] (fun path ->
+        Assert.ThrowsAny<exn>(fun () -> Run.readElfFile path |> ignore) |> ignore)
🤖 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 `@Tests/run/run.fs` around lines 105 - 113, Replace the manual try/with boolean
flag with xUnit's Assert.Throws to make the test clearer: in the test
``readElfFile throws on a non-ELF file`` call Assert.Throws<exn>(fun () ->
Run.readElfFile path |> ignore) (keeping the File.WriteAllBytes setup and
File.Delete cleanup in the finally block) so the assertion directly checks that
Run.readElfFile throws an exception.
risc-v.fsproj (1)

21-24: ⚡ Quick win

Consider removing coverlet.collector from the main project.

coverlet.collector is a test-time dependency and is already included in Tests/Tests.fsproj (lines 11-14). Adding it to the main executable project (risc-v.fsproj) is unconventional and may be unnecessary duplication. Coverage collection is typically handled by the test project alone.

♻️ Proposed fix to remove the duplicate dependency
     <ItemGroup>
-        <PackageReference Include="coverlet.collector" Version="10.0.1">
-          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
-          <PrivateAssets>all</PrivateAssets>
-        </PackageReference>
         <PackageReference Include="ELFSharp" Version="2.17.3" />
         <PackageReference Update="FSharp.Core" Version="10.0.107" />
     </ItemGroup>
🤖 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 `@risc-v.fsproj` around lines 21 - 24, Remove the test-only package reference
from the main project: delete the PackageReference element for
"coverlet.collector" in the risc-v.fsproj file (the block containing
Include="coverlet.collector" Version="10.0.1"), since coverage is already
declared in Tests/Tests.fsproj and this duplication is unnecessary; after
removal, restore/verify builds and test coverage run from the test project only.
🤖 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 @.github/workflows/dotnet.yml:
- Around line 29-32: The GitHub Actions step named "Upload coverage reports to
Codecov" currently pins the action by tag (`uses: codecov/codecov-action@v5`);
replace that tag with the corresponding commit SHA for the desired release
(e.g., `uses: codecov/codecov-action@<commit-sha>`) to prevent supply-chain
drift, leaving the token input (`token: ${{ secrets.CODECOV_TOKEN }}`)
unchanged; obtain the exact SHA from the codecov/codecov-action releases page
and update the `uses:` value in the same step.

In `@CLI.fs`:
- Around line 6-10: The current version computation uses
GetExecutingAssembly().GetName().Version which can be null; update the let
version binding to handle a null Version by checking the returned value (symbol:
version and local v) and falling back to a safe default string like "v0.0.0" (or
use individual null-coalesced numbers), e.g. match v with null -> fallback | _
-> sprintf "v%d.%d.%d" v.Major v.Minor v.Build; ensure you only access
v.Major/v.Minor/v.Build when v is non-null to avoid NullReferenceException.

In `@Program.fs`:
- Around line 16-20: The error handler accesses x.Files.Value.[0] without
ensuring the array is non-empty, which can raise IndexOutOfRangeException;
update the with ex -> block (the exception handling for Run.Run x) to safely
obtain a first-file string by checking x.Files (and the inner array length) or
pattern-matching the array and falling back to a placeholder like "<no files>"
before using it in the printfn error message so the logger never indexes an
empty array.

In `@README.md`:
- Line 130: The Markdown heading jumps two levels (from h2 to "#### Supported
`.NET 10`"); change the heading level to increment by one by replacing "####
Supported `.NET 10`" with "### Supported `.NET 10`" so it follows the previous
h2/h3 sequence and adheres to proper heading hierarchy.

---

Nitpick comments:
In `@risc-v.fsproj`:
- Around line 21-24: Remove the test-only package reference from the main
project: delete the PackageReference element for "coverlet.collector" in the
risc-v.fsproj file (the block containing Include="coverlet.collector"
Version="10.0.1"), since coverage is already declared in Tests/Tests.fsproj and
this duplication is unnecessary; after removal, restore/verify builds and test
coverage run from the test project only.

In `@Tests/run/run.fs`:
- Around line 105-113: Replace the manual try/with boolean flag with xUnit's
Assert.Throws to make the test clearer: in the test ``readElfFile throws on a
non-ELF file`` call Assert.Throws<exn>(fun () -> Run.readElfFile path |> ignore)
(keeping the File.WriteAllBytes setup and File.Delete cleanup in the finally
block) so the assertion directly checks that Run.readElfFile throws an
exception.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 58a40d32-707f-4b00-9195-a32d02b89aff

📥 Commits

Reviewing files that changed from the base of the PR and between 476b78f and cf7bfdf.

📒 Files selected for processing (29)
  • .github/workflows/dotnet.yml
  • .gitignore
  • .travis.yml
  • Arch.fs
  • CLI.fs
  • DecodeA64.fs
  • DecodeI.fs
  • DecodeM.fs
  • ExecuteA.fs
  • ExecuteA64.fs
  • ExecuteM.fs
  • ExecuteM64.fs
  • MachineState.fs
  • Program.fs
  • README.md
  • Run.fs
  • Tests/Tests.fsproj
  • Tests/run/run.fs
  • Tests/rv64a/amo.fs
  • Tests/rv64a/amoD.fs
  • Tests/rv64a/amoSem.fs
  • Tests/rv64i/alui.fs
  • Tests/rv64m/alu.fs
  • Tests/unit/app.fs
  • Tests/unit/cli.fs
  • Tests/unit/decode.fs
  • Tests/unit/execute.fs
  • Tests/unit/units.fs
  • risc-v.fsproj
💤 Files with no reviewable changes (1)
  • .travis.yml

Comment thread .github/workflows/dotnet.yml
Comment thread CLI.fs
Comment thread Program.fs Outdated
Comment thread README.md
@mrLSD mrLSD force-pushed the auido-2026-05-31 branch from 9f7b46a to 9679553 Compare June 1, 2026 15:15
@mrLSD mrLSD added this to the v0.5.0 milestone Jun 1, 2026
@mrLSD mrLSD merged commit 31983ca into master Jun 1, 2026
4 checks passed
@mrLSD mrLSD deleted the auido-2026-05-31 branch June 1, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant