ソースを参照

[test] Run self-tests as an embedded image

Allow iPXE to exit after running self-tests, rather than locking the
machine.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12年前
コミット
da76a489d6
2個のファイルの変更43行の追加4行の削除
  1. 1
    0
      src/include/ipxe/errfile.h
  2. 42
    4
      src/tests/test.c

+ 1
- 0
src/include/ipxe/errfile.h ファイルの表示

@@ -60,6 +60,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
60 60
 #define ERRFILE_null_sanboot	       ( ERRFILE_CORE | 0x00140000 )
61 61
 #define ERRFILE_edd		       ( ERRFILE_CORE | 0x00150000 )
62 62
 #define ERRFILE_parseopt	       ( ERRFILE_CORE | 0x00160000 )
63
+#define ERRFILE_test		       ( ERRFILE_CORE | 0x00170000 )
63 64
 
64 65
 #define ERRFILE_eisa		     ( ERRFILE_DRIVER | 0x00000000 )
65 66
 #define ERRFILE_isa		     ( ERRFILE_DRIVER | 0x00010000 )

+ 42
- 4
src/tests/test.c ファイルの表示

@@ -29,9 +29,11 @@ FILE_LICENCE ( GPL2_OR_LATER );
29 29
 
30 30
 #include <stddef.h>
31 31
 #include <stdio.h>
32
+#include <errno.h>
32 33
 #include <assert.h>
33 34
 #include <ipxe/test.h>
34 35
 #include <ipxe/init.h>
36
+#include <ipxe/image.h>
35 37
 
36 38
 /** Current self-test set */
37 39
 static struct self_test *current_tests;
@@ -100,8 +102,9 @@ static void run_tests ( struct self_test *tests ) {
100 102
 /**
101 103
  * Run all self-tests
102 104
  *
105
+ * @ret rc		Return status code
103 106
  */
104
-static void test_init ( void ) {
107
+static int run_all_tests ( void ) {
105 108
 	struct self_test *tests;
106 109
 	unsigned int failures = 0;
107 110
 	unsigned int assertions = 0;
@@ -125,15 +128,50 @@ static void test_init ( void ) {
125 128
 			printf ( " with %d assertion failures", assertions );
126 129
 		}
127 130
 		printf ( "\n" );
131
+		return -EINPROGRESS;
128 132
 	} else {
129 133
 		printf ( "OK: all %d tests passed\n", total );
134
+		return 0;
130 135
 	}
136
+}
137
+
138
+static int test_image_probe ( struct image *image __unused ) {
139
+	return -ENOTTY;
140
+}
141
+
142
+static int test_image_exec ( struct image *image __unused ) {
143
+	return run_all_tests();
144
+}
145
+
146
+static struct image_type test_image_type = {
147
+	.name = "self-tests",
148
+	.probe = test_image_probe,
149
+	.exec = test_image_exec,
150
+};
151
+
152
+static void test_image_free ( struct refcnt *refcnt __unused ) {
153
+	/* Do nothing */
154
+}
131 155
 
132
-	/* Lock system */
133
-	while ( 1 ) {}
156
+static struct image test_image = {
157
+	.refcnt = REF_INIT ( test_image_free ),
158
+	.name = "<TESTS>",
159
+	.type = &test_image_type,
160
+};
161
+
162
+static void test_init ( void ) {
163
+	int rc;
164
+
165
+	/* Register self-tests image */
166
+	if ( ( rc = register_image ( &test_image ) ) != 0 ) {
167
+		DBG ( "Could not register self-test image: %s\n",
168
+		      strerror ( rc ) );
169
+		/* No way to report failure */
170
+		return;
171
+	}
134 172
 }
135 173
 
136 174
 /** Self-test initialisation function */
137
-struct init_fn test_init_fn __init_fn ( INIT_NORMAL ) = {
175
+struct init_fn test_init_fn __init_fn ( INIT_EARLY ) = {
138 176
 	.initialise = test_init,
139 177
 };

読み込み中…
キャンセル
保存