Printer function test after distribution update
Into the Workings
In a normal case with a correct printer test, the call to lpq_busy()
in line 29 uses the function defined in line 49 to invoke lpq
and check whether the print queue has received a job. The print queue is empty on any newly installed system; the initial test in line 29 thus reports success if lpq_busy()
returns a value of false.
Next, the Path::Tiny CPAN module's spew()
function writes a text string to a temporary file, which system()
sends to the print queue using the lpr
command-line tool. The call to lpr
should return an exit code of
, which is verified by the test suite function is
. When lpr
returns, the job is already in the print queue, where a subsequent call to lpq
will show it if everything went as it should.
The while
loop in line 40 now checks every second whether the job actually disappeared from the queue; this is a sure sign that it has been sent to the printer and that the test has finally been successfully completed.
After these five tests, done_testing()
in line 47 wraps up and reports to the controlling test suite that nothing crashed in the meantime with a text string of 1..5
, a moniker for five completed test cases.
Part of the Whole
If the system test launches one or multiple test scripts of this kind, the scripts are typically invoked with a test runner, such as prove
, which comes with the Perl distribution. This tool receives the output from individual tests and, if successful, only outputs a summary of the results. In case of error, other details are output that help to troubleshoot the root cause. Figure 4 shows the output after a successful run; for better structuring, it makes sense to run multiple scripts rather than one, potentially using a glob character, as in
$ prove "/var/tests/*
The important thing is to automate everything rather than relying on individual steps that need manual intervention.
Well Packaged
But, how do you bootstrap the test on a new system? In other words, how does the test suite happen to be in place on the system with the installation you want to test? It makes sense to bundle the suite in a package using your distribution's package format, push the package to the repository, and install it from there with the help of the package manager.
The easiest approach uses the fpm
[4] packager, which supports Debian's .deb
format, Red Hat's .rpm
, and the OS X .pkg
format. Figure 5 shows the tool wrapping up a Debian package by the name of allmytests
. Because the location of the script on the target system will be /var/tests
, the build script first copies it into a newly local directory hierarchy var/tests
and then points fpm
to it with the -s dir
option.
Because the script requires the CPAN Path::Tiny module, which fortunately already exists as package libpath-tiny-perl
in the Debian repository, fpm
simply includes it with the -d
option. If you then run sudo apt-get install
to install the allmytests
package from the repository, the package manager picks up the dependent package from the repository and elegantly resolves the dependencies.
If the Perl core is not part of the distribution, you can install it on the system in the same way with another -d
option. If the distribution is missing a CPAN module not yet available as a package, the Carton module [5] introduced in a previous column will help to bundle it with the test suite. As your test suite keeps growing, you can be agile by making frequent changes to the system without losing sleep. The test suite will have your back by avoiding potential regressions.
Infos
- LDTP (Linux Desktop Test Project): https://ldtp.freedesktop.org/wiki/
- Listings for this article: ftp://ftp.linux-magazine.com/pub/listings/magazine/187/Perl
- "Label Maker" by Michael Schilli, Linux Magazine, issue 183: http://www.linux-magazine.com/Issues/2016/183/Perl-Producing-Labels
- "Effing Package Management: fpm": https://github.com/jordansissel/fpm/wiki
- Carton module: http://search.cpan.org/~miyagawa/Carton-v1.0.22/lib/Carton.pm
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.