Reference manual

Test harness API

enum renderer_type

Weston renderer type.

See

compositor_setup

Values:

enumerator RENDERER_NOOP

Dummy renderer that does nothing.

enumerator RENDERER_PIXMAN

Pixman-renderer.

enumerator RENDERER_GL

GL-renderer.

enum shell_type

Weston shell plugin.

See

compositor_setup

Values:

enumerator SHELL_TEST_DESKTOP

Desktop test-shell with predictable window placement and no helper clients.

enumerator SHELL_DESKTOP

The full desktop shell.

enumerator SHELL_IVI

The ivi-shell.

enumerator SHELL_FULLSCREEN

The fullscreen-shell.

enum test_result_code

Standard return codes.

Both Autotools and Meson use these codes as test program exit codes to denote the test result for the whole process.

Values:

enumerator RESULT_OK
enumerator RESULT_SKIP
enumerator RESULT_FAIL
enumerator RESULT_HARD_ERROR
const char *get_test_name(void)

Get the test name string with counter.

This is only usable from code paths inside TEST(), TEST_P(), PLUGIN_TEST() etc. defined functions.

Returns

The test name with fixture number -f%d added. For an array driven test, e.g. defined with TEST_P(), the name has also a -e%d suffix to indicate the array element number.

int get_test_fixture_index(void)

Get the current fixture index.

Returns the current fixture index which can be used directly as an index into the array passed as an argument to DECLARE_FIXTURE_SETUP_WITH_ARG().

This is only usable from code paths inside TEST(), TEST_P(), PLUGIN_TEST() etc. defined functions.

void testlog(const char *fmt, ...)

Print into test log.

This is exactly like printf() except the output goes to the test log, which is at stderr.

Parameters

fmt – printf format string

enum test_result_code weston_test_harness_execute_as_client(struct weston_test_harness *harness, const struct compositor_setup *setup)

Execute all tests as client tests.

Initializes the compositor with the given setup and executes the compositor. The compositor creates a new thread where all tests in the test program are serially executed. Once the thread finishes, the compositor returns from its event loop and cleans up.

Returns RESULT_SKIP if the requested compositor features, e.g. GL-renderer, are not built.

See

DECLARE_FIXTURE_SETUP(), DECLARE_FIXTURE_SETUP_WITH_ARG()

Parameters
  • harness – The test harness context.

  • setup – The compositor configuration.

enum test_result_code weston_test_harness_execute_as_plugin(struct weston_test_harness *harness, const struct compositor_setup *setup)

Execute all tests as plugin tests.

Initializes the compositor with the given setup and executes the compositor. The compositor executes all tests in the test program serially from an idle handler, then returns from its event loop and cleans up.

Returns RESULT_SKIP if the requested compositor features, e.g. GL-renderer, are not built.

See

DECLARE_FIXTURE_SETUP(), DECLARE_FIXTURE_SETUP_WITH_ARG()

Parameters
  • harness – The test harness context.

  • setup – The compositor configuration.

enum test_result_code weston_test_harness_execute_standalone(struct weston_test_harness *harness)

Execute all tests as standalone tests.

Executes all tests in the test program serially without any further setup, particularly without any compositor instance created.

See

DECLARE_FIXTURE_SETUP(), DECLARE_FIXTURE_SETUP_WITH_ARG()

Parameters

harness – The test harness context.

const struct fixture_setup_array *fixture_setup_array_get_(void)

Fixture data array getter method.

DECLARE_FIXTURE_SETUP_WITH_ARG() overrides this in test programs. The default implementation has no data and makes the tests run once.

enum test_result_code fixture_setup_run_(struct weston_test_harness *harness, const void *arg_)

Fixture setup function.

DECLARE_FIXTURE_SETUP() and DECLARE_FIXTURE_SETUP_WITH_ARG() override this in test programs. The default implementation just calls weston_test_harness_execute_standalone().

compositor_setup_defaults(s)

Initialize compositor setup to defaults.

The defaults are:

  • backend: headless

  • renderer: noop

  • shell: desktop shell

  • xwayland: no

  • width: 320

  • height: 240

  • scale: 1

  • transform: WL_OUTPUT_TRANSFORM_NORMAL

  • config_file: none

  • extra_module: none

  • logging_scopes: compositor defaults

  • testset_name: the test name from meson.build

Parameters
  • s – The variable to initialize.

TEST(name)

Add a test with no parameters.

This defines one test as a new function. Use this macro in place of the function signature and put the function body after this.

Parameters
  • name – Name for the test, must be a valid function name.

TEST_P(name, data_array)

Add an array driven test with a parameter.

This defines an array of tests as a new function. Use this macro in place of the function signature and put the function body after this. The function will be executed once for each element in data_array, passing the element as the argument void *data to the function.

This macro is not usable if fixture setup is using weston_test_harness_execute_as_plugin().

Parameters
  • name – Name for the test, must be a valid function name.

  • data_array – A static const array of any type. The length will be recorded automatically.

PLUGIN_TEST(name)

Add a test with weston_compositor argument.

This defines one test as a new function. Use this macro in place of the function signature and put the function body after this. The function will have one argument struct weston_compositor *compositor.

This macro is only usable if fixture setup is using weston_test_harness_execute_as_plugin().

Parameters
  • name – Name for the test, must be a valid function name.

DECLARE_FIXTURE_SETUP(func_)

Register a fixture setup function.

This registers the given (preferably static) function to be used for setting up any fixtures you might need. The function must have the signature:

enum test_result_code func_(struct weston_test_harness *harness)

The function must call one of weston_test_harness_execute_standalone(), weston_test_harness_execute_as_plugin() or weston_test_harness_execute_as_client() passing in the harness argument, and return the return value from that call. The function can also return a test_result_code on its own if it does not want to run the tests, e.g. RESULT_SKIP or RESULT_HARD_ERROR.

The function will be called once to run all tests.

Parameters
  • func_ – The function to be used as fixture setup.

DECLARE_FIXTURE_SETUP_WITH_ARG(func_, array_, meta_)

Register a fixture setup function with a data array.

This registers the given (preferably static) function to be used for setting up any fixtures you might need. The function must have the signature:

enum test_result_code func_(struct weston_test_harness *harness, typeof(array_[0]) *arg)

The function must call one of weston_test_harness_execute_standalone(), weston_test_harness_execute_as_plugin() or weston_test_harness_execute_as_client() passing in the harness argument, and return the return value from that call. The function can also return a test_result_code on its own if it does not want to run the tests, e.g. RESULT_SKIP or RESULT_HARD_ERROR.

The function will be called once with each element of the array pointed to by arg, so that all tests would be repeated for each element in turn.

Parameters
  • func_ – The function to be used as fixture setup.

  • array_ – A static const array of arbitrary type.

  • meta_ – Name of the field with type struct fixture_metadata.

struct weston_testsuite_quirks
#include <libweston.h>

Weston test suite quirks.

There are some things that need a specific behavior when we run Weston in the test suite. Tests can use this struct to select for certain behaviors.

See

compositor_setup

Public Members

bool gl_force_full_upload

Force GL-renderer to do a full upload of wl_shm buffers.

bool gl_force_full_redraw_of_shadow_fb

Ensure GL shadow fb is used, and always repaint it fully.

uint32_t required_capabilities

Required enum weston_capability bit mask, otherwise skip run.

struct weston_testsuite_data
#include <libweston.h>

Weston test suite data that is given to compositor.

It contains two members:

  1. The struct weston_testsuite_quirks, which can be used by the tests to change certain behavior of Weston when running these tests.

  2. The void *test_private_data member which can be used by the testsuite of projects that uses libweston in order to give arbitrary test data to the compositor. Its type should be defined by the testsuite of the project.

See

compositor_setup

Public Members

struct weston_testsuite_quirks test_quirks
void *test_private_data
struct compositor_setup
#include <weston-test-fixture-compositor.h>

Weston compositor configuration.

This structure determines the Weston compositor command line arguments. You should always use compositor_setup_defaults() to initialize this, then override any members you need with assignments.

Public Members

struct weston_testsuite_quirks test_quirks

The test suite quirks.

enum weston_compositor_backend backend

The backend to use.

enum renderer_type renderer

The renderer to use.

enum shell_type shell

The shell plugin to use.

bool xwayland

Whether to enable xwayland support.

unsigned width

Default output width.

unsigned height

Default output height.

int scale

Default output scale.

enum wl_output_transform transform

Default output transform, one of WL_OUTPUT_TRANSFORM_*.

char *config_file

The absolute path to weston.ini to use, or NULL for no-config .

To properly fill this entry use weston_ini_setup()

const char *extra_module

Full path to an extra plugin to load, or NULL for none.

const char *logging_scopes

Debug scopes for the compositor log, or NULL for compositor defaults.

const char *testset_name

The name of this test program, used as a unique identifier.

struct fixture_metadata
#include <weston-test-runner.h>

Metadata for fixture setup array elements.

Every type used as a fixture setup array’s elements needs one member of this type, initialized.

See

DECLARE_FIXTURE_SETUP_WITH_ARG()

Public Members

const char *name

Human friendly name of the fixture setup.

Test harness Internals

enum test_type

Weston test types.

See

weston_test_harness_execute_standalone weston_test_harness_execute_as_plugin weston_test_harness_execute_as_client

Values:

enumerator TEST_TYPE_STANDALONE
enumerator TEST_TYPE_PLUGIN
enumerator TEST_TYPE_CLIENT
void compositor_setup_defaults_(struct compositor_setup *setup, const char *testset_name)

Initialize part of compositor setup.

Parameters
  • setup – The variable to initialize.

  • testset_name – Value for testset_name member.

int execute_compositor(const struct compositor_setup *setup, struct wet_testsuite_data *data)

Execute compositor.

Manufactures the compositor command line and calls wet_main().

Returns RESULT_SKIP if the given setup contains features that were disabled in the build, e.g. GL-renderer or DRM-backend.

struct weston_test_entry
#include <weston-test-runner.h>

Test program entry.

Each invocation of TEST(), TEST_P(), or PLUGIN_TEST() will create one more weston_test_entry in a custom named section in the final binary. Iterating through the section then allows to iterate through all the defined tests.

Public Members

const char *name
void (*run)(void*)
const void *table_data
size_t element_size
int n_elements
struct fixture_setup_array
#include <weston-test-runner.h>

Fixture setup array record.

Helper to store the attributes of the data array passed in to DECLARE_FIXTURE_SETUP_WITH_ARG().

Public Members

const void *array
size_t element_size
int n_elements
size_t meta_offset
struct wet_testsuite_data
#include <weston-testsuite-data.h>

Test harness specific data for running tests.

Public Members

void (*run)(struct wet_testsuite_data*)
const struct weston_test_entry *tests
unsigned tests_count
int case_index
enum test_type type
struct weston_compositor *compositor
int thread_event_pipe
int fixture_iteration
const char *fixture_name
unsigned counter
unsigned passed
unsigned skipped
unsigned failed
unsigned total