diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index 056d30ca..7dc6ce0a 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -4,7 +4,7 @@ on: push: branches: - main - pull_request_target: + pull_request: branches: - main @@ -15,7 +15,7 @@ jobs: test: name: ${{ matrix.platform }} runs-on: ${{ matrix.platform }} - timeout-minutes: 10 + timeout-minutes: 20 strategy: fail-fast: false matrix: @@ -61,29 +61,3 @@ jobs: - name: Test working-directory: ${{github.workspace}}/build run: ctest -C ${{env.BUILD_TYPE}} -L acquire-driver-zarr --output-on-failure - - merge: - name: Automerge - runs-on: "ubuntu-latest" - needs: test - if: ${{ github.actor == 'dependabot[bot]' }} - steps: - - name: Checkout PR - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - - - name: Approve PR - run: gh pr review --approve "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GH_TOKEN: ${{ secrets.PAT }} - - # Don't auto-merge major version updates - - name: Merge PR - if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }} - run: gh pr merge --auto --squash "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GH_TOKEN: ${{ secrets.PAT }} diff --git a/src/common/dimension.cpp b/src/common/dimension.cpp index 4e3154cb..e724acdd 100644 --- a/src/common/dimension.cpp +++ b/src/common/dimension.cpp @@ -1,19 +1,37 @@ #include "dimension.hh" -#include -#include -#include "utilities.hh" -#include "zarr.hh" -#include "platform.h" +#include namespace zarr = acquire::sink::zarr; +namespace { +inline std::string +trim(const std::string& s) +{ + // trim left + std::string trimmed = s; + trimmed.erase(trimmed.begin(), + std::find_if(trimmed.begin(), trimmed.end(), [](char c) { + return !std::isspace(c); + })); + + // trim right + trimmed.erase(std::find_if(trimmed.rbegin(), + trimmed.rend(), + [](char c) { return !std::isspace(c); }) + .base(), + trimmed.end()); + + return trimmed; +} +} // namespace + zarr::Dimension::Dimension(const std::string& name, DimensionType kind, uint32_t array_size_px, uint32_t chunk_size_px, uint32_t shard_size_chunks) - : name{ name } + : name{ trim(name) } , kind{ kind } , array_size_px{ array_size_px } , chunk_size_px{ chunk_size_px } @@ -22,6 +40,7 @@ zarr::Dimension::Dimension(const std::string& name, EXPECT(kind < DimensionTypeCount, "Invalid dimension type."); EXPECT(!name.empty(), "Dimension name cannot be empty."); } + zarr::Dimension::Dimension(const StorageDimension& dim) : Dimension(dim.name.str, dim.kind, @@ -30,3 +49,31 @@ zarr::Dimension::Dimension(const StorageDimension& dim) dim.shard_size_chunks) { } + +#ifndef NO_UNIT_TESTS +#ifdef _WIN32 +#define acquire_export __declspec(dllexport) +#else +#define acquire_export +#endif // _WIN32 + +extern "C" acquire_export int +unit_test__trim() +{ + try { + EXPECT(trim(" foo") == "foo", "Failed to trim left."); + EXPECT(trim("foo ") == "foo", "Failed to trim right."); + EXPECT(trim(" foo ") == "foo", "Failed to trim both."); + EXPECT(trim("foo") == "foo", "Failed to trim either."); + EXPECT(trim("").empty(), "Failed to trim empty."); + return 1; + } catch (const std::exception& e) { + LOGE("Exception: %s", e.what()); + } catch (...) { + LOGE("Unknown exception"); + } + + return 0; +} + +#endif // NO_UNIT_TESTS diff --git a/src/common/dimension.hh b/src/common/dimension.hh index 646cd19f..7cf14188 100644 --- a/src/common/dimension.hh +++ b/src/common/dimension.hh @@ -1,6 +1,6 @@ -#ifndef H_ACQUIRE_STORAGE_ZARR_COMMON_DIMENSION_V0 -#define H_ACQUIRE_STORAGE_ZARR_COMMON_DIMENSION_V0 +#pragma once +#include "macros.hh" #include "device/props/storage.h" #include @@ -14,6 +14,7 @@ struct Dimension unsigned int array_size_px, unsigned int chunk_size_px, unsigned int shard_size_chunks); + explicit Dimension(const StorageDimension& dim); const std::string name; @@ -23,4 +24,3 @@ struct Dimension const unsigned int shard_size_chunks; }; } // namespace acquire::sink::zarr -#endif // H_ACQUIRE_STORAGE_ZARR_COMMON_DIMENSION_V0 diff --git a/src/common/macros.hh b/src/common/macros.hh new file mode 100644 index 00000000..b4a5c263 --- /dev/null +++ b/src/common/macros.hh @@ -0,0 +1,20 @@ +#pragma once + +#include "logger.h" +#include + +#define LOG(...) aq_logger(0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) +#define LOGE(...) aq_logger(1, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) +#define EXPECT(e, ...) \ + do { \ + if (!(e)) { \ + LOGE(__VA_ARGS__); \ + throw std::runtime_error("Expression was false: " #e); \ + } \ + } while (0) +#define CHECK(e) EXPECT(e, "Expression evaluated as false:\n\t%s", #e) + +#define TRACE(...) + +#define containerof(ptr, T, V) ((T*)(((char*)(ptr)) - offsetof(T, V))) +#define countof(e) (sizeof(e) / sizeof(*(e))) \ No newline at end of file diff --git a/src/common/thread.pool.cpp b/src/common/thread.pool.cpp index 79a57eb5..0071fbff 100644 --- a/src/common/thread.pool.cpp +++ b/src/common/thread.pool.cpp @@ -4,20 +4,19 @@ namespace zarr = acquire::sink::zarr; namespace common = zarr::common; -common::ThreadPool::ThreadPool(size_t n_threads, +common::ThreadPool::ThreadPool(unsigned int n_threads, std::function err) : error_handler_{ err } , is_accepting_jobs_{ true } { n_threads = std::clamp( - n_threads, - (size_t)1, - (size_t)std::max(std::thread::hardware_concurrency(), (unsigned)1)); + n_threads, 1u, std::max(std::thread::hardware_concurrency(), 1u)); for (auto i = 0; i < n_threads; ++i) { threads_.emplace_back([this] { thread_worker_(); }); } } + common::ThreadPool::~ThreadPool() noexcept { { @@ -29,26 +28,26 @@ common::ThreadPool::~ThreadPool() noexcept await_stop(); } + void common::ThreadPool::push_to_job_queue(JobT&& job) { std::unique_lock lock(jobs_mutex_); CHECK(is_accepting_jobs_); - jobs_.push(std::move(job)); - lock.unlock(); cv_.notify_one(); } + void common::ThreadPool::await_stop() noexcept { { std::scoped_lock lock(jobs_mutex_); is_accepting_jobs_ = false; - } - cv_.notify_all(); + cv_.notify_all(); + } // spin down threads for (auto& thread : threads_) { @@ -57,6 +56,7 @@ common::ThreadPool::await_stop() noexcept } } } + std::optional common::ThreadPool::pop_from_job_queue_() noexcept { @@ -68,11 +68,13 @@ common::ThreadPool::pop_from_job_queue_() noexcept jobs_.pop(); return job; } + bool common::ThreadPool::should_stop_() const noexcept { return !is_accepting_jobs_ && jobs_.empty(); } + void common::ThreadPool::thread_worker_() { diff --git a/src/common/thread.pool.hh b/src/common/thread.pool.hh index ac29ae9d..a5e24c01 100644 --- a/src/common/thread.pool.hh +++ b/src/common/thread.pool.hh @@ -20,7 +20,7 @@ struct ThreadPool final // std::string& argument to the error handler is a diagnostic message from // the failing job and is logged to the error stream by the Zarr driver when // the next call to `append()` is made. - ThreadPool(size_t n_threads, std::function err); + ThreadPool(unsigned int n_threads, std::function err); ~ThreadPool() noexcept; void push_to_job_queue(JobT&& job); diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp index af4bf976..63b98f94 100644 --- a/src/common/utilities.cpp +++ b/src/common/utilities.cpp @@ -166,28 +166,22 @@ common::bytes_per_chunk(const std::vector& dimensions, return n_bytes; } -const char* -common::sample_type_to_dtype(SampleType t) - -{ - static const char* table[] = { "u1", "u2", "i1", "i2", - "f4", "u2", "u2", "u2" }; - if (t < countof(table)) { - return table[t]; - } else { - throw std::runtime_error("Invalid sample type."); - } -} - const char* common::sample_type_to_string(SampleType t) noexcept { - static const char* table[] = { "u8", "u16", "i8", "i16", - "f32", "u16", "u16", "u16" }; - if (t < countof(table)) { - return table[t]; - } else { - return "unrecognized pixel type"; + switch (t) { + case SampleType_u8: + return "u8"; + case SampleType_u16: + return "u16"; + case SampleType_i8: + return "i8"; + case SampleType_i16: + return "i16"; + case SampleType_f32: + return "f32"; + default: + return "unrecognized pixel type"; } } @@ -207,15 +201,11 @@ common::split_uri(const std::string& uri) auto end = uri.find_first_of(delim); std::vector out; - while (end <= std::string::npos) { + while (end != std::string::npos) { if (end > begin) { out.emplace_back(uri.substr(begin, end - begin)); } - if (end == std::string::npos) { - break; - } - begin = end + 1; end = uri.find_first_of(delim, begin); } diff --git a/src/common/utilities.hh b/src/common/utilities.hh index 5ce35e37..1290c53e 100644 --- a/src/common/utilities.hh +++ b/src/common/utilities.hh @@ -4,6 +4,7 @@ #include "logger.h" #include "device/props/components.h" #include "device/props/storage.h" +#include "macros.hh" #include "dimension.hh" #include @@ -15,23 +16,6 @@ #include #include -#define LOG(...) aq_logger(0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) -#define LOGE(...) aq_logger(1, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) -#define EXPECT(e, ...) \ - do { \ - if (!(e)) { \ - LOGE(__VA_ARGS__); \ - throw std::runtime_error("Expression was false: " #e); \ - } \ - } while (0) -#define CHECK(e) EXPECT(e, "Expression evaluated as false:\n\t%s", #e) - -// #define TRACE(...) LOG(__VA_ARGS__) -#define TRACE(...) - -#define containerof(ptr, T, V) ((T*)(((char*)(ptr)) - offsetof(T, V))) -#define countof(e) (sizeof(e) / sizeof(*(e))) - namespace fs = std::filesystem; namespace acquire::sink::zarr { @@ -96,13 +80,6 @@ size_t bytes_per_chunk(const std::vector& dimensions, const SampleType& dtype); -/// @brief Get the Zarr dtype for a given SampleType. -/// @param t An enumerated sample type. -/// @throw std::runtime_error if @par t is not a valid SampleType. -/// @return A representation of the SampleType @par t expected by a Zarr reader. -const char* -sample_type_to_dtype(SampleType t); - /// @brief Get a string representation of the SampleType enum. /// @param t An enumerated sample type. /// @return A human-readable representation of the SampleType @par t. diff --git a/src/zarr.v2.cpp b/src/zarr.v2.cpp index eabed67b..73b80444 100644 --- a/src/zarr.v2.cpp +++ b/src/zarr.v2.cpp @@ -4,6 +4,8 @@ #include "nlohmann/json.hpp" +#include + namespace zarr = acquire::sink::zarr; namespace { @@ -22,6 +24,33 @@ compressed_zarr_v2_init() } return nullptr; } + +std::string +sample_type_to_dtype(SampleType t) + +{ + const std::string dtype_prefix = + std::endian::native == std::endian::big ? ">" : "<"; + + switch (t) { + case SampleType_u8: + return dtype_prefix + "u1"; + case SampleType_u10: + case SampleType_u12: + case SampleType_u14: + case SampleType_u16: + return dtype_prefix + "u2"; + case SampleType_i8: + return dtype_prefix + "i1"; + case SampleType_i16: + return dtype_prefix + "i2"; + case SampleType_f32: + return dtype_prefix + "f4"; + default: + throw std::runtime_error("Invalid SampleType: " + + std::to_string(static_cast(t))); + } +} } // end ::{anonymous} namespace /// ZarrV2 @@ -250,7 +279,7 @@ zarr::ZarrV2::write_array_metadata_(size_t level) const metadata["zarr_format"] = 2; metadata["shape"] = array_shape; metadata["chunks"] = chunk_shape; - metadata["dtype"] = common::sample_type_to_dtype(image_shape.type); + metadata["dtype"] = sample_type_to_dtype(image_shape.type); metadata["fill_value"] = 0; metadata["order"] = "C"; metadata["filters"] = nullptr; diff --git a/src/zarr.v3.cpp b/src/zarr.v3.cpp index 2c7d500b..612d81df 100644 --- a/src/zarr.v3.cpp +++ b/src/zarr.v3.cpp @@ -24,6 +24,30 @@ compressed_zarr_v3_init() } return nullptr; } + +std::string +sample_type_to_dtype(SampleType t) + +{ + switch (t) { + case SampleType_u8: + return "uint8"; + case SampleType_u10: + case SampleType_u12: + case SampleType_u14: + case SampleType_u16: + return "uint16"; + case SampleType_i8: + return "int8"; + case SampleType_i16: + return "int16"; + case SampleType_f32: + return "float32"; + default: + throw std::runtime_error("Invalid SampleType: " + + std::to_string(static_cast(t))); + } +} } // end ::{anonymous} namespace zarr::ZarrV3::ZarrV3(BloscCompressionParams&& compression_params) @@ -176,7 +200,7 @@ zarr::ZarrV3::write_array_metadata_(size_t level) const }); metadata["chunk_memory_layout"] = "C"; - metadata["data_type"] = common::sample_type_to_dtype(image_shape.type); + metadata["data_type"] = sample_type_to_dtype(image_shape.type); metadata["extensions"] = json::array(); metadata["fill_value"] = 0; metadata["shape"] = array_shape; diff --git a/tests/multiscales-metadata.cpp b/tests/multiscales-metadata.cpp index b1fb4cc4..44c17b4a 100644 --- a/tests/multiscales-metadata.cpp +++ b/tests/multiscales-metadata.cpp @@ -182,6 +182,10 @@ verify_layer(const LayerTestCase& test_case) std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + const auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_layer, shape[0]); ASSERT_EQ(int, "%d", layer_frame_height, shape[1]); diff --git a/tests/repeat-start.cpp b/tests/repeat-start.cpp index cb9c2a49..e65eea9e 100644 --- a/tests/repeat-start.cpp +++ b/tests/repeat-start.cpp @@ -187,7 +187,9 @@ validate(AcquireRuntime* runtime) ASSERT_EQ(int, "%d", 32, chunk_shape[3]); CHECK("C" == metadata["chunk_memory_layout"]); - CHECK("u1" == metadata["data_type"]); + + CHECK("uint8" == metadata["data_type"].get()); + CHECK(metadata["extensions"].empty()); const auto array_shape = metadata["shape"]; diff --git a/tests/unit-tests.cpp b/tests/unit-tests.cpp index b04c4f2d..52aed336 100644 --- a/tests/unit-tests.cpp +++ b/tests/unit-tests.cpp @@ -82,6 +82,7 @@ main() }; const std::vector tests{ #define CASE(e) { .name = #e, .test = (int (*)())lib_load(&lib, #e) } + CASE(unit_test__trim), CASE(unit_test__average_frame), CASE(unit_test__thread_pool__push_to_job_queue), CASE(unit_test__s3_connection__make_bucket), diff --git a/tests/write-zarr-v2-compressed-multiscale.cpp b/tests/write-zarr-v2-compressed-multiscale.cpp index 870ebd03..1e4ed823 100644 --- a/tests/write-zarr-v2-compressed-multiscale.cpp +++ b/tests/write-zarr-v2-compressed-multiscale.cpp @@ -202,6 +202,10 @@ verify_layer(const LayerTestCase& test_case) std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + const auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_layer, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-compressed-with-chunking-and-rollover.cpp b/tests/write-zarr-v2-compressed-with-chunking-and-rollover.cpp index ecbe9f71..411b1eb0 100644 --- a/tests/write-zarr-v2-compressed-with-chunking-and-rollover.cpp +++ b/tests/write-zarr-v2-compressed-with-chunking-and-rollover.cpp @@ -174,6 +174,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", chunk_planes + 1, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-compressed-with-chunking.cpp b/tests/write-zarr-v2-compressed-with-chunking.cpp index c393422f..8944de71 100644 --- a/tests/write-zarr-v2-compressed-with-chunking.cpp +++ b/tests/write-zarr-v2-compressed-with-chunking.cpp @@ -171,6 +171,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", chunk_planes, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-raw-chunk-size-larger-than-frame-size.cpp b/tests/write-zarr-v2-raw-chunk-size-larger-than-frame-size.cpp index 6f576b71..0e732a49 100644 --- a/tests/write-zarr-v2-raw-chunk-size-larger-than-frame-size.cpp +++ b/tests/write-zarr-v2-raw-chunk-size-larger-than-frame-size.cpp @@ -233,6 +233,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_chunk, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-raw-multiscale-with-trivial-tile-size.cpp b/tests/write-zarr-v2-raw-multiscale-with-trivial-tile-size.cpp index d638719d..6a1b6c1f 100644 --- a/tests/write-zarr-v2-raw-multiscale-with-trivial-tile-size.cpp +++ b/tests/write-zarr-v2-raw-multiscale-with-trivial-tile-size.cpp @@ -185,6 +185,10 @@ verify_layer(const LayerTestCase& test_case) std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + const auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_layer, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-raw-multiscale.cpp b/tests/write-zarr-v2-raw-multiscale.cpp index 1108ee88..88a8e5b8 100644 --- a/tests/write-zarr-v2-raw-multiscale.cpp +++ b/tests/write-zarr-v2-raw-multiscale.cpp @@ -192,6 +192,10 @@ verify_layer(const LayerTestCase& test_case) std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + const auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_layer, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-raw-with-even-chunking-and-rollover.cpp b/tests/write-zarr-v2-raw-with-even-chunking-and-rollover.cpp index 7f0e33d8..18379436 100644 --- a/tests/write-zarr-v2-raw-with-even-chunking-and-rollover.cpp +++ b/tests/write-zarr-v2-raw-with-even-chunking-and-rollover.cpp @@ -162,6 +162,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", chunk_planes + 1, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-raw-with-even-chunking.cpp b/tests/write-zarr-v2-raw-with-even-chunking.cpp index 8d9ddfb9..58fbdb9b 100644 --- a/tests/write-zarr-v2-raw-with-even-chunking.cpp +++ b/tests/write-zarr-v2-raw-with-even-chunking.cpp @@ -161,6 +161,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", chunk_planes, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-raw-with-ragged-chunking.cpp b/tests/write-zarr-v2-raw-with-ragged-chunking.cpp index c7232038..971eb66e 100644 --- a/tests/write-zarr-v2-raw-with-ragged-chunking.cpp +++ b/tests/write-zarr-v2-raw-with-ragged-chunking.cpp @@ -237,6 +237,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", max_frame_count, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-raw.cpp b/tests/write-zarr-v2-raw.cpp index 835f2590..d213ecad 100644 --- a/tests/write-zarr-v2-raw.cpp +++ b/tests/write-zarr-v2-raw.cpp @@ -3,6 +3,7 @@ #include "platform.h" // clock #include "logger.h" +#include #include #include #include @@ -233,6 +234,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_chunk, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-with-lz4-compression.cpp b/tests/write-zarr-v2-with-lz4-compression.cpp index d87526c8..686d0419 100644 --- a/tests/write-zarr-v2-with-lz4-compression.cpp +++ b/tests/write-zarr-v2-with-lz4-compression.cpp @@ -169,6 +169,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_chunk, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v2-with-zstd-compression.cpp b/tests/write-zarr-v2-with-zstd-compression.cpp index 1cd3a013..5430d558 100644 --- a/tests/write-zarr-v2-with-zstd-compression.cpp +++ b/tests/write-zarr-v2-with-zstd-compression.cpp @@ -169,6 +169,10 @@ validate() std::ifstream f(zarray_path); json zarray = json::parse(f); + const std::string dtype = + std::endian::native == std::endian::little ? "u1"; + CHECK(dtype == zarray["dtype"].get()); + auto shape = zarray["shape"]; ASSERT_EQ(int, "%d", frames_per_chunk, shape[0]); ASSERT_EQ(int, "%d", 1, shape[1]); diff --git a/tests/write-zarr-v3-compressed.cpp b/tests/write-zarr-v3-compressed.cpp index 391e639d..734e2521 100644 --- a/tests/write-zarr-v3-compressed.cpp +++ b/tests/write-zarr-v3-compressed.cpp @@ -270,7 +270,7 @@ validate() ASSERT_EQ(int, "%d", chunk_width, chunk_shape[3]); CHECK("C" == metadata["chunk_memory_layout"]); - CHECK("u1" == metadata["data_type"]); + CHECK("uint8" == metadata["data_type"]); CHECK(metadata["extensions"].empty()); const auto array_shape = metadata["shape"]; diff --git a/tests/write-zarr-v3-raw-chunk-exceeds-array.cpp b/tests/write-zarr-v3-raw-chunk-exceeds-array.cpp index bd9a223d..cfc3d7b0 100644 --- a/tests/write-zarr-v3-raw-chunk-exceeds-array.cpp +++ b/tests/write-zarr-v3-raw-chunk-exceeds-array.cpp @@ -261,7 +261,7 @@ validate() ASSERT_EQ(int, "%d", chunk_width, chunk_shape[2]); CHECK("C" == metadata["chunk_memory_layout"]); - CHECK("u1" == metadata["data_type"]); + CHECK("uint8" == metadata["data_type"]); CHECK(metadata["extensions"].empty()); const auto array_shape = metadata["shape"]; diff --git a/tests/write-zarr-v3-raw-with-ragged-sharding.cpp b/tests/write-zarr-v3-raw-with-ragged-sharding.cpp index 92632fa7..b3ccd51a 100644 --- a/tests/write-zarr-v3-raw-with-ragged-sharding.cpp +++ b/tests/write-zarr-v3-raw-with-ragged-sharding.cpp @@ -260,7 +260,7 @@ validate() ASSERT_EQ(int, "%d", chunk_width, chunk_shape[2]); CHECK("C" == metadata["chunk_memory_layout"]); - CHECK("u1" == metadata["data_type"]); + CHECK("uint8" == metadata["data_type"]); CHECK(metadata["extensions"].empty()); const auto array_shape = metadata["shape"]; diff --git a/tests/write-zarr-v3-raw.cpp b/tests/write-zarr-v3-raw.cpp index 5c4df05c..64d84197 100644 --- a/tests/write-zarr-v3-raw.cpp +++ b/tests/write-zarr-v3-raw.cpp @@ -270,7 +270,7 @@ validate() ASSERT_EQ(int, "%d", chunk_width, chunk_shape[3]); CHECK("C" == metadata["chunk_memory_layout"]); - CHECK("u1" == metadata["data_type"]); + CHECK("uint8" == metadata["data_type"]); CHECK(metadata["extensions"].empty()); const auto array_shape = metadata["shape"];