diff --git a/tests/FPGAIntegrationTest.cpp b/tests/FPGAIntegrationTest.cpp index 956ad33d2..b5a385ce3 100644 --- a/tests/FPGAIntegrationTest.cpp +++ b/tests/FPGAIntegrationTest.cpp @@ -1225,4 +1225,85 @@ TEST_CASE("HLS_C_Simulation_internal_packet_generator_spot_finder_snr_threshold" REQUIRE (spot_finder_result.count_threshold == 0); REQUIRE (spot_finder_result.strong_pixel[0] == (1<<0)); REQUIRE (spot_finder_result.strong_pixel[(89*1024 + 300) / 8] == (1<<4)); // 300 % 8 == 4 -} \ No newline at end of file +} + +TEST_CASE("HLS_C_Simulation_upside_down", "[FPGA][Full]") { + const uint16_t nmodules = 4; + + DiffractionExperiment x((DetectorGeometry(nmodules))); + + std::vector input_frame(FRAME_GENERATOR_MODULES*RAW_MODULE_SIZE); + std::vector input_frame_transformed(FRAME_GENERATOR_MODULES*RAW_MODULE_SIZE); + + std::mt19937 g1(1387); + std::uniform_int_distribution dist(0, 65535); + for (int n = 0; n < nmodules; n++) { + for (int line = 0; line < RAW_MODULE_LINES; line++) { + size_t line_transformed = RAW_MODULE_LINES - 1 - line; + for (int col = 0; col < RAW_MODULE_COLS; col++) { + uint16_t tmp = dist(g1); + input_frame[n * RAW_MODULE_SIZE + line * RAW_MODULE_COLS + col] = tmp; + input_frame_transformed[n * RAW_MODULE_SIZE + line_transformed * RAW_MODULE_COLS + col] = tmp; + } + } + } + + x.Mode(DetectorMode::Raw); + x.UseInternalPacketGenerator(true).ImagesPerTrigger(4).PedestalG0Frames(0); + + HLSSimulatedDevice test(0, 64); + test.SetInternalGeneratorFrame(input_frame); + + REQUIRE_NOTHROW(test.StartAction(x, MODE_MODULE_UPSIDE_DOWN)); + REQUIRE_NOTHROW(test.WaitForActionComplete()); + + REQUIRE(test.OutputStream().size() == 1); + + REQUIRE(test.GetBytesReceived() == 128 * nmodules * 4 * JUNGFRAU_PACKET_SIZE_BYTES); + + for (int image = 0; image < 4; image++) { + for (int m = 0; m < nmodules; m++) { + auto imageBuf = (uint16_t *) test.GetDeviceOutput(image, m)->pixels; + for (int i = 0; i < RAW_MODULE_SIZE; i++) { + REQUIRE(imageBuf[i] == input_frame_transformed[m * RAW_MODULE_SIZE + i]); + } + } + } +} + +TEST_CASE("HLS_C_Simulation_bitsuffle", "[FPGA][Full]") { + const uint16_t nmodules = 4; + + DiffractionExperiment x((DetectorGeometry(nmodules))); + + std::vector input_frame(FRAME_GENERATOR_MODULES*RAW_MODULE_SIZE); + + std::mt19937 g1(1387); + std::uniform_int_distribution dist(0, 65535); + for (auto &i: input_frame) + i = dist(g1); + + x.Mode(DetectorMode::Raw); + x.UseInternalPacketGenerator(true).ImagesPerTrigger(4).PedestalG0Frames(0); + + HLSSimulatedDevice test(0, 64); + test.SetInternalGeneratorFrame(input_frame); + + REQUIRE_NOTHROW(test.StartAction(x, MODE_BITSHUFFLE_FPGA)); + REQUIRE_NOTHROW(test.WaitForActionComplete()); + + REQUIRE(test.OutputStream().size() == 1); + + REQUIRE(test.GetBytesReceived() == 128 * nmodules * 4 * JUNGFRAU_PACKET_SIZE_BYTES); + + for (int image = 0; image < 4; image++) { + for (int m = 0; m < nmodules; m++) { + auto imageBuf = (uint16_t *) test.GetDeviceOutput(image, m)->pixels; + std::vector image_out_unshuf(RAW_MODULE_SIZE); + bshuf_bitunshuffle(imageBuf, image_out_unshuf.data(), RAW_MODULE_SIZE, sizeof(uint16_t), 2048); + for (int i = 0; i < RAW_MODULE_SIZE; i++) { + REQUIRE(image_out_unshuf[i] == input_frame[m * RAW_MODULE_SIZE + i]); + } + } + } +}