Update TP1
This commit is contained in:
parent
973b6eacd6
commit
b74b678386
@ -1,4 +1,5 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "vmap.h"
|
#include "vmap.h"
|
||||||
|
|
||||||
@ -6,10 +7,34 @@ int main() {
|
|||||||
// Add more tests here
|
// Add more tests here
|
||||||
VMap* vmap = vmap_init();
|
VMap* vmap = vmap_init();
|
||||||
|
|
||||||
char* data1 = my_malloc(vmap, 30*sizeof(char));
|
char* real1 = malloc(sizeof(char)*32);
|
||||||
char* data2 = my_malloc(vmap, 30*sizeof(char));
|
real1[0] = 'h';
|
||||||
|
real1[1] = 'e';
|
||||||
|
real1[2] = 'l';
|
||||||
|
real1[3] = 'l';
|
||||||
|
real1[4] = 'o';
|
||||||
|
real1[5] = '!';
|
||||||
|
real1[6] = '\0';
|
||||||
|
|
||||||
my_copy(vmap, data1, data2, 30*sizeof(char));
|
char* data1 = my_malloc(vmap, 32*sizeof(char));
|
||||||
|
char* data2 = my_malloc(vmap, 32*sizeof(char));
|
||||||
|
|
||||||
|
vmap_copy_from_memory(vmap, real1, data1, 8);
|
||||||
|
|
||||||
|
my_copy(vmap, data1, data2, 32*sizeof(char));
|
||||||
|
|
||||||
|
char* real = malloc(sizeof(char)*32);
|
||||||
|
|
||||||
|
vmap_copy_to_memory(vmap, data2, real, 7);
|
||||||
|
|
||||||
|
if (strcmp(real1, real1)) {
|
||||||
|
printf("%d\n", strcmp(real, real1));
|
||||||
|
fprintf(stderr, "copy test failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(real);
|
||||||
|
free(real1);
|
||||||
|
|
||||||
my_free(vmap, data1);
|
my_free(vmap, data1);
|
||||||
my_free(vmap, data2);
|
my_free(vmap, data2);
|
||||||
|
@ -24,9 +24,16 @@ VMap* vmap_init();
|
|||||||
*/
|
*/
|
||||||
PageMapInfo* vmap_get_page(VMap* vmap, void* ptr);
|
PageMapInfo* vmap_get_page(VMap* vmap, void* ptr);
|
||||||
|
|
||||||
void vmap_copy_from_memory(struct VMap *vmap, void *src, void *dst, int size);
|
/**
|
||||||
|
* From implemented memory to real memory
|
||||||
|
*/
|
||||||
void vmap_copy_to_memory(struct VMap *vmap, void *src, void *dst, int size);
|
void vmap_copy_to_memory(struct VMap *vmap, void *src, void *dst, int size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* From real memory to implemented memory
|
||||||
|
*/
|
||||||
|
void vmap_copy_from_memory(struct VMap *vmap, void *src, void *dst, int size);
|
||||||
|
|
||||||
void* my_malloc(VMap* vmap, int size);
|
void* my_malloc(VMap* vmap, int size);
|
||||||
void my_free(VMap* vmap, void* ptr);
|
void my_free(VMap* vmap, void* ptr);
|
||||||
void my_copy(VMap* vmap, void* src, void* dst, int size);
|
void my_copy(VMap* vmap, void* src, void* dst, int size);
|
||||||
|
Loading…
Reference in New Issue
Block a user