Commit 72008d9d authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Added test for gate counting

parent 743c795c
......@@ -276,6 +276,119 @@ TEST(GatedSpectrometer, array_sum) {
}
class GatedTestSink{
private:
size_t fft_length;
size_t call_count;
size_t nHeaps;
size_t naccumulate;
public:
GatedTestSink(size_t fft_length, size_t nHeaps, size_t naccumulate): fft_length(fft_length), nHeaps(nHeaps), naccumulate(naccumulate), call_count(0) {};
// Test the correctness of output of the processing test
void init(psrdada_cpp::RawBytes&){
};
bool operator()(psrdada_cpp::RawBytes& buf)
{
const size_t number_of_sc_items = 1;
const size_t nchans = fft_length / 2 + 1;
EXPECT_EQ(buf.used_bytes(), (32 / 8 * nchans + number_of_sc_items* 64 / 8) * 2);
// the first elements of the spectraa are related to the power
float *G0 = reinterpret_cast<float*>(buf.ptr());
float *G1 = reinterpret_cast<float*>(buf.ptr() + nchans * 32 /8);
uint64_t *S = reinterpret_cast<uint64_t*>(buf.ptr() + 2 *nchans * 32 /8);
// Expected half number of samples per gate
EXPECT_EQ(S[0], nHeaps * 4096 / 2);
EXPECT_EQ(S[1], nHeaps * 4096 / 2);
//EXPECT_FLOAT_EQ(G0[0], 12.) << "Call count: " << call_count ;
//EXPECT_FLOAT_EQ(G1[1], 23.) << "Call count: " << call_count ;;
call_count ++;
return false;
};
};
TEST(GatedSpectrometer, processing)
{
const size_t nbits = 8;
const size_t nHeaps = 1024;
const size_t fft_length = 1024 * 64;
const size_t naccumulate = 4096 * nHeaps / fft_length;
const size_t heapSize = 4096 * nbits / 8;
const size_t inputBufferSize = nHeaps * (heapSize + 64 / 8);
psrdada_cpp::DadaDB idbuffer(5, inputBufferSize, 1, 4096);
idbuffer.create();
psrdada_cpp::effelsberg::edd::DadaBufferLayout bufferLayout(idbuffer.key(), heapSize, 1);
GatedTestSink sink(fft_length, nHeaps, naccumulate);
psrdada_cpp::effelsberg::edd::GatedSpectrometer<
GatedTestSink,
psrdada_cpp::effelsberg::edd::SinglePolarizationInput,
psrdada_cpp::effelsberg::edd::GatedPowerSpectrumOutput>
spectrometer(bufferLayout,
0, 0,
fft_length,
naccumulate, nbits,
sink);
char *raw_buffer = new char[inputBufferSize];
psrdada_cpp::RawBytes buff(raw_buffer, inputBufferSize, inputBufferSize);
EXPECT_NO_THROW(spectrometer.init(buff));
for (int i = 0; i < nHeaps / 2; i++)
{
raw_buffer[i] = 0;
}
// fill data alternating 2,3 per heap
for (int i = 0; i < nHeaps; i+=2)
{
for (int j = 0; j < 4096; j++)
{
raw_buffer[i * 4096 + j] = 2;
}
for (int j = 4096; j < 2 * 4096; j++)
{
raw_buffer[i * 4096 + j] = 3;
}
}
//// fill sci data
uint64_t* sc_items = reinterpret_cast<uint64_t*>(raw_buffer + nHeaps * 4096);
for (int i = 0; i < nHeaps; i+=2)
{
SET_BIT(sc_items[i], 0);
//SET_BIT(sc_items[i+1], 0);
}
for (int i = 0; i < 5; i++)
{
EXPECT_NO_THROW(spectrometer(buff));
}
delete [] raw_buffer;
}
struct gated_params
{
std::size_t fft_length;
......@@ -319,7 +432,7 @@ TEST_P(ExecutionTests, SinglePolOutput)
char *raw_buffer = new char[inputBufferSize];
psrdada_cpp::RawBytes buff(raw_buffer, inputBufferSize);
psrdada_cpp::RawBytes buff(raw_buffer, inputBufferSize, inputBufferSize);
EXPECT_NO_THROW(spectrometer.init(buff)) << params.msg;
for (int i = 0; i < 5; i++)
......@@ -357,7 +470,7 @@ TEST_P(ExecutionTests, FullStokesOutput)
char *raw_buffer = new char[inputBufferSize];
psrdada_cpp::RawBytes buff(raw_buffer, inputBufferSize);
psrdada_cpp::RawBytes buff(raw_buffer, inputBufferSize, inputBufferSize);
EXPECT_NO_THROW(spectrometer.init(buff)) << params.msg;
for (int i = 0; i < 5; i++)
......@@ -383,3 +496,7 @@ INSTANTIATE_TEST_CASE_P (GatedSpectrometer,
gated_params({2*1024, 4096, 8, 1024, "1k Channel, integration larger than buffer"})
)
);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment