END_TEST /* Test to ensure that two zones with overlapping ranges can not be attached * to a PD. */ START_TEST(ZONE0500) { int error; okl4_virtmem_pool_t *zone_pool; okl4_zone_t *zone1, *zone2; okl4_pd_t *pd1, *pd2; okl4_pd_zone_attach_attr_t zone1_attr, zone2_attr; #if defined(ARM_SHARED_DOMAINS) zone_pool = create_derived_virt_pool(3 * OKL4_ZONE_ALIGNMENT, OKL4_ZONE_ALIGNMENT); zone1 = create_zone(zone_pool->virt.base, 2 * OKL4_ZONE_ALIGNMENT); zone2 = create_zone(zone_pool->virt.base, 4 * OKL4_ZONE_ALIGNMENT); #else zone_pool = create_derived_virt_pool(3 * OKL4_DEFAULT_PAGESIZE, 1); zone1 = create_zone(zone_pool->virt.base, 2 * OKL4_DEFAULT_PAGESIZE); zone2 = create_zone(zone_pool->virt.base, 4 * OKL4_DEFAULT_PAGESIZE); #endif /* Create pd1 */ pd1 = create_pd(); /* Create pd2 */ pd2 = create_pd(); /* Attach these zones to pd1 */ okl4_pd_zone_attach_attr_init(&zone1_attr); okl4_pd_zone_attach_attr_init(&zone2_attr); error = okl4_pd_zone_attach(pd1, zone1, &zone1_attr); fail_unless(error == OKL4_OK, "Could not attach a zone to a pd1"); error = okl4_pd_zone_attach(pd1, zone2, &zone2_attr); fail_unless(error != OKL4_OK, "Over Lapping zones got attached to pd1"); /* Attach zone2 to pd2 */ error = okl4_pd_zone_attach(pd2, zone2, &zone2_attr); fail_unless(error == OKL4_OK, "Could not attach a zone2 to pd2"); /* CleanUp */ delete_derived_virt_pool(zone_pool); okl4_pd_zone_detach(pd1, zone1); okl4_pd_zone_detach(pd2, zone2); okl4_pd_delete(pd1); free(pd1); okl4_pd_delete(pd2); free(pd2); }
END_TEST /* * Test to ensure that two memsections with overlapping ranges can not be * attached to a zone */ START_TEST(ZONE0125) { int error; okl4_zone_t *zone; ms_t *ms1, *ms2; okl4_word_t chunksize = OKL4_ZONE_ALIGNMENT; /* Create two over-lapping memsections */ ms1 = create_memsec(1 * chunksize, 3 * chunksize, NO_POOL); ms2 = create_memsec(2 * chunksize, 4 * chunksize, NO_POOL); /* Create a zone using the entire memsec pool so that the memsections fall * under the zone. */ zone = create_zone(1 * chunksize, 4 * chunksize); /* Attach the memsections to the zone. This should not succeed since the * memsections are over-lapping */ error = okl4_zone_memsec_attach(zone, ms1->memsec); fail_unless(error == OKL4_OK, "Could not attach a memsec to a zone"); error = okl4_zone_memsec_attach(zone, ms2->memsec); fail_unless(error != OKL4_OK, "Attached an over lapping memsection"); /* Clean Up */ okl4_zone_memsec_detach(zone, ms1->memsec); delete_memsec(ms1, NO_POOL); delete_memsec(ms2, NO_POOL); delete_zone(zone); }
END_TEST /* Try to attach an incompatible memsection to a zone. */ START_TEST(ZONE0120) { ms_t *m[4]; int error; int i; okl4_zone_t *zone; okl4_word_t chunksize = OKL4_ZONE_ALIGNMENT; /* Create a small zone. */ zone = create_zone(2 * chunksize, 3 * chunksize); /* Create memsections that do not fit into the zone. */ m[0] = create_memsec(chunksize, 2 * chunksize, NO_POOL); m[1] = create_memsec(1 * chunksize, 3 * chunksize, NO_POOL); m[2] = create_memsec(2 * chunksize, 4 * chunksize, NO_POOL); m[3] = create_memsec(3 * chunksize, 4 * chunksize, NO_POOL); /* Ensure that we can not attach any of the memsections. */ for (i = 0; i < 4; i++) { error = okl4_zone_memsec_attach(zone, m[i]->memsec); fail_unless(error != OKL4_OK, "Incompatible memsection attached to the pd"); } /* Clean up. */ delete_zone(zone); for (i = 0; i < 4; i++) { delete_memsec(m[i], NO_POOL); } }
/* * Create a zone covering all base memsecs. */ static okl4_zone_t * create_elf_segments_zone(void) { okl4_word_t i; okl4_word_t max_vaddr; okl4_word_t min_vaddr; okl4_word_t zone_size; okl4_zone_t *zone; /* Find the min and max vaddrs of the segment memsections - also the size * of the memsection with maximum vaddr. */ max_vaddr = 0; min_vaddr = (okl4_word_t)-1; for (i = 0; ctest_segments[i] != NULL; i++) { okl4_word_t base, size; okl4_range_item_t range; range = okl4_memsec_getrange(ctest_segments[i]); base = okl4_range_item_getbase(&range); size = okl4_range_item_getsize(&range); max_vaddr = MAX(max_vaddr, base + size); min_vaddr = MIN(min_vaddr, base); } /* Create a zone to cover all the above memsections. */ zone_size = max_vaddr - min_vaddr; #if defined(ARM_SHARED_DOMAINS) /* Round up size to the nearest multiple of window size. */ zone_size = (zone_size + (OKL4_ZONE_ALIGNMENT - 1)) & ~(OKL4_ZONE_ALIGNMENT - 1); /* Round down min_vaddr so that it is aligned to window size. */ min_vaddr = min_vaddr & ~(OKL4_ZONE_ALIGNMENT - 1); #endif zone = create_zone(min_vaddr, zone_size); assert(zone); /* Attach all segment memsections to this zone. */ for (i = 0; ctest_segments[i] != NULL; i++) { int error = okl4_zone_memsec_attach(zone, ctest_segments[i]); fail_unless(error == OKL4_OK, "Could not attach a memsec to a zone"); } return zone; }
END_TEST /* * Try to attach a zone of size 0 to a PD. */ START_TEST(ZONE0110) { okl4_zone_t *zone; okl4_pd_t *pd; /* Create a pd. */ pd = create_pd(); /* Create a zone which can accomadate the above memsections. */ zone = create_zone(0, 0); /* Attach the zone to a pd. 'attach_zone' checks for errors. */ attach_zone(pd, zone); /* Clean up. */ okl4_pd_zone_detach(pd, zone); delete_zone(zone); delete_pd(pd); }
int main(int argc, char **argv) { char g_name[BASIC_SSIZE], z_name[BASIC_SSIZE]; __u64 size_MB; int retval; char option; while ((option = getopt(argc, argv, "h")) != -1) { printf("option = %c\n",option); if (optarg) printf("optarg = %s\n",optarg); switch (option) { case 'h': help(); return EXIT_SUCCESS; break; case '?': fprintf(stderr,"Option inconnue\n"); help(); return EXIT_FAILURE; } } if (argc-optind != 2) { help(); return EXIT_FAILURE; } if (vrt_active() == FALSE) { fprintf(stderr, "échec : le virtualiseur n'est pas présent " "en mémoire\n"); return EXIT_FAILURE; } retval = sscanf(argv[optind],"%16[A-Za-z0-9]:%16[A-Za-z0-9]", g_name, z_name); if (retval != 2) { fprintf(stderr,"impossible de parser le nom de la zone " "et le nom du groupe (taille limitée à 16 caractères" " chacun)\n"); return EXIT_FAILURE; } if (gname_active(g_name) == FALSE) { fprintf(stderr,"Le group '%s' n'est pas actif\n", g_name); return EXIT_FAILURE; } if (zname_in_group(z_name, g_name) == TRUE) { fprintf(stderr,"La zone '%s:%s' existe déjà\n", z_name, g_name); return EXIT_FAILURE; } retval = sscanf(argv[optind+1],"%Ld",&size_MB); if (retval != 1) { fprintf(stderr,"impossible de parser la taille de la zone\n"); return EXIT_FAILURE; } return create_zone(g_name, z_name, size_MB); }