From 533d557d27f96b8dfc1cf816c6e5e1865b12eb19 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 28 Nov 2024 15:41:37 +0100 Subject: [PATCH 1/4] skeleton for tests --- test/Project.toml | 2 ++ test/runtests.jl | 5 +++++ test/test_interface.jl | 9 +++++++++ 3 files changed, 16 insertions(+) create mode 100644 test/Project.toml create mode 100644 test/runtests.jl create mode 100644 test/test_interface.jl diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..0c36332 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,2 @@ +[deps] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..249e919 --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,5 @@ +using Test + +@time @testset verbose=true showtiming=true "ParaViewCatalyst.jl tests" begin + include("test_interface.jl") +end diff --git a/test/test_interface.jl b/test/test_interface.jl new file mode 100644 index 0000000..d19c0de --- /dev/null +++ b/test/test_interface.jl @@ -0,0 +1,9 @@ +module TestInterface + +using Test +using ParaViewCatalyst + +@testset verbose=true showtiming=true "Initialization" begin + @test_throws AssertionError("\n set CATALYST_IMPLEMENTATION_PATHS environment variable to the path of your catalyst library\n or use the libpath parameter of catalyst_initialize") catalyst_initialize() +end +end From 86ce19d08125ddff7a73a2aa166025abd037767e Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 4 Dec 2024 15:09:12 +0100 Subject: [PATCH 2/4] add getindex for ConduitNode --- src/conduit.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/conduit.jl b/src/conduit.jl index be990b5..d5214b5 100644 --- a/src/conduit.jl +++ b/src/conduit.jl @@ -9,6 +9,10 @@ struct ConduitNode nptr = API.conduit_node_create() return new(nptr) end + + function ConduitNode(ptr::Ptr{API.conduit_node}) + return new(ptr) + end end Base.unsafe_convert(::Type{Ptr{API.conduit_node}}, node::ConduitNode) = node.ptr @@ -23,11 +27,24 @@ function ConduitNode(f::Function) end Base.setindex!(node::ConduitNode, val, path::String) = node_set!(node, path, val) +Base.getindex(node::ConduitNode, path::String) = node_get(node, path) + +function node_get(node::ConduitNode, path::String) + if !node_has_path(node, path) + throw(KeyError(path)) + end + node_at_path = API.conduit_node_fetch(node, path) + dtype = API.conduit_node_dtype(node_at_path) + dtypename = Symbol(unsafe_string(API.conduit_datatype_name(dtype))) + return node_get(node_at_path, Val(dtypename)) +end for numtype in (:UInt8, :Int8, :UInt16, :Int16, :UInt32, :Int32, :UInt64, :Int64, :Float32, :Float64) cnumtype = Symbol(lowercase("$(numtype)")) node_set_path = Symbol("conduit_node_set_path_$(cnumtype)") node_set_path_ptr = Symbol("conduit_node_set_path_$(cnumtype)_ptr") + node_as = Symbol("conduit_node_as_$(cnumtype)") + node_as_ptr = Symbol("conduit_node_as_$(cnumtype)_ptr") @eval begin function node_set!(node::ConduitNode, path::String, val::$numtype) API.$node_set_path(node, path, val) @@ -37,6 +54,12 @@ for numtype in (:UInt8, :Int8, :UInt16, :Int16, :UInt32, :Int32, :UInt64, :Int64 API.$node_set_path_ptr(node, path, pointer(val), length(val)) return node end + function node_get(nodeptr::Ptr{API.conduit_node}, ::$(Val{cnumtype})) + return API.$node_as(nodeptr) + end + function node_get(nodeptr::Ptr{API.conduit_node}, ::$(Val{Array{cnumtype}})) + return API.$node_as_ptr(nodeptr) + end end end @@ -50,6 +73,14 @@ function node_set!(node::ConduitNode, path::String, val::ConduitNode) return node end +function node_get(nodeptr::Ptr{API.conduit_node}, ::Val{:object}) + return ConduitNode(nodeptr) +end + +function node_get(nodeptr::Ptr{API.conduit_node}, ::Val{:char8_str}) + return unsafe_string(API.conduit_node_as_char8_str(nodeptr)) +end + function node_has_path(node::ConduitNode, path::String) return Bool(API.conduit_node_has_path(node, path)) end From 534c61ba025bcbb636ee05dc9dd8a16d2ee82aac Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 4 Dec 2024 15:41:01 +0100 Subject: [PATCH 3/4] add test using Catalyst_jll --- .github/workflows/ci.yml | 63 +++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 2 +- test/test_catalyst_jll.jl | 24 +++++++++++++++ test/test_interface.jl | 9 ------ 4 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 test/test_catalyst_jll.jl delete mode 100644 test/test_interface.jl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f11bc5e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,63 @@ +name: CI + +on: + push: + branches: + - main + paths-ignore: + - 'LICENSE.md' + - 'README.md' + - 'docs/**' + pull_request: + paths-ignore: + - 'LICENSE.md' + - 'README.md' + - 'docs/**' + workflow_dispatch: + inputs: + debug_enabled: + description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)' + required: false + default: "false" + +jobs: + test: + name: ${{ matrix.os }} - Julia ${{ matrix.julia_version }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + arch: + - x64 + julia_version: + - '1.10' + - '1.11' + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Enable Julia cache + uses: julia-actions/cache@v2 + + - name: Install Julia + uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.julia_version }} + arch: ${{ matrix.arch }} + show-versioninfo: true + + - name: Run Julia tests + uses: julia-actions/julia-runtest@v1 + with: + coverage: false + + # Enable tmate debugging of manually-triggered workflows if the input option was provided + - name: Setup tmate session for debugging + if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled && always() }} + uses: mxschmitt/action-tmate@v3 + timeout-minutes: 15 diff --git a/test/runtests.jl b/test/runtests.jl index 249e919..1ebf72b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using Test @time @testset verbose=true showtiming=true "ParaViewCatalyst.jl tests" begin - include("test_interface.jl") + include("test_catalyst_jll.jl") end diff --git a/test/test_catalyst_jll.jl b/test/test_catalyst_jll.jl new file mode 100644 index 0000000..f5ddd2f --- /dev/null +++ b/test/test_catalyst_jll.jl @@ -0,0 +1,24 @@ +module TestCatalyst_jll + +using Test +using ParaViewCatalyst +using ParaViewCatalyst.API + +# Manually override the usual initialization and +# - do not provide search paths +# - request the stub implementation +# This test should then pick up the catalyst library shipped with Catalyst_jll +@testset verbose=true showtiming=true "Check stub" begin + ConduitNode() do node + node["catalyst_load/implementation"] = "stub" + catalyst_initialize(node) + end + ConduitNode() do node + status = API.catalyst_about(node) + @test status === API.catalyst_status_ok + @test node["catalyst/implementation"] == "stub" + Conduit.node_print(node, detailed=false) + end + catalyst_finalize() +end +end diff --git a/test/test_interface.jl b/test/test_interface.jl deleted file mode 100644 index d19c0de..0000000 --- a/test/test_interface.jl +++ /dev/null @@ -1,9 +0,0 @@ -module TestInterface - -using Test -using ParaViewCatalyst - -@testset verbose=true showtiming=true "Initialization" begin - @test_throws AssertionError("\n set CATALYST_IMPLEMENTATION_PATHS environment variable to the path of your catalyst library\n or use the libpath parameter of catalyst_initialize") catalyst_initialize() -end -end From 897b3b941a0ceea38f4fc7abff7390e632c72b2e Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 4 Dec 2024 16:09:33 +0100 Subject: [PATCH 4/4] enable catalyst debug --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f11bc5e..ce751d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,8 @@ jobs: uses: julia-actions/julia-runtest@v1 with: coverage: false + env: + CATALYST_DEBUG: 1 # Enable tmate debugging of manually-triggered workflows if the input option was provided - name: Setup tmate session for debugging