partisan_otp_test_gen (partisan v6.0.0)

View Source

Generates partisan-adapted versions of OTP test suites.

Takes an OTP test suite source file (e.g., gen_server_SUITE.erl) and applies the same mechanical AST rewrites used by partisan_otp_rewrite to produce a partisan test suite (e.g., partisan_gen_server_SUITE.erl) that tests the generated partisan modules.

Helper modules (oc_server.erl, supervisor_1.erl, etc.) are also transformed so they use partisan behaviours and calls.

Summary

Functions

Generate all test suites and helpers for the current OTP version. Generates adapted SUITE beams and sets up data_dir directories with the original OTP helper source files (callback modules don't need renaming — they work as-is with partisan gen_server/supervisor).

Generate an adapted helper module from an OTP test helper source file. Renames the module with a partisan_ prefix.

Generate an adapted helper, keeping the original module name. Applies the partisan rewrite (gen_server→partisan_gen_server, etc.) but keeps the module name unchanged so existing references work.

Generate an adapted test suite from an OTP source file. SourceFile is the path to the OTP SUITE .erl file. OutDir is the directory to write the generated .beam file. Returns {ok, NewModule} or {error, Reason}.

Returns the directory holding the OTP test sources for the running OTP version, fetching them when the local cache is incomplete.

Inject code path arguments into peer node options. Called at runtime by the adapted test suites when starting peer nodes via ?CT_PEER(). Ensures the peer node has partisan modules available.

Run every generated compatibility suite under Common Test and print a summary. Returns ok only when each suite completed with zero failures and at least one case ran, so callers can map the result onto an exit status (see the otp-compat-test Makefile target). Dir holds the suite beams produced by generate_all_suites/1. LogDir is created when absent: ct:run_test/1 requires its logdir to exist and reports an enoent error for every suite when it does not.

Functions

generate_all_suites(OutDir)

-spec generate_all_suites(file:filename()) -> ok | {error, term()}.

Generate all test suites and helpers for the current OTP version. Generates adapted SUITE beams and sets up data_dir directories with the original OTP helper source files (callback modules don't need renaming — they work as-is with partisan gen_server/supervisor).

generate_helper(SourceFile, OutDir)

-spec generate_helper(file:filename(), file:filename()) -> {ok, module()} | {error, term()}.

Generate an adapted helper module from an OTP test helper source file. Renames the module with a partisan_ prefix.

generate_rewritten_helper(SourceFile, OutDir)

-spec generate_rewritten_helper(file:filename(), file:filename()) -> {ok, module()} | {error, term()}.

Generate an adapted helper, keeping the original module name. Applies the partisan rewrite (gen_server→partisan_gen_server, etc.) but keeps the module name unchanged so existing references work.

generate_suite(SourceFile, OutDir)

-spec generate_suite(file:filename(), file:filename()) -> {ok, module()} | {error, term()}.

Generate an adapted test suite from an OTP source file. SourceFile is the path to the OTP SUITE .erl file. OutDir is the directory to write the generated .beam file. Returns {ok, NewModule} or {error, Reason}.

otp_src_dir()

Returns the directory holding the OTP test sources for the running OTP version, fetching them when the local cache is incomplete.

An installed OTP release ships module sources but not its own test suites. The compatibility suites therefore cannot read gen_server_SUITE.erl and its siblings from the installed tree, the way partisan_gen_transform reads module beams. They come instead from the OTP-<version> tag and are cached under otp_src/otp_<version>/, which version control ignores.

A directory matching the running OTP major takes precedence, so an offline or hermetic build can pre-seed the cache and avoid the network entirely.

peer_opts(Opts)

-spec peer_opts(list() | map()) -> list() | map().

Inject code path arguments into peer node options. Called at runtime by the adapted test suites when starting peer nodes via ?CT_PEER(). Ensures the peer node has partisan modules available.

test_server:start_peer accepts either: - A list of arg strings (e.g., ["-pa", "/path"]) - A map #{args => [...], name => ...} ?CT_PEER() passes [] (empty args list). ?CT_PEER(#{args => [...]}) passes a map.

run_all_suites(Dir, LogDir)

-spec run_all_suites(file:filename(), file:filename()) -> ok | error.

Run every generated compatibility suite under Common Test and print a summary. Returns ok only when each suite completed with zero failures and at least one case ran, so callers can map the result onto an exit status (see the otp-compat-test Makefile target). Dir holds the suite beams produced by generate_all_suites/1. LogDir is created when absent: ct:run_test/1 requires its logdir to exist and reports an enoent error for every suite when it does not.