C unit tests for runtime log-level, allow-list, conversion, and profiling helpers. More...
#include "test_support.h"#include "logging.h"#include "interpolation.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 | ReadCsvHeaderAndRow (const char *path, PetscInt row_index, char *header, size_t header_len, char *row, size_t row_len) |
| Reads the CSV header and the requested 1-based data row from a text file. | |
| static PetscErrorCode | CsvFindColumnIndex (const char *header, const char *column_name, PetscInt *index_out) |
| Returns the zero-based column index for one CSV header field. | |
| static PetscErrorCode | CsvGetColumnText (const char *header, const char *row, const char *column_name, char *value, size_t value_len) |
| Extracts one CSV cell as text by header name. | |
| static PetscErrorCode | CsvGetColumnInt (const char *header, const char *row, const char *column_name, PetscInt *value_out) |
| Extracts one CSV cell as an integer by header name. | |
| static PetscErrorCode | CsvGetColumnReal (const char *header, const char *row, const char *column_name, PetscReal *value_out) |
| Extracts one CSV cell as a real by header name. | |
| 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 pipe-delimited solution-convergence log file. | |
| static PetscErrorCode | LogFindColumnIndex (const char *header, const char *column_name, PetscInt *index_out) |
| Returns the zero-based column index for one pipe-delimited header field. | |
| static PetscErrorCode | LogGetColumnText (const char *header, const char *row, const char *column_name, char *value, size_t value_len) |
| Extracts one pipe-delimited 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 pipe-delimited 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 pipe-delimited 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 | 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 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 | 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 405 of file test_logging.c.
| Data Fields | ||
|---|---|---|
| FieldId | field_id | |
| const char * | stage_name | |
Definition at line 403 of file test_logging.c.
| typedef struct AnatomyCaptureCtx AnatomyCaptureCtx |
|
static |
Asserts that one text file contains a required substring.
Definition at line 24 of file test_logging.c.
|
static |
Asserts that one text file does not contain an excluded substring.
Definition at line 69 of file test_logging.c.
|
static |
Reads the CSV header and the requested 1-based data row from a text file.
Definition at line 114 of file test_logging.c.
|
static |
Returns the zero-based column index for one CSV header field.
Definition at line 149 of file test_logging.c.
|
static |
Extracts one CSV cell as text by header name.
Definition at line 179 of file test_logging.c.
|
static |
Extracts one CSV cell as an integer by header name.
Definition at line 215 of file test_logging.c.
|
static |
Extracts one CSV cell as a real by header name.
Definition at line 233 of file test_logging.c.
|
static |
Reads the column header and the requested 1-based data row from a pipe-delimited solution-convergence log file.
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 256 of file test_logging.c.
|
static |
Returns the zero-based column index for one pipe-delimited header field.
Definition at line 300 of file test_logging.c.
|
static |
Extracts one pipe-delimited log cell as text by header name.
Definition at line 332 of file test_logging.c.
|
static |
Extracts one pipe-delimited log cell as an integer by header name.
Definition at line 370 of file test_logging.c.
|
static |
Extracts one pipe-delimited log cell as a real by header name.
Definition at line 388 of file test_logging.c.
|
static |
Captures stdout emitted by one logging helper into a temporary file-backed buffer.
Definition at line 413 of file test_logging.c.
Adapts LOG_PARTICLE_FIELDS() to the generic stdout-capture callback shape.
Definition at line 464 of file test_logging.c.
|
static |
Adapts EmitParticleConsoleSnapshot() to the generic stdout-capture callback shape.
Definition at line 477 of file test_logging.c.
|
static |
Adapts EmitStatisticsConsoleSnapshot() to the generic stdout-capture callback shape.
Definition at line 489 of file test_logging.c.
Adapts LOG_FIELD_ANATOMY() to the generic stdout-capture callback shape.
Definition at line 501 of file test_logging.c.
|
static |
Creates a small particle-bearing runtime fixture used by logging tests.
Definition at line 514 of file test_logging.c.
|
static |
Fills one Cartesian velocity field with a uniform constant state.
Definition at line 562 of file test_logging.c.
|
static |
Fills one scalar field with a uniform constant state.
Definition at line 587 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 612 of file test_logging.c.
|
static |
Tests string-conversion helpers for configured enums and unknown values.
Definition at line 643 of file test_logging.c.
|
static |
Tests that log level selection honors the environment variable.
Definition at line 680 of file test_logging.c.
|
static |
Tests the function allow-list filter used by the logging layer.
Definition at line 692 of file test_logging.c.
|
static |
Tests periodic particle console snapshot enablement and cadence.
Definition at line 712 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 741 of file test_logging.c.
|
static |
Tests periodic statistics console snapshot enablement and cadence.
Definition at line 760 of file test_logging.c.
|
static |
Tests logging-side file parsing, helper formatting, and progress utilities.
Definition at line 809 of file test_logging.c.
|
static |
Tests continuity, min/max, and anatomy logging helpers on minimal runtime fixtures.
Definition at line 874 of file test_logging.c.
|
static |
Tests interpolation-error logging against an analytically matched particle field.
Definition at line 961 of file test_logging.c.
|
static |
Tests file-backed scatter metrics logging against a fully occupied constant field.
Definition at line 1022 of file test_logging.c.
|
static |
Tests stdout particle-table logging on a production-like swarm fixture.
Definition at line 1096 of file test_logging.c.
|
static |
Tests console snapshot logging against the public periodic-snapshot helper.
Definition at line 1117 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 1143 of file test_logging.c.
|
static |
Sets the pressure field to a uniform value across the owned range.
Definition at line 1198 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 1217 of file test_logging.c.
|
static |
Asserts two accumulator vectors are bit-identical.
Definition at line 1243 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 1262 of file test_logging.c.
|
static |
Tests file-backed particle metrics logging after derived metrics are computed.
Definition at line 1318 of file test_logging.c.
|
static |
Tests file-backed search metrics logging with the compact CSV contract.
Definition at line 1354 of file test_logging.c.
|
static |
Tests stdout field-anatomy logging on the corrected production-like DM fixture.
Definition at line 1405 of file test_logging.c.
|
static |
Tests profiling helper lifecycle logging for timestep and final-summary outputs.
Definition at line 1429 of file test_logging.c.
|
static |
Tests runtime memory log header, step rows, final rows, and disabled mode.
Definition at line 1488 of file test_logging.c.
|
static |
Verifies -solution_convergence_enabled=false suppresses the convergence writer.
Definition at line 1533 of file test_logging.c.
|
static |
Tests steady solution-convergence log output, IBM masking, and gauge-invariant pressure drift.
Definition at line 1562 of file test_logging.c.
|
static |
Tests periodic solution-convergence warmup and phase-aligned reference reuse.
Definition at line 1647 of file test_logging.c.
|
static |
Tests statistical solution-convergence sliding-window metrics.
Definition at line 1732 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 1809 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 1866 of file test_logging.c.
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Runs the unit-logging PETSc test binary.
Definition at line 1913 of file test_logging.c.