PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
Loading...
Searching...
No Matches
Functions
test_logging.c File Reference

C test module for PICurv. More...

#include "test_support.h"
#include "logging.h"
#include <stdlib.h>
Include dependency graph for test_logging.c:

Go to the source code of this file.

Functions

static PetscErrorCode TestGetLogLevelFromEnvironment (void)
 Test-local routine.
 
static PetscErrorCode TestAllowedFunctionsFilter (void)
 Test-local routine.
 
static PetscErrorCode TestParticleConsoleSnapshotCadence (void)
 Test-local routine.
 
int main (int argc, char **argv)
 Entry point for this unit-test binary.
 

Detailed Description

C test module for PICurv.

Definition in file test_logging.c.

Function Documentation

◆ TestGetLogLevelFromEnvironment()

static PetscErrorCode TestGetLogLevelFromEnvironment ( void  )
static

Test-local routine.

Definition at line 15 of file test_logging.c.

16{
17 PetscFunctionBeginUser;
19 "get_log_level should honor LOG_LEVEL=INFO in this test binary"));
20 PetscCall(print_log_level());
21 PetscFunctionReturn(0);
22}
PetscErrorCode print_log_level(void)
Prints the current logging level to the console.
Definition logging.c:68
LogLevel get_log_level()
Retrieves the current logging level from the environment variable LOG_LEVEL.
Definition logging.c:36
@ LOG_INFO
Informational messages about program execution.
Definition logging.h:30
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Shared test-support routine.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestAllowedFunctionsFilter()

static PetscErrorCode TestAllowedFunctionsFilter ( void  )
static

Test-local routine.

Definition at line 27 of file test_logging.c.

28{
29 const char *allow_list[] = {"ComputeSpecificKE", "WriteEulerianFile"};
30
31 PetscFunctionBeginUser;
32 set_allowed_functions(allow_list, 2);
33 PetscCall(PicurvAssertBool(is_function_allowed("ComputeSpecificKE"),
34 "Allowed list should include ComputeSpecificKE"));
35 PetscCall(PicurvAssertBool((PetscBool)!is_function_allowed("UnlistedFunction"),
36 "Allowed list should exclude unknown function names"));
37
38 set_allowed_functions(NULL, 0);
39 PetscCall(PicurvAssertBool(is_function_allowed("AnyFunction"),
40 "Empty allow-list should permit all functions"));
41 PetscFunctionReturn(0);
42}
void set_allowed_functions(const char **functionList, int count)
Sets the global list of function names that are allowed to log.
Definition logging.c:104
PetscBool is_function_allowed(const char *functionName)
Checks if a given function is in the allow-list.
Definition logging.c:135
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Shared test-support routine.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestParticleConsoleSnapshotCadence()

static PetscErrorCode TestParticleConsoleSnapshotCadence ( void  )
static

Test-local routine.

Definition at line 47 of file test_logging.c.

48{
49 SimCtx simCtx;
50
51 PetscFunctionBeginUser;
52 PetscCall(PetscMemzero(&simCtx, sizeof(simCtx)));
53 simCtx.np = 32;
55
57 "Particle snapshot contract should be enabled when particles and cadence are configured"));
59 "Snapshot should emit on cadence-aligned completed steps"));
60 PetscCall(PicurvAssertBool((PetscBool)!ShouldEmitPeriodicParticleConsoleSnapshot(&simCtx, 7),
61 "Snapshot should not emit off-cadence"));
62
64 PetscCall(PicurvAssertBool((PetscBool)!IsParticleConsoleSnapshotEnabled(&simCtx),
65 "Zero cadence should disable periodic particle snapshots"));
67 "NULL SimCtx should never emit periodic snapshots"));
68 PetscFunctionReturn(0);
69}
PetscBool ShouldEmitPeriodicParticleConsoleSnapshot(const SimCtx *simCtx, PetscInt completed_step)
Returns whether a particle console snapshot should be emitted for the completed timestep.
Definition logging.c:494
PetscBool IsParticleConsoleSnapshotEnabled(const SimCtx *simCtx)
Returns whether periodic particle console snapshots are enabled.
Definition logging.c:477
PetscInt np
Definition variables.h:683
PetscInt particleConsoleOutputFreq
Definition variables.h:604
The master context for the entire simulation.
Definition variables.h:591
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Entry point for this unit-test binary.

Definition at line 74 of file test_logging.c.

75{
76 PetscErrorCode ierr;
77 const PicurvTestCase cases[] = {
78 {"get-log-level-from-environment", TestGetLogLevelFromEnvironment},
79 {"allowed-functions-filter", TestAllowedFunctionsFilter},
80 {"particle-console-snapshot-cadence", TestParticleConsoleSnapshotCadence},
81 };
82
83 (void)setenv("LOG_LEVEL", "INFO", 1);
84
85 ierr = PetscInitialize(&argc, &argv, NULL, "PICurv logging tests");
86 if (ierr) {
87 return (int)ierr;
88 }
89
90 ierr = PicurvRunTests("unit-logging", cases, sizeof(cases) / sizeof(cases[0]));
91 if (ierr) {
92 PetscFinalize();
93 return (int)ierr;
94 }
95
96 set_allowed_functions(NULL, 0);
97
98 ierr = PetscFinalize();
99 return (int)ierr;
100}
static PetscErrorCode TestParticleConsoleSnapshotCadence(void)
Test-local routine.
static PetscErrorCode TestGetLogLevelFromEnvironment(void)
Test-local routine.
static PetscErrorCode TestAllowedFunctionsFilter(void)
Test-local routine.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Shared test-support routine.
Named test case descriptor consumed by PicurvRunTests.
Here is the call graph for this function: