Files
Jungfraujoch/tests/jfjoch_hdf5_enospc_test.cpp
T
leonarski_fandClaude Opus 5 b2058d1a79 Feed the ENOSPC test the pixel format it declares
DetJF4M is signed - a JUNGFRAU in photon-counting conversion is signed by default - and the fixture
handed the writer uint16 images, so the pixel-format cross-check added in this branch refused them
and the test failed before it reached what it is about. Nothing here reads a pixel value back.

Missed when the other fixtures were corrected, because jfjoch_hdf5_enospc_test is a separate binary
that jfjoch_test does not run; CI runs it as its own step.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VfYvJT5Nb71suJCowRBn5z
2026-08-23 12:39:00 +02:00

58 lines
2.2 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
// Run with LD_PRELOAD=enospc_shim.so ./jfjoch_hdf5_enospc_test
#include <catch2/catch_all.hpp>
#include "../writer/HDF5Objects.h"
#include "../writer/FileWriter.h"
#include "../common/DiffractionExperiment.h"
#include <iostream>
TEST_CASE("HDF5File_enospc") {
auto file = std::make_unique<HDF5File>("enospc_test.h5");
std::vector<uint8_t> small_vector(2056), large_vector(40 * 1024 * 1024);
REQUIRE_NOTHROW(file->SaveVector("/small", small_vector));
REQUIRE_THROWS(file->SaveVector("/large1", large_vector));
REQUIRE_THROWS(file->SaveVector("/large2", large_vector));
REQUIRE_THROWS(file->Close());
REQUIRE_NOTHROW(file.reset());
// No leftover HDF5 objects
REQUIRE (H5Fget_obj_count(H5F_OBJ_ALL, H5F_OBJ_ALL) == 0);
}
TEST_CASE("FileWriter_enospc") {
{
RegisterHDF5Filter();
DiffractionExperiment x(DetJF4M());
x.FilePrefix("fw_enospc").ImagesPerTrigger(5).ImagesPerFile(2).Compression(CompressionAlgorithm::NO_COMPRESSION)
.SetFileWriterFormat(FileWriterFormat::NXmxVDS);
StartMessage start_message;
x.FillMessage(start_message);
FileWriter file_set(start_message);
// int16, because a JUNGFRAU in photon-counting conversion is signed by default and the
// writer refuses a stream whose images do not match the format its start message declares.
// Nothing here reads a pixel value back - the test is about running out of space.
std::vector<int16_t> image(x.GetPixelsNum());
DataMessage message{};
message.image = CompressedImage(image, x.GetXPixelsNum(), x.GetYPixelsNum());
message.number = 0;
REQUIRE_NOTHROW(file_set.Write(message));
message.number = 1;
REQUIRE_THROWS(file_set.Write(message));
message.number = 2;
REQUIRE_THROWS(file_set.Write(message));
EndMessage end_message{
.max_image_number = 3
};
REQUIRE_THROWS(file_set.WriteHDF5(end_message));
}
// No leftover HDF5 objects
REQUIRE (H5Fget_obj_count(H5F_OBJ_ALL, H5F_OBJ_ALL) == 0);
}