ZDTM API

From CRIU
Revision as of 16:17, 23 January 2015 by Xemul (talk | contribs)
Jump to navigation Jump to search

This page describes the API one should use to write new test in ZDTM.

Overview

The ZDTM test-suite is the automated suite that launches individual subtests as processes, waits for them to get prepared, then dumps the process(es) started, then restores them and asks to check whether the restored state is what test thinks to be proper. In order to write more subtests developer should use the API declared below.

API for test itself

The test should clearly describe 3 stages:

Preparations
These are actions that test does before the process(es) get checkpointed
Actions
During this the process(es) will be interrupted at arbitrary place and get dumped
Checks
After restore test should verify whether everything is OK or not and report the result

This is achieved by using the following API calls:

test_init(argc, argv)
Just initializes the test subsystem. After this call the preparations stage starts.
test_daemon()
This one says that we finished preparations and ready to get dumped at any time. I.e. -- the actions begin.
test_go()
This routine checks whether the process was dumped and restored or not yet, i.e. the actions stage still goes on.
test_waitsig()
Calling this blocks the task till it's restored. After this the checks stage starts.
pass()
Calling this marks test as PASSED
fail(message)
Calling this would report test failure. The message argument will be written into logs
err(message)
Use this function to mark the test as being unable to work at all.
test_msg(message)
This is for logging.


From the code perspective this looks like this:

int main(int argc, char **argv)
{
	test_init(argc, argv);

	/* Preparations */

	test_daemon();

#if test want to act and get c/r-ed unexpectedly
	while (test_go()) {
		/* Actions go here */
	}
#else test just want to wait for c/r to happen
	/* Actions go here. */

	test_waitsig();
#endif

	/* checks */

	if (test_passed())
		pass();
	else
		fail("Something went wrong");

	return 0;
}

Options

Sometimes a test might need an option to work. E.g. a file or directory to work with or some string to operate on. This can be done by declaring the options.

TEST_OPTION(name, type, description);

The name is some name for the option. The variable of the same name should be declared and the --$name CLI argument would be passed upon test start.

The type is data type. Currently supported types are string, bool, int, uint, long and ulong.

Description is just arbitrary text.

Adding test to automatic suite