CS2621 Emulator v0.1.0 Emulation View Source

This module is a wrapper around ComBase that simplifies its use in student code. It does so by saving the context as a named Agent, and retrieving it when necessary.

Link to this section Summary

Functions

Add to the list of fuzzers used when messages are received. Note this function must be called before any messages are sent.

Send message to all active processes.

Cancel a timer previously set using either timer/1 or timer/2. timer is the reference returned by those calls. Returns the number of milliseconds left on the timer or false if the timer had already expired.

Convert emulation time units (e.g., from succesive calls to now) into microsecons. This is useful for human readable output.

Convert emulation time units (e.g., from succesive calls to now) into milliseconds. This is useful for human readable output.

Get the current fuzzer list

Setup the emulation

Get a list of all registed processes

Mark this process as one whose messages (i.e., those sent or received by the process) should not be fuzzed. This is meant as an aid to testing, and should not be used by code not within a test.

Convert milliseconds to emulation time units. This is useful when providing estimates.

Get current time.

Send a message to the process named proc. Message can be anything. ctx should be the context in which the process was created.

Set current time.

Spawn a process with supplied name and function.

Teardown emulation

Set a timer for ms milliseconds, and send a message to the calling process with the atom :timer when done.

Set a timer for ms milliseconds, and send a message to the calling process with atom when done.

Translate time (gotten from System.monotonic_time()) to time at process p. This should only be used for testing.

Get ID for the current process.

Link to this section Functions

Link to this function

append_fuzzers(fuzzer_list)

View Source

Specs

append_fuzzers([{atom(), float() | pid()}]) :: :ok

Add to the list of fuzzers used when messages are received. Note this function must be called before any messages are sent.

Specs

broadcast(any()) :: boolean()

Send message to all active processes.

Specs

cancel_timer(reference()) :: number() | false

Cancel a timer previously set using either timer/1 or timer/2. timer is the reference returned by those calls. Returns the number of milliseconds left on the timer or false if the timer had already expired.

Specs

emu_to_micros(number()) :: number()

Convert emulation time units (e.g., from succesive calls to now) into microsecons. This is useful for human readable output.

Specs

emu_to_millis(number()) :: number()

Convert emulation time units (e.g., from succesive calls to now) into milliseconds. This is useful for human readable output.

Specs

get_fuzzers() :: [{atom(), float() | pid()}]

Get the current fuzzer list

Specs

init() :: {:ok, pid()}

Setup the emulation

Specs

list_proc() :: [atom()]

Get a list of all registed processes

Specs

mark_unfuzzable() :: :ok

Mark this process as one whose messages (i.e., those sent or received by the process) should not be fuzzed. This is meant as an aid to testing, and should not be used by code not within a test.

Specs

millis_to_emu(number()) :: number()

Convert milliseconds to emulation time units. This is useful when providing estimates.

Specs

now() :: number()

Get current time.

Specs

send(atom() | pid(), any()) :: boolean()

Send a message to the process named proc. Message can be anything. ctx should be the context in which the process was created.

Specs

set_time(number()) :: :ok

Set current time.

Specs

spawn(atom(), (() -> any())) :: pid()

Spawn a process with supplied name and function.

Teardown emulation

Specs

timer(non_neg_integer()) :: reference()

Set a timer for ms milliseconds, and send a message to the calling process with the atom :timer when done.

Specs

timer(non_neg_integer(), atom()) :: reference()

Set a timer for ms milliseconds, and send a message to the calling process with atom when done.

Specs

translate_time(atom(), number()) :: number()

Translate time (gotten from System.monotonic_time()) to time at process p. This should only be used for testing.

Specs

whoami() :: atom() | pid()

Get ID for the current process.