iPXE
pixbuf_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * Pixel buffer self-tests
29  *
30  */
31 
32 /* Forcibly enable assertions */
33 #undef NDEBUG
34 
35 #include <assert.h>
36 #include <ipxe/image.h>
37 #include <ipxe/pixbuf.h>
38 #include <ipxe/test.h>
39 #include "pixbuf_test.h"
40 
41 /**
42  * Report pixel buffer test result
43  *
44  * @v test Pixel buffer test
45  * @v file Test code file
46  * @v line Test code line
47  */
48 void pixbuf_okx ( struct pixel_buffer_test *test, const char *file,
49  unsigned int line ) {
50  struct pixel_buffer *pixbuf;
51  int rc;
52 
53  /* Sanity check */
54  assert ( ( test->width * test->height * sizeof ( test->data[0] ) )
55  == test->len );
56 
57  /* Correct image data pointer */
58  test->image->data = virt_to_user ( ( void * ) test->image->data );
59 
60  /* Check that image is detected as correct type */
61  okx ( register_image ( test->image ) == 0, file, line );
62  okx ( test->image->type == test->type, file, line );
63 
64  /* Check that a pixel buffer can be created from the image */
65  okx ( ( rc = image_pixbuf ( test->image, &pixbuf ) ) == 0, file, line );
66  if ( rc == 0 ) {
67 
68  /* Check pixel buffer dimensions */
69  okx ( pixbuf->width == test->width, file, line );
70  okx ( pixbuf->height == test->height, file, line );
71 
72  /* Check pixel buffer data */
73  okx ( pixbuf->len == test->len, file, line );
74  okx ( memcmp_user ( pixbuf->data, 0,
75  virt_to_user ( test->data ), 0,
76  test->len ) == 0, file, line );
77 
78  pixbuf_put ( pixbuf );
79  }
80 
81  /* Unregister image */
82  unregister_image ( test->image );
83 }
int image_pixbuf(struct image *image, struct pixel_buffer **pixbuf)
Create pixel buffer from image.
Definition: pixbuf.c:97
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
unsigned int height
Height.
Definition: pixbuf.h:23
Self-test infrastructure.
Pixel buffer.
size_t len
Total length.
Definition: pixbuf.h:27
#define okx(success, file, line)
Report test result.
Definition: test.h:44
Assertions.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
Executable images.
int register_image(struct image *image)
Register executable image.
Definition: image.c:267
A pixel buffer.
Definition: pixbuf.h:17
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:303
int memcmp_user(userptr_t first, off_t first_off, userptr_t second, off_t second_off, size_t len)
Compare data between user buffers.
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
userptr_t data
32-bit (8:8:8:8) xRGB pixel data, in host-endian order
Definition: pixbuf.h:25
void pixbuf_okx(struct pixel_buffer_test *test, const char *file, unsigned int line)
Report pixel buffer test result.
Definition: pixbuf_test.c:48
A pixel buffer test.
Definition: pixbuf_test.h:12
static int test
Definition: epic100.c:73
unsigned int width
Width.
Definition: pixbuf.h:21