User's Guide
Reference Manual
Release Notes
PDF
Top

Common Test
Reference Manual
Version 1.6.3

Expand All
Contract All

Table of Contents

- common_test
  - Top of manual page
  - Module:all/0
  - Module:groups/0
  - Module:suite/0
  - Module:init_per_suite/1
  - Module:end_per_suite/1
  - Module:group/1
  - Module:init_per_group/2
  - Module:end_per_group/2
  - Module:init_per_testcase/2
  - Module:end_per_testcase/2
  - Module:Testcase/0
  - Module:Testcase/1
- ct_run
- ct
  - Top of manual page
  - abort_current_testcase/1
  - add_config/2
  - break/1
  - break/2
  - capture_get/0
  - capture_get/1
  - capture_start/0
  - capture_stop/0
  - comment/1
  - comment/2
  - continue/0
  - continue/1
  - decrypt_config_file/2
  - decrypt_config_file/3
  - encrypt_config_file/2
  - encrypt_config_file/3
  - fail/1
  - fail/2
  - get_config/1
  - get_config/2
  - get_config/3
  - get_status/0
  - get_target_name/1
  - get_timetrap_info/0
  - install/1
  - listenv/1
  - log/1
  - log/2
  - log/3
  - log/4
  - make_priv_dir/0
  - notify/2
  - pal/1
  - pal/2
  - pal/3
  - pal/4
  - parse_table/1
  - print/1
  - print/2
  - print/3
  - print/4
  - reload_config/1
  - remove_config/2
  - require/1
  - require/2
  - run/1
  - run/2
  - run/3
  - run_test/1
  - run_testspec/1
  - sleep/1
  - start_interactive/0
  - step/3
  - step/4
  - stop_interactive/0
  - sync_notify/2
  - testcases/2
  - timetrap/1
  - userdata/2
  - userdata/3
- ct_master
  - Top of manual page
  - abort/0
  - abort/1
  - basic_html/1
  - progress/0
  - run/1
  - run/3
  - run/4
  - run_on_node/2
  - run_on_node/3
  - run_test/2
- ct_cover
  - Top of manual page
  - add_nodes/1
  - remove_nodes/1
- ct_ftp
  - Top of manual page
  - cd/2
  - close/1
  - delete/2
  - get/3
  - ls/2
  - open/1
  - put/3
  - recv/2
  - recv/3
  - send/2
  - send/3
  - type/2
- ct_ssh
  - Top of manual page
  - apread/4
  - apread/5
  - apwrite/4
  - apwrite/5
  - aread/3
  - aread/4
  - awrite/3
  - awrite/4
  - close/2
  - close/3
  - connect/1
  - connect/2
  - connect/3
  - del_dir/2
  - del_dir/3
  - delete/2
  - delete/3
  - disconnect/1
  - exec/2
  - exec/3
  - exec/4
  - get_file_info/2
  - get_file_info/3
  - list_dir/2
  - list_dir/3
  - make_dir/2
  - make_dir/3
  - make_symlink/3
  - make_symlink/4
  - open/3
  - open/4
  - opendir/2
  - opendir/3
  - position/3
  - position/4
  - pread/4
  - pread/5
  - pwrite/4
  - pwrite/5
  - read/3
  - read/4
  - read_file/2
  - read_file/3
  - read_file_info/2
  - read_file_info/3
  - read_link/2
  - read_link/3
  - read_link_info/2
  - read_link_info/3
  - receive_response/2
  - receive_response/3
  - receive_response/4
  - rename/3
  - rename/4
  - send/3
  - send/4
  - send/5
  - send_and_receive/3
  - send_and_receive/4
  - send_and_receive/5
  - send_and_receive/6
  - session_close/2
  - session_open/1
  - session_open/2
  - sftp_connect/1
  - subsystem/3
  - subsystem/4
  - write/3
  - write/4
  - write_file/3
  - write_file/4
  - write_file_info/3
  - write_file_info/4
- ct_netconfc
  - Top of manual page
  - action/2
  - action/3
  - close_session/1
  - close_session/2
  - copy_config/3
  - copy_config/4
  - create_subscription/1
  - create_subscription/2
  - create_subscription/3
  - create_subscription/4
  - create_subscription/5
  - create_subscription/6
  - delete_config/2
  - delete_config/3
  - edit_config/3
  - edit_config/4
  - format_data/2
  - get/2
  - get/3
  - get_capabilities/1
  - get_capabilities/2
  - get_config/3
  - get_config/4
  - get_event_streams/2
  - get_event_streams/3
  - get_session_id/1
  - get_session_id/2
  - handle_msg/2
  - hello/1
  - hello/2
  - kill_session/2
  - kill_session/3
  - lock/2
  - lock/3
  - only_open/1
  - only_open/2
  - open/1
  - open/2
  - unlock/2
  - unlock/3
- ct_rpc
  - Top of manual page
  - app_node/2
  - app_node/3
  - app_node/4
  - call/4
  - call/5
  - call/6
  - cast/4
  - cast/5
- ct_snmp
  - Top of manual page
  - get_next_values/3
  - get_values/3
  - load_mibs/1
  - register_agents/2
  - register_users/2
  - register_usm_users/2
  - set_info/1
  - set_values/4
  - start/2
  - start/3
  - stop/1
  - unregister_agents/1
  - unregister_users/1
  - update_usm_users/2
- ct_telnet
  - Top of manual page
  - close/1
  - cmd/2
  - cmd/3
  - cmdf/3
  - cmdf/4
  - cont_log/2
  - end_log/0
  - expect/2
  - expect/3
  - get_data/1
  - open/1
  - open/2
  - open/3
  - open/4
  - send/2
  - sendf/3
- unix_telnet
- ct_slave
  - Top of manual page
  - start/1
  - start/2
  - start/3
  - stop/1
  - stop/2
- ct_hooks
  - Top of manual page
  - Module:init/2
  - Module:pre_init_per_suite/3
  - Module:post_init_per_suite/4
  - Module:pre_init_per_group/3
  - Module:post_init_per_group/4
  - Module:pre_init_per_testcase/3
  - Module:post_end_per_testcase/4
  - Module:pre_end_per_group/3
  - Module:post_end_per_group/4
  - Module:pre_end_per_suite/3
  - Module:post_end_per_suite/4
  - Module:on_tc_fail/3
  - Module:on_tc_skip/3
  - Module:terminate/1
  - Module:id/1

# common_test

### MODULE

common_test

### MODULE SUMMARY

A framework for automated testing of arbitrary target nodes

### DESCRIPTION

The Common Test framework is an environment for implementing and performing automatic and semi-automatic execution of test cases. Common Test uses the OTP Test Server as engine for test case execution and logging.

In brief, Common Test supports:

- Automated execution of test suites (sets of test cases).
- Logging of the events during execution.
- HTML presentation of test suite results.
- HTML presentation of test suite code.
- Support functions for test suite authors.
- Step by step execution of test cases.

The following sections describe the mandatory and optional test suite functions Common Test will call during test execution. For more details see Common Test User's Guide.

### TEST CASE CALLBACK FUNCTIONS

The following functions define the callback interface for a test suite.

### EXPORTS

Module:all() -> Tests | {skip,Reason}

Types:

Tests = [TestCase | {group,GroupName} | {group,GroupName,Properties} | {group,GroupName,Properties,SubGroups}]
TestCase = atom()
GroupName = atom()
Properties = [parallel | sequence | Shuffle | {RepeatType,N}] | default
SubGroups = [{GroupName,Properties} | {GroupName,Properties,SubGroups}]
Shuffle = shuffle | {shuffle,Seed}
Seed = {integer(),integer(),integer()}
RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | repeat_until_any_ok | repeat_until_any_fail
N = integer() | forever
Reason = term()

MANDATORY

This function must return the list of all test cases and test case groups in the test suite module that are to be executed. This list also specifies the order the cases and groups will be executed by Common Test. A test case is represented by an atom, the name of the test case function. A test case group is represented by a group tuple, where GroupName, an atom, is the name of the group (defined in groups/0). Execution properties for groups may also be specified, both for a top level group and for any of its sub-groups. Group execution properties specified here, will override properties in the group definition (see groups/0). (With value default, the group definition properties will be used).

If {skip,Reason} is returned, all test cases in the module will be skipped, and the Reason will be printed on the HTML result page.

For details on groups, see Test case groups in the User's Guide.

Module:groups() -> GroupDefs

Types:

GroupDefs = [Group]
Group = {GroupName,Properties,GroupsAndTestCases}
GroupName = atom()
Properties = [parallel | sequence | Shuffle | {RepeatType,N}]
GroupsAndTestCases = [Group | {group,GroupName} | TestCase]
TestCase = atom()
Shuffle = shuffle | {shuffle,Seed}
Seed = {integer(),integer(),integer()}
RepeatType = repeat | repeat_until_all_ok | repeat_until_all_fail | repeat_until_any_ok | repeat_until_any_fail
N = integer() | forever

OPTIONAL

Function for defining test case groups. Please see Test case groups in the User's Guide for details.

Module:suite() -> [Info]

Types:

Info = {timetrap,Time} | {require,Required} | {require,Name,Required} | {userdata,UserData} | {silent_connections,Conns} | {stylesheet,CSSFile} | {ct_hooks, CTHs}
Time = TimeVal | TimeFunc
TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | {hours,integer()}
TimeFunc = {Mod,Func,Args} | Fun
MilliSec = integer()
Mod = atom()
Func = atom()
Args = list()
Fun = fun()
Required = Key | {Key,SubKeys} | {Key,SubKey} | {Key,SubKey,SubKeys}
Key = atom()
SubKeys = SubKey | [SubKey]
SubKey = atom()
Name = atom()
UserData = term()
Conns = [atom()]
CSSFile = string()
CTHs = [CTHModule | {CTHModule, CTHInitArgs} | {CTHModule, CTHInitArgs, CTHPriority}]
CTHModule = atom()
CTHInitArgs = term()

OPTIONAL

This is the test suite info function. It is supposed to return a list of tagged tuples that specify various properties related to the execution of this test suite (common for all test cases in the suite).

The timetrap tag sets the maximum time each test case is allowed to execute (including init_per_testcase/2 and end_per_testcase/2). If the timetrap time is exceeded, the test case fails with reason timetrap_timeout. A TimeFunc function can be used to set a new timetrap by returning a TimeVal. It may also be used to trigger a timetrap timeout by, at some point, returning a value other than a TimeVal. (See the User's Guide for details).

The require tag specifies configuration variables that are required by test cases (and/or configuration functions) in the suite. If the required configuration variables are not found in any of the configuration files, all test cases are skipped. For more information about the 'require' functionality, see the reference manual for the function ct:require/1/2.

With userdata, it is possible for the user to specify arbitrary test suite related information which can be read by calling ct:userdata/2.

The ct_hooks tag specifies which Common Test Hooks are to be run together with this suite.

Other tuples than the ones defined will simply be ignored.

For more information about the test suite info function, see Test suite info function in the User's Guide.

Module:init_per_suite(Config) -> NewConfig | {skip,Reason} | {skip_and_save,Reason,SaveConfig}

Types:

Config = NewConfig = SaveConfig = [{Key,Value}]
Key = atom()
Value = term()
Reason = term()

OPTIONAL

This configuration function is called as the first function in the suite. It typically contains initializations which are common for all test cases in the suite, and which shall only be done once. The Config parameter is the configuration data which can be modified here. Whatever is returned from this function is given as Config to all configuration functions and test cases in the suite. If {skip,Reason} is returned, all test cases in the suite will be skipped and Reason printed in the overview log for the suite.

For information on save_config and skip_and_save, please see Dependencies between Test Cases and Suites in the User's Guide.

Module:end_per_suite(Config) -> void() | {save_config,SaveConfig}

Types:

Config = SaveConfig = [{Key,Value}]
Key = atom()
Value = term()

OPTIONAL

This function is called as the last test case in the suite. It is meant to be used for cleaning up after init_per_suite/1. For information on save_config, please see Dependencies between Test Cases and Suites in the User's Guide.

Module:group(GroupName) -> [Info]

Types:

Info = {timetrap,Time} | {require,Required} | {require,Name,Required} | {userdata,UserData} | {silent_connections,Conns} | {stylesheet,CSSFile} | {ct_hooks, CTHs}
Time = TimeVal | TimeFunc
TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | {hours,integer()}
TimeFunc = {Mod,Func,Args} | Fun
MilliSec = integer()
Mod = atom()
Func = atom()
Args = list()
Fun = fun()
Required = Key | {Key,SubKeys} | {Key,Subkey} | {Key,Subkey,SubKeys}
Key = atom()
SubKeys = SubKey | [SubKey]
SubKey = atom()
Name = atom()
UserData = term()
Conns = [atom()]
CSSFile = string()
CTHs = [CTHModule | {CTHModule, CTHInitArgs} | {CTHModule, CTHInitArgs, CTHPriority}]
CTHModule = atom()
CTHInitArgs = term()

OPTIONAL

This is the test case group info function. It is supposed to return a list of tagged tuples that specify various properties related to the execution of a test case group (i.e. its test cases and sub-groups). Properties set by group/1 override properties with the same key that have been previously set by suite/0.

The timetrap tag sets the maximum time each test case is allowed to execute (including init_per_testcase/2 and end_per_testcase/2). If the timetrap time is exceeded, the test case fails with reason timetrap_timeout. A TimeFunc function can be used to set a new timetrap by returning a TimeVal. It may also be used to trigger a timetrap timeout by, at some point, returning a value other than a TimeVal. (See the User's Guide for details).

The require tag specifies configuration variables that are required by test cases (and/or configuration functions) in the suite. If the required configuration variables are not found in any of the configuration files, all test cases in this group are skipped. For more information about the 'require' functionality, see the reference manual for the function ct:require/1/2.

With userdata, it is possible for the user to specify arbitrary test case group related information which can be read by calling ct:userdata/2.

The ct_hooks tag specifies which Common Test Hooks are to be run together with this suite.

Other tuples than the ones defined will simply be ignored.

For more information about the test case group info function, see Test case group info function in the User's Guide.

Module:init_per_group(GroupName, Config) -> NewConfig | {skip,Reason}

Types:

GroupName = atom()
Config = NewConfig = [{Key,Value}]
Key = atom()
Value = term()
Reason = term()

OPTIONAL

This configuration function is called before execution of a test case group. It typically contains initializations which are common for all test cases and sub-groups in the group, and which shall only be performed once. GroupName is the name of the group, as specified in the group definition (see groups/0). The Config parameter is the configuration data which can be modified here. The return value of this function is given as Config to all test cases and sub-groups in the group. If {skip,Reason} is returned, all test cases in the group will be skipped and Reason printed in the overview log for the group.

For information about test case groups, please see Test case groups chapter in the User's Guide.

Module:end_per_group(GroupName, Config) -> void() | {return_group_result,Status}

Types:

GroupName = atom()
Config = [{Key,Value}]
Key = atom()
Value = term()
Status = ok | skipped | failed

OPTIONAL

This function is called after the execution of a test case group is finished. It is meant to be used for cleaning up after init_per_group/2. By means of {return_group_result,Status}, it is possible to return a status value for a nested sub-group. The status can be retrieved in end_per_group/2 for the group on the level above. The status will also be used by Common Test for deciding if execution of a group should proceed in case the property sequence or repeat_until_* is set.

For more information about test case groups, please see Test case groups chapter in the User's Guide.

Module:init_per_testcase(TestCase, Config) -> NewConfig | {fail,Reason} | {skip,Reason}

Types:

TestCase = atom()
Config = NewConfig = [{Key,Value}]
Key = atom()
Value = term()
Reason = term()

OPTIONAL

This function is called before each test case. The TestCase argument is the name of the test case, and Config (list of key-value tuples) is the configuration data that can be modified here. The NewConfig list returned from this function is given as Config to the test case. If {fail,Reason} is returned, the test case is marked as failed without being executed. If {skip,Reason} is returned, the test case will be skipped and Reason printed in the overview log for the suite.

Module:end_per_testcase(TestCase, Config) -> void() | {fail,Reason} | {save_config,SaveConfig}

Types:

TestCase = atom()
Config = SaveConfig = [{Key,Value}]
Key = atom()
Value = term()
Reason = term()

OPTIONAL

This function is called after each test case, and can be used to clean up after init_per_testcase/2 and the test case. Any return value (besides {fail,Reason} and {save_config,SaveConfig}) is ignored. By returning {fail,Reason}, TestCase will be marked as failed (even though it was actually successful in the sense that it returned a value instead of terminating). For information on save_config, please see Dependencies between Test Cases and Suites in the User's Guide

Module:Testcase() -> [Info]

Types:

Info = {timetrap,Time} | {require,Required} | {require,Name,Required} | {userdata,UserData} | {silent_connections,Conns}
Time = TimeVal | TimeFunc
TimeVal = MilliSec | {seconds,integer()} | {minutes,integer()} | {hours,integer()}
TimeFunc = {Mod,Func,Args} | Fun
MilliSec = integer()
Mod = atom()
Func = atom()
Args = list()
Fun = fun()
Required = Key | {Key,SubKeys} | {Key,Subkey} | {Key,Subkey,SubKeys}
Key = atom()
SubKeys = SubKey | [SubKey]
SubKey = atom()
Name = atom()
UserData = term()
Conns = [atom()]

OPTIONAL

This is the test case info function. It is supposed to return a list of tagged tuples that specify various properties related to the execution of this particular test case. Properties set by Testcase/0 override properties that have been previously set for the test case by group/1 or suite/0.

The timetrap tag sets the maximum time the test case is allowed to execute. If the timetrap time is exceeded, the test case fails with reason timetrap_timeout. init_per_testcase/2 and end_per_testcase/2 are included in the timetrap time. A TimeFunc function can be used to set a new timetrap by returning a TimeVal. It may also be used to trigger a timetrap timeout by, at some point, returning a value other than a TimeVal. (See the User's Guide for details).

The require tag specifies configuration variables that are required by the test case (and/or init/end_per_testcase/2). If the required configuration variables are not found in any of the configuration files, the test case is skipped. For more information about the 'require' functionality, see the reference manual for the function ct:require/1/2.

If timetrap and/or require is not set, the default values specified by suite/0 (or group/1) will be used.

With userdata, it is possible for the user to specify arbitrary test case related information which can be read by calling ct:userdata/3.

Other tuples than the ones defined will simply be ignored.

For more information about the test case info function, see Test case info function in the User's Guide.

Module:Testcase(Config) -> void() | {skip,Reason} | {comment,Comment} | {save_config,SaveConfig} | {skip_and_save,Reason,SaveConfig} | exit()

Types:

Config = SaveConfig = [{Key,Value}]
Key = atom()
Value = term()
Reason = term()
Comment = string()

MANDATORY

This is the implementation of a test case. Here you must call the functions you want to test, and do whatever you need to check the result. If something fails, make sure the function causes a runtime error, or call ct:fail/1/2 (which also causes the test case process to terminate).

Elements from the Config list can e.g. be read with proplists:get_value/2 (or the macro ?config defined in ct.hrl).

You can return {skip,Reason} if you decide not to run the test case after all. Reason will then be printed in 'Comment' field on the HTML result page.

You can return {comment,Comment} if you wish to print some information in the 'Comment' field on the HTML result page.

If the function returns anything else, the test case is considered successful. (The return value always gets printed in the test case log file).

For more information about test case implementation, please see Test cases in the User's Guide.

For information on save_config and skip_and_save, please see Dependencies between Test Cases and Suites in the User's Guide.