-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgtest_NodeVoxelization.cpp
More file actions
8830 lines (7295 loc) · 308 KB
/
Copy pathgtest_NodeVoxelization.cpp
File metadata and controls
8830 lines (7295 loc) · 308 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-3-Clause-Clear
#include "QC/sample/BufferManager.hpp"
#include "OpenCLMock.h"
#include <CL/cl.h>
#include "gtest/gtest.h"
// Define friend class macros BEFORE including headers
//#define VOXELIZATIONCONFIG_FRIEND_CLASS() friend class VoxelizationConfigTest
#define VOXELIZATIONIMPL_FRIEND_CLASS() friend class VoxelizationImplTest
#include "QC/Node/Voxelization.hpp"
#include "VoxelizationImpl.hpp"
#include <chrono>
#include <fstream>
#include <iostream>
#include <string>
using namespace QC;
using namespace QC::Node;
using namespace QC::sample;
#define EXPAND_JSON( ... ) #__VA_ARGS__
extern int g_createBffrCall;
std::string g_Config_XYZR = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"inputMode": "xyzr",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7],
"plrPointsBufferId": 8,
"coordToPlrIdxBufferId": 9
}
} );
std::string g_Config_XYZRT = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "gpu",
"Xsize": 0.2,
"Ysize": 0.2,
"Zsize": 8.0,
"Xmin": -51.2,
"Ymin": -51.2,
"Zmin": -5.0,
"Xmax": 51.2,
"Ymax": 51.2,
"Zmax": 3.0,
"maxPointNum": 300000,
"maxPlrNum": 25000,
"maxPointNumPerPlr": 32,
"inputMode": "xyzrt",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7],
"plrPointsBufferId": 8,
"coordToPlrIdxBufferId": 9
}
} );
static void RandomGenPoints( float *pVoxels, uint32_t numPts )
{
for ( uint32_t i = 0; i < numPts; i++ )
{
pVoxels[0] = ( rand() % 10000 ) / 100;
pVoxels[1] = ( rand() % 10000 ) / 100;
pVoxels[2] = ( rand() % 300 ) / 100;
pVoxels[3] = 0.9;
pVoxels += 4;
}
}
static void LoadPoints( void *pData, uint32_t size, uint32_t &numPts, const char *pcdFile )
{
FILE *pFile = fopen( pcdFile, "rb" );
ASSERT_NE( nullptr, pFile );
fseek( pFile, 0, SEEK_END );
int length = ftell( pFile );
ASSERT_LT( length, size );
numPts = length / 16;
fseek( pFile, 0, SEEK_SET );
int r = fread( pData, 1, numPts * 16, pFile );
ASSERT_EQ( r, length );
printf( "load %u points from %s\n", numPts, pcdFile );
fclose( pFile );
ASSERT_NE( 0, numPts );
}
static void LoadRaw( void *pData, uint32_t length, const char *rawFile )
{
printf( "load raw from %s\n", rawFile );
FILE *pFile = fopen( rawFile, "rb" );
ASSERT_NE( nullptr, pFile );
fseek( pFile, 0, SEEK_END );
int size = ftell( pFile );
ASSERT_EQ( size, length );
fseek( pFile, 0, SEEK_SET );
int r = fread( pData, 1, length, pFile );
ASSERT_EQ( r, length );
fclose( pFile );
}
static void SANITY_Voxelization( std::string jsonStr, std::string processorType,
std::string inputMode, const char *pcdFile = nullptr )
{
QCStatus_e ret;
DataTree dt;
DataTree staticCfg;
QCNodeInit_t config;
std::string errors;
uint32_t globalIdx = 0;
float Xsize = 0;
float Ysize = 0;
float Zsize = 0;
float Xmin = 0;
float Ymin = 0;
float Zmin = 0;
float Xmax = 0;
float Ymax = 0;
float Zmax = 0;
uint32_t maxPointNum = 0;
uint32_t maxPlrNum = 0;
uint32_t maxPointNumPerPlr = 0;
uint32_t inputFeatureDimNum = 0;
uint32_t outputFeatureDimNum = 0;
uint32_t plrPointsBufferId = 0;
uint32_t coordToPlrIdxBufferId = 0;
uint32_t gridXSize = 0;
uint32_t gridYSize = 0;
QCProcessorType_e processor;
std::vector<uint32_t> outputPlrBufferIds;
std::vector<uint32_t> outputFeatureBufferIds;
TensorDescriptor_t inputTensor;
TensorDescriptor_t outputPlrTensor;
TensorDescriptor_t outputFeatureTensor;
TensorDescriptor_t plrPointsTensor;
TensorDescriptor_t coordToPlrIdxTensor;
TensorProps_t inputTensorProp;
TensorProps_t outputPlrTensorProp;
TensorProps_t outputFeatureTensorProp;
TensorProps_t plrPointsTensorProp;
TensorProps_t coordToPlrIdxTensorProp;
BufferManager bufMgr = BufferManager( { "VOXEL", QC_NODE_TYPE_VOXEL, 0 } );
QC::Node::Voxelization voxel;
ret = dt.Load( jsonStr, errors );
if ( QC_STATUS_OK == ret )
{
dt.Set<std::string>( "static.processorType", processorType );
dt.Set<std::string>( "static.inputMode", inputMode );
ret = dt.Get( "static", staticCfg );
}
else
{
std::cout << "Get config error: " << errors << std::endl;
}
if ( QC_STATUS_OK == ret )
{
Xsize = staticCfg.Get<float>( "Xsize", 0 );
Ysize = staticCfg.Get<float>( "Ysize", 0 );
Zsize = staticCfg.Get<float>( "Zsize", 0 );
Xmin = staticCfg.Get<float>( "Xmin", 0 );
Ymin = staticCfg.Get<float>( "Ymin", 0 );
Zmin = staticCfg.Get<float>( "Zmin", 0 );
Xmax = staticCfg.Get<float>( "Xmax", 0 );
Ymax = staticCfg.Get<float>( "Ymax", 0 );
Zmax = staticCfg.Get<float>( "Zmax", 0 );
maxPointNum = staticCfg.Get<uint32_t>( "maxPointNum", 0 );
maxPlrNum = staticCfg.Get<uint32_t>( "maxPlrNum", 0 );
maxPointNumPerPlr = staticCfg.Get<uint32_t>( "maxPointNumPerPlr", 0 );
outputFeatureDimNum = staticCfg.Get<uint32_t>( "outputFeatureDimNum", 0 );
outputPlrBufferIds =
staticCfg.Get<uint32_t>( "outputPlrBufferIds", std::vector<uint32_t>{} );
outputFeatureBufferIds =
staticCfg.Get<uint32_t>( "outputFeatureBufferIds", std::vector<uint32_t>{} );
plrPointsBufferId = staticCfg.Get<uint32_t>( "plrPointsBufferId", 0 );
coordToPlrIdxBufferId = staticCfg.Get<uint32_t>( "coordToPlrIdxBufferId", 0 );
processor = staticCfg.GetProcessorType( "processorType", QC_PROCESSOR_HTP0 );
}
if ( QC_STATUS_OK == ret )
{
config = { dt.Dump() };
}
if ( inputMode == "xyzr" )
{
inputFeatureDimNum = 4;
}
else if ( inputMode == "xyzrt" )
{
inputFeatureDimNum = 5;
}
if ( ( maxPointNum > 0 ) && ( inputFeatureDimNum > 0 ) )
{
inputTensorProp.tensorType = QC_TENSOR_TYPE_FLOAT_32;
inputTensorProp.dims[0] = maxPointNum;
inputTensorProp.dims[1] = inputFeatureDimNum;
inputTensorProp.dims[2] = 0;
inputTensorProp.numDims = 2;
}
if ( ( maxPlrNum > 0 ) && ( maxPointNumPerPlr > 0 ) && ( outputFeatureDimNum > 0 ) )
{
if ( inputMode == "xyzrt" )
{
outputPlrTensorProp.tensorType = QC_TENSOR_TYPE_INT_32;
outputPlrTensorProp.dims[0] = maxPlrNum;
outputPlrTensorProp.dims[1] = 2;
outputPlrTensorProp.dims[2] = 0;
outputPlrTensorProp.numDims = 2;
}
else
{
outputPlrTensorProp.tensorType = QC_TENSOR_TYPE_FLOAT_32;
outputPlrTensorProp.dims[0] = maxPlrNum;
outputPlrTensorProp.dims[1] = VOXELIZATION_PILLAR_COORDS_DIM;
outputPlrTensorProp.dims[2] = 0;
outputPlrTensorProp.numDims = 2;
}
outputFeatureTensorProp.tensorType = QC_TENSOR_TYPE_FLOAT_32;
outputFeatureTensorProp.dims[0] = maxPlrNum;
outputFeatureTensorProp.dims[1] = maxPointNumPerPlr;
outputFeatureTensorProp.dims[2] = outputFeatureDimNum;
outputFeatureTensorProp.dims[3] = 0;
outputFeatureTensorProp.numDims = 3;
size_t gridXSize = ceil( ( Xmax - Xmin ) / Xsize );
size_t gridYSize = ceil( ( Ymax - Ymin ) / Ysize );
plrPointsTensorProp.tensorType = QC_TENSOR_TYPE_INT_32;
plrPointsTensorProp.dims[0] = maxPlrNum + 1;
plrPointsTensorProp.dims[1] = 0;
plrPointsTensorProp.numDims = 1;
coordToPlrIdxTensorProp.tensorType = QC_TENSOR_TYPE_INT_32;
coordToPlrIdxTensorProp.dims[0] = (uint32_t) ( gridXSize * gridYSize * 2 );
coordToPlrIdxTensorProp.dims[1] = 0;
coordToPlrIdxTensorProp.numDims = 1;
}
const uint32_t outputPlrBufferNum = outputPlrBufferIds.size();
const uint32_t outputFeatureBufferNum = outputFeatureBufferIds.size();
TensorDescriptor_t inputTensors;
TensorDescriptor_t outputPlrTensors[outputPlrBufferNum];
TensorDescriptor_t outputFeatureTensors[outputFeatureBufferNum];
NodeFrameDescriptor frameDesc( 3 );
ret = bufMgr.Allocate( inputTensorProp, inputTensors );
ASSERT_EQ( QC_STATUS_OK, ret );
uint32_t numPts = 0;
if ( nullptr == pcdFile )
{
numPts = ( maxPointNum / 3 ) + ( rand() % ( 2 * maxPointNum / 3 ) );
RandomGenPoints( (float *) inputTensors.pBuf, numPts );
}
else
{
LoadPoints( inputTensors.pBuf, inputTensors.size, numPts, pcdFile );
std::cout << "using point cloud file: " << pcdFile << std::endl;
}
inputTensors.dims[0] = numPts;
for ( uint32_t i = 0; i < outputPlrBufferNum; i++ )
{
ret = bufMgr.Allocate( outputPlrTensorProp, outputPlrTensors[i] );
ASSERT_EQ( QC_STATUS_OK, ret );
config.buffers.push_back( outputPlrTensors[i] );
}
for ( uint32_t i = 0; i < outputFeatureBufferNum; i++ )
{
ret = bufMgr.Allocate( outputFeatureTensorProp, outputFeatureTensors[i] );
ASSERT_EQ( QC_STATUS_OK, ret );
config.buffers.push_back( outputFeatureTensors[i] );
}
if ( QC_PROCESSOR_GPU == processor )
{
ret = bufMgr.Allocate( plrPointsTensorProp, plrPointsTensor );
ASSERT_EQ( QC_STATUS_OK, ret );
ret = bufMgr.Allocate( coordToPlrIdxTensorProp, coordToPlrIdxTensor );
ASSERT_EQ( QC_STATUS_OK, ret );
config.buffers.push_back( plrPointsTensor );
config.buffers.push_back( coordToPlrIdxTensor );
}
ret = frameDesc.SetBuffer( 0, inputTensors );
ASSERT_EQ( QC_STATUS_OK, ret );
ret = frameDesc.SetBuffer( 1, outputPlrTensors[0] );
ASSERT_EQ( QC_STATUS_OK, ret );
ret = frameDesc.SetBuffer( 2, outputFeatureTensors[0] );
ASSERT_EQ( QC_STATUS_OK, ret );
ret = voxel.Initialize( config );
ASSERT_EQ( QC_STATUS_OK, ret );
ret = voxel.Start();
ASSERT_EQ( QC_STATUS_OK, ret );
ret = voxel.ProcessFrameDescriptor( frameDesc );
ASSERT_EQ( QC_STATUS_OK, ret );
ret = voxel.Stop();
ASSERT_EQ( QC_STATUS_OK, ret );
ret = voxel.DeInitialize();
ASSERT_EQ( QC_STATUS_OK, ret );
ret = bufMgr.Free( inputTensors );
ASSERT_EQ( QC_STATUS_OK, ret );
for ( uint32_t i = 0; i < outputPlrBufferNum; i++ )
{
ret = bufMgr.Free( outputPlrTensors[i] );
ASSERT_EQ( QC_STATUS_OK, ret );
}
for ( uint32_t i = 0; i < outputFeatureBufferNum; i++ )
{
ret = bufMgr.Free( outputFeatureTensors[i] );
ASSERT_EQ( QC_STATUS_OK, ret );
}
if ( QC_PROCESSOR_GPU == processor )
{
ret = bufMgr.Free( coordToPlrIdxTensor );
ASSERT_EQ( QC_STATUS_OK, ret );
ret = bufMgr.Free( plrPointsTensor );
ASSERT_EQ( QC_STATUS_OK, ret );
}
}
TEST( FadasPlr, SANITY_VoxelizationCPU_XYZR )
{
std::string processorType = "cpu";
std::string inputMode = "xyzr";
const char *pcdFile = "./data/test/voxelization/pointcloud.bin";
SANITY_Voxelization( g_Config_XYZR, processorType, inputMode, pcdFile );
}
TEST( FadasPlr, Stress_VoxelizationCPU_XYZR )
{
uint32_t loopNumber = 100;
const char *envValue = getenv( "VOXEL_TEST_LOOP_NUMBER" );
if ( nullptr != envValue )
{
loopNumber = (uint32_t) atoi( envValue );
}
for ( int i = 0; i < loopNumber; i++ )
{
printf( "InitDeinit Stress_VoxelizationCPU_XYZR %d times\n", i );
SANITY_Voxelization( g_Config_XYZR, "cpu", "xyzr", nullptr );
}
}
TEST( FadasPlr, SANITY_VoxelizationGPU_XYZR )
{
std::string processorType = "gpu";
std::string inputMode = "xyzr";
const char *pcdFile = "./data/test/voxelization/pointcloud.bin";
SANITY_Voxelization( g_Config_XYZR, processorType, inputMode, pcdFile );
}
TEST( FadasPlr, Stress_VoxelizationGPU_XYZR )
{
uint32_t loopNumber = 100;
const char *envValue = getenv( "VOXEL_TEST_LOOP_NUMBER" );
if ( nullptr != envValue )
{
loopNumber = (uint32_t) atoi( envValue );
}
for ( int i = 0; i < loopNumber; i++ )
{
printf( "InitDeinit Stress_VoxelizationGPU_XYZR %d times\n", i );
SANITY_Voxelization( g_Config_XYZR, "gpu", "xyzr", nullptr );
}
}
TEST( FadasPlr, SANITY_VoxelizationGPU_XYZRT )
{
std::string processorType = "gpu";
std::string inputMode = "xyzrt";
const char *pcdFile = "./data/test/voxelization/pointcloud_XYZRT.bin";
SANITY_Voxelization( g_Config_XYZRT, processorType, inputMode, pcdFile );
}
TEST( FadasPlr, Stress_VoxelizationGPU_XYZRT )
{
uint32_t loopNumber = 100;
const char *envValue = getenv( "VOXEL_TEST_LOOP_NUMBER" );
if ( nullptr != envValue )
{
loopNumber = (uint32_t) atoi( envValue );
}
for ( int i = 0; i < loopNumber; i++ )
{
printf( "InitDeinit Stress_VoxelizationGPU_XYZRT %d times\n", i );
SANITY_Voxelization( g_Config_XYZRT, "gpu", "xyzrt", nullptr );
}
}
TEST( FadasPlr, SANITY_VoxelizationHTP0_XYZR )
{
std::string processorType = "htp0";
std::string inputMode = "xyzr";
const char *pcdFile = "./data/test/voxelization/pointcloud.bin";
SANITY_Voxelization( g_Config_XYZR, processorType, inputMode, pcdFile );
}
TEST( FadasPlr, Stress_VoxelizationHTP0_XYZR )
{
uint32_t loopNumber = 100;
const char *envValue = getenv( "VOXEL_TEST_LOOP_NUMBER" );
if ( nullptr != envValue )
{
loopNumber = (uint32_t) atoi( envValue );
}
for ( int i = 0; i < loopNumber; i++ )
{
printf( "InitDeinit Stress_VoxelizationHTP0_XYZR %d times\n", i );
SANITY_Voxelization( g_Config_XYZR, "htp0", "xyzr", nullptr );
}
}
#if ( QC_TARGET_SOC == 8650 )
TEST( FadasPlr, SANITY_VoxelizationHTP1_XYZR )
{
std::string processorType = "htp1";
std::string inputMode = "xyzr";
const char *pcdFile = "./data/test/voxelization/pointcloud.bin";
SANITY_Voxelization( g_Config_XYZR, processorType, inputMode, pcdFile );
}
#endif
// ============================================================================
// EXTENDED TESTS FOR 100% COVERAGE
// ============================================================================
// ============================================================================
// MONITOR TESTS - VoxelizationMonitor.cpp (0% coverage -> 100%)
// ============================================================================
TEST( VoxelizationMonitor, GetOptions_ReturnsEmptyJSON )
{
QC::Node::Voxelization voxel;
// GetOptions from Monitor interface should return "{}"
const std::string &options = voxel.GetMonitoringIfs().GetOptions();
EXPECT_EQ( "{}", options );
}
TEST( VoxelizationMonitor, VerifyAndSet_ReturnsUnsupported )
{
QC::Node::Voxelization voxel;
std::string config = "{}";
std::string errors;
// VerifyAndSet should return UNSUPPORTED for monitoring
// This covers lines 12-15 in VoxelizationMonitor.cpp
QCStatus_e ret = voxel.GetMonitoringIfs().VerifyAndSet( config, errors );
EXPECT_EQ( QC_STATUS_UNSUPPORTED, ret );
}
TEST( VoxelizationConfig, GetOptions_ReturnsEmptyString )
{
QC::Node::Voxelization voxel;
// GetOptions from Config interface should return empty string
const std::string &options = voxel.GetConfigurationIfs().GetOptions();
EXPECT_EQ( "", options );
}
TEST( VoxelizationMonitor, Get_ReturnsMonitorConfig )
{
// This test covers the VoxelizationMonitor::Get() method (lines 23-26)
// to achieve 100% coverage for VoxelizationMonitor.cpp
QCStatus_e ret;
DataTree dt;
std::string errors;
// Use a valid configuration
ret = dt.Load( g_Config_XYZR, errors );
ASSERT_EQ( QC_STATUS_OK, ret );
// Setup configuration
QCNodeInit_t config;
config.config = dt.Dump();
// Create buffer manager and allocate buffers
BufferManager bufMgr = BufferManager( { "VOXEL_MONITOR_TEST", QC_NODE_TYPE_VOXEL, 0 } );
// Get configuration parameters
DataTree staticCfg;
ret = dt.Get( "static", staticCfg );
ASSERT_EQ( QC_STATUS_OK, ret );
uint32_t maxPointNum = staticCfg.Get<uint32_t>( "maxPointNum", 0 );
uint32_t maxPlrNum = staticCfg.Get<uint32_t>( "maxPlrNum", 0 );
uint32_t maxPointNumPerPlr = staticCfg.Get<uint32_t>( "maxPointNumPerPlr", 0 );
uint32_t outputFeatureDimNum = staticCfg.Get<uint32_t>( "outputFeatureDimNum", 0 );
// Setup tensor properties
TensorProps_t inputTensorProp;
inputTensorProp.tensorType = QC_TENSOR_TYPE_FLOAT_32;
inputTensorProp.dims[0] = maxPointNum;
inputTensorProp.dims[1] = 4; // XYZR mode
inputTensorProp.dims[2] = 0;
inputTensorProp.numDims = 2;
TensorProps_t outputPlrTensorProp;
outputPlrTensorProp.tensorType = QC_TENSOR_TYPE_FLOAT_32;
outputPlrTensorProp.dims[0] = maxPlrNum;
outputPlrTensorProp.dims[1] = VOXELIZATION_PILLAR_COORDS_DIM;
outputPlrTensorProp.dims[2] = 0;
outputPlrTensorProp.numDims = 2;
TensorProps_t outputFeatureTensorProp;
outputFeatureTensorProp.tensorType = QC_TENSOR_TYPE_FLOAT_32;
outputFeatureTensorProp.dims[0] = maxPlrNum;
outputFeatureTensorProp.dims[1] = maxPointNumPerPlr;
outputFeatureTensorProp.dims[2] = outputFeatureDimNum;
outputFeatureTensorProp.dims[3] = 0;
outputFeatureTensorProp.numDims = 3;
// Allocate buffers
TensorDescriptor_t inputTensor;
TensorDescriptor_t outputPlrTensors[4];
TensorDescriptor_t outputFeatureTensors[4];
ret = bufMgr.Allocate( inputTensorProp, inputTensor );
ASSERT_EQ( QC_STATUS_OK, ret );
for ( uint32_t i = 0; i < 4; i++ )
{
ret = bufMgr.Allocate( outputPlrTensorProp, outputPlrTensors[i] );
ASSERT_EQ( QC_STATUS_OK, ret );
config.buffers.push_back( outputPlrTensors[i] );
}
for ( uint32_t i = 0; i < 4; i++ )
{
ret = bufMgr.Allocate( outputFeatureTensorProp, outputFeatureTensors[i] );
ASSERT_EQ( QC_STATUS_OK, ret );
config.buffers.push_back( outputFeatureTensors[i] );
}
// Initialize Voxelization node
QC::Node::Voxelization voxel;
ret = voxel.Initialize( config );
ASSERT_EQ( QC_STATUS_OK, ret );
// TEST: Call Get() on monitoring interface to cover lines 23-26
const QCNodeMonitoringBase_t &monitorConfig = voxel.GetMonitoringIfs().Get();
// Verify the returned monitor configuration
// The purpose of this test is to cover the Get() method (lines 23-26)
// We just verify the call succeeds (doesn't crash) and returns a valid reference
// Note: numOfEntries may be uninitialized, so we only verify the pointer is valid
EXPECT_NE( nullptr, &monitorConfig );
// Cleanup
ret = voxel.DeInitialize();
EXPECT_EQ( QC_STATUS_OK, ret );
ret = bufMgr.Free( inputTensor );
EXPECT_EQ( QC_STATUS_OK, ret );
for ( uint32_t i = 0; i < 4; i++ )
{
ret = bufMgr.Free( outputPlrTensors[i] );
EXPECT_EQ( QC_STATUS_OK, ret );
}
for ( uint32_t i = 0; i < 4; i++ )
{
ret = bufMgr.Free( outputFeatureTensors[i] );
EXPECT_EQ( QC_STATUS_OK, ret );
}
}
TEST( VoxelizationLifecycle, Initialize_FailsAfterNodeBaseInit )
{
// Valid config that passes VerifyAndSet
std::string validConfig = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"inputMode": "xyzr",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = validConfig;
// Leave config.buffers empty - this should cause VoxelizationImpl::Initialize to fail
// after NodeBase::Init succeeds
QCStatus_e ret = voxel.Initialize( config );
// Should fail because buffers are not provided
EXPECT_NE( QC_STATUS_OK, ret );
}
// ============================================================================
// CONFIGURATION ERROR TESTS - VoxelizationConfig.cpp
// ============================================================================
TEST( VoxelizationConfig, InvalidConfig_EmptyString )
{
std::string emptyConfig = "";
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = emptyConfig;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_NE( QC_STATUS_OK, ret );
}
TEST( VoxelizationConfig, InvalidConfig_MalformedJSON )
{
std::string malformedConfig = "{ invalid json }";
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = malformedConfig;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_NE( QC_STATUS_OK, ret );
}
TEST( VoxelizationConfig, InvalidConfig_EmptyName )
{
// Test with name field explicitly set to empty string to trigger empty name check
// This is the CRITICAL test to cover lines 17-21 in VoxelizationConfig.cpp
std::string configEmptyName = EXPAND_JSON( {
"static": {
"name": "",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"inputMode": "xyzr",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configEmptyName;
QCStatus_e ret = voxel.Initialize( config );
// Should fail with BAD_ARGUMENTS due to empty name string
// This covers lines 17 (TRUE), 19, and 20 in VoxelizationConfig.cpp
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_ZeroMaxPointNum )
{
std::string configZeroMaxPointNum = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 0,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"inputMode": "xyzr",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configZeroMaxPointNum;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_ZeroMaxPlrNum )
{
std::string configZeroMaxPlrNum = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 0,
"maxPointNumPerPlr": 32,
"inputMode": "xyzr",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configZeroMaxPlrNum;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_ZeroMaxPointNumPerPlr )
{
std::string configZeroMaxPointNumPerPlr = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 0,
"inputMode": "xyzr",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configZeroMaxPointNumPerPlr;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_EmptyInputMode )
{
// Test with inputMode field missing to trigger empty inputMode check
std::string configMissingInputMode = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configMissingInputMode;
std::cout << "Config buffer is filled with configMissingInputMode Start" << std::endl;
QCStatus_e ret = voxel.Initialize( config );
std::cout << "Config buffer is filled with configMissingInputMode Stop" << std::endl;
// Should fail with BAD_ARGUMENTS due to missing/empty inputMode
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_InvalidInputMode )
{
std::string configInvalidInputMode = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"inputMode": "invalid_mode",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configInvalidInputMode;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_ZeroOutputFeatureDimNum )
{
std::string configZeroOutputFeatureDimNum = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"inputMode": "xyzr",
"outputFeatureDimNum": 0,
"outputPlrBufferIds": [0, 1, 2, 3],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configZeroOutputFeatureDimNum;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_EmptyOutputPlrBufferIds )
{
std::string configEmptyOutputPlrBufferIds = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,
"inputMode": "xyzr",
"outputFeatureDimNum": 10,
"outputPlrBufferIds": [],
"outputFeatureBufferIds": [4, 5, 6, 7]
}
} );
QCNodeInit_t config;
QC::Node::Voxelization voxel;
config.config = configEmptyOutputPlrBufferIds;
QCStatus_e ret = voxel.Initialize( config );
EXPECT_EQ( QC_STATUS_BAD_ARGUMENTS, ret );
}
TEST( VoxelizationConfig, InvalidConfig_EmptyOutputFeatureBufferIds )
{
std::string configEmptyOutputFeatureBufferIds = EXPAND_JSON( {
"static": {
"name": "voxelization",
"id": 0,
"processorType": "cpu",
"Xsize": 0.16,
"Ysize": 0.16,
"Zsize": 4.0,
"Xmin": 0.0,
"Ymin": -39.68,
"Zmin": -3.0,
"Xmax": 69.12,
"Ymax": 39.68,
"Zmax": 1.0,
"maxPointNum": 300000,
"maxPlrNum": 12000,
"maxPointNumPerPlr": 32,