summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorMichael Brown2014-01-06 18:58:46 +0100
committerMichael Brown2014-01-12 22:53:16 +0100
commitda7224f9b6f8e89daefc811ac727401c31af5ed6 (patch)
treeb360729a014c086ba8bc5a8e738a65a5e96969c7 /src/tests
parent[uaccess] Add memcmp_user() (diff)
downloadipxe-da7224f9b6f8e89daefc811ac727401c31af5ed6.tar.gz
ipxe-da7224f9b6f8e89daefc811ac727401c31af5ed6.tar.xz
ipxe-da7224f9b6f8e89daefc811ac727401c31af5ed6.zip
[test] Rewrite pnm_ok() using okx()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/pnm_test.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/tests/pnm_test.c b/src/tests/pnm_test.c
index a7b6752a..099ccbc5 100644
--- a/src/tests/pnm_test.c
+++ b/src/tests/pnm_test.c
@@ -243,36 +243,43 @@ PNM ( ppm_binary,
* Report PNM test result
*
* @v test PNM test
+ * @v file Test code file
+ * @v line Test code line
*/
-#define pnm_ok( test ) do { \
- struct pixel_buffer *pixbuf; \
- uint8_t data[ (test)->len ]; \
- int rc; \
- \
- /* Sanity check */ \
- assert ( ( (test)->width * (test)->height * \
- sizeof ( (test)->data[0] ) ) == (test)->len ); \
- \
- /* Correct image data pointer */ \
- (test)->image->data = \
- virt_to_user ( ( void * ) (test)->image->data ); \
- \
- /* Perform tests */ \
- ok ( image_probe ( (test)->image ) == 0 ); \
- ok ( (test)->image->type == &pnm_image_type ); \
- ok ( ( rc = image_pixbuf ( (test)->image, &pixbuf ) ) == 0 ); \
- if ( rc == 0 ) { \
- ok ( pixbuf->width == (test)->width ); \
- ok ( pixbuf->height == (test)->height ); \
- ok ( pixbuf->len == (test)->len ); \
- copy_from_user ( data, pixbuf->data, 0, \
- sizeof ( data ) ); \
- ok ( memcmp ( data, (test)->data, \
- sizeof ( data ) ) == 0 ); \
- DBGC_HDA ( (test)->image, 0, data, sizeof ( data ) ); \
- pixbuf_put ( pixbuf ); \
- } \
- } while ( 0 )
+static void pnm_okx ( struct pnm_test *test, const char *file,
+ unsigned int line ) {
+ struct pixel_buffer *pixbuf;
+ int rc;
+
+ /* Sanity check */
+ assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
+ == test->len );
+
+ /* Correct image data pointer */
+ test->image->data = virt_to_user ( ( void * ) test->image->data );
+
+ /* Check that image is detected as PNM */
+ okx ( image_probe ( test->image ) == 0, file, line );
+ okx ( test->image->type == &pnm_image_type, file, line );
+
+ /* Check that a pixel buffer can be created from the image */
+ okx ( ( rc = image_pixbuf ( test->image, &pixbuf ) ) == 0, file, line );
+ if ( rc == 0 ) {
+
+ /* Check pixel buffer dimensions */
+ okx ( pixbuf->width == test->width, file, line );
+ okx ( pixbuf->height == test->height, file, line );
+
+ /* Check pixel buffer data */
+ okx ( pixbuf->len == test->len, file, line );
+ okx ( memcmp_user ( pixbuf->data, 0,
+ virt_to_user ( test->data ), 0,
+ test->len ) == 0, file, line );
+
+ pixbuf_put ( pixbuf );
+ }
+}
+#define pnm_ok( test ) pnm_okx ( test, __FILE__, __LINE__ )
/**
* Perform PNM self-test