Commit 8b046ac7 authored by Jørgen Lind's avatar Jørgen Lind
Browse files

CreateSyntheticVDS unit test

It creates an in memory noise VDS. It then uploads it to the specified
network location, before it downloads it again from the network location
and verifies that the data is the same as the in memory VDS.
parent c483f045
......@@ -71,7 +71,7 @@ set (PRIVATE_HEADER_FILES
VDS/Rle.h
VDS/VolumeDataRequestProcessor.h
VDS/ThreadPool.h
VDS/SimplexNoiceKernel.h
VDS/SimplexNoiseKernel.h
)
set (EXPORTED_HEADER_FILES
......
......@@ -171,8 +171,7 @@ void Noise2DKernel(T* output, VolumeIndexer2D const &outputIndexer2D, FloatVecto
}
}
void
CalculateNoise2D(void* output, VolumeDataChannelDescriptor::Format eFormat, VolumeIndexer2D *pOutputIndexer, FloatVector2 frequency, float threshold, float noValue, bool useNoValue, unsigned int random)
static void CalculateNoise2D(void* output, VolumeDataChannelDescriptor::Format eFormat, VolumeIndexer2D *pOutputIndexer, FloatVector2 frequency, float threshold, float noValue, bool useNoValue, unsigned int random)
{
if (useNoValue)
{
......@@ -240,7 +239,7 @@ void Noise3DKernel(T* output, VolumeIndexer3D const &outputIndexer3D, FloatVecto
}
}
void CalculateNoise3D(void* output, VolumeDataChannelDescriptor::Format eFormat, VolumeIndexer3D *pOutputIndexer, FloatVector3 frequency, float threshold, float noValue, bool useNoValue, unsigned int random)
static void CalculateNoise3D(void* output, VolumeDataChannelDescriptor::Format eFormat, VolumeIndexer3D *pOutputIndexer, FloatVector3 frequency, float threshold, float noValue, bool useNoValue, unsigned int random)
{
if (useNoValue)
{
......@@ -308,7 +307,7 @@ void Noise4DKernel(T* output, VolumeIndexer4D const &outputIndexer4D, FloatVecto
}
}
void CalculateNoise4D(void* output, VolumeDataChannelDescriptor::Format eFormat, VolumeIndexer4D *pOutputIndexer, FloatVector4 frequency, float threshold, float noValue, bool useNoValue, unsigned int random)
static void CalculateNoise4D(void* output, VolumeDataChannelDescriptor::Format eFormat, VolumeIndexer4D *pOutputIndexer, FloatVector4 frequency, float threshold, float noValue, bool useNoValue, unsigned int random)
{
if (useNoValue)
{
......
......@@ -33,6 +33,7 @@ add_test_executable(io_tests
io/filetest.cpp
io/azureio.cpp
io/InMemoryIo.cpp
io/CreateSyntheticVDS.cpp
)
add_test_executable(jsoncpp_tests
......
......@@ -44,12 +44,12 @@ void setupIntegrationTestHandle(std::unique_ptr<OpenVDS::VDS, decltype(&OpenVDS:
//ASSERT_TRUE(handle);
}
void setupNoiceTestHandle(std::unique_ptr<OpenVDS::VDS, decltype(&OpenVDS::Close)> &handle)
void setupNoiseTestHandle(std::unique_ptr<OpenVDS::VDS, decltype(&OpenVDS::Close)> &handle)
{
OpenVDS::Error error;
handle.reset(generateSimpleInMemory3DVDS(60,60,60));
fill3DVDSWithNoice(handle.get());
fill3DVDSWithNoise(handle.get());
}
struct RequestSharedData
......@@ -57,7 +57,7 @@ struct RequestSharedData
RequestSharedData()
: handle(nullptr, &OpenVDS::Close)
{
setupNoiceTestHandle(handle);
setupNoiseTestHandle(handle);
layout = OpenVDS::GetLayout(handle.get());
accessManager = OpenVDS::GetAccessManager(handle.get());
......@@ -153,7 +153,7 @@ TEST_F(RequestVolumeSubsetFormat, test1Bit)
TEST(ReqeustVolumeSubsetFormat, source1Bit)
{
std::unique_ptr<OpenVDS::VDS, decltype(&OpenVDS::Close)> handle(generateSimpleInMemory3DVDS(60,60,60, OpenVDS::VolumeDataChannelDescriptor::Format_1Bit), OpenVDS::Close);
fill3DVDSWithBitNoice(handle.get());
fill3DVDSWithBitNoise(handle.get());
OpenVDS::VolumeDataLayout *layout = OpenVDS::GetLayout(handle.get());
OpenVDS::VolumeDataAccessManager *accessManager = OpenVDS::GetAccessManager(handle.get());
......
#include <gtest/gtest.h>
#include <OpenVDS/OpenVDS.h>
#include <OpenVDS/VolumeDataLayout.h>
#include <OpenVDS/VolumeDataAccess.h>
#include <VDS/VolumeDataLayoutImpl.h>
#include "../utils/GenerateVDS.h"
int handleUploadErrors(OpenVDS::VolumeDataAccessManager *accessManager)
{
int32_t errorCount = accessManager->UploadErrorCount();
for (int errorIndex = 0; errorIndex < errorCount; errorIndex++)
{
const char *object_id;
int32_t error_code;
const char *error_string;
accessManager->GetCurrentUploadError(&object_id, &error_code, &error_string);
fprintf(stderr, "\nFailed to upload object: %s. Error code %d: %s\n", object_id, error_code, error_string);
}
if (errorCount)
accessManager->ClearUploadErrors();
return errorCount;
}
TEST(IOTests, CreateSyntheticVDSAndVerifyUpload)
{
OpenVDS::Error error;
std::unique_ptr<OpenVDS::VDS, decltype(&OpenVDS::Close)> inMemoryVDS(generateSimpleInMemory3DVDS(60,60,60, OpenVDS::VolumeDataChannelDescriptor::Format_R32), OpenVDS::Close);
fill3DVDSWithNoise(inMemoryVDS.get());
OpenVDS::VolumeDataLayout *inMemoryLayout = OpenVDS::GetLayout(inMemoryVDS.get());
OpenVDS::AWSOpenOptions options;
options.region = TEST_AWS_REGION;
options.bucket = TEST_AWS_BUCKET;
options.key = "SIMPLE_NOISE_VDS";
if(options.region.empty() || options.bucket.empty() || options.key.empty())
{
GTEST_SKIP() << "Environment variables not set";
}
ASSERT_TRUE(options.region.size() && options.bucket.size() && options.key.size());
auto layoutDescriptor = inMemoryLayout->GetLayoutDescriptor();
int dimensions = inMemoryLayout->GetDimensionality();
std::vector<OpenVDS::VolumeDataAxisDescriptor> axisDescriptors;
std::vector<OpenVDS::VolumeDataChannelDescriptor> channelDescriptors;
for (int i = 0; i < dimensions; i++)
{
axisDescriptors.push_back(inMemoryLayout->GetAxisDescriptor(i));
}
int channels = inMemoryLayout->GetChannelCount();
for (int i = 0; i < channels; i++)
{
channelDescriptors.push_back(inMemoryLayout->GetChannelDescriptor(i));
}
OpenVDS::MetadataContainer metadata;
for (auto &meta : *inMemoryLayout)
{
switch(meta.type)
{
case OpenVDS::MetadataType::Int: metadata.SetMetadataInt(meta.category, meta.name, inMemoryLayout->GetMetadataInt(meta.category, meta.name)); break;
case OpenVDS::MetadataType::IntVector2: metadata.SetMetadataIntVector2(meta.category, meta.name, inMemoryLayout->GetMetadataIntVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::IntVector3: metadata.SetMetadataIntVector2(meta.category, meta.name, inMemoryLayout->GetMetadataIntVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::IntVector4: metadata.SetMetadataIntVector2(meta.category, meta.name, inMemoryLayout->GetMetadataIntVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::Float: metadata.SetMetadataFloat(meta.category, meta.name, inMemoryLayout->GetMetadataFloat(meta.category, meta.name)); break;
case OpenVDS::MetadataType::FloatVector2: metadata.SetMetadataFloatVector2(meta.category, meta.name, inMemoryLayout->GetMetadataFloatVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::FloatVector3: metadata.SetMetadataFloatVector2(meta.category, meta.name, inMemoryLayout->GetMetadataFloatVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::FloatVector4: metadata.SetMetadataFloatVector2(meta.category, meta.name, inMemoryLayout->GetMetadataFloatVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::Double: metadata.SetMetadataDouble(meta.category, meta.name, inMemoryLayout->GetMetadataDouble(meta.category, meta.name)); break;
case OpenVDS::MetadataType::DoubleVector2: metadata.SetMetadataDoubleVector2(meta.category, meta.name, inMemoryLayout->GetMetadataDoubleVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::DoubleVector3: metadata.SetMetadataDoubleVector2(meta.category, meta.name, inMemoryLayout->GetMetadataDoubleVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::DoubleVector4: metadata.SetMetadataDoubleVector2(meta.category, meta.name, inMemoryLayout->GetMetadataDoubleVector2(meta.category, meta.name)); break;
case OpenVDS::MetadataType::String: metadata.SetMetadataString(meta.category, meta.name, std::string(inMemoryLayout->GetMetadataString(meta.category, meta.name))); break;
case OpenVDS::MetadataType::BLOB:
{
std::vector<uint8_t> blob;
inMemoryLayout->GetMetadataBLOB(meta.category, meta.name, blob);
metadata.SetMetadataBLOB(meta.category, meta.name, blob);
break;
}
}
}
std::unique_ptr<OpenVDS::VDS, decltype(&OpenVDS::Close)> networkVDS(OpenVDS::Create(options, layoutDescriptor, axisDescriptors, channelDescriptors, metadata, error), &OpenVDS::Close);
ASSERT_TRUE(networkVDS);
OpenVDS::VolumeDataAccessManager *inMemoryAccessManager = OpenVDS::GetAccessManager(inMemoryVDS.get());
OpenVDS::VolumeDataPageAccessor *inMemoryPageAccessor = inMemoryAccessManager->CreateVolumeDataPageAccessor(inMemoryLayout, OpenVDS::Dimensions_012, 0, 0, 100, OpenVDS::VolumeDataAccessManager::AccessMode_ReadOnly);
int64_t chunkCount = inMemoryPageAccessor->GetChunkCount();
{
OpenVDS::VolumeDataLayout *networkLayout = OpenVDS::GetLayout(networkVDS.get());
OpenVDS::VolumeDataAccessManager *networkAccessManager = OpenVDS::GetAccessManager(networkVDS.get());
OpenVDS::VolumeDataPageAccessor *networkPageAccessor = networkAccessManager->CreateVolumeDataPageAccessor(networkLayout, OpenVDS::Dimensions_012, 0, 0, 100, OpenVDS::VolumeDataAccessManager::AccessMode_Create);
for (int64_t i = 0; i < chunkCount; i++)
{
int uploadErrors = handleUploadErrors(networkAccessManager);
ASSERT_TRUE(uploadErrors == 0);
int32_t min[OpenVDS::Dimensionality_Max];
int32_t max[OpenVDS::Dimensionality_Max];
int32_t size[OpenVDS::Dimensionality_Max];
inMemoryPageAccessor->GetChunkMinMax(i, min, max);
for (int dim = 0; dim < OpenVDS::Dimensionality_Max; dim++)
{
size[dim] = max[dim] - min[dim];
}
int32_t readPitch[OpenVDS::Dimensionality_Max];
OpenVDS::VolumeDataPage *inMemoryPage = inMemoryPageAccessor->ReadPage(i);
const void *readBuffer = inMemoryPage->GetBuffer(readPitch);
int32_t writePitch[OpenVDS::Dimensionality_Max];
OpenVDS::VolumeDataPage *networkPage = networkPageAccessor->CreatePage(i);
void *writeBuffer = networkPage->GetWritableBuffer(writePitch);
for (int dim = 0; dim < dimensions; dim++)
{
ASSERT_TRUE(readPitch[dim] == writePitch[dim]);
}
memcpy(writeBuffer, readBuffer, readPitch[2] * size[2] * 4);
inMemoryPage->Release();
networkPage->Release();
}
networkPageAccessor->Commit();
int uploadErrors = handleUploadErrors(networkAccessManager);
ASSERT_TRUE(uploadErrors == 0);
networkAccessManager->DestroyVolumeDataPageAccessor(networkPageAccessor);
}
networkVDS.reset(OpenVDS::Open(options, error));
ASSERT_TRUE(networkVDS);
OpenVDS::VolumeDataLayout *networkLayout = OpenVDS::GetLayout(networkVDS.get());
OpenVDS::VolumeDataAccessManager *networkAccessManager = OpenVDS::GetAccessManager(networkVDS.get());
OpenVDS::VolumeDataPageAccessor *networkPageAccessor = networkAccessManager->CreateVolumeDataPageAccessor(networkLayout, OpenVDS::Dimensions_012, 0, 0, 100, OpenVDS::VolumeDataAccessManager::AccessMode_ReadOnly);
for (int64_t i = 0; i < chunkCount; i++)
{
int32_t min[OpenVDS::Dimensionality_Max];
int32_t max[OpenVDS::Dimensionality_Max];
int32_t size[OpenVDS::Dimensionality_Max];
inMemoryPageAccessor->GetChunkMinMax(i, min, max);
for (int dim = 0; dim < OpenVDS::Dimensionality_Max; dim++)
{
size[dim] = max[dim] - min[dim];
}
int32_t inMemoryPitch[OpenVDS::Dimensionality_Max];
OpenVDS::VolumeDataPage *inMemoryPage = inMemoryPageAccessor->ReadPage(i);
const void *inMemoryBuffer = inMemoryPage->GetBuffer(inMemoryPitch);
int32_t networkPitch[OpenVDS::Dimensionality_Max];
OpenVDS::VolumeDataPage *networkPage = networkPageAccessor->ReadPage(i);
const void *networkBuffer = networkPage->GetBuffer(networkPitch);
for (int dim = 0; dim < dimensions; dim++)
{
ASSERT_TRUE(inMemoryPitch[dim] ==networkPitch[dim]);
}
ASSERT_TRUE(memcmp(inMemoryBuffer, networkBuffer, inMemoryPitch[2] * size[2] * 4) == 0);
inMemoryPage->Release();
networkPage->Release();
}
inMemoryAccessManager->DestroyVolumeDataPageAccessor(inMemoryPageAccessor);
networkAccessManager->DestroyVolumeDataPageAccessor(networkPageAccessor);
}
......@@ -36,7 +36,7 @@ TEST(IOTests, InMemory)
std::unique_ptr<OpenVDS::VDS, decltype(&OpenVDS::Close)> handle(generateSimpleInMemory3DVDS(60,60,60), &OpenVDS::Close);
ASSERT_TRUE(handle);
fill3DVDSWithNoice(handle.get());
fill3DVDSWithNoise(handle.get());
auto layout = OpenVDS::GetLayout(handle.get());
auto accessManager = OpenVDS::GetAccessManager(handle.get());
......
......@@ -7,7 +7,7 @@
#include <OpenVDS/VolumeDataLayout.h>
#include <OpenVDS/VolumeDataAccess.h>
#include <VDS/SimplexNoiceKernel.h>
#include <VDS/SimplexNoiseKernel.h>
#include <random>
......@@ -22,9 +22,9 @@ static OpenVDS::VDS *generateSimpleInMemory3DVDS(int32_t samplesX = 100, int32_t
OpenVDS::VolumeDataLayoutDescriptor layoutDescriptor(brickSize, negativeMargin, positiveMargin, brickSize2DMultiplier, lodLevels, layoutOptions);
std::vector<OpenVDS::VolumeDataAxisDescriptor> axisDescriptors;
axisDescriptors.push_back(OpenVDS::VolumeDataAxisDescriptor(100, KNOWNMETADATA_SURVEYCOORDINATE_INLINECROSSLINE_AXISNAME_SAMPLE, "ms", 0.0f, 4.f));
axisDescriptors.emplace_back(100, KNOWNMETADATA_SURVEYCOORDINATE_INLINECROSSLINE_AXISNAME_CROSSLINE, "", 1932.f, 2536.f);
axisDescriptors.emplace_back(100, KNOWNMETADATA_SURVEYCOORDINATE_INLINECROSSLINE_AXISNAME_INLINE, "", 9985.f, 10369.f);
axisDescriptors.emplace_back(samplesX, KNOWNMETADATA_SURVEYCOORDINATE_INLINECROSSLINE_AXISNAME_SAMPLE, "ms", 0.0f, 4.f);
axisDescriptors.emplace_back(samplesY, KNOWNMETADATA_SURVEYCOORDINATE_INLINECROSSLINE_AXISNAME_CROSSLINE, "", 1932.f, 2536.f);
axisDescriptors.emplace_back(samplesZ, KNOWNMETADATA_SURVEYCOORDINATE_INLINECROSSLINE_AXISNAME_INLINE, "", 9985.f, 10369.f);
std::vector<OpenVDS::VolumeDataChannelDescriptor> channelDescriptors;
channelDescriptors.emplace_back(format, OpenVDS::VolumeDataChannelDescriptor::Components_1, AMPLITUDE_ATTRIBUTE_NAME, "", -0.10919982194900513, 0.1099749207496643);
......@@ -35,18 +35,20 @@ static OpenVDS::VDS *generateSimpleInMemory3DVDS(int32_t samplesX = 100, int32_t
return OpenVDS::Create(options, layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, error);
}
static void fill3DVDSWithNoice(OpenVDS::VDS *vds, int32_t channel = 0, const OpenVDS::FloatVector3 &frequency = OpenVDS::FloatVector3(0.6f, 2.f, 4.f))
static void fill3DVDSWithNoise(OpenVDS::VDS *vds, int32_t channel = 0, const OpenVDS::FloatVector3 &frequency = OpenVDS::FloatVector3(0.6f, 2.f, 4.f))
{
OpenVDS::VolumeDataLayout *layout = OpenVDS::GetLayout(vds);
ASSERT_TRUE(layout);
//ASSERT_TRUE(layout);
OpenVDS::VolumeDataAccessManager *accessManager = OpenVDS::GetAccessManager(vds);
ASSERT_TRUE(accessManager);
//ASSERT_TRUE(accessManager);
OpenVDS::VolumeDataPageAccessor *pageAccessor = accessManager->CreateVolumeDataPageAccessor(layout, OpenVDS::Dimensions_012, channel, 0, 100, OpenVDS::VolumeDataAccessManager::AccessMode_Create);
ASSERT_TRUE(pageAccessor);
//ASSERT_TRUE(pageAccessor);
int32_t chunkCount = int32_t(pageAccessor->GetChunkCount());
OpenVDS::VolumeDataChannelDescriptor::Format format = layout->GetChannelFormat(channel);
for (int i = 0; i < chunkCount; i++)
{
OpenVDS::VolumeDataPage *page = pageAccessor->CreatePage(i);
......@@ -54,7 +56,7 @@ static void fill3DVDSWithNoice(OpenVDS::VDS *vds, int32_t channel = 0, const Ope
int pitch[OpenVDS::Dimensionality_Max];
void *buffer = page->GetWritableBuffer(pitch);
OpenVDS::CalculateNoise3D(buffer, OpenVDS::VolumeDataChannelDescriptor::Format_R32, &outputIndexer, frequency, 0.021f, 0.f, true, 345);
OpenVDS::CalculateNoise3D(buffer, format, &outputIndexer, frequency, 0.021f, 0.f, true, 345);
page->Release();
}
pageAccessor->Commit();
......@@ -64,15 +66,15 @@ static void fill3DVDSWithNoice(OpenVDS::VDS *vds, int32_t channel = 0, const Ope
}
static void fill3DVDSWithBitNoice(OpenVDS::VDS *vds, int32_t channel = 0)
static void fill3DVDSWithBitNoise(OpenVDS::VDS *vds, int32_t channel = 0)
{
OpenVDS::VolumeDataLayout *layout = OpenVDS::GetLayout(vds);
ASSERT_TRUE(layout);
//ASSERT_TRUE(layout);
OpenVDS::VolumeDataAccessManager *accessManager = OpenVDS::GetAccessManager(vds);
ASSERT_TRUE(accessManager);
//ASSERT_TRUE(accessManager);
OpenVDS::VolumeDataPageAccessor *pageAccessor = accessManager->CreateVolumeDataPageAccessor(layout, OpenVDS::Dimensions_012, channel, 0, 100, OpenVDS::VolumeDataAccessManager::AccessMode_Create);
ASSERT_TRUE(pageAccessor);
//ASSERT_TRUE(pageAccessor);
int32_t chunkCount = int32_t(pageAccessor->GetChunkCount());
......
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