i440fx-test.c (e93ded1bf6c94ab95015b33e188bc8b0b0c32670) | i440fx-test.c (3039fd4b6e9b80ab35b34493181202a22b952812) |
---|---|
1/* 2 * qtest I440FX test case 3 * 4 * Copyright IBM, Corp. 2012-2013 5 * Copyright Red Hat, Inc. 2013 6 * 7 * Authors: 8 * Anthony Liguori <aliguori@us.ibm.com> --- 264 unchanged lines hidden (view full) --- 273 g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x82)); 274 } 275 276 g_free(dev); 277 qpci_free_pc(bus); 278 qtest_end(); 279} 280 | 1/* 2 * qtest I440FX test case 3 * 4 * Copyright IBM, Corp. 2012-2013 5 * Copyright Red Hat, Inc. 2013 6 * 7 * Authors: 8 * Anthony Liguori <aliguori@us.ibm.com> --- 264 unchanged lines hidden (view full) --- 273 g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x82)); 274 } 275 276 g_free(dev); 277 qpci_free_pc(bus); 278 qtest_end(); 279} 280 |
281#ifndef _WIN32 282 | |
283#define BLOB_SIZE ((size_t)65536) 284#define ISA_BIOS_MAXSZ ((size_t)(128 * 1024)) 285 | 281#define BLOB_SIZE ((size_t)65536) 282#define ISA_BIOS_MAXSZ ((size_t)(128 * 1024)) 283 |
286/* Create a blob file, and return its absolute pathname as a dynamically | 284/* 285 * Create a blob file, and return its absolute pathname as a dynamically |
287 * allocated string. 288 * The file is closed before the function returns. | 286 * allocated string. 287 * The file is closed before the function returns. |
289 * In case of error, NULL is returned. The function prints the error message. | 288 * In case of error, the function aborts and prints the error message. |
290 */ 291static char *create_blob_file(void) 292{ | 289 */ 290static char *create_blob_file(void) 291{ |
293 int ret, fd; | 292 int i, fd; |
294 char *pathname; 295 GError *error = NULL; | 293 char *pathname; 294 GError *error = NULL; |
295 g_autofree uint8_t *buf = g_malloc(BLOB_SIZE); |
|
296 | 296 |
297 ret = -1; | |
298 fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error); | 297 fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error); |
299 if (fd == -1) { 300 fprintf(stderr, "unable to create blob file: %s\n", error->message); 301 g_error_free(error); 302 } else { 303 if (ftruncate(fd, BLOB_SIZE) == -1) { 304 fprintf(stderr, "ftruncate(\"%s\", %zu): %s\n", pathname, 305 BLOB_SIZE, strerror(errno)); 306 } else { 307 void *buf; | 298 g_assert_no_error(error); 299 close(fd); |
308 | 300 |
309 buf = mmap(NULL, BLOB_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); 310 if (buf == MAP_FAILED) { 311 fprintf(stderr, "mmap(\"%s\", %zu): %s\n", pathname, BLOB_SIZE, 312 strerror(errno)); 313 } else { 314 size_t i; 315 316 for (i = 0; i < BLOB_SIZE; ++i) { 317 ((uint8_t *)buf)[i] = i; 318 } 319 munmap(buf, BLOB_SIZE); 320 ret = 0; 321 } 322 } 323 close(fd); 324 if (ret == -1) { 325 unlink(pathname); 326 g_free(pathname); 327 } | 301 for (i = 0; i < BLOB_SIZE; i++) { 302 buf[i] = i; |
328 } 329 | 303 } 304 |
330 return ret == -1 ? NULL : pathname; | 305 g_file_set_contents(pathname, (char *)buf, BLOB_SIZE, &error); 306 g_assert_no_error(error); 307 308 return pathname; |
331} 332 333static void test_i440fx_firmware(FirmwareTestFixture *fixture, 334 gconstpointer user_data) 335{ 336 char *fw_pathname, *cmdline; 337 uint8_t *buf; 338 size_t i, isa_bios_size; --- 54 unchanged lines hidden (view full) --- 393} 394 395static void request_pflash(FirmwareTestFixture *fixture, 396 gconstpointer user_data) 397{ 398 fixture->is_bios = false; 399} 400 | 309} 310 311static void test_i440fx_firmware(FirmwareTestFixture *fixture, 312 gconstpointer user_data) 313{ 314 char *fw_pathname, *cmdline; 315 uint8_t *buf; 316 size_t i, isa_bios_size; --- 54 unchanged lines hidden (view full) --- 371} 372 373static void request_pflash(FirmwareTestFixture *fixture, 374 gconstpointer user_data) 375{ 376 fixture->is_bios = false; 377} 378 |
401#endif /* _WIN32 */ 402 | |
403int main(int argc, char **argv) 404{ 405 TestData data; 406 407 g_test_init(&argc, &argv, NULL); 408 409 data.num_cpus = 1; 410 411 qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults); 412 qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam); | 379int main(int argc, char **argv) 380{ 381 TestData data; 382 383 g_test_init(&argc, &argv, NULL); 384 385 data.num_cpus = 1; 386 387 qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults); 388 qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam); |
413#ifndef _WIN32 | |
414 add_firmware_test("i440fx/firmware/bios", request_bios); 415 add_firmware_test("i440fx/firmware/pflash", request_pflash); | 389 add_firmware_test("i440fx/firmware/bios", request_bios); 390 add_firmware_test("i440fx/firmware/pflash", request_pflash); |
416#endif | |
417 418 return g_test_run(); 419} | 391 392 return g_test_run(); 393} |