commit b25e56300a6b6cfdef60ebb06df7f2e909370775
parent faced5269910261592e0dacb15c87321434e8990
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 29 Sep 2020 15:47:12 +0200
First basic test of the suvm_volume_at function
Diffstat:
1 file changed, 57 insertions(+), 9 deletions(-)
diff --git a/src/test_suvm_volume.c b/src/test_suvm_volume.c
@@ -49,7 +49,7 @@ static const size_t box_indices[12/*#tetras*/*4/*#indices per tetra*/] = {
static const size_t box_ntetras = sizeof(box_indices) / sizeof(size_t[4]);
/*******************************************************************************
- * Helper functions
+ * Geometry functions
******************************************************************************/
static void
get_indices(const size_t itetra, size_t ids[4], void* ctx)
@@ -104,17 +104,13 @@ get_vert_data(const size_t ivert, void* data, void* ctx)
}
/*******************************************************************************
- * Main function
+ * Helper functions
******************************************************************************/
-int
-main(int argc, char** argv)
+static void
+test_tetrahedral_mesh_creation(struct suvm_device* dev)
{
struct suvm_tetrahedral_mesh_args args = SUVM_TETRAHEDRAL_MESH_ARGS_NULL;
- struct suvm_device* dev = NULL;
struct suvm_volume* vol = NULL;
- (void)argc, (void)argv;
-
- CHK(suvm_device_create(NULL, &mem_default_allocator, 1, &dev) == RES_OK);
args.ntetrahedra = box_ntetras;
args.nvertices = box_nverts;
@@ -146,7 +142,7 @@ main(int argc, char** argv)
args.get_indices = get_indices;
args.get_position = NULL;
CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_BAD_ARG);
- args.get_position = get_position;;
+ args.get_position = get_position;
CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_OK);
CHK(suvm_volume_ref_put(vol) == RES_OK);
@@ -181,6 +177,58 @@ main(int argc, char** argv)
args.vertex_data.alignment = 32;
CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_OK);
CHK(suvm_volume_ref_put(vol) == RES_OK);
+}
+
+static void
+test_volume_at(struct suvm_device* dev)
+{
+ struct suvm_tetrahedral_mesh_args args = SUVM_TETRAHEDRAL_MESH_ARGS_NULL;
+ struct suvm_primitive prim = SUVM_PRIMITIVE_NULL;
+ struct suvm_volume* vol = NULL;
+ double bcoords[4];
+ double pos[3];
+
+ args.ntetrahedra = box_ntetras;
+ args.nvertices = box_nverts;
+ args.get_indices = get_indices;
+ args.get_position = get_position;
+ args.tetrahedron_data.get = get_tetra_data;
+ args.tetrahedron_data.size = sizeof(size_t[4]);
+ args.tetrahedron_data.alignment = 64;
+ args.vertex_data.get = get_vert_data;
+ args.vertex_data.size = sizeof(double[3]);
+ args.vertex_data.alignment = 32;
+ args.context = NULL;
+
+ CHK(suvm_tetrahedral_mesh_create(dev, &args, &vol) == RES_OK);
+
+ pos[0] = 0.25;
+ pos[1] = 0.25;
+ pos[2] = 0.25;
+
+ CHK(suvm_volume_at(NULL, pos, &prim, bcoords) == RES_BAD_ARG);
+ CHK(suvm_volume_at(vol, NULL, &prim, bcoords) == RES_BAD_ARG);
+ CHK(suvm_volume_at(vol, pos, NULL, bcoords) == RES_BAD_ARG);
+ CHK(suvm_volume_at(vol, pos, &prim, NULL) == RES_BAD_ARG);
+ CHK(suvm_volume_at(vol, pos, &prim, bcoords) == RES_OK);
+ CHK(!SUVM_PRIMITIVE_NONE(&prim));
+
+ CHK(suvm_volume_ref_put(vol) == RES_OK);
+}
+
+/*******************************************************************************
+ * Main function
+ ******************************************************************************/
+int
+main(int argc, char** argv)
+{
+ struct suvm_device* dev = NULL;
+ (void)argc, (void)argv;
+
+ CHK(suvm_device_create(NULL, &mem_default_allocator, 1, &dev) == RES_OK);
+
+ test_tetrahedral_mesh_creation(dev);
+ test_volume_at(dev);
CHK(suvm_device_ref_put(dev) == RES_OK);