netatalk  4.6.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
test_capabilities.c File Reference

Test capabilities: environment/build features a unit test may depend on. More...

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <unistd.h>
#include <atalk/ea.h>
#include <atalk/volume.h>
#include "faultinject.h"
#include "test_capabilities.h"

Functions

const char * test_capability_name (enum test_capability cap)
 Short capability name for skip/log messages.
static int probe_ea_sys (const struct vol *vol)
 Does the filesystem under vol->v_path support user extended attributes?
static int probe_fault_inject (const struct vol *vol)
 Is the LD_PRELOAD interposer active and reaching libc here?
int test_capability (enum test_capability cap, const struct vol *vol)
 Probe a capability; the result is cached for the run.

Variables

static int cap_cache []

Detailed Description

Test capabilities: environment/build features a unit test may depend on.

Some tests can only run where a feature is present (the LD_PRELOAD shim reaches libatalk; the filesystem supports user extended attributes for an ea=sys volume). A test probes the capability it needs and returns TEST_SKIP when it is absent, so coverage stays honest per platform rather than failing where the feature is simply unavailable. Each capability is probed once by actually exercising it (e.g. an xattr round-trip), not by trusting a higher-level operation that may succeed without the underlying support; the result is cached for the run.

Function Documentation

◆ probe_ea_sys()

int probe_ea_sys ( const struct vol * vol)
static

Does the filesystem under vol->v_path support user extended attributes?

Round-trips a real xattr on a scratch file: set, read back, remove. An ea=sys volume stores AppleDouble metadata in xattrs, so without this the volume opens (openvol() does not write-probe) but every metadata write fails — which would surface as a test failure rather than an honest skip. Probing here keeps the skip honest.

◆ probe_fault_inject()

int probe_fault_inject ( const struct vol * vol)
static

Is the LD_PRELOAD interposer active and reaching libc here?

Arms a one-shot open() failure and checks it fired. macOS's two-level namespace ignores a plain symbol preload, so the injection never takes effect there and fault-injection-dependent tests skip.

◆ test_capability()

int test_capability ( enum test_capability cap,
const struct vol * vol )

Probe a capability; the result is cached for the run.

Parameters
capthe capability to probe
volsupplies a filesystem path for capabilities probed against the volume (TEST_CAP_EA_SYS, TEST_CAP_FAULT_INJECT use vol->v_path for a scratch file); must not be NULL.
Returns
1 if the capability is available, 0 otherwise.

◆ test_capability_name()

const char * test_capability_name ( enum test_capability cap)

Short capability name for skip/log messages.

Variable Documentation

◆ cap_cache

int cap_cache[]
static
Initial value:
= {
}
@ TEST_CAP_FAULT_INJECT
Definition test_capabilities.h:21
@ TEST_CAP_EA_SYS
Definition test_capabilities.h:22