Browse Source

[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 years ago
parent
commit
da76a489d6
2 changed files with 43 additions and 4 deletions
  1. 1
    0
      src/include/ipxe/errfile.h
  2. 42
    4
      src/tests/test.c

+ 1
- 0
src/include/ipxe/errfile.h View File

60
 #define ERRFILE_null_sanboot	       ( ERRFILE_CORE | 0x00140000 )
60
 #define ERRFILE_null_sanboot	       ( ERRFILE_CORE | 0x00140000 )
61
 #define ERRFILE_edd		       ( ERRFILE_CORE | 0x00150000 )
61
 #define ERRFILE_edd		       ( ERRFILE_CORE | 0x00150000 )
62
 #define ERRFILE_parseopt	       ( ERRFILE_CORE | 0x00160000 )
62
 #define ERRFILE_parseopt	       ( ERRFILE_CORE | 0x00160000 )
63
+#define ERRFILE_test		       ( ERRFILE_CORE | 0x00170000 )
63
 
64
 
64
 #define ERRFILE_eisa		     ( ERRFILE_DRIVER | 0x00000000 )
65
 #define ERRFILE_eisa		     ( ERRFILE_DRIVER | 0x00000000 )
65
 #define ERRFILE_isa		     ( ERRFILE_DRIVER | 0x00010000 )
66
 #define ERRFILE_isa		     ( ERRFILE_DRIVER | 0x00010000 )

+ 42
- 4
src/tests/test.c View File

29
 
29
 
30
 #include <stddef.h>
30
 #include <stddef.h>
31
 #include <stdio.h>
31
 #include <stdio.h>
32
+#include <errno.h>
32
 #include <assert.h>
33
 #include <assert.h>
33
 #include <ipxe/test.h>
34
 #include <ipxe/test.h>
34
 #include <ipxe/init.h>
35
 #include <ipxe/init.h>
36
+#include <ipxe/image.h>
35
 
37
 
36
 /** Current self-test set */
38
 /** Current self-test set */
37
 static struct self_test *current_tests;
39
 static struct self_test *current_tests;
100
 /**
102
 /**
101
  * Run all self-tests
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
 	struct self_test *tests;
108
 	struct self_test *tests;
106
 	unsigned int failures = 0;
109
 	unsigned int failures = 0;
107
 	unsigned int assertions = 0;
110
 	unsigned int assertions = 0;
125
 			printf ( " with %d assertion failures", assertions );
128
 			printf ( " with %d assertion failures", assertions );
126
 		}
129
 		}
127
 		printf ( "\n" );
130
 		printf ( "\n" );
131
+		return -EINPROGRESS;
128
 	} else {
132
 	} else {
129
 		printf ( "OK: all %d tests passed\n", total );
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
 /** Self-test initialisation function */
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
 	.initialise = test_init,
176
 	.initialise = test_init,
139
 };
177
 };

Loading…
Cancel
Save