ATF-TEST-CASE(4)

atf-test-case πŸ’…βœ¨

Section 4 Β· Kernel Interfaces Manual Β· ATF-TEST-CASE(4)

okay bestie, welcome to the group chat, because we are about to talk about atf-test-case β€” and ngl it's giving main character energy in the ATF world. πŸŽ€


✨ NAME ✨

atf-test-case β€” generic description of test cases πŸ¦‹


like. that's the whole vibe of this page, fr fr. it's the generic description β€” the blueprint, the template, the moment before the glow-up. every test case in the ATF universe is a lil cousin of this one. πŸ’–

bestie this page is long so it's coming to you in 2 parts β€” and this is part 1, so don't you dare close the tab, we are not done. 🌸

πŸ’– DESCRIPTION πŸ’–

okay so bestie, a test case is literally just a piece of code that stress-tests one specific feature of the software. and like, that feature is usually self-contained enough β€” either in how much code implements it, or in the general ~idea~ of it β€” that it deserves its own independent testing moment. which means test cases are very fine-grained, but they still group together similar smaller tests that are semantically related. it's giving organized chaos. πŸŽ€

so every test case, no matter what language it's written in, is made of three components: a header, a body, and a cleanup routine.

  • The header is basically a declarative lil piece of code that defines a bunch of properties describing what the test case does and how it behaves. in other words: it defines the test case's meta-data, which we get into more in the β€œMeta-data” section below. ✨
  • The body is the test case itself. it runs all the actions needed to reproduce the test, and it checks for failures. this body only runs if the abstract conditions in the header are met. no conditions met? no body. periodt.
  • The cleanup routine is a piece of code that always runs after the body, no matter what the exit status of the test case was. use it to undo side-effects of the test case. and bestie, note that almost all side-effects of a test case get automatically cleaned up by the library β€” that's explained in more detail in the rest of this document. 🫢

It is EXTREMELY important to keep the separation between a test case's header and body well-defined, because the header is always parsed, whereas the body is only executed when the conditions defined in the header are met AND when the user specifies that test case. two separate vibe checks, okay? don't mix them up. πŸ’…

and finally: test cases are always contained inside test programs. the test programs act as a front-end to them, giving a consistent interface to the user plus several APIs to make implementing them easier. πŸ‘‘


🌈 Results 🌈

when a test case terminates, it reports a status and, optionally, a textual reason explaining why it reported that status. now listen β€” the caller has to make sure the test case actually did the thing its status claims, because the test program could be bogus and therefore give a misleading result. like, it could say "success" while the program's error code says otherwise. awkward. 😭

the possible exit statuses of a test case are one of these:

  • expected_death β€” the test case expects to terminate abruptly. πŸ’€
  • expected_exit β€” the test case expects to exit cleanly.
  • expected_failure β€” the test case expects to exit with a controller fatal/non-fatal failure. if this happens, the test program exits with a success error code.
  • expected_signal β€” the test case expects to receive a signal that makes it terminate.
  • expected_timeout β€” the test case expects to execute for longer than its timeout.
  • passed β€” the test case was executed successfully. the test program exits with a success error code. slay! ✨
  • skipped β€” the test case could not be executed because some preconditions were not met. this is not a failure, because it can typically be resolved by adjusting the system to meet the necessary conditions. this is always accompanied by a reason, a message describing why the test was skipped. the test program exits with a success error code.
  • failed β€” an error appeared during the execution of the test case. this is always accompanied by a reason, a message describing why the test failed. the test program exits with a failure error code.

the usefulness of the β€˜expected_*’ results shows up when you're writing test cases that verify known failures β€” which are generally caused by programming errors (aka bugs, we've all been there πŸ™ˆ). whenever the faulty condition that the β€˜expected_*’ result is trying to cover gets fixed, the test case will be reported as β€˜failed’ and the developer will have to adjust it to match its new condition. character development fr fr.

⚠️ important bestie: all β€˜expected_*’ results are only provided as a hint to the caller. the caller must verify that the test case did actually terminate as the expected condition says. don't just trust it. πŸ’…

🌸 Input/output 🌸

test cases are free to print whatever they want to their stdout(4) and stderr(4) file descriptors. in fact they're encouraged to print status information as they execute, to keep the user informed of their actions. this is specially important for long test cases β€” nobody wants to stare at a silent terminal wondering if it's frozen. πŸ‘€

test cases will log their results to an auxiliary file, which then gets collected by the test program they're contained in. the developer doesn't need to care about this as long as he uses the correct APIs to implement the test cases. iykyk. 🧚

the standard input of the test cases is unconditionally connected to β€˜/dev/zero’. yeah. that's just how it is.


✨ Meta-data ✨

this next list describes all the meta-data properties interpreted internally by ATF. you're free to define new properties in your test cases and use them however you want, but non-standard properties must be prefixed by β€˜X-’. house rules, bestie. πŸŽ€

  • descr β€” Type: textual. Required.

a brief textual description of the test case's purpose. will be shown to the user in reports. also good for documentation purposes. πŸ“

  • has.cleanup β€” Type: boolean. Optional.

if set to true, specifies that the test case has a cleanup routine that has to be executed by the runtime engine during the cleanup phase of the execution. this property is automatically set by the framework when defining a test case with a cleanup routine, so it should never be set by hand. put your hands down, the framework's got this. πŸ™Œ

  • ident β€” Type: textual. Required.

the test case's identifier. must be unique inside the test program and should be short but descriptive.

  • require.arch β€” Type: textual. Optional.

a whitespace separated list of architectures that the test case can be run under without causing errors due to an architecture mismatch.

  • require.config β€” Type: textual. Optional.

a whitespace separated list of configuration variables that must be defined to execute the test case. if any of the required variables is not defined, the test case is skipped.

  • require.diskspace β€” Type: integer. Optional. specifies the minimum amount of available disk space needed by the test. the value can have a size suffix such as β€˜K’, β€˜M’, β€˜G’ or β€˜T’ to make the amount of bytes easier to type and read. πŸ’Ύ
  • require.files β€” Type: textual. Optional.

a whitespace separated list of files that must be present to execute the test case. the names of these files must be absolute paths. if any of the required files is not found, the test case is skipped.

  • require.machine β€” Type: textual. Optional.

a whitespace separated list of machine types that the test case can be run under without causing errors due to a machine type mismatch.

  • require.memory β€” Type: integer. Optional. specifies the minimum amount of physical memory needed by the test. the value can have a size suffix such as β€˜K’, β€˜M’, β€˜G’ or β€˜T’ to make the amount of bytes easier to type and read.
  • require.progs β€” Type: textual. Optional.

a whitespace separated list of programs that must be present to execute the test case. these can be given as plain names β€” in which case they're looked for in the user's PATH β€” or as absolute paths. if any of the required programs is not found, the test case is skipped.

  • require.user β€” Type: textual. Optional.

the required privileges to execute the test case. can be one of β€˜root’ or β€˜unprivileged’.

if the test case is running as a regular user and this property is β€˜root’, the test case is skipped.

if the test case is running as root and this property is β€˜unprivileged’, the runtime engine will automatically drop the privileges if the β€˜unprivileged-user’ configuration property is set; otherwise the test case is skipped.

  • timeout β€” Type: integral. Optional; defaults to β€˜300’.

specifies the maximum amount of time the test case can run. this is particularly useful because some tests can stall β€” either because they're incorrectly coded or because they trigger an anomalous behavior of the program. it is not acceptable for these tests to stall the whole execution of the test program. not on my watch. 😀

can optionally be set to zero, in which case the test case has no run-time limit. this is discouraged.


πŸ¦‹ Environment πŸ¦‹

every single time a test case is executed, several environment variables get cleared or reseted to sane values, so they can't make the test fail due to unexpected conditions. these variables are:

  • HOME β€” Set to the work directory's path.
  • LANG β€” Undefined.
  • LC_ALL β€” Undefined.
  • LC_COLLATE β€” Undefined.
  • LC_CTYPE β€” Undefined.
  • LC_MESSAGES β€” Undefined.
  • LC_MONETARY β€” Undefined.
  • LC_NUMERIC β€” Undefined.
  • LC_TIME β€” Undefined.
  • TZ β€” Hardcoded to β€˜UTC’. timezone consistency, we love to see it. ⏰

πŸ’œ Work directories πŸ’œ

the test program always creates a temporary directory and switches to it before running the test case's body. this way the test case is free to modify its current directory however it wishes, and the runtime engine will be able to clean it up later on in a safe way β€” removing any traces of its execution from the system. 🧹✨

to do so, the runtime engine will perform a recursive removal of the work directory without crossing mount points; if a mount point is found, the file system will be unmounted (if possible). careful, bestie, that's the spicy part. πŸ”₯


πŸŽ€ File creation mode mask (umask) πŸŽ€

test cases are always executed with a file creation mode mask (umask) of β€˜0022’. the test case's code is free to change this during execution though β€” live your truth. πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

atf-test-program(1)


and that's the whole page, bestie! this one came from the Debian crew, dated March 6, 2017, and it lives in the ATF-TEST-CASE(4) manual β€” go forth and write iconic test cases. mwah. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from