Skip to content
Open
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
31 changes: 29 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,44 @@ jobs:
- ubuntu-latest
arch:
- x64
# Coverage of this repository and bounds checks of its @inbounds code on one job only: each
# set of flags needs its own build of all dependencies (8 min on 1.12, #216)
include:
- version: '1'
coverage: --code-coverage=@${{ github.workspace }}
check_bounds: --check-bounds=yes
steps:
- uses: actions/checkout@v7
- uses: julia-actions/setup-julia@v3
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v3
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- name: Instantiate the test environment
shell: julia --project=test --color=yes {0}
env:
JULIA_PKG_PRECOMPILE_AUTO: "0"
run: |
using Pkg
Pkg.instantiate()
# Tests do not need fast first calls, and every change of BMO would compile the workloads again.
# Not a file of the repository, such that local test runs keep them; the docs build with them
- name: Switch off the precompile workloads
run: printf '[BeamletOptics]\nprecompile_workload = false\n' > test/LocalPreferences.toml
# A step of its own, such that the log shows its time and the workers do not wait for it.
# Without coverage: what was precompiled under it was compiled again in every run (#216)
- name: Precompile
run: julia --project=test --color=yes ${{ matrix.check_bounds }} -e 'using Pkg; Pkg.precompile()'
# The test environment on the load path, such that the preference also holds in the environment
# in which Aqua precompiles the package (persistent tasks)
- name: Run tests
env:
JULIA_LOAD_PATH: "@:${{ github.workspace }}/test:@stdlib"
run: julia --project=test --color=yes ${{ matrix.check_bounds }} ${{ matrix.coverage }} test/runtests.jl --jobs=4
- uses: julia-actions/julia-processcoverage@v1
if: matrix.coverage
- uses: codecov/codecov-action@v7
if: matrix.coverage
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
20 changes: 17 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,25 @@ agent has to ask again.
## Tests

- Single test module: `julia --project=test -e 'using Pkg; Pkg.instantiate()'` once, then
`julia --project=test test/<path>.jl`. Run the modules of the code you change.
`julia --project=test test/<path>.jl`. Run the modules of the code you change. After a change
of `test/Project.toml`, an existing `Manifest.toml` needs `Pkg.resolve()` before that.
- Full suite: `julia --project=. -e 'using Pkg; Pkg.test()'`, once before handing over.
[test/runtests.jl](test/runtests.jl) runs the test files in parallel worker processes
(ParallelTestRunner.jl); `julia --project=test test/runtests.jl --help` lists its options
(`--jobs=N`, a subset of tests by name prefix). The default number of workers is limited by
free memory (2 GiB each) and may drop to 1; set it with `Pkg.test(; test_args = ["--jobs=4"])`
or `PTR_NUM_JOBS`.
- CI runs the tests without the precompile workloads: the step "Switch off the precompile
workloads" sets the preference `precompile_workload` of BMO, which the workload of the Makie
extension reads as well. Coverage and `--check-bounds=yes` run on the Julia 1 job only, since
each set of flags needs its own build of all dependencies. A test must not depend on how fast
its first call is.
- Test-only dependencies go into `test/Project.toml`, never the root `Project.toml`.
- New test files are `module TestXyz ... end`, included in [test/runtests.jl](test/runtests.jl).
`Rendering/TestRenderErrors.jl` must run before anything loads the Makie extension.
- New test files are `module TestXyz ... end` anywhere under `test/`; they are found
automatically and must not depend on other test files or on their order.
`Rendering/TestRenderErrors.jl` runs in a fresh worker because it needs a process that never
loaded the Makie extension; a new test with such a need goes into `makie_free_tests` of
`runtests.jl`.

## Agent skill

Expand Down
6 changes: 4 additions & 2 deletions docs/src/api/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ We would also love to feature your work with this package as part of the **Examp

## Running the tests

To run the full test suite, use `] test` in the package environment. To run a single test
To run the full test suite, use `] test` in the package environment; the test files run in
parallel worker processes. To run a single test
file standalone, run `julia --project=test -e 'using Pkg; Pkg.instantiate()'` once, then
`julia --project=test test/<path>.jl`. Tests live in a Pkg workspace subproject
`julia --project=test test/<path>.jl`; if `test/Project.toml` changed since then, run
`Pkg.resolve()` before `Pkg.instantiate()`. Tests live in a Pkg workspace subproject
(`test/Project.toml`); new test-only dependencies are added there, not to the root
`Project.toml`.

Expand Down
4 changes: 3 additions & 1 deletion ext/BeamletOpticsMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Makie
using Makie: Figure, Axis3, LScene, mesh!, surface!, lines!, linesegments!, RGBf, RGBAf, scatter!, text!,
update_cam!, cameracontrols, arrows3d!
using PrecompileTools: @setup_workload, @compile_workload
using Preferences: load_preference
using GeometryBasics: Point2, Point3, Point3f, Point3d, Vec3f, Vec3d, GLTriangleFace, Mesh
using StaticArrays: SMatrix
using Base.ScopedValues: ScopedValue, with
Expand Down Expand Up @@ -74,6 +75,7 @@ include("RenderCamera.jl")
# live rendering, must come after all static renderers
include("RenderLive.jl")
# precompiles the static and live rendering, must come last
include("RenderPrecompile.jl")
# PrecompileTools does not find the preference for an extension: the one of BMO switches off both
load_preference(BeamletOptics, "precompile_workload", true) && include("RenderPrecompile.jl")

end
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
OpticsBase = "0a174593-c395-4975-8599-97e6c4e949e6"
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Expand All @@ -23,4 +24,5 @@ GeometryBasics = "0.5"
Logging = "1"
Makie = "0.24"
OpticsBase = "0.1"
ParallelTestRunner = "2.10"
Test = "1"
97 changes: 8 additions & 89 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,92 +1,11 @@
# order or inclusion matters!
include(joinpath(@__DIR__, "TestUtils.jl"))
include(joinpath(@__DIR__, "TestAbstractTypes.jl"))
# Every file in test/ is a self-contained test module, run in parallel worker processes.
# Usage: julia --project=test test/runtests.jl [--jobs=N] [--list] [TESTS...]
using BeamletOptics
using ParallelTestRunner

# Test ray and beam types
include(joinpath(@__DIR__, "TestRays.jl"))
include(joinpath(@__DIR__, "TestPolarizedRays.jl"))
include(joinpath(@__DIR__, "TestBeams.jl"))
include(joinpath(@__DIR__, "TestBeamGroups.jl"))
include(joinpath(@__DIR__, "TestPathSegments.jl"))
include(joinpath(@__DIR__, "TestGaussianBeamlet.jl"))
include(joinpath(@__DIR__, "TestAstigmaticGaussianBeamlet.jl"))
include(joinpath(@__DIR__, "TestAstigmaticGaussianPhysical.jl"))
include(joinpath(@__DIR__, "TestAstigmaticGaussianSources.jl"))
include(joinpath(@__DIR__, "TestBeamletDecompositions.jl"))
include(joinpath(@__DIR__, "TestSourceKinematics.jl"))
include(joinpath(@__DIR__, "TestKinematicTrait.jl"))
# MUST run in a fresh worker: tests the errors of render! before the BMO Makie ext is loaded
const makie_free_tests = ("Rendering/TestRenderErrors",)

# Test geometry representation
include(joinpath(@__DIR__, "Geometry", "TestMesh.jl"))
include(joinpath(@__DIR__, "Geometry", "TestBoundingSphere.jl"))
include(joinpath(@__DIR__, "Geometry", "SDFs", "TestAbstractSDF.jl"))
include(joinpath(@__DIR__, "Geometry", "SDFs", "TestUnionSDF.jl"))
include(joinpath(@__DIR__, "Geometry", "SDFs", "TestDifferenceSDF.jl"))
include(joinpath(@__DIR__, "Geometry", "SDFs", "TestConicSDF.jl"))
include(joinpath(@__DIR__, "Geometry", "SDFs", "TestSDFBoundingSpheres.jl"))

# Test system and object containers
include(joinpath(@__DIR__, "TestSystem.jl"))
include(joinpath(@__DIR__, "TestObjectGroups.jl"))
include(joinpath(@__DIR__, "TestSharedParts.jl"))
include(joinpath(@__DIR__, "TestProperties.jl"))

# Test lens models
include(joinpath(@__DIR__, "Lenses", "TestSphericalLenses.jl"))
include(joinpath(@__DIR__, "Lenses", "TestSurfaces.jl"))
include(joinpath(@__DIR__, "Lenses", "TestAsphericalLenses.jl"))
include(joinpath(@__DIR__, "Lenses", "TestCylindricalLenses.jl"))

# Test component models
include(joinpath(@__DIR__, "Components", "TestDummies.jl"))
include(joinpath(@__DIR__, "Components", "TestDetectorUtils.jl"))
include(joinpath(@__DIR__, "Components", "TestDetector.jl"))
include(joinpath(@__DIR__, "Components", "TestHitBuffers.jl"))
include(joinpath(@__DIR__, "Components", "TestDetectorSampling.jl"))
include(joinpath(@__DIR__, "Components", "TestBeamsplitters.jl"))
include(joinpath(@__DIR__, "Components", "TestPolarizers.jl"))
include(joinpath(@__DIR__, "Components", "TestPrisms.jl"))
include(joinpath(@__DIR__, "Components", "ConicMirrors", "TestConicMirror.jl"))
include(joinpath(@__DIR__, "Components", "ConicMirrors", "TestParabolicMirror.jl"))
include(joinpath(@__DIR__, "Components", "ConicMirrors", "TestEllipsoidalMirror.jl"))
include(joinpath(@__DIR__, "Components", "ConicMirrors", "TestHyperbolicMirror.jl"))

# Test automatic differentiation through the tracing
include(joinpath(@__DIR__, "TestAutoDiff.jl"))

# Test progress bars of long-running calls
include(joinpath(@__DIR__, "TestProgress.jl"))

# Test end-to-end models
include(joinpath(@__DIR__, "E2E", "TestDoubleGaussLens.jl"))
include(joinpath(@__DIR__, "E2E", "TestSonnarLens.jl"))
include(joinpath(@__DIR__, "E2E", "TestMichelson.jl"))
include(joinpath(@__DIR__, "E2E", "TestMachZehnder.jl"))
include(joinpath(@__DIR__, "E2E", "TestFraunhofer.jl"))
include(joinpath(@__DIR__, "E2E", "TestAnalyticReferences.jl"))
include(joinpath(@__DIR__, "TestBeamletFieldInMedia.jl"))

# Test rendering
# MUST stay first: TestRenderErrors.jl needs to run before anything loads the BMO Makie ext.
include(joinpath(@__DIR__, "Rendering", "TestRenderErrors.jl"))
include(joinpath(@__DIR__, "Rendering", "TestRenderPolarization.jl"))
include(joinpath(@__DIR__, "Rendering", "TestTessellation.jl"))
include(joinpath(@__DIR__, "Rendering", "TestRenderMirrors.jl"))
include(joinpath(@__DIR__, "Rendering", "TestRenderLook.jl"))
include(joinpath(@__DIR__, "Rendering", "TestRenderLive.jl"))
include(joinpath(@__DIR__, "Rendering", "TestRenderBoundingSphere.jl"))
include(joinpath(@__DIR__, "Rendering", "TestLiveBeams.jl"))
include(joinpath(@__DIR__, "Rendering", "TestWavelengthColor.jl"))

# Test regressions
include(joinpath(@__DIR__, "TestBugFixes.jl"))

# Test package extensions
include(joinpath(@__DIR__, "TestOpticsBaseExt.jl"))

# Test agent skill docs against the public API
include(joinpath(@__DIR__, "TestAgentSkill.jl"))

# Test misc.
include(joinpath(@__DIR__, "TestMisc.jl"))
worker_of(test::String) = test in makie_free_tests ? addworker() : nothing

runtests(BeamletOptics, ARGS; testsuite = find_tests(@__DIR__), test_worker = worker_of)
Loading