Popcorn.Support.AtomVM (Popcorn v0.3.1)
View SourceUsed to run AtomVM instances in tests.
Provides convenience assertions and eval/3 function
to evaluate Erlang or Elixir code as a string.
compile_quoted/2 and run/3 are lower level API used for tests
that run one-off code without evaluation. This works by first compiling
a module with some AST that can use var! for runtime input.
This input is provided by serializing terms to opts.bin which is read
when this module runs start/0. We then write code output to result.bin.
Compiled files are cached under tmp/modules/ using a hash of the generated
module plus this support file's source, so helper changes invalidate stale bundles.
All eval tests run the same underlying code so eval expects
module to be compiled and cached prior to call.
Input and output files for tests running concurently are keyed by AVM_RUN_DIR which stores path prefix.
Summary
Functions
Appends passed ast to common code that reads input from args.bin and writing to result.bin.
Ast may reference args variable that is read from input file while calling run/3.
Evaluates a string using precompiled evaluation code.
Runs compiled .avm bundle with passed args.
Evaluates a string using precompiled evaluation code.
Path to the native AtomVM binary used by the :unix target.
Functions
Appends passed ast to common code that reads input from args.bin and writing to result.bin.
Ast may reference args variable that is read from input file while calling run/3.
Evaluates a string using precompiled evaluation code.
Runs compiled .avm bundle with passed args.
Evaluates a string using precompiled evaluation code.
Doesn't crash in case of failure, always returns an info map.
Path to the native AtomVM binary used by the :unix target.
Defaults to popcorn's own test fixture location; consumers building the runtime
via mix popcorn.build_runtime --target unix should point this at their
artifacts dir, e.g. in test_helper.exs:
Application.put_env(:popcorn, :atomvm_unix_runtime_path,
Path.join([File.cwd!(), "popcorn_runtime_source/artifacts/unix", "AtomVM"]))