요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
===================================================
The Kernel Test Anything Protocol (KTAP), version 1
===================================================
TAP, or the Test Anything Protocol is a format for specifying test results used
by a number of projects. Its website and specification are found at this `link
<https://testanything.org/>`_. The Linux Kernel largely uses TAP output for test
results. However, Kernel testing frameworks have special needs for test results
which don't align with the original TAP specification. Thus, a "Kernel TAP"
(KTAP) format is specified to extend and alter TAP to support these use-cases.
This specification describes the generally accepted format of KTAP as it is
currently used in the kernel.
KTAP test results describe a series of tests (which may be nested: i.e., test
can have subtests), each of which can contain both diagnostic data -- e.g., log
lines -- and a final result. The test structure and results are
machine-readable, whereas the diagnostic data is unstructured and is there to
aid human debugging.
KTAP output is built from four different types of lines:
- Version lines
- Plan lines
- Test case result lines
- Diagnostic lines
In general, valid KTAP output should also form valid TAP output, but some
information, in particular nested test results, may be lost. Also note that
there is a stagnant draft specification for TAP14, KTAP diverges from this in
a couple of places (notably the "Subtest" header), which are described where
relevant later in this document.
Version lines
-------------
All KTAP-formatted results begin with a "version line" which specifies which
version of the (K)TAP standard the result is compliant with.
For example:
- "KTAP version 1"
- "TAP version 13"
- "TAP version 14"
Note that, in KTAP, subtests also begin with a version line, which denotes the
start of the nested test results. This differs from TAP14, which uses a
separate "Subtest" line.
While, going forward, "KTAP version 1" should be used by compliant tests, it
is expected that most parsers and other tooling will accept the other versions
listed here for compatibility with existing tests and frameworks.
Plan lines
----------
A test plan provides the number of tests (or subtests) in the KTAP output.
Plan lines must follow the format of "1..N" where N is the number of tests or subtests.
Plan lines follow version lines to indicate the number of nested tests.
While there are cases where the number of tests is not known in advance -- in
which case the test plan may be omitted -- it is strongly recommended one is
present where possible.
Test case result lines
----------------------
Test case result lines indicate the final status of a test.
They are required and must have the format:
.. code-block:: none
<result> <number> [<description>][ # [<directive>] [<diagnostic data>]]
The result can be either "ok", which indicates the test case passed,
or "not ok", which indicates that the test case failed.
<number> represents the number of the test being performed. The first test must
have the number 1 and the number then must increase by 1 for each additional
subtest within the same test at the same nesting level.
The description is a description of the test, generally the name of
the test, and can be any string of characters other than # or a
newline. The description is optional, but recommended.
The directive and any diagnostic data is optional. If either are present, they
must follow a hash sign, "#".
A directive is a keyword that indicates a different outcome for a test other
than passed and failed. The directive is optional, and consists of a single
keyword preceding the diagnostic data. In the event that a parser encounters
a directive it doesn't support, it should fall back to the "ok" / "not ok"
result.
Currently accepted directives are:
- "SKIP", which indicates a test was skipped (note the result of the test case
result line can be either "ok" or "not ok" if the SKIP directive is used)
- "TODO", which indicates that a test is not expected to pass at the moment,
e.g. because the feature it is testing is known to be broken. While this
directive is inherited from TAP, its use in the kernel is discouraged.
- "XFAIL", which indicates that a test is expected to fail. This is similar
to "TODO", above, and is used by some kselftest tests.
- “TIMEOUT”, which indicates a test has timed out (note the result of the test
case result line should be “not ok” if the TIMEOUT directive is used)
- “ERROR”, which indicates that the execution of a test has failed due to a
specific error that is included in the diagnostic data. (note the result of
the test case result line should be “not ok” if the ERROR directive is used)
The diagnostic data is a plain-text field which contains any additional details
about why this result was produced. This is typically an error message for ERROR
or failed tests, or a description of missing dependencies for a SKIP result.
The diagnostic data field is optional, and results which have neither a
directive nor any diagnostic data do not need to include the "#" field
separator.
Example result lines include::
ok 1 test_case_name
The test "test_case_name" passed.
::
not ok 1 test_case_name
The test "test_case_name" failed.
::
ok 1 test # SKIP necessary dependency unavailable
The test "test" was SKIPPED with the diagnostic message "necessary dependency
unavailable".
::
not ok 1 test # TIMEOUT 30 seconds
The test "test" timed out, with diagnostic data "30 seconds".
::
ok 5 check return code # rcode=0
The test "check return code" passed, with additional diagnostic data “rcode=0”
Diagnostic lines
----------------
If tests wish to output any further information, they should do so using
"diagnostic lines". Diagnostic lines are optional, freeform text, and are
often used to describe what is being tested and any intermediate results in
more detail than the final result and diagnostic data line provides.
Diagnostic lines are formatted as "# <diagnostic_description>", where the
description can be any string. Diagnostic lines can be anywhere in the test
output. As a rule, diagnostic lines regarding a test are directly before the
test result line for that test.
Note that most tools will treat unknown lines (see below) as diagnostic lines,
even if they do not start with a "#": this is to capture any other useful
kernel output which may help debug the test. It is nevertheless recommended
that tests always prefix any diagnostic output they have with a "#" character.
Unknown lines
-------------
There may be lines within KTAP output that do not follow the format of one of
the four formats for lines described above. This is allowed, however, they will
not influence the status of the tests.
This is an important difference from TAP. Kernel tests may print messages
to the system console or a log file. Both of these destinations may contain
messages either from unrelated kernel or userspace activity, or kernel
messages from non-test code that is invoked by the test. The kernel code
invoked by the test likely is not aware that a test is in progress and
thus can not print the message as a diagnostic message.
Nested tests
------------
In KTAP, tests can be nested. This is done by having a test include within its
output an entire set of KTAP-formatted results. This can be used to categorize
and group related tests, or to split out different results from the same test.
The "parent" test's result should consist of all of its subtests' results,
starting with another KTAP version line and test plan, and end with the overall
result. If one of the subtests fail, for example, the parent test should also
fail.
Additionally, all lines in a subtest should be indented. One level of
indentation is two spaces: " ". The indentation should begin at the version
line and should end before the parent test's result line.
"Unknown lines" are not considered to be lines in a subtest and thus are
allowed to be either indented or not indented.
An example of a test with two nested subtests:
::
KTAP version 1
1..1
KTAP version 1
1..2
ok 1 test_1
not ok 2 test_2
# example failed
not ok 1 example
An example format with multiple levels of nested testing:
::
KTAP version 1
1..2
KTAP version 1
1..2
KTAP version 1
1..2
not ok 1 test_1
ok 2 test_2
not ok 1 test_3
ok 2 test_4 # SKIP
not ok 1 example_test_1
ok 2 example_test_2
Major differences between TAP and KTAP
--------------------------------------
================================================== ========= ===============
Feature TAP KTAP
================================================== ========= ===============
yaml and json in diagnosic message ok not recommended
TODO directive ok not recognized
allows an arbitrary number of tests to be nested no yes
"Unknown lines" are in category of "Anything else" yes no
"Unknown lines" are incorrect allowed
================================================== ========= ===============
The TAP14 specification does permit nested tests, but instead of using another
nested version line, uses a line of the form
"Subtest: <name>" where <name> is the name of the parent test.
Example KTAP output
--------------------
::
KTAP version 1
1..1
KTAP version 1
1..3
KTAP version 1
1..1
# test_1: initializing test_1
ok 1 test_1
ok 1 example_test_1
KTAP version 1
1..2
ok 1 test_1 # SKIP test_1 skipped
ok 2 test_2
ok 2 example_test_2
KTAP version 1
1..3
ok 1 test_1
# test_2: FAIL
not ok 2 test_2
ok 3 test_3 # SKIP test_3 skipped
not ok 3 example_test_3
not ok 1 main_test
This output defines the following hierarchy:
A single test called "main_test", which fails, and has three subtests:
- "example_test_1", which passes, and has one subtest:
- "test_1", which passes, and outputs the diagnostic message "test_1: initializing test_1"
- "example_test_2", which passes, and has two subtests:
- "test_1", which is skipped, with the explanation "test_1 skipped"
- "test_2", which passes
- "example_test_3", which fails, and has three subtests
- "test_1", which passes
- "test_2", which outputs the diagnostic line "test_2: FAIL", and fails.
- "test_3", which is skipped with the explanation "test_3 skipped"
Note that the individual subtests with the same names do not conflict, as they
are found in different parent tests. This output also exhibits some sensible
rules for "bubbling up" test results: a test fails if any of its subtests fail.
Skipped tests do not affect the result of the parent test (though it often
makes sense for a test to be marked skipped if _all_ of its subtests have been
skipped).
See also:
---------
- The TAP specification:
https://testanything.org/tap-version-13-specification.html
- The (stagnant) TAP version 14 specification:
https://github.com/TestAnything/Specification/blob/tap-14-specification/specification.md
- The kselftest documentation:
Documentation/dev-tools/kselftest.rst
- The KUnit documentation:
Documentation/dev-tools/kunit/index.rst
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
KTAP 개요와 출력 구성
1-34SPDX 라이선스 식별자: GPL-2.0
Kernel Test Anything Protocol (KTAP), version 1
TAP, 즉 Test Anything Protocol은 여러 프로젝트가 테스트 결과를 표현하는 데 사용하는 형식입니다. 웹사이트와 명세는 https://testanything.org/ 에 있습니다. Linux kernel은 테스트 결과에 TAP 출력을 널리 사용하지만 kernel testing framework에는 원래 TAP 명세와 맞지 않는 특별한 요구가 있습니다. 이에 TAP를 확장하고 변경해 이러한 용례를 지원하는 Kernel TAP, 즉 KTAP 형식을 정의했습니다. 이 명세는 현재 커널에서 일반적으로 인정되고 사용되는 KTAP 형식을 설명합니다.
KTAP 테스트 결과는 일련의 테스트를 기술합니다. 테스트는 중첩되어 subtest를 가질 수 있으며, 각 테스트는 log line 같은 diagnostic data와 최종 결과를 모두 포함할 수 있습니다. 테스트 구조와 결과는 machine-readable이고 diagnostic data는 정형화되지 않은 사람의 디버깅을 위한 정보입니다.
KTAP 출력은 다음 네 종류의 line으로 구성됩니다.
Version line
Plan line
Test case result line
Diagnostic line
일반적으로 유효한 KTAP 출력은 유효한 TAP 출력이기도 해야 하지만 특히 중첩된 테스트 결과 같은 일부 정보는 손실될 수 있습니다. 정체된 TAP14 draft specification도 존재하지만 KTAP는 몇 군데, 특히 `Subtest` header에서 이 명세와 다르며 관련 차이는 뒤에서 설명합니다.
Version line과 plan line
35-66Version line
KTAP 형식의 모든 결과는 해당 결과가 어느 (K)TAP 표준 version을 따르는지 지정하는 version line으로 시작합니다.
예: `KTAP version 1`
예: `TAP version 13`
예: `TAP version 14`
KTAP에서는 subtest도 version line으로 시작하며, 이 line이 중첩된 테스트 결과의 시작을 나타냅니다. 별도의 `Subtest` line을 사용하는 TAP14와 다른 점입니다.
앞으로 명세를 준수하는 테스트는 `KTAP version 1`을 사용해야 합니다. 다만 기존 테스트와 framework의 호환성을 위해 parser와 기타 tooling 대부분은 위에 나열한 다른 version도 받아들일 것으로 예상합니다.
Plan line
Test plan은 KTAP 출력에 포함된 test 또는 subtest 수를 제공합니다.
Plan line은 `1..N` 형식이어야 하며 N은 test 또는 subtest 수입니다. 중첩된 테스트 수를 알리기 위해 version line 다음에 plan line이 옵니다.
테스트 수를 미리 알 수 없어 test plan을 생략할 수 있는 경우도 있지만 가능한 곳에서는 plan을 넣기를 강하게 권장합니다.
Test case result line과 directive
67-151Test case result line
Test case result line은 테스트의 최종 상태를 나타냅니다. 반드시 있어야 하며 다음 형식을 따라야 합니다.
<result> <number> [<description>][ # [<directive>] [<diagnostic data>]]
필수 결과와 번호 뒤에 선택적 설명, directive, 진단 정보를 붙이는 문법입니다.
Result는 test case가 성공했음을 나타내는 `ok` 또는 실패했음을 나타내는 `not ok`입니다.
`number`는 수행하는 테스트 번호입니다. 첫 테스트는 1이어야 하며 같은 테스트와 같은 nesting level의 subtest가 추가될 때마다 1씩 증가해야 합니다.
Description은 일반적으로 테스트 이름인 설명입니다. `#` 또는 newline을 제외한 임의 문자열을 사용할 수 있습니다. 선택 사항이지만 넣기를 권장합니다.
Directive와 diagnostic data는 선택 사항입니다. 둘 중 하나라도 있으면 hash sign `#` 뒤에 와야 합니다.
Directive는 pass와 fail 외의 다른 결과를 나타내는 선택적 keyword이며 diagnostic data보다 앞에 옵니다. Parser가 지원하지 않는 directive를 만나면 `ok` 또는 `not ok` 결과로 돌아가 해석해야 합니다.
현재 허용되는 directive는 다음과 같습니다.
`SKIP`: 테스트를 건너뛰었음을 나타냅니다. SKIP을 사용할 때 result line은 `ok` 또는 `not ok` 모두 가능합니다.
`TODO`: 현재 테스트가 성공할 것으로 예상하지 않음을 나타냅니다. 예를 들어 검사 대상 기능이 고장 난 것으로 알려진 경우입니다. TAP에서 물려받은 directive지만 kernel에서는 사용을 권장하지 않습니다.
`XFAIL`: 테스트가 실패할 것으로 예상함을 나타냅니다. 위의 TODO와 비슷하며 일부 kselftest가 사용합니다.
`TIMEOUT`: 테스트가 timeout되었음을 나타냅니다. 이 directive를 사용할 때 result line은 `not ok`여야 합니다.
`ERROR`: diagnostic data에 포함된 특정 오류 때문에 테스트 실행이 실패했음을 나타냅니다. 이 directive를 사용할 때 result line은 `not ok`여야 합니다.
Diagnostic data는 결과가 나온 이유에 대한 추가 세부 정보를 담는 plain-text field입니다. 보통 ERROR나 실패한 테스트의 error message 또는 SKIP 결과에서 빠진 dependency에 대한 설명입니다.
Diagnostic data field는 선택 사항입니다. Directive와 diagnostic data가 모두 없는 결과는 `#` field separator를 넣지 않아도 됩니다.
다음은 result line 예입니다.
ok 1 test_case_name
`test_case_name` 테스트가 성공했습니다.
not ok 1 test_case_name
`test_case_name` 테스트가 실패했습니다.
ok 1 test # SKIP necessary dependency unavailable
`test`를 건너뛰었고 diagnostic message는 `necessary dependency unavailable`입니다.
not ok 1 test # TIMEOUT 30 seconds
`test`가 timeout되었고 diagnostic data는 `30 seconds`입니다.
ok 5 check return code # rcode=0
`check return code` 테스트가 성공했으며 추가 diagnostic data는 `rcode=0`입니다.
Diagnostic line과 unknown line
152-183Diagnostic line
테스트가 추가 정보를 출력하려면 diagnostic line을 사용해야 합니다. Diagnostic line은 선택적인 자유 형식 text이며 최종 result와 diagnostic data line보다 더 자세하게 검사 대상과 중간 결과를 설명할 때 자주 사용합니다.
Diagnostic line 형식은 `# <diagnostic_description>`이며 description은 임의 문자열일 수 있습니다. 출력 어디에나 둘 수 있지만 일반적으로 한 테스트에 대한 diagnostic line은 그 테스트의 result line 바로 앞에 둡니다.
대부분의 tool은 아래에서 설명하는 unknown line이 `#`로 시작하지 않더라도 diagnostic line으로 취급합니다. 테스트 디버깅에 도움이 되는 다른 kernel 출력을 포착하기 위해서입니다. 그래도 테스트가 내보내는 모든 diagnostic output에는 항상 `#` 문자를 붙이기를 권장합니다.
Unknown line
KTAP 출력에는 앞서 설명한 네 형식 중 어느 것에도 맞지 않는 line이 있을 수 있습니다. 이를 허용하지만 테스트 상태에는 영향을 주지 않습니다.
이는 TAP와의 중요한 차이입니다. Kernel 테스트는 system console 또는 log file에 message를 출력할 수 있습니다. 두 위치에는 관계없는 kernel 또는 userspace activity의 message나 테스트가 호출한 비테스트 kernel code의 message가 섞일 수 있습니다. 호출된 kernel code는 테스트가 진행 중임을 모를 가능성이 크므로 message를 diagnostic message 형식으로 출력할 수 없습니다.
중첩 테스트와 들여쓰기
184-233중첩 테스트
KTAP에서는 테스트를 중첩할 수 있습니다. 한 테스트의 출력 안에 KTAP 형식의 전체 결과 집합을 포함하는 방식입니다. 관련 테스트를 분류하고 묶거나 같은 테스트에서 나온 서로 다른 결과를 나누는 데 사용할 수 있습니다.
Parent test의 결과는 다른 KTAP version line과 test plan으로 시작하는 모든 subtest 결과를 포함하고 마지막에 전체 결과로 끝나야 합니다. 예를 들어 subtest 하나가 실패하면 parent test도 실패해야 합니다.
또한 subtest의 모든 line은 들여써야 합니다. 들여쓰기 한 level은 두 칸 ` `입니다. Version line부터 들여쓰기하고 parent test result line 앞에서 끝내야 합니다.
Unknown line은 subtest의 line으로 간주하지 않으므로 들여쓰거나 들여쓰지 않아도 됩니다.
두 subtest를 가진 테스트의 예입니다.
KTAP version 1
1..1
KTAP version 1
1..2
ok 1 test_1
not ok 2 test_2
# example failed
not ok 1 example
여러 level로 중첩된 테스트 형식의 예입니다.
KTAP version 1
1..2
KTAP version 1
1..2
KTAP version 1
1..2
not ok 1 test_1
ok 2 test_2
not ok 1 test_3
ok 2 test_4 # SKIP
not ok 1 example_test_1
ok 2 example_test_2
각 level이 독립적인 version과 plan을 가진 뒤 결과가 parent로 올라가는 구조입니다.
TAP와 KTAP의 주요 차이
234-250TAP와 KTAP의 주요 차이
================================================== ========= ===============
Feature TAP KTAP
================================================== ========= ===============
yaml and json in diagnosic message ok not recommended
TODO directive ok not recognized
allows an arbitrary number of tests to be nested no yes
"Unknown lines" are in category of "Anything else" yes no
"Unknown lines" are incorrect allowed
================================================== ========= ===============
원문의 표를 한국어 구조화 표로 다시 정리했습니다.
TAP14 명세도 중첩 테스트를 허용하지만 중첩된 version line 대신 `Subtest: <name>` 형식의 line을 사용합니다. 여기서 `<name>`은 parent test 이름입니다.
전체 KTAP 예제와 결과 전파
251-303KTAP 출력 예
KTAP version 1
1..1
KTAP version 1
1..3
KTAP version 1
1..1
# test_1: initializing test_1
ok 1 test_1
ok 1 example_test_1
KTAP version 1
1..2
ok 1 test_1 # SKIP test_1 skipped
ok 2 test_2
ok 2 example_test_2
KTAP version 1
1..3
ok 1 test_1
# test_2: FAIL
not ok 2 test_2
ok 3 test_3 # SKIP test_3 skipped
not ok 3 example_test_3
not ok 1 main_test
이 출력은 다음 hierarchy를 정의합니다.
`main_test`라는 단일 테스트가 실패하며 세 개의 subtest를 가집니다.
`example_test_1`은 성공하며 한 subtest를 가집니다. `test_1`은 성공하고 `test_1: initializing test_1` diagnostic message를 출력합니다.
`example_test_2`는 성공하며 두 subtest를 가집니다. 첫 번째 `test_1`은 `test_1 skipped` 설명과 함께 skip되고, `test_2`는 성공합니다.
`example_test_3`은 실패하며 세 subtest를 가집니다. `test_1`은 성공하고, `test_2`는 `test_2: FAIL` diagnostic line을 출력한 뒤 실패하며, `test_3`은 `test_3 skipped` 설명과 함께 skip됩니다.
이름이 같은 개별 subtest는 서로 다른 parent test에 있으므로 충돌하지 않습니다. 이 출력은 결과를 위로 전파하는 합리적인 규칙도 보여 줍니다. Subtest 하나라도 실패하면 parent test가 실패합니다. Skip된 테스트는 parent 결과에 영향을 주지 않지만 모든 subtest가 skip되었다면 parent도 skip으로 표시하는 것이 타당한 경우가 많습니다.
관련 명세와 문서
304-314관련 자료
TAP 명세: https://testanything.org/tap-version-13-specification.html
정체된 TAP version 14 명세: https://github.com/TestAnything/Specification/blob/tap-14-specification/specification.md
Kselftest 문서: `Documentation/dev-tools/kselftest.rst`
KUnit 문서: `Documentation/dev-tools/kunit/index.rst`
요약과 해설
ktap.rst:1-314KTAP는 kernel test output을 machine-readable하게 만드는 TAP 확장 형식입니다. 각 level은 version line과 가능하면 plan line을 갖고, 순차 번호가 붙은 ok 또는 not ok 결과 뒤에 SKIP, XFAIL, TIMEOUT, ERROR 같은 directive와 diagnostic data를 덧붙입니다.
Kernel console에는 테스트와 무관한 출력이 섞일 수 있으므로 unknown line을 허용하며 결과 판정에는 반영하지 않습니다. 중첩된 subtest는 level마다 두 칸씩 들여쓰고 자체 version과 plan을 사용하며, 실패 결과는 parent로 전파하되 skip은 일반적으로 parent의 성공 또는 실패에 영향을 주지 않습니다.