C unit tests for runtime log-level, allow-list, conversion, and profiling helpers. More...
#include "test_support.h"#include "verification_sources.h"#include "AnalyticalSolutions.h"#include "logging.h"#include "interpolation.h"#include "les.h"#include "setup.h"#include "statistics_accumulator.h"#include "statistics_window.h"#include <fcntl.h>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>Go to the source code of this file.
Data Structures | |
| struct | AnatomyCaptureCtx |
Typedefs | |
| typedef PetscErrorCode(* | CapturedLoggingFn) (UserCtx *user, SimCtx *simCtx, void *ctx) |
| typedef struct AnatomyCaptureCtx | AnatomyCaptureCtx |
Functions | |
| static PetscErrorCode | AssertFileContains (const char *path, const char *needle, const char *context) |
| Asserts that one text file contains a required substring. | |
| static PetscErrorCode | AssertFileNotContains (const char *path, const char *needle, const char *context) |
| Asserts that one text file does not contain an excluded substring. | |
| static PetscErrorCode | ReadLogHeaderAndRow (const char *path, PetscInt row_index, char *header, size_t header_len, char *row, size_t row_len) |
| Reads the column header and the requested 1-based data row from a comma-separated solution-convergence CSV. | |
| static PetscErrorCode | LogFindColumnIndex (const char *header, const char *column_name, PetscInt *index_out) |
| Returns the zero-based column index for one comma-separated header field. | |
| static PetscErrorCode | LogGetColumnText (const char *header, const char *row, const char *column_name, char *value, size_t value_len) |
| Extracts one comma-separated log cell as text by header name. | |
| static PetscErrorCode | LogGetColumnInt (const char *header, const char *row, const char *column_name, PetscInt *value_out) |
| Extracts one comma-separated log cell as an integer by header name. | |
| static PetscErrorCode | LogGetColumnReal (const char *header, const char *row, const char *column_name, PetscReal *value_out) |
| Extracts one comma-separated log cell as a real by header name. | |
| static PetscErrorCode | CaptureLoggingOutput (UserCtx *user, SimCtx *simCtx, CapturedLoggingFn fn, void *ctx, char *captured, size_t captured_len) |
| Captures stdout emitted by one logging helper into a temporary file-backed buffer. | |
| static PetscErrorCode | InvokeParticleFieldLog (UserCtx *user, SimCtx *simCtx, void *ctx) |
Adapts LOG_PARTICLE_FIELDS() to the generic stdout-capture callback shape. | |
| static PetscErrorCode | InvokeParticleConsoleSnapshot (UserCtx *user, SimCtx *simCtx, void *ctx) |
Adapts EmitParticleConsoleSnapshot() to the generic stdout-capture callback shape. | |
| static PetscErrorCode | InvokeStatisticsConsoleSnapshot (UserCtx *user, SimCtx *simCtx, void *ctx) |
Adapts EmitStatisticsConsoleSnapshot() to the generic stdout-capture callback shape. | |
| static PetscErrorCode | InvokeFieldAnatomyLog (UserCtx *user, SimCtx *simCtx, void *ctx) |
Adapts LOG_FIELD_ANATOMY() to the generic stdout-capture callback shape. | |
| static PetscErrorCode | SeedLoggingParticleFixture (SimCtx **simCtx_out, UserCtx **user_out) |
| Creates a small particle-bearing runtime fixture used by logging tests. | |
| static PetscErrorCode | SetUniformVelocityField (UserCtx *user, Vec field, PetscReal ux, PetscReal uy, PetscReal uz) |
| Fills one Cartesian velocity field with a uniform constant state. | |
| static PetscErrorCode | SetUniformScalarField (UserCtx *user, Vec field, PetscReal value) |
| Fills one scalar field with a uniform constant state. | |
| static PetscErrorCode | SetSinusoidalVZField (UserCtx *user, Vec field, PetscReal v_amp, PetscReal w_const) |
| Fills one Cartesian velocity field with u=0, v=v_amp*sin(2π*k/km), w=w_const. | |
| static PetscErrorCode | TestStringConversionHelpers (void) |
| Tests string-conversion helpers for configured enums and unknown values. | |
| static PetscErrorCode | TestGetLogLevelFromEnvironment (void) |
| Tests that log level selection honors the environment variable. | |
| static PetscErrorCode | TestAllowedFunctionsFilter (void) |
| Tests the function allow-list filter used by the logging layer. | |
| static PetscErrorCode | TestParticleConsoleSnapshotCadence (void) |
| Tests periodic particle console snapshot enablement and cadence. | |
| static PicurvWindowDefinition | LoggingStatisticsDefinition (void) |
| Builds the window definition backing this suite's statistics console fixture. | |
| static PetscErrorCode | TestStatisticsConsoleSnapshotCadence (void) |
| Tests periodic statistics console snapshot enablement and cadence. | |
| static PetscErrorCode | TestLoggingFileParsingAndFormattingHelpers (void) |
| Tests logging-side file parsing, helper formatting, and progress utilities. | |
| static PetscErrorCode | TestLoggingContinuityAndFieldDiagnostics (void) |
| Tests continuity, min/max, and anatomy logging helpers on minimal runtime fixtures. | |
| static PetscErrorCode | TestInterpolationErrorLogging (void) |
| Tests interpolation-error logging against an analytically matched particle field. | |
| static PetscErrorCode | TestLESDiagnosticsConstantModelHasNoMeasuredCoefficient (void) |
| Tests that the constant Smagorinsky model reports its configured coefficient, not a measured one. | |
| static PetscErrorCode | TestScatterMetricsLogging (void) |
| Tests file-backed scatter metrics logging against a fully occupied constant field. | |
| static PetscErrorCode | TestParticleFieldTableLogging (void) |
| Tests stdout particle-table logging on a production-like swarm fixture. | |
| static PetscErrorCode | TestParticleConsoleSnapshotLogging (void) |
| Tests console snapshot logging against the public periodic-snapshot helper. | |
| static PetscErrorCode | TestStatisticsConsoleSnapshotLogging (void) |
| Tests statistics console snapshot content, and its silence when disabled. | |
| static PetscErrorCode | SetUniformPressure (UserCtx *user, PetscReal value) |
| Sets the pressure field to a uniform value across the owned range. | |
| static PetscErrorCode | AccumulateAtConsoleCadence (SimCtx *simCtx, UserCtx *user, PicurvWindow *window, PicurvWindowStorage *storage, const PicurvWindowDefinition *definition, PetscInt console_frequency) |
| Drives one accumulation run at a given console cadence, in the runloop's order. | |
| static PetscErrorCode | AssertVecsIdentical (Vec expected, Vec actual, const char *context) |
| Asserts two accumulator vectors are bit-identical. | |
| static PetscErrorCode | TestConsoleCadenceDoesNotChangeAccumulation (void) |
| Tests that the console cadence has no effect on any accumulated result. | |
| static PetscErrorCode | TestParticleMetricsLogging (void) |
| Tests file-backed particle metrics logging after derived metrics are computed. | |
| static PetscErrorCode | TestSearchMetricsLogging (void) |
| Tests file-backed search metrics logging with the compact CSV contract. | |
| static PetscErrorCode | TestFieldAnatomyLogging (void) |
| Tests stdout field-anatomy logging on the corrected production-like DM fixture. | |
| static void | ProfiledFlowSolver (void) |
| Profiled stand-in: an aggregate named FlowSolver. | |
| static void | ProfiledUnselectedAggregate (void) |
| Profiled stand-in: an aggregate the per-step list does not select. | |
| static void | ProfiledEnabledHelper (void) |
| Profiled stand-in: a helper that profiling.helpers names. | |
| static void | ProfiledDisabledHelper (void) |
| Profiled stand-in: a helper that profiling.helpers does not name. | |
| static PetscErrorCode | TestProfilingLifecycleHelpers (void) |
| Tests profiling helper lifecycle logging for timestep and final-summary outputs. | |
| static PetscErrorCode | TestRuntimeMemoryLogHelpers (void) |
| Tests runtime memory log header, step rows, final rows, and disabled mode. | |
| static PetscErrorCode | TestRunCsvFirstOpenIsTrackedPerRun (void) |
| The run's first open of a CSV record is found by path, whenever it falls: a step-0 write survives a later open on a fresh run, and a continuation is marked once, at its first write, even when that is not in step StartStep + 1. | |
| static PetscErrorCode | TestSolutionConvergenceDisabled (void) |
| Verifies -solution_convergence_enabled=false suppresses the convergence writer. | |
| static PetscErrorCode | TestSolutionConvergenceSteadyLogging (void) |
| Tests steady solution-convergence log output, IBM masking, and gauge-invariant pressure drift. | |
| static PetscErrorCode | TestSolutionConvergencePeriodicLogging (void) |
| Tests periodic solution-convergence warmup and phase-aligned reference reuse. | |
| static PetscErrorCode | TestSolutionConvergenceStatisticalLogging (void) |
| Tests statistical solution-convergence sliding-window metrics. | |
| static PetscErrorCode | TestSolutionConvergenceMeansExcludeGhostLayers (void) |
| Regression test: convergence observables ignore the ghost layers of a walled box. | |
| static PetscErrorCode | TestPeriodicSinusoidalMeanKE (void) |
| Regression test: volume-averaged mean KE of a sinusoidal field in a fully periodic domain. | |
| int | main (int argc, char **argv) |
| Runs the unit-logging PETSc test binary. | |
C unit tests for runtime log-level, allow-list, conversion, and profiling helpers.
Definition in file test_logging.c.
| struct AnatomyCaptureCtx |
Definition at line 271 of file test_logging.c.
| Data Fields | ||
|---|---|---|
| FieldId | field_id | |
| const char * | stage_name | |
Definition at line 269 of file test_logging.c.
| typedef struct AnatomyCaptureCtx AnatomyCaptureCtx |
|
static |
Asserts that one text file contains a required substring.
Definition at line 27 of file test_logging.c.
|
static |
Asserts that one text file does not contain an excluded substring.
Definition at line 72 of file test_logging.c.
|
static |
Reads the column header and the requested 1-based data row from a comma-separated solution-convergence CSV.
Lines starting with '=' (banner) or '-' (separator) are skipped. The first non-skipped line is treated as the column header; subsequent non-skipped lines are data rows numbered from 1.
Definition at line 122 of file test_logging.c.
|
static |
Returns the zero-based column index for one comma-separated header field.
Definition at line 166 of file test_logging.c.
|
static |
Extracts one comma-separated log cell as text by header name.
Definition at line 198 of file test_logging.c.
|
static |
Extracts one comma-separated log cell as an integer by header name.
Definition at line 236 of file test_logging.c.
|
static |
Extracts one comma-separated log cell as a real by header name.
Definition at line 254 of file test_logging.c.
|
static |
Captures stdout emitted by one logging helper into a temporary file-backed buffer.
Definition at line 279 of file test_logging.c.
Adapts LOG_PARTICLE_FIELDS() to the generic stdout-capture callback shape.
Definition at line 330 of file test_logging.c.
|
static |
Adapts EmitParticleConsoleSnapshot() to the generic stdout-capture callback shape.
Definition at line 343 of file test_logging.c.
|
static |
Adapts EmitStatisticsConsoleSnapshot() to the generic stdout-capture callback shape.
Definition at line 355 of file test_logging.c.
Adapts LOG_FIELD_ANATOMY() to the generic stdout-capture callback shape.
Definition at line 367 of file test_logging.c.
|
static |
Creates a small particle-bearing runtime fixture used by logging tests.
Definition at line 380 of file test_logging.c.
|
static |
Fills one Cartesian velocity field with a uniform constant state.
Definition at line 428 of file test_logging.c.
|
static |
Fills one scalar field with a uniform constant state.
Definition at line 453 of file test_logging.c.
|
static |
Fills one Cartesian velocity field with u=0, v=v_amp*sin(2π*k/km), w=w_const.
Sets the sinusoidal profile at ALL owned nodes (including the periodic duplicate endpoint), matching how the IC routines populate fields before any periodic-endpoint fix is applied.
Definition at line 478 of file test_logging.c.
|
static |
Tests string-conversion helpers for configured enums and unknown values.
Definition at line 509 of file test_logging.c.
|
static |
Tests that log level selection honors the environment variable.
Definition at line 536 of file test_logging.c.
|
static |
Tests the function allow-list filter used by the logging layer.
Definition at line 548 of file test_logging.c.
|
static |
Tests periodic particle console snapshot enablement and cadence.
Definition at line 568 of file test_logging.c.
|
static |
Builds the window definition backing this suite's statistics console fixture.
One bounded pressure window on a per-step cadence: bounded so the snapshot exercises its percentage-progress branch, and a single field so the fixture stays cheap.
Definition at line 597 of file test_logging.c.
|
static |
Tests periodic statistics console snapshot enablement and cadence.
Definition at line 616 of file test_logging.c.
|
static |
Tests logging-side file parsing, helper formatting, and progress utilities.
Definition at line 665 of file test_logging.c.
|
static |
Tests continuity, min/max, and anatomy logging helpers on minimal runtime fixtures.
Definition at line 730 of file test_logging.c.
|
static |
Tests interpolation-error logging against an analytically matched particle field.
Definition at line 817 of file test_logging.c.
|
static |
Tests that the constant Smagorinsky model reports its configured coefficient, not a measured one.
cs_effective is the dynamic procedure's Germano contraction ratio. The constant model has none, so the row carries nan there and the configured Cs in cs_mean; it once wrote 0, which reads like a measurement.
Definition at line 888 of file test_logging.c.
|
static |
Tests file-backed scatter metrics logging against a fully occupied constant field.
Definition at line 925 of file test_logging.c.
|
static |
Tests stdout particle-table logging on a production-like swarm fixture.
Definition at line 994 of file test_logging.c.
|
static |
Tests console snapshot logging against the public periodic-snapshot helper.
Definition at line 1015 of file test_logging.c.
|
static |
Tests statistics console snapshot content, and its silence when disabled.
Covers both halves of the monitoring contract from one fixture: an active window reports its window-level scalars, and the identical call on a disabled subsystem writes nothing at all, which is the observable form of the gate the runloop relies on to keep a non-statistics run's log untouched.
Definition at line 1041 of file test_logging.c.
|
static |
Sets the pressure field to a uniform value across the owned range.
Definition at line 1096 of file test_logging.c.
|
static |
Drives one accumulation run at a given console cadence, in the runloop's order.
Reproduces the sequence the run loop applies for each completed step so the console observes exactly the states a real run would present to it.
Definition at line 1115 of file test_logging.c.
|
static |
Asserts two accumulator vectors are bit-identical.
Definition at line 1141 of file test_logging.c.
|
static |
Tests that the console cadence has no effect on any accumulated result.
This is the observable form of the console cadence's exclusion from the window definition hash: two runs over an identical field series, one reporting every step and one reporting never, must leave bit-identical accumulator state. Running it where the log level is at least LOG_INFO matters, because a snapshot that silently declined to emit would make the comparison vacuous.
Definition at line 1160 of file test_logging.c.
|
static |
Tests file-backed particle metrics logging after derived metrics are computed.
Definition at line 1216 of file test_logging.c.
|
static |
Tests file-backed search metrics logging with the compact CSV contract.
Definition at line 1268 of file test_logging.c.
|
static |
Tests stdout field-anatomy logging on the corrected production-like DM fixture.
Definition at line 1321 of file test_logging.c.
|
static |
Profiled stand-in: an aggregate named FlowSolver.
Definition at line 1343 of file test_logging.c.
|
static |
Profiled stand-in: an aggregate the per-step list does not select.
Definition at line 1345 of file test_logging.c.
|
static |
Profiled stand-in: a helper that profiling.helpers names.
Definition at line 1347 of file test_logging.c.
|
static |
Profiled stand-in: a helper that profiling.helpers does not name.
Definition at line 1349 of file test_logging.c.
|
static |
Tests profiling helper lifecycle logging for timestep and final-summary outputs.
Aggregates are always timed; a helper is timed only when profiling.helpers names it; the per-step file lists selected aggregates; the summary lists every timed PICurv function and then PETSc's own events.
Definition at line 1357 of file test_logging.c.
|
static |
Tests runtime memory log header, step rows, final rows, and disabled mode.
Definition at line 1427 of file test_logging.c.
|
static |
The run's first open of a CSV record is found by path, whenever it falls: a step-0 write survives a later open on a fresh run, and a continuation is marked once, at its first write, even when that is not in step StartStep + 1.
Definition at line 1471 of file test_logging.c.
|
static |
Verifies -solution_convergence_enabled=false suppresses the convergence writer.
Definition at line 1508 of file test_logging.c.
|
static |
Tests steady solution-convergence log output, IBM masking, and gauge-invariant pressure drift.
Definition at line 1537 of file test_logging.c.
|
static |
Tests periodic solution-convergence warmup and phase-aligned reference reuse.
Definition at line 1622 of file test_logging.c.
|
static |
Tests statistical solution-convergence sliding-window metrics.
Definition at line 1707 of file test_logging.c.
|
static |
Regression test: convergence observables ignore the ghost layers of a walled box.
Interior cells carry speed 1 and every ghost layer carries speed 100, as a boundary-condition image may. The volume-averaged mean speed must be exactly 1: the loops once ran over the ghost layers too, which put wall images into every mean.
Definition at line 1784 of file test_logging.c.
|
static |
Regression test: volume-averaged mean KE of a sinusoidal field in a fully periodic domain.
For u=0, v=0.1*sin(2πz), w=1 on a uniform [0,1]³ grid the exact continuous mean KE is 0.5025. With identity metrics (Aj=1) the discrete mean over the N physical cells also equals 0.5025 for any N >= 3, because Σ_{k=0}^{N-1} sin²(2πk/N) = N/2.
The physical cells are 1..mz-2. The ghost layers at 0 and mz-1 hold periodic copies of the opposite cells, so counting either one weights a cell twice. The loops once counted the upper ghost, and later still counted the lower one; this test requires both excluded.
Definition at line 1841 of file test_logging.c.
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Runs the unit-logging PETSc test binary.
Definition at line 1888 of file test_logging.c.