[so] tema 5

Octavian Purdila so@atlantis.cs.pub.ro
Fri, 30 Jan 2004 11:03:20 +0200


------------3Mn5kEBfQICbBT18GkwWN9
Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-1
Content-Transfer-Encoding: 8bit


Buna dimineata,

Pentru neclaritati legate de corectarea temei 5 va rog sa-mi dati mail  
(tavi@cs.pub.ro). Programul de test
cu care a fost testata tema e atasat.

tavi

------------3Mn5kEBfQICbBT18GkwWN9
Content-Disposition: attachment; filename=t.c
Content-Type: text/x-c; name=t.c
Content-Transfer-Encoding: 8bit

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

void* (*vinit)(int virt_pages, int phys_pages, int algorithm);


int main(int argc, char **argv)
{
	int virt, phys, alg;
	int *m, i;
	const char *lib;
	void *libh;
	
	if (argc != 5) {
		printf("usage: t virt phys alg lib\n");
		return -1;
	}
		
	virt=atoi(argv[1]); phys=atoi(argv[2]); alg=atoi(argv[3]); lib=argv[4];

	if (!(libh=dlopen(lib, RTLD_LAZY))) {
		printf("can't dlopen '%s':%s\n", lib, dlerror());
		return -1;
	}
	
	if (!(vinit=dlsym(libh, "vinit"))) {
		printf("can't dlsym\n");
		return -1;
	}
	
	if (!(m=vinit(virt, phys, alg))) {
		printf("can't vinit\n");
		return -1;
	}

	for(i=0; i<virt*4096/4; i++) 
		if (m[i]!=0) 
			printf("bug: m[%d] not zero\n", i);
		
	for(i=0; i<virt*4096/4; i++) 
		m[i]=i;

	
	for(i=0; i<virt*4096/4; i++) {
		if (m[i] != i) 
			printf("bug: m[%d] != %d\n", i, i);
	}
			

	return 0;		
}

------------3Mn5kEBfQICbBT18GkwWN9--