Commit 3593ef78 authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Fix signed/unsigned conversion

parent 0de28718
......@@ -74,7 +74,7 @@ uint32_t bitMask(uint32_t firstBit, uint32_t lastBit) {
void setBitsWithValue(uint32_t &target, uint32_t firstBit, uint32_t lastBit,
uint32_t value) {
// check if value is larger than bit range
if (value > (1 << (lastBit + 1 - firstBit))) {
if (value > (1u << (lastBit + 1u - firstBit))) {
BOOST_LOG_TRIVIAL(error)
<< "value: " << value << ", 1 << (last-bit - firstbit) "
<< (1 << (lastBit - firstBit)) << ", bitrange: " << lastBit - firstBit
......
......@@ -170,7 +170,7 @@ int main(int argc, char **argv) {
// convert from 8 bit unsigned to 8 bit signed
uint8_t *A_unsigned = reinterpret_cast<uint8_t*>(thrust::raw_pointer_cast(output.data()));
int8_t *A_signed = reinterpret_cast<int8_t*>(thrust::raw_pointer_cast(output.data()));
for(int i = 0; i < output.size() * 4; i++)
for(size_t i = 0; i < output.size() * 4; i++)
{
int f = A_unsigned[i];
A_signed[i] = f - 128;
......
......@@ -68,6 +68,8 @@ TEST(GatedSpectrometer, GatingKernel)
// everything to G0
{
thrust::fill(_nG0.begin(), _nG0.end(), 0);
thrust::fill(_nG1.begin(), _nG1.end(), 0);
baseLine[0] = 0.;
const uint64_t *sideCD =
(uint64_t *)(thrust::raw_pointer_cast(_sideChannelData.data()));
......@@ -89,11 +91,13 @@ TEST(GatedSpectrometer, GatingKernel)
EXPECT_EQ(*minmax.second, 0);
EXPECT_EQ(_nG0[0], G0.size());
EXPECT_EQ(_nG1[0], 0);
EXPECT_EQ(_nG1[0], 0u);
}
// everything to G1 // with baseline -5
{
thrust::fill(_nG0.begin(), _nG0.end(), 0);
thrust::fill(_nG1.begin(), _nG1.end(), 0);
baseLine[0] = -5. * G0.size();
thrust::fill(_sideChannelData.begin(), _sideChannelData.end(), 1L);
const uint64_t *sideCD =
......@@ -116,8 +120,8 @@ TEST(GatedSpectrometer, GatingKernel)
EXPECT_EQ(*minmax.second, 42);
EXPECT_EQ(_nG0[0], G0.size());
EXPECT_EQ(_nG1[0], 0);
EXPECT_EQ(_nG0[0], 0u);
EXPECT_EQ(_nG1[0], G1.size());
}
}
......
......@@ -21,7 +21,7 @@ class PackerTest: public ::testing::Test
maxV = 2;
srand (time(NULL));
for (int i =0; i < input.size(); i++)
for (size_t i =0; i < input.size(); i++)
{
input[i] = ((float(rand()) / RAND_MAX) - 0.5) * 2.5 * (maxV-minV) + maxV + minV;
}
......@@ -47,7 +47,7 @@ class PackerTest: public ::testing::Test
float step = (maxV - minV) / ((1 << bit_depth) - 1);
const size_t nbp = 32 / bit_depth;
for(int i = 0; i < input.size() / nbp; i++)
for(size_t i = 0; i < input.size() / nbp; i++)
{
uint32_t of = output[i];
for (size_t j =0; j< nbp; j++)
......@@ -76,7 +76,7 @@ TEST_F(PackerTest, 2bit)
float L4 = minV + 3 * step;
const size_t nbp = 16; // 16 samples per output value
for(int i = 0; i < input.size() / nbp; i++)
for(size_t i = 0; i < input.size() / nbp; i++)
{
uint32_t of = output[i];
for (size_t j =0; j< nbp; j++)
......@@ -84,13 +84,13 @@ TEST_F(PackerTest, 2bit)
uint32_t a = ((of >> (j *2)) & 3);
int k = i * nbp + j;
if (input[k] >= L4)
EXPECT_EQ(a, 3);
EXPECT_EQ(a, 3u);
else if (input[k] >= L3)
EXPECT_EQ(a, 2);
EXPECT_EQ(a, 2u);
else if (input[k] >= L2)
EXPECT_EQ(a, 1);
EXPECT_EQ(a, 1u);
else
EXPECT_EQ(a, 0);
EXPECT_EQ(a, 0u);
}
}
}
......
......@@ -22,13 +22,13 @@ TEST(BitManipulation, setBitsWithValue)
{
uint32_t data = 0;
setBitsWithValue(data, 0, 2, 3);
EXPECT_EQ(data, 3);
EXPECT_EQ(data, 3u);
setBitsWithValue(data, 2, 4, 3);
EXPECT_EQ(data, 15);
EXPECT_EQ(data, 15u);
EXPECT_EQ(3, getBitsValue(data, 1, 2));
EXPECT_EQ(1, getBitsValue(data, 3, 12));
EXPECT_EQ(3u, getBitsValue(data, 1, 2));
EXPECT_EQ(1u, getBitsValue(data, 3, 12));
}
......@@ -43,36 +43,36 @@ TEST(VDIFHeader, getSetWord0)
header.setValid();
EXPECT_TRUE(header.isValid());
EXPECT_EQ(header.getSecondsFromReferenceEpoch(), 0);
EXPECT_EQ(header.getSecondsFromReferenceEpoch(), 0u);
header.setSecondsFromReferenceEpoch(12345);
EXPECT_EQ(header.getSecondsFromReferenceEpoch(), 12345);
EXPECT_EQ(header.getSecondsFromReferenceEpoch(), 12345u);
}
TEST(VDIFHeader, getSetWord1)
{
VDIFHeader header;
EXPECT_EQ(header.getReferenceEpoch(), 0);
EXPECT_EQ(header.getReferenceEpoch(), 0u);
header.setReferenceEpoch(16);
EXPECT_EQ(header.getReferenceEpoch(), 16);
EXPECT_EQ(header.getReferenceEpoch(), 16u);
EXPECT_EQ(header.getDataFrameNumber(), 0);
EXPECT_EQ(header.getDataFrameNumber(), 0u);
header.setDataFrameNumber(5);
EXPECT_EQ(header.getDataFrameNumber(), 5);
EXPECT_EQ(header.getDataFrameNumber(), 5u);
}
TEST(VDIFHeader, getSetWord2)
{
VDIFHeader header;
EXPECT_EQ(header.getVersionNumber(), 1);
EXPECT_EQ(header.getVersionNumber(), 1u);
EXPECT_EQ(header.getDataFrameLength(), 0);
EXPECT_EQ(header.getDataFrameLength(), 0u);
header.setDataFrameLength(1024);
EXPECT_EQ(header.getDataFrameLength(), 1024);
EXPECT_EQ(header.getDataFrameLength(), 1024u);
EXPECT_EQ(header.getNumberOfChannels(), 0);
EXPECT_EQ(header.getNumberOfChannels(), 0u);
header.setNumberOfChannels(10);
EXPECT_EQ(header.getNumberOfChannels(), 10);
EXPECT_EQ(header.getNumberOfChannels(), 10u);
}
......@@ -85,17 +85,17 @@ TEST(VDIFHeader, getSetWord3)
EXPECT_FALSE(header.isRealDataType());
EXPECT_TRUE(header.isComplexDataType());
EXPECT_EQ(header.getBitsPerSample(), 0);
EXPECT_EQ(header.getBitsPerSample(), 0u);
header.setBitsPerSample(13);
EXPECT_EQ(header.getBitsPerSample(), 13);
EXPECT_EQ(header.getBitsPerSample(), 13u);
EXPECT_EQ(header.getThreadId(), 0);
EXPECT_EQ(header.getThreadId(), 0u);
header.setThreadId(23);
EXPECT_EQ(header.getThreadId(), 23);
EXPECT_EQ(header.getThreadId(), 23u);
EXPECT_EQ(header.getStationId(), 0);
EXPECT_EQ(header.getStationId(), 0u);
header.setStationId(42);
EXPECT_EQ(header.getStationId(), 42);
EXPECT_EQ(header.getStationId(), 42u);
}
TEST(VDIFHeader, testTimeStampConversion)
......@@ -107,16 +107,16 @@ TEST(VDIFHeader, testTimeStampConversion)
EXPECT_EQ(currentTime, header.getTimestamp()) << "Reference epoch: " << header.getReferenceEpoch() << " + " << header.getSecondsFromReferenceEpoch() << " s";
header.setTimeReferencesFromTimestamp(946684800);
EXPECT_EQ(0, header.getReferenceEpoch());
EXPECT_EQ(0, header.getSecondsFromReferenceEpoch());
EXPECT_EQ(0u, header.getReferenceEpoch());
EXPECT_EQ(0u, header.getSecondsFromReferenceEpoch());
header.setTimeReferencesFromTimestamp(962409600);
EXPECT_EQ(1, header.getReferenceEpoch());
EXPECT_EQ(0, header.getSecondsFromReferenceEpoch());
EXPECT_EQ(1u, header.getReferenceEpoch());
EXPECT_EQ(0u, header.getSecondsFromReferenceEpoch());
header.setTimeReferencesFromTimestamp(962409600 + 100);
EXPECT_EQ(1, header.getReferenceEpoch());
EXPECT_EQ(100, header.getSecondsFromReferenceEpoch());
EXPECT_EQ(1u, header.getReferenceEpoch());
EXPECT_EQ(100u, header.getSecondsFromReferenceEpoch());
}
//int main(int argc, char **argv) {
......
......@@ -65,7 +65,7 @@ TEST_F(UnpackerTester, paf_unpack_test)
std::default_random_engine generator;
std::uniform_int_distribution<int> distribution(1,1<<31);
InputType host_input(n);
for (int ii = 0; ii < n; ++ii)
for (size_t ii = 0; ii < n; ++ii)
{
host_input[ii] = distribution(generator);
}
......
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