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

#include "../lve-ctl.h"

int main(void)
{
	uint32_t cookie, cookie1;
	int rc,ve_id;
	struct liblve *lve;

	ve_id=10;

	printf("*\t*  LVE API TEST  *\t*\n");

	rc = lve_set_default(10,11);
	if (rc) {
		printf("can't set default \n");
	}

	rc = lve_instance_init(NULL);
	printf("\tsize for lve struct %d\n", rc);
	lve = malloc(rc);

	rc = lve_instance_init(lve);
	if (rc != 0) {
		printf("can't init lve instance %d\n", rc);
		return 1;
	}
        /* drop root privilegess before test */
        setuid(9999);
//	printf("\tbefore enter uid %d / gid %d\n", getuid(), getgid());
//---------------------------------------------------------------------------
	printf("lve_enter\t\t\t");
	rc = lve_enter(lve, ve_id, 101, 110, &cookie);
	if (rc < 0) {
		printf("ERROR %d\nexiting\n", rc);
		return rc;
	} else printf("OK\n");
//	printf("\tafter enter uid %d / gid %d - %x\n", getuid(), getgid(), cookie);
//---------------------------------------------------------------------------

	printf("lve_leave\t\t\t");
	rc = lve_leave(lve, &cookie);
	if (rc < 0) {
		printf("ERROR %d\nexiting\n", rc);
		return rc;
	} else printf("OK\n");
//	printf("\tafter leave uid %d / gid %d\n", getuid(), getgid());
//---------------------------------------------------------------------------

	printf("lve_enter\t\t\t");
	rc = lve_enter(lve, ve_id, -1, -1, &cookie);
	if (rc < 0) {
		printf("error enter %d\nexiting\n", rc);
		return rc;
	} else printf("OK\n");
//	printf("\tafter enter uid %d / gid %d - %x\n", getuid(), getgid(), cookie);
//---------------------------------------------------------------------------

	printf("lve_leave\t\t\t");
	rc = lve_leave(lve, &cookie);
	if (rc < 0) {
		printf("ERROR %d\nexiting\n", rc);
		return rc;
	} else printf("OK\n");

	return 0;
}
