void cos_init(void)
{
    LOGD("BEGIN");

    td_t t1, t2;
    long evt1;
    int ret;
    char *params1 = "unused";
    char *sql = NULL;

    evt1 = evt_split(cos_spd_id(), 0, 0);
    assert(evt1 > 0);


    t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
    if (t1 < 0) {
        LOGD("Can't open database");
        return;
    }

    trelease(cos_spd_id(), t1);
    LOGD("Opened database successfully!");
	 
	sql = "CREATE TABLE COMPANY("  \
         "ID INT PRIMARY KEY     NOT NULL," \
         "NAME           TEXT    NOT NULL," \
         "AGE            INT     NOT NULL," \
         "ADDRESS        CHAR(50)," \
         "SALARY         REAL );";
    t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
    ret = twrite_pack(cos_spd_id(), t1, sql, 1024);
    LOGD("%s: Table created ", ret < 0 ? "unsuccessfully" : "successfully");
}
void cos_init(void)
{
    LOGD("BEGIN");

    td_t t1, t2;
    long evt1;
    int ret;
    char *params1 = "unused";
    char *sql = NULL;

    evt1 = evt_split(cos_spd_id(), 0, 0);
    assert(evt1 > 0);


    t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
    if (t1 < 0) {
        LOGD("FAILED: split");
        return;
    }

    trelease(cos_spd_id(), t1);
    LOGD("PASSED: split->release");

    sql = "CREATE TABLE student("  \
         "id    INTEGER PRIMARY KEY AUTOINCREMENT," \
         "name  TEXT NOT NULL," \
         "age   INTEGER );" ;
    t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
    ret = twrite_pack(cos_spd_id(), t1, sql, 1024);
    LOGD("%s: Create table.", ret < 0 ? "FAILED" : "PASSED");
    //trelease(cos_spd_id(), t1);
}
Beispiel #3
0
/*Send Query Response*/
int write_response() {
	td_t write_tor;
	long evt;
	unsigned int ret;

	printc("SQLITE: Begin querying db\n");
	evt = evt_split(cos_spd_id(), 0, 0);
	write_tor = tsplit(cos_spd_id(), td_root, response, strlen(response), TOR_ALL, evt);
	if (write_tor < 1) {
		printc("SQLITE: split failed %d\n", write_tor);
		return 1;
	}
	ret = twrite_pack(cos_spd_id(), write_tor, response_buffer, strlen(response_buffer));
	printc("SQLITE: WROTE %d (%s), ret %d\n", strlen(response_buffer), response_buffer, ret);
	trelease(cos_spd_id(), write_tor);
	return 0;
}
void cos_init(void)
{
    LOGD("BEGIN");

    td_t t1, t2;
    long evt1;
    int ret;
    char *params1 = "unused";
    char *sql = NULL;

    evt1 = evt_split(cos_spd_id(), 0, 0);
    assert(evt1 > 0);


    t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
    if (t1 < 0) {
        LOGD("Can't open database");
        return;
    }

    trelease(cos_spd_id(), t1);
    LOGD("Opened database successfully!");
	 
	sql = "CREATE TABLE COMPANY("  \
         "ID INT PRIMARY KEY     NOT NULL," \
         "NAME           TEXT    NOT NULL," \
         "AGE            INT     NOT NULL," \
         "ADDRESS        CHAR(50)," \
         "SALARY         REAL ;" \
		 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
         "VALUES (1, 'Paul', 32, 'California', 20000.00 ); " \
         "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
         "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \
         "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
         "VALUES (3, 'Teddy', 23, 'Norway', 20000.00 );" \
         "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
         "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );" \
		 "UPDATE COMPANY set SALARY = 25000.00 where ID=1; ";
		 
    t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
    ret = twrite_pack(cos_spd_id(), t1, sql, 1024);
    LOGD("%s: Operation done ", ret < 0 ? "unsuccessfully" : "successfully");
}
Beispiel #5
0
static void from_data_new(struct tor_conn *tc)
{
	int from, to, amnt;
	char *buf;

	from = tc->from;
	to   = tc->to;
	buf = cos_argreg_alloc(BUFF_SZ);
	assert(buf);
	while (1) {
		int ret;

		amnt = net_recv(cos_spd_id(), from, buf, BUFF_SZ-1);
		if (0 == amnt) break;
		else if (-EPIPE == amnt) {
			goto close;
		} else if (amnt < 0) {
			printc("read from fd %d produced %d.\n", from, amnt);
			BUG();
		}
		if (amnt != (ret = twrite_pack(cos_spd_id(), to, buf, amnt))) {
			printc("conn_mgr: write failed w/ %d on fd %d\n", ret, to);
			goto close;

		}
	}
done:
	cos_argreg_free(buf);
	return;
close:
	net_close(cos_spd_id(), from);
	trelease(cos_spd_id(), to);
	tor_del_pair(from, to);
	if (tc->feid) cvect_del(&evts, tc->feid);
	if (tc->teid) cvect_del(&evts, tc->teid);
	goto done;
}
Beispiel #6
0
void cos_init(void)
{
	td_t t1, t2;
	long evt1, evt2;
	char *params1 = "bar";
	char *params2 = "foo/";
	char *params3 = "foo/bar";
	char *data1 = "1234567890", *data2 = "asdf;lkj", *data3 = "asdf;lkj1234567890";
	unsigned int ret1, ret2;

	int a = 0, b = 0, c = 0;
	c = treadp(cos_spd_id(), 0, &a, &b);

	printc("UNIT TEST Unit tests for torrents...\n");

	printc("%d %d %d\n", a, b, c);

	evt1 = evt_split(cos_spd_id(), 0, 0);
	evt2 = evt_split(cos_spd_id(), 0, 0);
	assert(evt1 > 0 && evt2 > 0);

	t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
	if (t1 < 1) {
		printc("UNIT TEST FAILED: split failed %d\n", t1);
		return;
	}
	trelease(cos_spd_id(), t1);
	printc("UNIT TEST PASSED: split->release\n");

	t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1);
	if (t1 < 1) {
		printc("UNIT TEST FAILED: split2 failed %d\n", t1); return;
	}
	t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2);
	if (t2 < 1) {
		printc("UNIT TEST FAILED: split3 failed %d\n", t2); return;
	}

	ret1 = twrite_pack(cos_spd_id(), t1, data1, strlen(data1));
	ret2 = twrite_pack(cos_spd_id(), t2, data2, strlen(data2));
	printv("write %d & %d, ret %d & %d\n", strlen(data1), strlen(data2), ret1, ret2);

	trelease(cos_spd_id(), t1);
	trelease(cos_spd_id(), t2);
	printc("UNIT TEST PASSED: 2 split -> 2 write -> 2 release\n");

	t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1);
	t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2);
	if (t1 < 1 || t2 < 1) {
		printc("UNIT TEST FAILED: later splits failed\n");
		return;
	}
	
	ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023);
	if (ret1 > 0) buffer[ret1] = '\0';
	printv("read %d (%d): %s (%s)\n", ret1, strlen(data1), buffer, data1);
	assert(!strcmp(buffer, data1));
	assert(ret1 == strlen(data1));
	buffer[0] = '\0';

	ret1 = tread_pack(cos_spd_id(), t2, buffer, 1023);
	if (ret1 > 0) buffer[ret1] = '\0';
	assert(!strcmp(buffer, data2));
	assert(ret1 == strlen(data2));
	printv("read %d: %s\n", ret1, buffer);
	buffer[0] = '\0';

	trelease(cos_spd_id(), t1);
	trelease(cos_spd_id(), t2);

	printc("UNIT TEST PASSED: 2 split -> 2 read -> 2 release\n");

	t1 = tsplit(cos_spd_id(), td_root, params3, strlen(params3), TOR_ALL, evt1);
	ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023);
	if (ret1 > 0) buffer[ret1] = '\0';
	printv("read %d: %s\n", ret1, buffer);
	assert(!strcmp(buffer, data2));
	assert(ret1 == strlen(data2));
	printc("UNIT TEST PASSED: split with absolute addressing -> read\n");
	buffer[0] = '\0';

	ret1 = twrite_pack(cos_spd_id(), t1, data1, strlen(data1));
	printv("write %d, ret %d\n", strlen(data1), ret1);

	trelease(cos_spd_id(), t1);
	t1 = tsplit(cos_spd_id(), td_root, params3, strlen(params3), TOR_ALL, evt1);
	ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023);
	if (ret1 > 0 && ret1 < 1024) buffer[ret1] = '\0';
	printv("read %d: %s (%s)\n", ret1, buffer, data3);
	assert(ret1 == strlen(data2)+strlen(data1));
	assert(!strcmp(buffer, data3));
	buffer[0] = '\0';
	printc("UNIT TEST PASSED: writing to an existing file\n");

	printc("UNIT TEST ALL PASSED\n");

	return;
}
static void
test0(void)
{
	/* struct cbuf_alloc_desc *d; */
	/* int i; */

	/* d = &cbufp_alloc_freelists[0]; */
	/* assert(EMPTY_LIST(d, next, prev)); */
	/* for (i = 0 ; i < CBUFP_NUM ; i++) { */
	/* 	buf[i] = cbufp_alloc(4096, &p[i]); */
	/* 	cbufp_send(p[i]); */
	/* 	assert(buf[i]); */
	/* } */
	/* for (i = 0 ; i < CBUFP_NUM ; i++) { */
	/* 	cbufp_deref(p[i]); */
	/* } */


	td_t t1, t2, t3;
	long evt1, evt2, evt3;
	char *params1 = "bar";
	char *params2 = "foo/";
	char *params3 = "foo/bar";
	char *data1 = "1234567890", *data2 = "asdf;lkj", *data3 = "asdf;lkj1234567890";
	unsigned int ret1, ret2;

	evt1 = evt_split(cos_spd_id(), 0, 0);
	evt2 = evt_split(cos_spd_id(), 0, 0);
	/* evt3 = evt_create(cos_spd_id()); */
	assert(evt1 > 0 && evt2 > 0);
	
	printc("\nRAMFS Testing Starting.....(thd %d)\n\n", cos_get_thd_id());

	t1 = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_ALL, evt1);
	if (t1 < 1) {
		printc("UNIT TEST FAILED: split failed %d\n", t1);
		return;
	}
	trelease(cos_spd_id(), t1);
	
	t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1);
	if (t1 < 1) {
		printc("UNIT TEST FAILED: split2 failed %d\n", t1); return;
	}

	t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2);
	if (t2 < 1) {
		printc("UNIT TEST FAILED: split3 failed %d\n", t2); return;
	}

#ifdef TEST_RAMFS_C3
	ret1 = twritep_pack(cos_spd_id(), t1, data1, strlen(data1));
	ret2 = twritep_pack(cos_spd_id(), t2, data2, strlen(data2));
#else 
	ret1 = twrite_pack(cos_spd_id(), t1, data1, strlen(data1));
	ret2 = twrite_pack(cos_spd_id(), t2, data2, strlen(data2));
#endif
	printc("write %d & %d, ret %d & %d\n", strlen(data1), strlen(data2), ret1, ret2);

	/* This is important!!!! release in the opposite order */
	trelease(cos_spd_id(), t2);
	trelease(cos_spd_id(), t1);

	int max_test;
	
	// need test for max number of allowed faults (ureboot)
	for (max_test = 0; max_test < 400; max_test++) {
		printc("\n>>>>>>ramfs test phase 3 start .... (iter %d)\n", max_test);
		t1 = tsplit(cos_spd_id(), td_root, params2, strlen(params2), TOR_ALL, evt1);
		/* printc("\n[[[[[[.... 2nd tsplit\n"); */
		t2 = tsplit(cos_spd_id(), t1, params1, strlen(params1), TOR_ALL, evt2);
		if (t1 < 1 || t2 < 1) {
			printc("UNIT TEST FAILED: later splits failed\n");
			return;
		}

		/* printc("\n[[[[[[.... 1st tread\n"); */
#ifdef TEST_RAMFS_C3
		ret1 = treadp_pack(cos_spd_id(), t1, buffer, 1023);
#else
		ret1 = tread_pack(cos_spd_id(), t1, buffer, 1023);
#endif
		if (ret1 > 0) buffer[ret1] = '\0';
		assert(!strcmp(buffer, data1));
		// treadp does not return length, instead return cbid
		/* assert(ret1 == strlen(data1)); */
		printc("read %d (%d): %s (%s)\n", ret1, strlen(data1), buffer, data1);
		buffer[0] = '\0';

#ifdef TEST_RAMFS_C3
		ret1 = treadp_pack(cos_spd_id(), t2, buffer, 1023);
#else
		ret1 = tread_pack(cos_spd_id(), t2, buffer, 1023);
#endif
		if (ret1 > 0) buffer[ret1] = '\0';
		assert(!strcmp(buffer, data2));
		/* assert(ret1 == strlen(data2)); */
		printc("read %d (%d): %s (%s)\n", ret1, strlen(data2), buffer, data2);
		buffer[0] = '\0';

		trelease(cos_spd_id(), t2);
		trelease(cos_spd_id(), t1);
	}

	printc("\nRAMFS Testing Done.....\n\n");
	return;
}