Example #1
0
/**
 * Report pixel buffer test result
 *
 * @v test		Pixel buffer test
 * @v file		Test code file
 * @v line		Test code line
 */
void pixbuf_okx ( struct pixel_buffer_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 == test->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 );
    }
}
Example #2
0
/**
 * Initialise command line
 *
 * @ret rc		Return status code
 */
static int cmdline_init ( void ) {
	userptr_t cmdline_user;
	char *cmdline;
	size_t len;
	int rc;

	/* Do nothing if no command line was specified */
	if ( ! cmdline_phys ) {
		DBGC ( colour, "RUNTIME found no command line\n" );
		return 0;
	}
	cmdline_user = phys_to_user ( cmdline_phys );
	len = ( strlen_user ( cmdline_user, 0 ) + 1 /* NUL */ );

	/* Allocate and copy command line */
	cmdline_copy = malloc ( len );
	if ( ! cmdline_copy ) {
		DBGC ( colour, "RUNTIME could not allocate %zd bytes for "
		       "command line\n", len );
		rc = -ENOMEM;
		goto err_alloc_cmdline_copy;
	}
	cmdline = cmdline_copy;
	copy_from_user ( cmdline, cmdline_user, 0, len );
	DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
	       cmdline, cmdline_phys );

	/* Mark command line as consumed */
	cmdline_phys = 0;

	/* Strip unwanted cruft from the command line */
	cmdline_strip ( cmdline, "BOOT_IMAGE=" );
	cmdline_strip ( cmdline, "initrd=" );
	while ( isspace ( *cmdline ) )
		cmdline++;
	DBGC ( colour, "RUNTIME using command line \"%s\"\n", cmdline );

	/* Prepare and register image */
	cmdline_image.data = virt_to_user ( cmdline );
	cmdline_image.len = strlen ( cmdline );
	if ( cmdline_image.len ) {
		if ( ( rc = register_image ( &cmdline_image ) ) != 0 ) {
			DBGC ( colour, "RUNTIME could not register command "
			       "line: %s\n", strerror ( rc ) );
			goto err_register_image;
		}
	}

	/* Drop our reference to the image */
	image_put ( &cmdline_image );

	return 0;

 err_register_image:
	image_put ( &cmdline_image );
 err_alloc_cmdline_copy:
	return rc;
}
Example #3
0
/**
 * Report content information test result
 *
 * @v test		Content information test
 * @v info		Content information to fill in
 * @v file		Test code file
 * @v line		Test code line
 */
static void peerdist_info_okx ( struct peerdist_info_test *test,
				struct peerdist_info *info,
				const char *file, unsigned int line ) {

	/* Parse content information */
	okx ( peerdist_info ( virt_to_user ( test->data ), test->len,
			      info ) == 0, file, line );

	/* Verify content information */
	okx ( info->raw.data == virt_to_user ( test->data ), file, line );
	okx ( info->raw.len == test->len, file, line );
	okx ( info->digest == test->expected_digest, file, line );
	okx ( info->digestsize == test->expected_digestsize, file, line );
	okx ( info->trim.start >= info->range.start, file, line );
	okx ( info->trim.start == test->expected_trim.start, file, line );
	okx ( info->trim.end <= info->range.end, file, line );
	okx ( info->trim.end == test->expected_trim.end, file, line );
	okx ( info->segments == test->expected_segments, file, line );
}
Example #4
0
/**
 * Register all embedded images
 */
static void embedded_init ( void ) {
	int i;
	struct image *image;
	void *data;
	int rc;

	/* Skip if we have no embedded images */
	if ( ! sizeof ( embedded_images ) )
		return;

	/* Fix up data pointers and register images */
	for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
				    sizeof ( embedded_images[0] ) ) ; i++ ) {
		image = &embedded_images[i];

		/* virt_to_user() cannot be used in a static
		 * initialiser, so we cast the pointer to a userptr_t
		 * in the initialiser and fix it up here.  (This will
		 * actually be a no-op on most platforms.)
		 */
		data = ( ( void * ) image->data );
		image->data = virt_to_user ( data );

		DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
		      image->name, image->len, data );

		if ( ( rc = register_image ( image ) ) != 0 ) {
			DBG ( "Could not register embedded image \"%s\": "
			      "%s\n", image->name, strerror ( rc ) );
			return;
		}
	}

	/* Select the first image */
	image = &embedded_images[0];
	if ( ( rc = image_select ( image ) ) != 0 ) {
		DBG ( "Could not select embedded image \"%s\": %s\n",
		      image->name, strerror ( rc ) );
		return;
	}
}