Checkbox
Size: 7116
Comment:
|
Size: 8995
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 6: | Line 6: |
Checkbox (https://launchpad.net/checkbox) is a test runner for Ubuntu. It aims is to provide a common framework to run all types of tests, from hardware tests, to command line tests, unit tests or desktop tests and send their results to Launchpad, automatically. | Checkbox (https://launchpad.net/checkbox) is a test runner for Ubuntu. It aims to provide a common framework to run all types of tests, from hardware tests, to command line tests, unit tests or desktop tests and send their results to Launchpad, automatically. |
Line 14: | Line 14: |
This is the general config file. It will be inherit by all the checkbox flavours. | This is the general config file. Properties listed here will be inherited by all checkbox flavours. |
Line 16: | Line 16: |
* [DEFAULT]. Under this section they are covered all general configuration properties. * version. The version of checkbox to use the configuration with. * plugins. Folder where checkbox plugins are stored. * registries. Folder where checkbox registries are stored. |
Example: {{{ [DEFAULT] version = 0.9.1 plugins = checkbox/plugins |
Line 21: | Line 22: |
== Tests == Test are defined in plain text files, that can be stored anywhere. They consists in some required fields and some optional fields. Let's look at one example: {{{ name: audio plugin: manual categories: laptop, desktop requires: alsa.type == 'control' command: audio_playback $data_path/audio_playback.wav description: Testing detected sound card: . $(audio_playback --view) . Did you hear a sound? |
[checkbox/plugins] modules = %(checkbox_share)s/plugins/*.py |
Line 38: | Line 26: |
=== Tests fields === | Explanation of options: |
Line 40: | Line 28: |
==== Required fields ==== | * '''[DEFAULT]''' - This section covers all general configuration properties. * ''version'' - The version of checkbox to use the configuration with. * '''[checkbox/plugins]''' - This section controls the checkbox plugin system. * ''modules'' - The path to the checkbox plugin executable scripts. * ''checkbox_share'' - Where the checkbox core files are located. By default: ''/usr/share/checkbox'' |
Line 42: | Line 34: |
|| '''Field''' || '''Explanation''' || || name || Unique name for a test || || plugin || Plugin name to handle this test. Checkbox provides "manual" and "shell" by default || || description || A description on what the test does. In the case of manual tests, this is the actual question asked to the enduser. In the case of automated tests, this is strictly informational. || |
== Jobs == === What is a job? === A job is a task or unit of work that is used to define many different things including test suites and test cases. All jobs are composed of a list of '''fields''' that have a special meaning. |
Line 47: | Line 38: |
==== Optional fields ==== | For more information about writing jobs, please refer to the following sections: * [[/WritingTestsHowTo|Writing tests How-To]] * [[/Walkthrough|Walkthrough]] |
Line 49: | Line 42: |
|| '''Field''' || '''Explanation''' || || architectures || List of architectures for which this test is relevant: amd64, i386, powerpc and/or sparc || || categories || List of categories for which this test is relevant: desktop, laptop and/or server || || command || Command to run for the test. This is not required for manual tests, but it can be used, anyway. || || depends || List of names of tests on which this test depends. So, if the other test fails, this test will be skipped. || || requires || Registry expressions which are requirements for this test: 'input.mouse' in info.capabilities || || timeout || Timeout for running the command. || || optional || Boolean expression set to True if this test is optional or False if this test is required. || |
=== What fields may a job include? === A job can include any of the following fields: * name: Unique identifier for a job * plugin: Takes care of the interpretation of the job (describes the type of job: maunal, automated, resource, etc) * depends: The job will only run if it's dependency job passes. If JobA depends on JobB, and JobB fails, then JobA will be skipped. * requires: Set of requirements that must be satisfied for the job to be executed. Typical requirements are of the kind ''some package must be installed'' or ''some hardware must be detected''. * timeout: How much time should checkbox wait before cancelling job execution * command: A string that must be executed using the same commands as in a shell * user: Don't execute command with the same user that launched checkbox, but with a different user (usually ''root'') * description: Human-readable description of the job purpose |
Line 58: | Line 53: |
==== Special fields ==== | === Are there any mandatory fields? === Yes, '''name''' and '''plugin''' must always be present. Depending on the ''plugin'', '''description''' and '''command''' may also be required. However, it's advised to use ''description'' in every job (even when not needed) for documentation purposes. |
Line 60: | Line 56: |
* $output: This will be changed by the output of the command. Example: | === Where are jobs stored? === In source code you'll always find jobs under '''jobs''' directory. In an installed package, such as ''checkbox'', the jobs are under '''/usr/share/checkbox/jobs''' directory. |
Line 62: | Line 60: |
{{{ command: date description: was uds good for you on $output? |
=== Which format is used for jobs? === Jobs are stored using rfc822 format. Despite this might not seem a very convenient format, it's really useful because it supported by the translations tools and this makes possible to translate jobs easily. |
Line 67: | Line 63: |
}}} | === What's the difference between .txt.in and .txt? === On one hand, in source code you'll find that jobs use the ''.txt.in'' extension. This is because in they are translations templates that contain extra information information about which strings are expected to be translated. |
Line 69: | Line 66: |
In this case, the description will shown the current date. Clicking on "Test again" will re-render the description. | On the other hand, in the package you'll find that jobs use the ''.txt'' extension. This is because they are just job description files and the information for translations has been processed and stored in special files. |
Line 71: | Line 68: |
=== Test Suites === | === Why _description instead of description? === In rfc822 files, the underscore prefix is used to mark a field as translatable. Hence all ''.txt.in'' files use this prefix to mark description as a translatable string. |
Line 73: | Line 71: |
These tests can be grouped by suites. A suite is basically a text file that contains one or more tests. Suites are available under the directory: /usr/share/checkbox/suites All the files under that directory are automatically parsed for tests. Tests suites are parsed by the suites_info plugin (check the Plugin section for more information about plugins) Some of the options that we can see in the configuration file (checkbox.ini) for this plugin are: \[checkbox/plugins/suites_info\] * directories = %(checkbox_directory)s/suites The folder or folders where test suites are stored. * scripts_path = %(checkbox_directory)s/scripts The folder where runnable scripts are stored. ==== Environment variables ==== Apart from the two options explained above, this is the place to define the environment variables that we want for our tests. From the example above this would be: data_path = %(checkbox_directory)s/data == Testing your suites in a bzr checkout of checkbox == If you are adding new suites to checkbox, you can simply test them from within the checkout, you can test directly from there: {{{ ./bin/checkbox-gtk --config="checkbox/plugins/suites_info/whitelist=mysuite.txt.in" }}} == Easiest way to run your test with Checkbox == If you don't need any particular parsing of the results and you only want to run your test with Checkbox all you need to do is: * Write a test as explained in [[Testing/Automation/Checkbox#Tests]] * Place it at /usr/share/hwtest/suites by itself or as part of another suite * Place any necessary scripts at /usr/share/hwtest/scripts * Run checkbox == Test results == Test results are sent automatically to Launchpad if an internet connection is available. Apart from sending them, they are stored temporarily at /var/cache/checkbox. This is the default folder, but it can be changed with the environment variable CHECKBOX_DATA. To change the results folder in run time just start the application with: {{{ CHECKBOX_DATA=/tmp sudo -E checkbox-gtk }}} |
=== Is there an easy way to write job files? === [[https://launchpad.net/checkbox-editor|Checkbox Editor]] is a tool that lets you write jobs easily without having to take care of the formatting required. This tool is available in the [[https://launchpad.net/~oem-community-qa/+archive/ppa|OEM Community PPA]] and it already includes a complete manual. |
Line 125: | Line 75: |
=== What is a plugin? === A plugin, in the checkbox vocabulary, is a script that takes care of the interpretation of a ''job'', that's to say, it implements the policy that is going to be applied to that ''job''. |
|
Line 126: | Line 78: |
Plugins are the mechanism to change Checkbox default behaviour. In fact, the "checkbox default behaviour" are plugins themselves. | === What plugins are available? === The list of currently available plugins is: * local: Include ''local'' test suites that have been written for checkbox. Local jobs are run first and are usually used to create dynamic job descriptions (e.g. create a storage test for every detected hard drive) or for other pre-testing needs such as generating test suites (e.g. parsing the name.txt file and loading all the job descriptions contained in the file). * remote: Integrate ''remote'' third party test suites that have been written for another framework (i.e. LTP, mago, ...) *NOTE that remote jobs only pass or fail based on the return code of the external framework. So if running LTP and 10 of 50 tests fail, but LTP itself returns a 0 exit status, the remote job will be marked as successful. * manual: ''manual'' test cases, or those which the user must perform and action and evaluate the results. For example: "Plug in headphones and select the Test button. Did you hear the sound clearly?" * shell: Automated test cases, those which are run automatically by checkbox and do not require or ask for any user action at all. * attachment: Add ''attachment'' to report, that is, important information that must be kept for reference * resource: Gather hardware ''resource'' information |
Line 128: | Line 87: |
=== What plugins do I really need to write tests? === For test suites: '''local'''. For test cases: '''manual''' and '''shell''' (for non-interactive tests). === Implementation === |
|
Line 154: | Line 117: |
== Registries == | == Resources == === What is a resource? === A resource is a specialized job that uses the plugin of the same name. In addition to this, it also needs a command that, when executed, prints to the standard output pieces of information in rfc822 format that the '''resource''' plugin is able to parse. |
Line 156: | Line 121: |
Registries provide a consistent way of accessing hierarchical information in the system. They are meant to expose a single rooted data structure which can be accessed consistently regardless of where the information might be stored. | === What are resources used for? === Resources are used to gather information that is suitable to be added as requirements in other jobs. |
Line 158: | Line 124: |
One of the motivations for providing this kind of data structure is to be able to define the requires: field in tests in a consistent way. Another is to provide plugins with a convenient way to obtain and query information about the system. A registry is simply a Python module that extends the Registry class. A minimal registry would look like: |
For example, if a job requires the totem package to be executed, then the following lines can be added to the job description: |
Line 163: | Line 126: |
class Cr3Registry(Registry): def items(self): return (("foo": 1), ("bar": 2)) factory = Cr3Registry |
requires: package.name == 'totem' |
Line 171: | Line 130: |
The new Registry simply needs to define an items method and then the RegistryManager handles the rest. | and '''checkbox''' will make sure that, in the information gathered by the package resource, there's a field called name that matches the string totem. === Where can I find some examples of resource jobs? === Some examples of resource jobs can be found in the `/usr/share/checkbox/jobs/resource.txt` file. In particular, the package resource shown in the previous section: {{{ name: package plugin: resource command: package_resource | filter_templates -w 'desired=Install' -w 'status=Installed' }}} As it can be guessed from the `command` line the information that is gathered in this case is the list of installed packages. If the command is executed, it will print blocks of rfc822 data with some fields regarding the package being printed. In particular, for the totem package in the previous section example, the output is: {{{ status: Installed desired: Install version: 2.30.2-0ubuntu1 name: totem description: A simple media player for the GNOME desktop based on GStreamer }}} where the `name` field indeed contains the `totem` string as was required in the previous section example. |
Introduction
Checkbox (https://launchpad.net/checkbox) is a test runner for Ubuntu. It aims to provide a common framework to run all types of tests, from hardware tests, to command line tests, unit tests or desktop tests and send their results to Launchpad, automatically.
General Configuration
Checkbox general configuration is stored at /etc/checkbox.d. Each way of calling checkbox (GUI, cli) has its own configuration file.
checkbox.ini
This is the general config file. Properties listed here will be inherited by all checkbox flavours.
Example:
[DEFAULT] version = 0.9.1 plugins = checkbox/plugins [checkbox/plugins] modules = %(checkbox_share)s/plugins/*.py
Explanation of options:
[DEFAULT] - This section covers all general configuration properties.
version - The version of checkbox to use the configuration with.
[checkbox/plugins] - This section controls the checkbox plugin system.
modules - The path to the checkbox plugin executable scripts.
checkbox_share - Where the checkbox core files are located. By default: /usr/share/checkbox
Jobs
What is a job?
A job is a task or unit of work that is used to define many different things including test suites and test cases. All jobs are composed of a list of fields that have a special meaning.
For more information about writing jobs, please refer to the following sections:
What fields may a job include?
A job can include any of the following fields:
- name: Unique identifier for a job
- plugin: Takes care of the interpretation of the job (describes the type of job: maunal, automated, resource, etc)
- depends: The job will only run if it's dependency job passes. If JobA depends on JobB, and JobB fails, then JobA will be skipped.
requires: Set of requirements that must be satisfied for the job to be executed. Typical requirements are of the kind some package must be installed or some hardware must be detected.
- timeout: How much time should checkbox wait before cancelling job execution
- command: A string that must be executed using the same commands as in a shell
user: Don't execute command with the same user that launched checkbox, but with a different user (usually root)
- description: Human-readable description of the job purpose
Are there any mandatory fields?
Yes, name and plugin must always be present. Depending on the plugin, description and command may also be required. However, it's advised to use description in every job (even when not needed) for documentation purposes.
Where are jobs stored?
In source code you'll always find jobs under jobs directory. In an installed package, such as checkbox, the jobs are under /usr/share/checkbox/jobs directory.
Which format is used for jobs?
Jobs are stored using rfc822 format. Despite this might not seem a very convenient format, it's really useful because it supported by the translations tools and this makes possible to translate jobs easily.
What's the difference between .txt.in and .txt?
On one hand, in source code you'll find that jobs use the .txt.in extension. This is because in they are translations templates that contain extra information information about which strings are expected to be translated.
On the other hand, in the package you'll find that jobs use the .txt extension. This is because they are just job description files and the information for translations has been processed and stored in special files.
Why _description instead of description?
In rfc822 files, the underscore prefix is used to mark a field as translatable. Hence all .txt.in files use this prefix to mark description as a translatable string.
Is there an easy way to write job files?
Checkbox Editor is a tool that lets you write jobs easily without having to take care of the formatting required. This tool is available in the OEM Community PPA and it already includes a complete manual.
Plugins
What is a plugin?
A plugin, in the checkbox vocabulary, is a script that takes care of the interpretation of a job, that's to say, it implements the policy that is going to be applied to that job.
What plugins are available?
The list of currently available plugins is:
local: Include local test suites that have been written for checkbox. Local jobs are run first and are usually used to create dynamic job descriptions (e.g. create a storage test for every detected hard drive) or for other pre-testing needs such as generating test suites (e.g. parsing the name.txt file and loading all the job descriptions contained in the file).
remote: Integrate remote third party test suites that have been written for another framework (i.e. LTP, mago, ...) *NOTE that remote jobs only pass or fail based on the return code of the external framework. So if running LTP and 10 of 50 tests fail, but LTP itself returns a 0 exit status, the remote job will be marked as successful.
manual: manual test cases, or those which the user must perform and action and evaluate the results. For example: "Plug in headphones and select the Test button. Did you hear the sound clearly?"
- shell: Automated test cases, those which are run automatically by checkbox and do not require or ask for any user action at all.
attachment: Add attachment to report, that is, important information that must be kept for reference
resource: Gather hardware resource information
What plugins do I really need to write tests?
For test suites: local. For test cases: manual and shell (for non-interactive tests).
Implementation
A plugin is simply a Python module which registers for events. A minimal plugin would look like:
class Cr3Plugin(Plugin): def register(self, manager): super(Cr3Plugin, self).register(manager) self._manager.reactor.call_on("report", self.report) def report(self): self._manager.reactor.fire("report-cr3", "cr3 is in #ubuntu-classroom") factory = Cr3Plugin
A plugin should inherit from the Plugin class and it should register to be called on particular events. In this example it is registered to call the report method upon the "report" event.
self._manager.reactor.call_on("report", self.report)
The report method itself fires the "report-cr3" and anyone who has registered for this particular event will be called.
self._manager.reactor.fire("report-cr3", "cr3 is in #ubuntu-classroom")
The plugin should provide a global factory variable which will be the hook for instantiating your plugin.
Resources
What is a resource?
A resource is a specialized job that uses the plugin of the same name. In addition to this, it also needs a command that, when executed, prints to the standard output pieces of information in rfc822 format that the resource plugin is able to parse.
What are resources used for?
Resources are used to gather information that is suitable to be added as requirements in other jobs.
For example, if a job requires the totem package to be executed, then the following lines can be added to the job description:
requires: package.name == 'totem'
and checkbox will make sure that, in the information gathered by the package resource, there's a field called name that matches the string totem.
Where can I find some examples of resource jobs?
Some examples of resource jobs can be found in the /usr/share/checkbox/jobs/resource.txt file. In particular, the package resource shown in the previous section:
name: package plugin: resource command: package_resource | filter_templates -w 'desired=Install' -w 'status=Installed'
As it can be guessed from the command line the information that is gathered in this case is the list of installed packages. If the command is executed, it will print blocks of rfc822 data with some fields regarding the package being printed. In particular, for the totem package in the previous section example, the output is:
status: Installed desired: Install version: 2.30.2-0ubuntu1 name: totem description: A simple media player for the GNOME desktop based on GStreamer
where the name field indeed contains the totem string as was required in the previous section example.
Tips And Tricks
Testing/Automation/Checkbox (last edited 2021-10-20 11:49:54 by sylvain-pineau)