File tree Expand file tree Collapse file tree 6 files changed +57
-51
lines changed Expand file tree Collapse file tree 6 files changed +57
-51
lines changed Original file line number Diff line number Diff line change @@ -167,11 +167,13 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
167
167
--extern build_error --extern macros \
168
168
--extern bindings \
169
169
--no-run --crate-name kernel -Zunstable-options \
170
- --test-builder $(srctree ) /scripts/rustdoc_test_builder.py \
170
+ --test-builder $(objtree ) /scripts/rustdoc_test_builder \
171
171
$< $(rustdoc_test_kernel_quiet ) ; \
172
172
$(srctree ) /scripts/rustdoc_test_gen.py
173
173
174
- % /doctests_kernel_generated.rs % /doctests_kernel_generated_kunit.c : $(src ) /kernel/lib.rs $(obj ) /kernel.o FORCE
174
+ % /doctests_kernel_generated.rs % /doctests_kernel_generated_kunit.c : \
175
+ $(src)/kernel/lib.rs $(obj)/kernel.o \
176
+ $(objtree)/scripts/rustdoc_test_builder FORCE
175
177
$(call if_changed,rustdoc_test_kernel)
176
178
177
179
# We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
Original file line number Diff line number Diff line change 6
6
/kallsyms
7
7
/module.lds
8
8
/recordmcount
9
+ /rustdoc_test_builder
9
10
/sign-file
10
11
/sorttable
11
12
/unifdef
Original file line number Diff line number Diff line change @@ -10,9 +10,12 @@ hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable
10
10
hostprogs-always-$(CONFIG_ASN1) += asn1_compiler
11
11
hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file
12
12
hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
13
- hostprogs-always-$(CONFIG_RUST) += generate_rust_target
13
+ hostprogs-always-$(CONFIG_RUST) += \
14
+ generate_rust_target \
15
+ rustdoc_test_builder
14
16
15
17
generate_rust_target-rust := y
18
+ rustdoc_test_builder-rust := y
16
19
17
20
HOSTCFLAGS_sorttable.o = -I$(srctree ) /tools/include
18
21
HOSTLDLIBS_sorttable = -lpthread
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: GPL-2.0
2
+
3
+ //! Test builder for `rustdoc`-generated tests.
4
+
5
+ use std:: fs:: File ;
6
+ use std:: io:: { BufWriter , Read , Write } ;
7
+
8
+ fn main ( ) {
9
+ let mut stdin = std:: io:: stdin ( ) . lock ( ) ;
10
+ let mut body = String :: new ( ) ;
11
+ stdin. read_to_string ( & mut body) . unwrap ( ) ;
12
+
13
+ let name = body
14
+ . lines ( )
15
+ . find_map ( |line| {
16
+ Some (
17
+ line. split_once ( "fn " ) ?
18
+ . 1
19
+ . split_once ( "rust_kernel_" ) ?
20
+ . 1
21
+ . split_once ( "()" ) ?
22
+ . 0 ,
23
+ )
24
+ . filter ( |x| x. chars ( ) . all ( |c| c. is_alphanumeric ( ) || c == '_' ) )
25
+ } )
26
+ . expect ( "No test name found." ) ;
27
+
28
+ // Qualify `Result` to avoid the collision with our own `Result`
29
+ // coming from the prelude.
30
+ let body = body. replace (
31
+ & format ! ( "rust_kernel_{name}() -> Result<(), impl core::fmt::Debug> {{" ) ,
32
+ & format ! ( "rust_kernel_{name}() -> core::result::Result<(), impl core::fmt::Debug> {{" ) ,
33
+ ) ;
34
+
35
+ let name = format ! ( "rust_kernel_doctest_{name}" ) ;
36
+ let path = format ! ( "rust/test/doctests/kernel/{name}" ) ;
37
+
38
+ write ! (
39
+ BufWriter :: new( File :: create( path) . unwrap( ) ) ,
40
+ "{name}\n {body}"
41
+ )
42
+ . unwrap ( ) ;
43
+ }
Original file line number Diff line number Diff line change 3
3
"""rustdoc_test_gen - Generates KUnit tests from saved `rustdoc`-generated tests.
4
4
"""
5
5
6
- import json
7
6
import os
8
7
import pathlib
9
8
@@ -136,16 +135,16 @@ def main():
136
135
c_test_cases = ""
137
136
for filename in sorted (os .listdir (TESTS_DIR )):
138
137
with open (TESTS_DIR / filename , "r" ) as fd :
139
- test = json . load ( fd )
138
+ ( test_name , test_body ) = fd . read (). split ( ' \n ' , 1 )
140
139
rust_tests += RUST_TEMPLATE_TEST .format (
141
- test_name = test [ "name" ] ,
142
- test_body = test [ "body" ]
140
+ test_name = test_name ,
141
+ test_body = test_body
143
142
)
144
143
c_test_declarations += C_TEMPLATE_TEST_DECLARATION .format (
145
- test_name = test [ "name" ]
144
+ test_name = test_name
146
145
)
147
146
c_test_cases += C_TEMPLATE_TEST_CASE .format (
148
- test_name = test [ "name" ]
147
+ test_name = test_name
149
148
)
150
149
151
150
with open (RUST_FILE , "w" ) as fd :
You can’t perform that action at this time.
0 commit comments