git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #44439 from Ekleog/meta-tests

[RFC] Use `meta.tests` to link from packages to the tests that test them

commit6141939d6e0a77c84905efd560c03c3032164ef1 authorTimo Kaufmann <timokau@zoho.com> dateWed 7 Nov 2018, 00:05 (8 years ago) parent13892da02e1f00
7 files changed+98−4
doc/meta.xml+55 nixos/lib/testing.nix+3−1 nixos/tests/opensmtpd.nix+2 pkgs/servers/mail/dovecot/default.nix+4 pkgs/servers/mail/opensmtpd/default.nix+4−1 pkgs/stdenv/generic/check-meta.nix+10−2 pkgs/top-level/all-packages.nix+20
doc/meta.xml+55
@@ -250,6 +250,61 @@ meta.platforms = stdenv.lib.platforms.linux;
250250 </para>
251251 </listitem>
252252 </varlistentry>
253+ <varlistentry>
254+ <term>
255+ <varname>tests</varname>
256+ </term>
257+ <listitem>
258+ <para>
259+ An attribute set with as values tests. A test is a derivation, which
260+ builds successfully when the test passes, and fails to build otherwise. A
261+ derivation that is a test requires some <literal>meta</literal> elements
262+ to be defined: <literal>needsVMSupport</literal> (automatically filled-in
263+ for NixOS tests) and <literal>timeout</literal>.
264+ </para>
265+ <para>
266+ The NixOS tests are available as <literal>nixosTests</literal> in
267+ parameters of derivations. For instance, the OpenSMTPD derivation
268+ includes lines similar to:
269+<programlisting>
270+{ /* ... */, nixosTests }:
271+{
272+ # ...
273+ meta.tests = {
274+ basic-functionality-and-dovecot-integration = nixosTests.opensmtpd;
275+ };
276+}
277+</programlisting>
278+ </para>
279+ </listitem>
280+ </varlistentry>
281+ <varlistentry>
282+ <term>
283+ <varname>timeout</varname>
284+ </term>
285+ <listitem>
286+ <para>
287+ A timeout (in seconds) for building the derivation. If the derivation
288+ takes longer than this time to build, it can fail due to breaking the
289+ timeout. However, all computers do not have the same computing power,
290+ hence some builders may decide to apply a multiplicative factor to this
291+ value. When filling this value in, try to keep it approximately
292+ consistent with other values already present in
293+ <literal>nixpkgs</literal>.
294+ </para>
295+ </listitem>
296+ </varlistentry>
297+ <varlistentry>
298+ <term>
299+ <varname>needsVMSupport</varname>
300+ </term>
301+ <listitem>
302+ <para>
303+ A boolan that states whether the derivation requires build-time support
304+ for Virtual Machine to build successfully.
305+ </para>
306+ </listitem>
307+ </varlistentry>
253308 <varlistentry>
254309 <term>
255310 <varname>hydraPlatforms</varname>
nixos/lib/testing.nix+3−1
@@ -69,7 +69,9 @@ in rec {
6969 mkdir -p $out/coverage-data
7070 mv $i $out/coverage-data/$(dirname $(dirname $i))
7171 done
72− ''; # */
72+ '';
73+
74+ meta.needsVMSupport = true;
7375 };
7476
7577
nixos/tests/opensmtpd.nix+2
@@ -120,4 +120,6 @@ import ./make-test.nix {
120120 $smtp2->waitUntilFails('smtpctl show queue | egrep .');
121121 $client->succeed('check-mail-landed >&2');
122122 '';
123+
124+ meta.timeout = 30;
123125}
pkgs/servers/mail/dovecot/default.nix+4
@@ -1,6 +1,7 @@
11{ stdenv, lib, fetchurl, perl, pkgconfig, systemd, openssl
22, bzip2, zlib, lz4, inotify-tools, pam, libcap
33, clucene_core_2, icu, openldap, libsodium, libstemmer, cyrus_sasl
4+, nixosTests
45# Auth modules
56, withMySQL ? false, mysql
67, withPgSQL ? false, postgresql
@@ -74,5 +75,8 @@ stdenv.mkDerivation rec {
7475 description = "Open source IMAP and POP3 email server written with security primarily in mind";
7576 maintainers = with stdenv.lib.maintainers; [ peti rickynils fpletz ];
7677 platforms = stdenv.lib.platforms.unix;
78+ tests = {
79+ opensmtpd-interaction = nixosTests.opensmtpd;
80+ };
7781 };
7882}
pkgs/servers/mail/opensmtpd/default.nix+4−1
@@ -1,5 +1,5 @@
11{ stdenv, lib, fetchurl, fetchpatch, autoconf, automake, libtool, bison
2−, libasr, libevent, zlib, libressl, db, pam
2+, libasr, libevent, zlib, libressl, db, pam, nixosTests
33}:
44
55stdenv.mkDerivation rec {
@@ -61,5 +61,8 @@ stdenv.mkDerivation rec {
6161 license = licenses.isc;
6262 platforms = platforms.linux;
6363 maintainers = with maintainers; [ rickynils obadz ekleog ];
64+ tests = {
65+ basic-functionality-and-dovecot-interaction = nixosTests.opensmtpd;
66+ };
6467 };
6568}
pkgs/stdenv/generic/check-meta.nix+10−2
@@ -165,6 +165,16 @@ let
165165 platforms = listOf (either str lib.systems.parsedPlatform.types.system);
166166 hydraPlatforms = listOf str;
167167 broken = bool;
168+ # TODO: refactor once something like Profpatsch's types-simple will land
169+ tests = attrsOf (mkOptionType {
170+ name = "test";
171+ check = x: isDerivation x &&
172+ x ? meta.timeout &&
173+ x ? meta.needsVMSupport;
174+ merge = lib.options.mergeOneOption;
175+ });
176+ needsVMSupport = bool;
177+ timeout = int;
168178
169179 # Weirder stuff that doesn't appear in the documentation?
170180 knownVulnerabilities = listOf str;
@@ -184,8 +194,6 @@ let
184194 isIbusEngine = bool;
185195 isGutenprint = bool;
186196 badPlatforms = platforms;
187− # Hydra build timeout
188− timeout = int;
189197 };
190198
191199 checkMetaAttr = k: v:
pkgs/top-level/all-packages.nix+20
@@ -71,6 +71,26 @@ with pkgs;
7171
7272 common-updater-scripts = callPackage ../common-updater/scripts.nix { };
7373
74+ ### Push NixOS tests inside the fixed point
75+
76+ nixosTests =
77+ let
78+ # TODO(Ericson2314,ekleog): Check this will work correctly with cross-
79+ system = builtins.currentSystem;
80+ rawTests = (import ../../nixos/release.nix {
81+ nixpkgs = pkgs;
82+ }).tests;
83+ testNames = builtins.attrNames rawTests;
84+ filteredList = builtins.filter
85+ (test: rawTests.${test} ? ${system})
86+ testNames;
87+ finalList = map
88+ (test: { name = test; value = rawTests.${test}.${system}; })
89+ filteredList;
90+ finalTests = builtins.listToAttrs finalList;
91+ in
92+ finalTests;
93+
7494 ### BUILD SUPPORT
7595
7696 autoreconfHook = makeSetupHook