| 
				
			 | 
			
			
				
				@@ -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
			 | 
			
			
				
				 }; 
			 |