@@ -282,7 +282,7 @@ TEST(TaskTest, DestructorTerminatesIfWrongOrder) {
282
282
DummyTask task;
283
283
EXPECT_THROW (task.Run (), std::runtime_error);
284
284
}
285
-
285
+
286
286
// Create a new task to complete the lifecycle properly
287
287
DummyTask task2;
288
288
task2.Validation ();
@@ -360,9 +360,7 @@ TEST(PerfTest, GetStringParamNameTest) {
360
360
EXPECT_EQ (GetStringParamName (PerfResults::kNone ), " none" );
361
361
}
362
362
363
- TEST (PerfTest, DefaultTimerReturnsNegativeOne) {
364
- EXPECT_EQ (DefaultTimer (), -1.0 );
365
- }
363
+ TEST (PerfTest, DefaultTimerReturnsNegativeOne) { EXPECT_EQ (DefaultTimer (), -1.0 ); }
366
364
367
365
TEST (PerfTest, PerfAttrDefaultValues) {
368
366
PerfAttr attr;
@@ -386,9 +384,9 @@ TEST(PerfTest, PerfResultsEnumValues) {
386
384
TEST (PerfTest, PerfConstructorSetsTaskState) {
387
385
auto task_ptr = std::make_shared<DummyTask>();
388
386
Perf<int , int > perf (task_ptr);
389
-
387
+
390
388
EXPECT_EQ (task_ptr->GetStateOfTesting (), ppc::task::StateOfTesting::kPerf );
391
-
389
+
392
390
// Complete the task lifecycle to avoid destructor issues
393
391
task_ptr->Validation ();
394
392
task_ptr->PreProcessing ();
@@ -399,25 +397,25 @@ TEST(PerfTest, PerfConstructorSetsTaskState) {
399
397
TEST (PerfTest, GetPerfResultsReturnsCorrectResults) {
400
398
auto task_ptr = std::make_shared<DummyTask>();
401
399
Perf<int , int > perf (task_ptr);
402
-
400
+
403
401
// Initially should be default values
404
402
auto initial_results = perf.GetPerfResults ();
405
403
EXPECT_EQ (initial_results.time_sec , 0.0 );
406
404
EXPECT_EQ (initial_results.type_of_running , PerfResults::kNone );
407
-
405
+
408
406
PerfAttr attr;
409
407
double time = 0.0 ;
410
408
attr.current_timer = [&time]() {
411
409
double t = time;
412
410
time += 0.5 ;
413
411
return t;
414
412
};
415
-
413
+
416
414
perf.PipelineRun (attr);
417
415
auto pipeline_results = perf.GetPerfResults ();
418
416
EXPECT_EQ (pipeline_results.type_of_running , PerfResults::kPipeline );
419
417
EXPECT_GT (pipeline_results.time_sec , 0.0 );
420
-
418
+
421
419
perf.TaskRun (attr);
422
420
auto taskrun_results = perf.GetPerfResults ();
423
421
EXPECT_EQ (taskrun_results.type_of_running , PerfResults::kTaskRun );
@@ -427,83 +425,83 @@ TEST(PerfTest, GetPerfResultsReturnsCorrectResults) {
427
425
TEST (PerfTest, CommonRunCalculatesAverageTime) {
428
426
auto task_ptr = std::make_shared<DummyTask>();
429
427
Perf<int , int > perf (task_ptr);
430
-
428
+
431
429
PerfAttr attr;
432
430
int call_count = 0 ;
433
431
attr.num_running = 3 ;
434
432
attr.current_timer = [&call_count]() {
435
433
if (call_count == 0 ) {
436
434
call_count++;
437
- return 0.0 ; // Start time
435
+ return 0.0 ; // Start time
438
436
} else {
439
- return 3.0 ; // End time after 3 runs
437
+ return 3.0 ; // End time after 3 runs
440
438
}
441
439
};
442
-
440
+
443
441
perf.PipelineRun (attr);
444
442
auto results = perf.GetPerfResults ();
445
-
443
+
446
444
// Total time should be 3 seconds, average should be 1 second (3.0 - 0.0) / 3
447
445
EXPECT_DOUBLE_EQ (results.time_sec , 1.0 );
448
446
}
449
447
450
448
TEST (PerfTest, PrintPerfStatisticPipelineOutput) {
451
449
auto task_ptr = std::make_shared<DummyTask>();
452
450
Perf<int , int > perf (task_ptr);
453
-
451
+
454
452
PerfAttr attr;
455
453
double time = 0.0 ;
456
454
attr.current_timer = [&time]() {
457
455
double t = time;
458
456
time += 0.1 ;
459
457
return t;
460
458
};
461
-
459
+
462
460
perf.PipelineRun (attr);
463
-
461
+
464
462
testing::internal::CaptureStdout ();
465
463
perf.PrintPerfStatistic (" test_pipeline" );
466
464
std::string output = testing::internal::GetCapturedStdout ();
467
-
465
+
468
466
EXPECT_NE (output.find (" test_pipeline:pipeline:" ), std::string::npos);
469
- EXPECT_NE (output.find (" 0.0200000000" ), std::string::npos); // 0.1/5 = 0.02
467
+ EXPECT_NE (output.find (" 0.0200000000" ), std::string::npos); // 0.1/5 = 0.02
470
468
}
471
469
472
470
TEST (PerfTest, PrintPerfStatisticTaskRunOutput) {
473
471
auto task_ptr = std::make_shared<DummyTask>();
474
472
Perf<int , int > perf (task_ptr);
475
-
473
+
476
474
PerfAttr attr;
477
475
double time = 0.0 ;
478
476
attr.current_timer = [&time]() {
479
477
double t = time;
480
478
time += 0.25 ;
481
479
return t;
482
480
};
483
-
481
+
484
482
perf.TaskRun (attr);
485
-
483
+
486
484
testing::internal::CaptureStdout ();
487
485
perf.PrintPerfStatistic (" test_taskrun" );
488
486
std::string output = testing::internal::GetCapturedStdout ();
489
-
487
+
490
488
EXPECT_NE (output.find (" test_taskrun:task_run:" ), std::string::npos);
491
489
}
492
490
493
491
TEST (PerfTest, PrintPerfStatisticThrowsOnExceedingMaxTime) {
494
492
auto task_ptr = std::make_shared<DummyTask>();
495
493
Perf<int , int > perf (task_ptr);
496
-
494
+
497
495
PerfAttr attr;
498
496
double time = 0.0 ;
499
497
attr.current_timer = [&time]() {
500
498
double t = time;
501
- time += 55.0 ; // Exceeds kMaxTime (10.0)
499
+ time += 55.0 ; // Exceeds kMaxTime (10.0)
502
500
return t;
503
501
};
504
-
502
+
505
503
perf.PipelineRun (attr);
506
-
504
+
507
505
testing::internal::CaptureStdout ();
508
506
try {
509
507
perf.PrintPerfStatistic (" test_exceed_time" );
@@ -523,73 +521,74 @@ TEST(PerfTest, TaskRunCompletesPipelineAfterTiming) {
523
521
int preprocessing_count = 0 ;
524
522
int run_count = 0 ;
525
523
int postprocessing_count = 0 ;
526
-
524
+
527
525
// Create a custom task that counts method calls
528
526
class CountingTask : public Task <int , int > {
529
527
public:
530
528
int * validation_count_;
531
529
int * preprocessing_count_;
532
530
int * run_count_;
533
531
int * postprocessing_count_;
534
-
535
- CountingTask (int * vc, int * pc, int * rc, int * ppc)
532
+
533
+ CountingTask (int * vc, int * pc, int * rc, int * ppc)
536
534
: validation_count_(vc), preprocessing_count_(pc), run_count_(rc), postprocessing_count_(ppc) {}
537
-
535
+
538
536
bool ValidationImpl () override {
539
537
(*validation_count_)++;
540
538
return true ;
541
539
}
542
-
540
+
543
541
bool PreProcessingImpl () override {
544
542
(*preprocessing_count_)++;
545
543
return true ;
546
544
}
547
-
545
+
548
546
bool RunImpl () override {
549
547
(*run_count_)++;
550
548
return true ;
551
549
}
552
-
550
+
553
551
bool PostProcessingImpl () override {
554
552
(*postprocessing_count_)++;
555
553
return true ;
556
554
}
557
555
};
558
-
559
- auto counting_task = std::make_shared<CountingTask>(&validation_count, &preprocessing_count, &run_count, &postprocessing_count);
556
+
557
+ auto counting_task =
558
+ std::make_shared<CountingTask>(&validation_count, &preprocessing_count, &run_count, &postprocessing_count);
560
559
Perf<int , int > counting_perf (counting_task);
561
-
560
+
562
561
PerfAttr attr;
563
562
attr.num_running = 1 ;
564
-
563
+
565
564
counting_perf.TaskRun (attr);
566
-
565
+
567
566
// TaskRun should call:
568
567
// 1. Validation + PreProcessing + Run (num_running times) + PostProcessing
569
568
// 2. Validation + PreProcessing + Run + PostProcessing (one additional complete cycle)
570
569
EXPECT_EQ (validation_count, 2 ); // Called twice
571
- EXPECT_EQ (preprocessing_count, 2 ); // Called twice
570
+ EXPECT_EQ (preprocessing_count, 2 ); // Called twice
572
571
EXPECT_EQ (run_count, 2 ); // Called twice (once in timing, once in final cycle)
573
572
EXPECT_EQ (postprocessing_count, 2 ); // Called twice
574
573
}
575
574
576
575
namespace test_namespace {
577
576
struct TestType {};
578
- }
577
+ } // namespace test_namespace
579
578
580
579
TEST (PerfTest, TemplateInstantiationWithDifferentTypes) {
581
580
// Test that Perf template can be instantiated with different types
582
581
auto int_task = std::make_shared<DummyTask>();
583
582
Perf<int , int > int_perf (int_task);
584
-
583
+
585
584
auto vector_task = std::make_shared<ppc::test::TestPerfTask<std::vector<int >, int >>(std::vector<int >{1 , 2 , 3 });
586
585
Perf<std::vector<int >, int > vector_perf (vector_task);
587
-
586
+
588
587
PerfAttr attr;
589
-
588
+
590
589
EXPECT_NO_THROW (int_perf.PipelineRun (attr));
591
590
EXPECT_NO_THROW (vector_perf.PipelineRun (attr));
592
-
591
+
593
592
EXPECT_EQ (int_perf.GetPerfResults ().type_of_running , PerfResults::kPipeline );
594
593
EXPECT_EQ (vector_perf.GetPerfResults ().type_of_running , PerfResults::kPipeline );
595
594
}
@@ -598,7 +597,7 @@ TEST(PerfTest, PerfAttrCustomValues) {
598
597
PerfAttr attr;
599
598
attr.num_running = 10 ;
600
599
attr.current_timer = []() { return 42.0 ; };
601
-
600
+
602
601
EXPECT_EQ (attr.num_running , 10U );
603
602
EXPECT_EQ (attr.current_timer (), 42.0 );
604
603
}
0 commit comments