summaryrefslogtreecommitdiffstats
path: root/tests/basic.py
blob: c6dec81f9bae5ccdf7191cfab513d2f12f0c0280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python -u
import libvirt
import sys
import os

if not os.access("/proc/xen", os.R_OK):
    print 'System is not running a Xen kernel'
    sys.exit(1)

conn = libvirt.openReadOnly(None)
if conn == None:
    print 'Failed to open connection to the hypervisor'
    sys.exit(1)

# print conn

try:
    dom0 = conn.lookupByName("Domain-0")
except:
    print 'Failed to find the main domain'
    sys.exit(1)

# print dom0

print "Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType())
print dom0.info()
del dom0
del conn
print "OK"

sys.exit(0)
1 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
// SPDX-License-Identifier: GPL-2.0+
/*
 * efi_selftest_bitblt
 *
 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
 *
 * Test the block image transfer in the graphical output protocol.
 * An animated submarine is shown.
 */

#include <efi_selftest.h>

#define WIDTH	200
#define HEIGHT	120
#define DEPTH	 60

static const struct efi_gop_pixel BLACK =	{  0,   0,   0, 0};
static const struct efi_gop_pixel RED =		{  0,   0, 255, 0};
static const struct efi_gop_pixel ORANGE =	{  0, 128, 255, 0};
static const struct efi_gop_pixel YELLOW =	{  0, 255, 255, 0};
static const struct efi_gop_pixel GREEN =	{  0, 255,   0, 0};
static const struct efi_gop_pixel DARK_BLUE =	{128,   0,   0, 0};
static const struct efi_gop_pixel LIGHT_BLUE =	{255, 192, 192, 0};

static struct efi_boot_services *boottime;
static efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
static struct efi_gop *gop;
static struct efi_gop_pixel *bitmap;
static struct efi_event *event;
static efi_uintn_t xpos;

static void ellipse(efi_uintn_t x, efi_uintn_t y,
		    efi_uintn_t x0, efi_uintn_t y0,
		    efi_uintn_t x1, efi_uintn_t y1,
		    const struct efi_gop_pixel col, struct efi_gop_pixel *pix)
{
	efi_uintn_t xm = x0 + x1;
	efi_uintn_t ym = y0 + y1;
	efi_uintn_t dx = x1 - x0 + 1;
	efi_uintn_t dy = y1 - y0 + 1;

	if (dy * dy * (2 * x - xm) * (2 * x - xm) +
	    dx * dx * (2 * y - ym) * (2 * y - ym) <= dx * dx * dy * dy)
		*pix = col;
}

static void rectangle(efi_uintn_t x, efi_uintn_t y,
		      efi_uintn_t x0, efi_uintn_t y0,
		      efi_uintn_t x1, efi_uintn_t y1,
		      const struct efi_gop_pixel col, struct efi_gop_pixel *pix)
{
	if (x >= x0 && y >= y0 && x <= x1 && y <= y1)
		*pix = col;
}

/*
 * Notification function, copies image to video.
 * The position is incremented in each call.
 *
 * @event	notified event
 * @context	pointer to the notification count
 */
static void EFIAPI notify(struct efi_event *event, void *context)
{
	efi_uintn_t *pos = context;
	efi_uintn_t dx, sx, width;

	if (!pos)
		return;

	/* Increment position */
	*pos += 5;
	if (*pos >= WIDTH + gop->mode->info->width)
		*pos = 0;

	width = WIDTH;
	dx = *pos - WIDTH;
	sx = 0;
	if (*pos >= gop->mode->info->width) {
		width = WIDTH +  gop->mode->info->width - *pos;
	} else if (*pos < WIDTH) {
		dx = 0;
		sx = WIDTH - *pos;
		width = *pos;
	}

	/* Copy image to video */
	gop->blt(gop, bitmap, EFI_BLT_BUFFER_TO_VIDEO, sx, 0, dx, DEPTH,
		 width, HEIGHT, WIDTH * sizeof(struct efi_gop_pixel));
}

/*
 * Setup unit test.
 *
 * @handle:	handle of the loaded image
 * @systable:	system table
 * @return:	EFI_ST_SUCCESS for success
 */
static int setup(const efi_handle_t handle,
		 const struct efi_system_table *systable)
{
	efi_status_t ret;
	struct efi_gop_pixel pix;
	efi_uintn_t x, y;

	boottime = systable->boottime;

	/* Create event */
	ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL,
				     TPL_CALLBACK, notify, (void *)&xpos,
				     &event);
	if (ret != EFI_SUCCESS) {
		efi_st_error("could not create event\n");
		return EFI_ST_FAILURE;
	}

	/* Get graphical output protocol */
	ret = boottime->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
	if (ret != EFI_SUCCESS) {
		gop = NULL;
		efi_st_printf("Graphical output protocol is not available.\n");
		return EFI_ST_SUCCESS;
	}

	/* Prepare image of submarine */
	ret = boottime->allocate_pool(EFI_LOADER_DATA,
				      sizeof(struct efi_gop_pixel) *
				      WIDTH * HEIGHT, (void **)&bitmap);
	if (ret != EFI_SUCCESS) {
		efi_st_error("Out of memory\n");
		return EFI_ST_FAILURE;
	}
	for (y = 0; y < HEIGHT; ++y) {
		for (x = 0; x < WIDTH; ++x) {
			pix = DARK_BLUE;

			/* Propeller */
			ellipse(x, y, 35, 55, 43, 75, BLACK, &pix);
			ellipse(x, y, 36, 56, 42, 74, LIGHT_BLUE, &pix);

			ellipse(x, y, 35, 75, 43, 95, BLACK, &pix);
			ellipse(x, y, 36, 76, 42, 94, LIGHT_BLUE, &pix);

			/* Shaft */
			rectangle(x, y, 35, 73, 100, 77, BLACK, &pix);

			/* Periscope */
			ellipse(x, y, 120, 10, 160, 50, BLACK, &pix);
			ellipse(x, y, 121, 11, 159, 59, YELLOW, &pix);