示例#1
0
文件: div.c 项目: bigml/mbase
int main(int argc, char **argv, char **envp)
{
    char *bm = NULL;
	NEOERR *err;
    int cnt = 0;

    char *s = argv[1];

    mtc_init("div", 7);

#if 0

    err = ediv_init_from_file(&bm, "/home/bigml/web/moon/eii/data/dict.txt", &cnt);
    DIE_NOK_MTL(err);

    mtc_foo("%u words seted\n", cnt);

    //mtc_foo("%u distinct word\n", ediv_word_distinct(bm));

    ediv_word_split(bm, s, strlen(s), NULL, div_cbk, EDIV_SOPT_ONLY_MAXMATCH |
        EDIV_SOPT_SKIP_NUTF);

    free(bm);

#endif

    return 0;
}
示例#2
0
文件: load_hash.c 项目: dodoma/reef
int main()
{
    MHASH *table;
    MERR *err;
    char str[101], *pstr[NODE_NUM];

    mtc_init("load.log", MTC_DEBUG);

    for (int i = 0; i < NODE_NUM; i++) {
        //mstr_rand_string(str, 100);
        //mstr_rand_string_fixlen(str, 100);
        snprintf(str, sizeof(str), "%d", i);

        pstr[i] = strdup(str);
    }

    err = mhash_init(&table, mhash_str_hash, mhash_str_comp, mhash_str_free);
    TRACE_NOK(err);

    mtimer_start();
    for (int i = 0; i < NODE_NUM; i++) {
        mhash_insert(table, pstr[i], NULL);
    }
    mtimer_stop("hash insert");

    mtimer_start();
    for (int i = 0; i < NODE_NUM; i++) {
        mhash_lookup(table, pstr[i]);
    }
    mtimer_stop("hash lookup");

    mhash_destroy(&table);

    return 0;
}
示例#3
0
文件: prestat.c 项目: kingiol/cmoon
int main(int argc, char *argv[])
{
    NEOERR *err = STATUS_OK;
    HASH *dbh, *evth;

    mtc_init(TC_ROOT"prestat");

    err = lerr_init();
    DIE_NOK_MTL(err);

    err = mconfig_parse_file(SITE_CONFIG, &g_cfg);
    DIE_NOK_MTL(err);

    err = ldb_init(&dbh);
    DIE_NOK_MTL(err);

    err = levt_init(&evth);
    DIE_NOK_MTL(err);

    err = fill_trackarea(evth, dbh);
    TRACE_NOK(err);

    levt_destroy(evth);
    ldb_destroy(dbh);
    mconfig_cleanup(&g_cfg);
    return 0;
}
示例#4
0
文件: login.c 项目: kingiol/cmoon
int main()
{
    CGI *cgi;
    NEOERR *err;
    int ret;

    //sleep(20);
    mtc_init(TC_ROOT"login");
    mconfig_parse_file(SITE_CONFIG, &g_cfg);

    err = cgi_init(&cgi, NULL);
    DIE_NOK_CGI(err);
    err = cgi_parse(cgi);
    DIE_NOK_CGI(err);

    mdb_conn *conn = NULL;
    ret = mdb_init(&conn, DB_DSN);
    mdb_opfinish_json(ret, cgi->hdf, conn);

    ret = login_get(cgi, conn);
    mdb_opfinish_json(ret, cgi->hdf, conn);
    mjson_output_hdf(cgi->hdf, 0);
    
#ifdef DEBUG_HDF
    hdf_write_file(cgi->hdf, TC_ROOT"hdf.login");
#endif

    mdb_destroy(conn);
    cgi_destroy(&cgi);
    return 0;
}
示例#5
0
文件: test.c 项目: bigmaliang/sam
int main(int argc, char **argv, char **envp)
{
	CGI *cgi = NULL;
	NEOERR *err;
	mdb_conn *conn = NULL;

	char *s, *u, *p, *r, *jcbk;

	mtc_init("test");
	mconfig_parse_file(SITE_CONFIG, &g_cfg);

	if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) {
		mtc_err("init db error %s", mdb_get_errmsg(conn));
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("{errcode: %d}", SAM_ERR_INIT);
		return 1;
	}
	
	err = cgi_init(&cgi, NULL);
	if (err != STATUS_OK) {
		mtc_err("init cgi error");
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("初始化错误");
		return 1;
	}
	err = cgi_parse(cgi);
	if (err != STATUS_OK) {
		mtc_err("parse cgi error");
		hdf_set_value(cgi->hdf, PRE_OUTPUT".errmsg", "初始化出错");
		goto finish;
	}

	u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL);
	s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL);
	if (s && u) {
		if (user_has_login(conn, u, s)) {
			hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser");
			hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey");
			hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "1");
			goto finish;
		}
	}

	hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "2");

finish:
	cgi_display(cgi, F_TPL_TEST);
	cgi_destroy(&cgi);
	mdb_destroy(conn);
	return 0;
}
示例#6
0
文件: cshdf.c 项目: bigml/mbase
int main(int argc, char **argv, char **envp)
{
    char key[10];
    HDF *bignode;

    mtc_init("cshdf", 7);

    hdf_init(&bignode);

    for (int i = 0; i < 5003929; i++) {
        mstr_rand_string_with_len(key, 10);

        hdf_set_valuef(bignode, "%s.today=10", key);
        hdf_set_valuef(bignode, "%s.toweek=11", key);
        hdf_set_valuef(bignode, "%s.tomonth=12", key);
        hdf_set_valuef(bignode, "%s.total=234", key);

        if (i % 10000 == 0) printf("%d\n", i);
    }

    //hdf_dump(bignode, NULL);

    printf("child num %d\n", mcs_get_child_num(bignode, NULL));

    int count = 0;

    mtimer_start();

    HDF *cnode = hdf_obj_child(bignode);
    while (cnode) {
        char *name = hdf_obj_name(cnode);

        if (mcs_get_int_valuef(bignode, 0, "%s.today", name) != 10) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.toweek", name) != 11) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.tomonth", name) != 12) printf("error\n");
        if (mcs_get_int_valuef(bignode, 0, "%s.total", name) != 234) printf("error\n");

        count++;

        cnode = hdf_obj_next(cnode);
    }

    mtimer_stop("get time");

    printf("get child count %d\n", count);

    hdf_destroy(&bignode);

    return 0;
}
示例#7
0
文件: threadsafe.c 项目: bigml/mbase
int main(int argc, char **argv, char **envp)
{
    mtc_init("multi_thread_log", 7);

    for (int i = 0; i < 4; i++) {
        m_thread[i] = calloc(1, sizeof(pthread_t));
        pthread_create(m_thread[i], NULL, log_routine, (void*)&m_num[i]);
    }

    m_thread[4] = calloc(1, sizeof(pthread_t));
    pthread_create(m_thread[4], NULL, write_routine, (void*)&m_num[4]);

    for (int i = 0; i < m_thread_size; i++) {
        pthread_join(*m_thread[i], NULL);
    }

    return 0;
}
示例#8
0
文件: viki.c 项目: kingiol/cmoon
int main(int argc, char **argv, char **envp)
{
    CGI *cgi;
    NEOERR *err;
    int ret;

    HASH *dbh;
    HASH *tplh;
    session_t *session = NULL;
    char *requri, *jsoncb;

    int (*data_handler)(CGI *cgi, HASH *dbh, session_t *session);
    void *lib;

    //sleep(20);
    mconfig_parse_file(SITE_CONFIG, &g_cfg);
    mtc_init(TC_ROOT"viki");

    ret = ltpl_init(&tplh);
    if (ret != RET_RBTOP_OK) {
        mtc_err("init templates error");
        mutil_redirect("初始化模板失败", TGT_SELF, URL_CLOSE, true);
        return ret;
    }

    ret = ldb_init(&dbh);
    if (ret != RET_RBTOP_OK) {
        mtc_err("init db error");
        mutil_redirect("初始化数据库失败", TGT_SELF, URL_CLOSE, true);
        return ret;
    }

    lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
    if (lib == NULL) {
        mtc_err("possible? %s", dlerror());
        mutil_redirect("初始化库函数失败", TGT_SELF, URL_CLOSE, true);
        return 1;
    }
    
#ifndef DROP_FCGI
    cgiwrap_init_emu(NULL, &read_cb, &printf_cb, &write_cb, NULL, NULL, NULL);
    while (FCGI_Accept() >= 0) {
#endif
        cgiwrap_init_std(argc, argv, environ);
        err = cgi_init(&cgi, NULL);
        JUMP_NOK_CGI(err, response);
        err = cgi_parse(cgi);
        JUMP_NOK_CGI(err, response);

#ifdef NCGI_MODE
        hdf_set_value(cgi->hdf, PRE_REQ_URI_RW, "/csc/hc");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uin", "1001");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uname", "bigml");
        hdf_set_value(cgi->hdf, PRE_COOKIE".musn", "8Y]u0|v=*MS]U3J");
#endif
        
        ret = session_init(cgi->hdf, dbh, &session);
        if (ret != RET_RBTOP_OK) {
            mtc_err("init session failure");
            goto response;
        }

        requri = hdf_get_value(cgi->hdf, PRE_REQ_URI_RW, "NULL");
        if (mutil_client_attack(cgi->hdf, requri, LMT_CLI_ATTACK,
                                PERIOD_CLI_ATTACK)) {
            goto response;
        }
        
        ret = lfile_access_rewrited(cgi, dbh, session);
        if (ret != RET_RBTOP_OK) {
            goto response;
        }

        data_handler = lutil_get_data_handler(lib, cgi);
        if (data_handler == NULL) {
            mtc_err("get handler failure");
            ret = RET_RBTOP_NEXIST;
            goto response;
        }

        ret = (*data_handler)(cgi, dbh, session);
        
    response:
        if (cgi != NULL && cgi->hdf != NULL) {
#ifdef DEBUG_HDF
            hdf_write_file(cgi->hdf, TC_ROOT"hdf.viki");
#endif
            switch (CGI_REQ_TYPE(cgi)) {
            case CGI_REQ_HTML:
                if (CGI_REQ_METHOD(cgi) != CGI_REQ_GET) {
                    goto resp_ajax;
                }
                if (ret != RET_RBTOP_OK && ret == RET_RBTOP_NEXIST) {
                    cgi_redirect(cgi, "/404.html");
                } else {
                    ret = ltpl_render(cgi, tplh, session);
                    if (ret != RET_RBTOP_OK) {
                        if (ret == RET_RBTOP_NEXIST)
                            cgi_redirect(cgi, "/404.html");
                        else
                            cgi_redirect(cgi, "/503.html");
                    }
                }
                break;
            case CGI_REQ_AJAX:
            resp_ajax:
                ldb_opfinish_json(ret, cgi->hdf, NULL, 0);
                jsoncb = hdf_get_value(cgi->hdf, PRE_REQ_AJAX_FN, NULL);
                if (jsoncb != NULL) {
                    mjson_execute_hdf(cgi->hdf, jsoncb, session->tm_cache_browser);
                } else {
                    mjson_output_hdf(cgi->hdf, session->tm_cache_browser);
                }
                break;
            default:
                cgi_redirect(cgi, "/503.html");
                break;
            }
            cgi_destroy(&cgi);
            session_destroy(&session);
        }
#ifndef DROP_FCGI
    }
#endif

    ldb_destroy(dbh);
    ltpl_destroy(tplh);
    mconfig_cleanup(&g_cfg);
    return 0;
}
示例#9
0
文件: login.c 项目: bigmaliang/sam
int main(int argc, char **argv, char **envp)
{
	CGI *cgi = NULL;
	NEOERR *err;
	mdb_conn *conn = NULL;

	/* skey, user, pass, return jsoncallback*/
	char *s, *u, *p, *r, *jcbk;
	/* keeptime(hours)  */
	int t;
	char tm[LEN_TM_GMT];
	
	//sleep(20);
	mtc_init("login");
	mconfig_parse_file(SITE_CONFIG, &g_cfg);
	mutil_wrap_fcgi(argc, argv, envp);
	if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) {
		mtc_err("init db error %s", mdb_get_errmsg(conn));
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("{errcode: %d}", SAM_ERR_INIT);
		return 1;
	}
	
#ifndef DROP_FCGI
	while (FCGI_Accept() >= 0) {
#endif

		/*
		 * cgi init 
		 */
		err = cgi_init(&cgi, NULL);
		if (err != STATUS_OK) {
			mtc_err("init cgi error");
			printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
			printf("{errcode: %d}", SAM_ERR_INIT);
			goto opfinish;
		}
		err = cgi_parse(cgi);
		if (err != STATUS_OK) {
			mtc_err("parse cgi error");
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PARSE);
			goto opfinish;
		}
#if 0
		if (mutil_client_attack_cookie(cgi->hdf, "login", 30, 60)) {
			mtc_err("client attack");
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDREST);
			goto opfinish;
		}
#endif

		u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL);
		s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL);
		if (s && u) {
			if (user_has_login(conn, u, s)) {
				hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser");
				hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey");
				goto done;
			}
		}
		
		u = hdf_get_value(cgi->hdf, PRE_QUERY".u", NULL);
		p = hdf_get_value(cgi->hdf, PRE_QUERY".p", NULL);
		if (!u || !p) {
			mtc_err("parameter miss %s %s", u, p);
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDINPUT);
			goto opfinish;
		}
		s = user_login_auth(conn, u, p);
		if (!s) {
			mtc_err("login error %s %s", u, p);
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PASSW);
			goto opfinish;
		}

		cgiwrap_write(P3P_HEADER, strlen(P3P_HEADER));
		cgi_cookie_set(cgi, "samuser", u, NULL, SITE_DOMAIN, NULL, 1, 0);
		cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, NULL, 1, 0);
#if 0
		t = hdf_get_int_value(cgi->hdf, PRE_QUERY".t", 0);
		mmisc_getdatetime_gmt(tm, sizeof(tm), "%A, %d-%b-%Y %T GMT", 60*60*t);
		cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, tm, 1, 0);
#endif
		
		hdf_set_value(cgi->hdf, PRE_OUTPUT".samuser", u);
		hdf_set_value(cgi->hdf, PRE_OUTPUT".samkey", s);
		free(s);

	done:
		/*
		 * TODO set samkey, samuser to app's domain
		 * DONE this is done by jsonp
		 */
		hdf_set_value(cgi->hdf, PRE_OUTPUT".success", "1");
	opfinish:
		if (cgi) {
			r = hdf_get_value(cgi->hdf, PRE_QUERY".r", NULL);
			if (r) {
				cgi_redirect(cgi, r);
			} else {
				jcbk = hdf_get_value(cgi->hdf, PRE_QUERY".jsoncallback", NULL);
				if (jcbk != NULL) {
					mjson_execute_hdf(cgi->hdf, jcbk, 0);
				} else {
					mjson_output_hdf(cgi->hdf, 0);
				}
			}
#ifdef DEBUG_HDF
			hdf_write_file(cgi->hdf, HF_LOG_PATH"hdf.login");
#endif
			cgi_destroy(&cgi);
		}
		
#ifndef DROP_FCGI
 	} /* FCGI_Accept() */
#endif

	mdb_destroy(conn);
	return 0;
}
示例#10
0
文件: blg.c 项目: kingiol/cmoon
int main(int argc, char *argv[])
{
    HASH *tplh = NULL, *dbh = NULL;
    NEOERR *err;
    int c, bid = 0, indexid = -1, pgtt;
    bool dorecurse = false;

    mtc_init(TC_ROOT"blg");

    err = mconfig_parse_file(SITE_CONFIG, &g_cfg);
    DIE_NOK_MTL(err);

    while ( (c=getopt(argc, argv, "b:i:r")) != -1 ) {
        switch(c) {
        case 'b':
            bid = atoi(optarg);
            break;
        case 'i':
            indexid = atoi(optarg);
            break;
        case 'r':
            dorecurse = true;
            break;
        default:
            useage(argv[0]);
        }
    }

    err = ldb_init(&dbh);
    DIE_NOK_MTL(err);
    
    err = hash_init(&tplh, hash_str_hash, hash_str_comp);
    DIE_NOK_MTL(err);

    err = ltpl_parse_file(dbh, NULL, PATH_PAGER, "blog.hdf", tplh);
    DIE_NOK_MTL(err);

    if (indexid >= 0) {
        err = rend_blog_index(dbh, tplh, indexid, &pgtt);
        TRACE_NOK(err);

        if (indexid > 0 && pgtt > indexid) pgtt = indexid;
        if (dorecurse) {
            while (pgtt-- > 0) {
                err = rend_blog_index(dbh, tplh, pgtt, NULL);
                TRACE_NOK(err);
            }
        }
    }
    
    if (bid > 0) {
        if (bid > 1)
            rend_blog(dbh, tplh, bid-1);
        rend_blog(dbh, tplh, bid);
        rend_blog(dbh, tplh, bid+1);
    }

    ldb_destroy(dbh);
    ltpl_destroy(tplh);
    mconfig_cleanup(&g_cfg);

    return 0;
}
示例#11
0
文件: viki.c 项目: pombredanne/cmoon
int main(int argc, char **argv, char **envp)
{
    CGI *cgi;
    NEOERR *err = STATUS_OK;

    HASH *dbh, *tplh, *evth;
    session_t *session = NULL;
    char *temps;
    int http_max_upload;

    NEOERR* (*data_handler)(CGI *cgi, HASH *dbh, HASH *evth, session_t *session);
    void *lib;
    
    //sleep(20);
    mutil_makesure_coredump();
    mtc_init(TC_ROOT"viki");

    err = lerr_init();
    DIE_NOK_CGI(err);
    
    err = mcfg_parse_file(SITE_CONFIG, &g_cfg);
    DIE_NOK_CGI(err);

    err = mtpl_set_tplpath(PATH_TPL);
    DIE_NOK_CGI(err);

    err = mtpl_InConfigRend_init(PATH_TPL"/config/email", "email", &g_datah);
    DIE_NOK_CGI(err);

    err = mtpl_InConfigRend_init(PATH_TPL"/config/inbox", "inbox", &g_datah);
    DIE_NOK_CGI(err);

    err = ltpl_init(&tplh, NULL);
    DIE_NOK_CGI(err);

    err = hash_insert(g_datah, "runtime_templates", (void*)tplh);
    DIE_NOK_CGI(err);

    err = ldb_init(&dbh);
    DIE_NOK_CGI(err);

    err = levt_init(&evth);
    DIE_NOK_CGI(err);

    lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
    if (!lib) {
        err = nerr_raise(NERR_SYSTEM, "dlopen %s", dlerror());
        DIE_NOK_CGI(err);
    }
    
#ifdef USE_FASTCGI
    cgiwrap_init_emu(NULL, &read_cb, &printf_cb, &write_cb, NULL, NULL, NULL);
    while (FCGI_Accept() >= 0) {
#endif
        cgiwrap_init_std(argc, argv, environ);
        err = cgi_init(&cgi, NULL);
        if (err != STATUS_OK) goto response;
        
        http_max_upload = hdf_get_int_value(g_cfg, PRE_CONFIG".http_max_upload", 0);
        if (http_max_upload > 0) {
            err = mcs_register_upload_parse_cb(cgi, &http_max_upload);
            if (err != STATUS_OK) goto response;
        }
        
        err = cgi_parse(cgi);
        if (err != STATUS_OK) goto response;

#ifdef NCGI_MODE
        hdf_set_value(cgi->hdf, PRE_REQ_URI_RW, "/image/member/pic");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uin", "1001");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uname", "bigml");
        hdf_set_value(cgi->hdf, PRE_COOKIE".musn", "8Y]u0|v=*MS]U3J");
        hdf_set_value(cgi->hdf, PRE_QUERY".ip", "222.247.56.14");
        hdf_set_value(cgi->hdf, PRE_QUERY".to", "cj_BXTSJ");
        hdf_set_value(cgi->hdf, PRE_QUERY".s", "koldddd");
        hdf_set_value(cgi->hdf, PRE_QUERY".JsonCallback", "Ape.transport.read");
        hdf_set_value(cgi->hdf, PRE_QUERY".type", "phone");
        hdf_set_value(cgi->hdf, PRE_QUERY".mid", "485010473");
#endif
        
        err = session_init(cgi, dbh, &session);
        if (err != STATUS_OK) goto response;

        if (lutil_client_attack(cgi->hdf, session, "lcs_uname")) {
            err = nerr_raise(LERR_ATTACK, "%s need a rest, babey!", session->dataer);
            goto response;
        }
        
        if ((data_handler = lutil_get_data_handler(lib, cgi, session)) == NULL) {
            err = nerr_raise(LERR_MISS_DATA, "dataer %s not found", session->dataer);
            goto response;
        }

        err = (*data_handler)(cgi, dbh, evth, session);
        
    response:
        if (cgi != NULL && cgi->hdf != NULL) {
            lerr_opfinish_json(err, cgi->hdf);

            if (!session) session = session_default();
            switch (session->reqtype) {
            case CGI_REQ_HTML:
                err = ltpl_render(cgi, tplh, session);
                if (err != STATUS_OK) {
                    SAFE_FREE(session->render);
                    if (nerr_match(err, LERR_MISS_TPL)) {
                        session->render = strdup("404");
                    } else {
                        session->render = strdup("503");
                    }
                    TRACE_NOK(err);
                    err = ltpl_render(cgi, tplh, session);
                    TRACE_NOK(err);
                }
                break;
            case CGI_REQ_AJAX:
            resp_ajax:
                temps = hdf_get_value(cgi->hdf, PRE_REQ_AJAX_FN, NULL);
                if (temps != NULL) {
                    mjson_execute_hdf(cgi->hdf, temps, session->tm_cache_browser);
                } else {
                    mjson_output_hdf(cgi->hdf, session->tm_cache_browser);
                }
                break;
            case CGI_REQ_IMAGE:
                temps = hdf_get_value(cgi->hdf, PRE_OUTPUT".302", NULL);
                if (temps) {
                    cgi_redirect_uri(cgi, temps);
                } else if (session->data) {
                    mimg_output(session->data);
                    session->data = NULL;
                } else goto resp_ajax;
                break;
            default:
                cgi_redirect(cgi, "/503.html");
                break;
            }
            
#ifdef DEBUG_HDF
            hdf_write_file(cgi->hdf, TC_ROOT"hdf.viki");
#endif
            
            cgi_destroy(&cgi);
            session_destroy(&session);
            cgi = NULL;
            session = NULL;
        }
#ifdef USE_FASTCGI
    }
#endif

    levt_destroy(evth);
    ldb_destroy(dbh);
    ltpl_destroy(tplh);
    mtpl_InConfigRend_destroy(g_datah);
    mcfg_cleanup(&g_cfg);

    return 0;
}
示例#12
0
文件: hdftest.c 项目: adderly/cmoon
int main(int argc, char **argv, char **envp)
{
    struct json_object *jso;
    HDF *node;
    bson *doc;
    NEOERR *err;
    
    mtc_init("hdftest");

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        hdf_init(&node);
        //err = mjson_string_to_hdf(node, bdatam);
        OUTPUT_NOK(err);
        if (VERBERSE) hdf_dump(node, NULL);
        hdf_destroy(&node);
    }
    mtimer_stop("json => hdf");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        doc = mbson_new_from_string(bdatam, true);
        if (!doc) printf("bson error");
        if (VERBERSE) printf("%s\n", mbson_string(doc));
        bson_free(doc);
    }
    mtimer_stop("json => bson");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));


    

    hdf_init(&node);
    hdf_set_value(node, NULL, bdatam);
    //err = mjson_string_to_hdf(node, bdatam);
    OUTPUT_NOK(err);
    
    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        err = mjson_import_from_hdf(node, &jso);
        OUTPUT_NOK(err);
        if (VERBERSE) printf("%s\n", json_object_to_json_string(jso));
        json_object_put(jso);
    }
    mtimer_stop("hdf => json");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        err = mbson_import_from_hdf(node, &doc, true);
        OUTPUT_NOK(err);
        if (VERBERSE) printf("%s\n", mbson_string(doc));
        bson_free(doc);
    }
    mtimer_stop("hdf => bson");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));





    doc = mbson_new_from_string(bdatam, true);
    if (!doc) printf("bson error");

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        char *s = mbson_string(doc);
        if (!s) printf("bson->string error");
        if (VERBERSE) printf("%s\n", s);
        free(s);
    }
    mtimer_stop("bson => json");
    mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));

    mtimer_start();
    for (int i = 0; i < NUM_TOTAL_TEST; i++) {
        hdf_init(&node);
        //err = mbson_export_to_hdf(node, doc, false, false);
        OUTPUT_NOK(err);
        if (VERBERSE) hdf_dump(node, NULL);
        hdf_destroy(&node);
    }
    mtimer_stop("bson => hdf");
    //mtc_foo("%d per second", (int)(NUM_TOTAL_TEST/(elapsed/1000000.0f)));
    bson_free(doc);

    return 0;
}
示例#13
0
文件: planet.c 项目: bigml/emoon
int main(int argc, char **argv)
{
    mtc_init("planet", 7);

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        mtc_err("sdl init error: %s", SDL_GetError());
        return 1;
    }

    if (TTF_Init() == -1) {
        mtc_err("ttf init error: %s", TTF_GetError());
        return 1;
    }

	SDL_Window *win = SDL_CreateWindow("Hello OpenGL!",
                                       100, 100, WIN_WIDTH, WIN_HEIGHT, SDL_WINDOW_SHOWN);
	if (!win) {
        mtc_err("SDL_CreateWindow Error: %s", SDL_GetError());
		return 1;
	}

	m_render = SDL_CreateRenderer(win, -1,
                                  SDL_RENDERER_ACCELERATED |
                                  SDL_RENDERER_PRESENTVSYNC);
	if (!m_render) {
        mtc_err("SDL_CreateRenderer Error: %s", SDL_GetError());
		return 1;
	}

    set_glversion();
    gl_info();

    glLoadIdentity();
    glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
    glEnable(GL_DEPTH_TEST);
    glEnable( GL_TEXTURE_2D );
    glDepthFunc(GL_LEQUAL);
    //glCullFace(GL_BACK);
    //glFrontFace(GL_CCW);
    //glEnable(GL_CULL_FACE);

    GLuint etex = LoadTextureRAW("earth.raw");
    if (etex == 0) {
        mtc_err("Load texture failure");
        return 1;
    }

    mutil_create_earth(5, 0, 0, 0);

    SDL_Event e;
    bool quit = false;
    while (!quit) {
        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_KEYDOWN) {
                switch (e.key.keysym.sym) {
                case SDLK_ESCAPE:
                    quit = true;
                    break;
                }
            }
        }

        rend_sun();
        mutil_rend_earth(etex);

        SDL_RenderPresent(m_render);
    }
    
	SDL_DestroyRenderer(m_render);
	SDL_DestroyWindow(win);
	SDL_Quit();

    return 0;
}
示例#14
0
文件: logout.c 项目: bigmaliang/sam
int main(int argc, char **argv, char **envp)
{
	CGI *cgi = NULL;
	NEOERR *err;
	mdb_conn *conn = NULL;

	/* skey, user, pass, return jsoncallback*/
	char *s, *u, *r, *jcbk;
	
	//sleep(20);
	mtc_init("logout");
	mconfig_parse_file(SITE_CONFIG, &g_cfg);
	mutil_wrap_fcgi(argc, argv, envp);
	if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) {
		mtc_err("init db error %s", mdb_get_errmsg(conn));
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("{errcode: %d}", SAM_ERR_INIT);
		return 1;
	}
	
#ifndef DROP_FCGI
	while (FCGI_Accept() >= 0) {
#endif

		/*
		 * cgi init 
		 */
		err = cgi_init(&cgi, NULL);
		if (err != STATUS_OK) {
			mtc_err("init cgi error");
			printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
			printf("{errcode: %d}", SAM_ERR_INIT);
			goto opfinish;
		}
		err = cgi_parse(cgi);
		if (err != STATUS_OK) {
			mtc_err("parse cgi error");
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PARSE);
			goto opfinish;
		}

		u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL);
		s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL);
		if (s && u) {
			if (user_has_login(conn, u, s)) {
				user_logout(conn, u);
				cgi_cookie_clear(cgi, "samuser", SITE_DOMAIN, NULL);
				cgi_cookie_clear(cgi, "samkey", SITE_DOMAIN, NULL);
				hdf_set_value(cgi->hdf, PRE_OUTPUT".success", "1");
				goto opfinish;
			}
		}
		hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NOTLOGIN);
	opfinish:
		if (cgi) {
			r = hdf_get_value(cgi->hdf, PRE_QUERY".r", NULL);
			if (r) {
				cgi_redirect(cgi, r);
			} else {
				jcbk = hdf_get_value(cgi->hdf, PRE_QUERY".jsoncallback", NULL);
				if (jcbk != NULL) {
					mjson_execute_hdf(cgi->hdf, jcbk, 0);
				} else {
					mjson_output_hdf(cgi->hdf, 0);
				}
			}
#ifdef DEBUG_HDF
			hdf_write_file(cgi->hdf, HF_LOG_PATH"hdf.logout");
#endif
			cgi_destroy(&cgi);
		}
		
#ifndef DROP_FCGI
 	} /* FCGI_Accept() */
#endif

	mdb_destroy(conn);
	return 0;
}
示例#15
0
void *pt_ecal(void *args)
{
  ecal_t arg = *(ecal_t *) args; 
  free(args);

  int i,j;
  int result;

  char ecal_id[250];
  // now we can unlock our things, since nothing else should use them

  fd_set thread_fdset;
  FD_ZERO(&thread_fdset);
  for (i=0;i<19;i++){
    if ((0x1<<i) & arg.crate_mask)
      FD_SET(rw_xl3_fd[i],&thread_fdset);
  }

  char comments[1000];
  memset(comments,'\0',1000);
  char command_buffer[1000];
  memset(command_buffer,'\0',1000);

  system("clear");
  pt_printsend("------------------------------------------\n");
  pt_printsend("Welcome to ECAL+!\n");
  pt_printsend("------------------------------------------\n");



  if (!arg.old_ecal){
    // once this is set we can no longer send other commands
    running_ecal = 1;
    sbc_lock = 0;
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask)
        xl3_lock[i] = 0;
    }



    get_new_id(ecal_id);


    pt_printsend("\nYou have selected the following slots:\n\n");
    for (i=0;i<19;i++){
      if ((0x1<<(i)) & arg.crate_mask){
        pt_printsend("crate %d: 0x%08x\n",i,arg.slot_mask[i]);
      }
    }
    pt_printsend("------------------------------------------\n");
    pt_printsend("Hit enter to start, or type quit if anything is incorrect\n");
    read_from_tut(comments);
    if (strncmp("quit",comments,4) == 0){
      pt_printsend("Exiting ECAL\n");
      running_ecal = 0;
      unthread_and_unlock(0,0x0,arg.thread_num); 
      return;
    }
    pt_printsend("------------------------------------------\n");

    time_t curtime = time(NULL);
    struct timeval moretime;
    gettimeofday(&moretime,0);
    struct tm *loctime = localtime(&curtime);
    char log_name[500] = {'\0'};  // random size, it's a pretty nice number though.

    strftime(log_name, 256, "ECAL_%Y_%m_%d_%H_%M_%S_", loctime);
    sprintf(log_name+strlen(log_name), "%d.log", (int)moretime.tv_usec);
    start_logging_to_file(log_name);

    sbc_lock = 1;
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask)
        xl3_lock[i] = 1;
    }



    pt_printsend("Creating ECAL document...\n");
    // post ecal doc
    post_ecal_doc(arg.crate_mask,arg.slot_mask,log_name,ecal_id,&thread_fdset);

    pt_printsend("Created! ECAL id: %s\n\n",ecal_id);
    pt_printsend("------------------------------------------\n");
    
    sbc_lock = 0;
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask)
        xl3_lock[i] = 0;
    }

    // ok we are set up, time to start

    // initial CRATE_INIT
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -x -v",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // FEC_TEST
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"fec_test -c %d -s %04x -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = fec_test(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }

        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("-------------------------------------------\n");
      }
    }


    // BOARD_ID
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"board_id -c %d -s %04x",i,arg.slot_mask[i]);
          result = board_id(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }

        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("-------------------------------------------\n");
      }
    }


    // MTC_INIT
    do {
      sprintf(command_buffer,"mtc_init -x");
      result = mtc_init(command_buffer);
      if (result == -2 || result == -3){
        running_ecal = 0;
        unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
        return;
      }
    } while (result != 0);
    while (sbc_lock != 0){}
    pt_printsend("-------------------------------------------\n");

    

    // CGT_TEST

    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"cgt_test_1 -c %d -s %04x -p FFFFFFFF -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = cgt_test(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }

        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("-------------------------------------------\n");
      }
    }

    // MTC_INIT
    do {
      sprintf(command_buffer,"mtc_init -x");
      result = mtc_init(command_buffer);
      if (result == -2 || result == -3){
        running_ecal = 0;
        unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
        return;
      }
    } while (result != 0);
    while (sbc_lock != 0){}
    pt_printsend("-------------------------------------------\n");


    // CRATE_INIT with default values
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // CRATE_CBAL
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_cbal -c %d -s %04x -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = crate_cbal(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // CRATE_INIT with vbal values
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -B",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("-------------------------------------------\n");
      }
    }


    // PED_RUN
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"ped_run -c %d -s %04x -b -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = ped_run(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("-------------------------------------------\n");
      }
    }

//    pt_printsend("Time to do the cable business\n");
//    pt_printsend("ECL output --> EXT PED (long cable)\n");
//    pt_printsend("TTL input --> Global trigger)\n");
//    pt_printsend("Hit enter when ready\n");

//    read_from_tut(comments);

    // MTC_INIT
    do {
      sprintf(command_buffer,"mtc_init -x");
      result = mtc_init(command_buffer);
      if (result == -2 || result == -3){
        running_ecal = 0;
        unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
        return;
      }
    } while (result != 0);
    while (sbc_lock != 0){}
    pt_printsend("-------------------------------------------\n");


    // CRATE_INIT with default + vbal values
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -B",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // SET_TTOT
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"set_ttot -c %d -s %04x -t 420 -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = set_ttot(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // CRATE_INIT with default + vbal + tdisc values
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -B -D",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // GET_TTOT
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"get_ttot -c %d -s %04x -t 400 -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = get_ttot(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


//    pt_printsend("Time to remove cables\n");
//    pt_printsend("Hit enter when ready\n");

//    read_from_tut(comments);


    // CRATE_INIT with default + vbal + tdisc values
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -B -D",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // DISC_CHECK
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"disc_check -c %d -s %04x -n 500000 -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = disc_check(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // MTC_INIT
    do {
      sprintf(command_buffer,"mtc_init -x");
      result = mtc_init(command_buffer);
      if (result == -2 || result == -3){
        running_ecal = 0;
        unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
        return;
      }
    } while (result != 0);
    while (sbc_lock != 0){}
    pt_printsend("-------------------------------------------\n");


    // CRATE_INIT with default + vbal + tdisc values
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -B -D",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // CMOS_M_GTVALID
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"cmos_m_gtvalid -c %d -s %04x -g 410 -n -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = cmos_m_gtvalid(command_buffer); 
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // MTC_INIT
    do {
      sprintf(command_buffer,"mtc_init -x");
      result = mtc_init(command_buffer);
      if (result == -2 || result == -3){
        running_ecal = 0;
        unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
        return;
      }
    } while (result != 0);
    while (sbc_lock != 0){}
    pt_printsend("-------------------------------------------\n");


    // CRATE_INIT with default + vbal + tdisc + tcmos values
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -B -D -C",i,arg.slot_mask[i]);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }


    // ZDISC
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        do {
          sprintf(command_buffer,"zdisc -c %d -s %04x -o 0 -r 100 -d -E %s",i,arg.slot_mask[i],ecal_id);
          result = zdisc(command_buffer);
          if (result == -2 || result == -3){
            running_ecal = 0;
            unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
            return;
          }
        } while (result != 0);
        while (xl3_lock[i] != 0){}
        pt_printsend("------------------------------------------\n");
      }
    }

    pt_printsend("-------------------------------------------\n");
    pt_printsend("ECAL finished.\n");

    sbc_lock = 1;
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask)
        xl3_lock[i] = 1;
    }



  }else{
    sprintf(ecal_id,"%s",arg.ecal_id);
  }


  if (arg.update_hwdb){
    pt_printsend("Now updating FEC database with test results\n");

    // get the ecal document with the configuration
    char get_db_address[500];
    sprintf(get_db_address,"%s/%s/%s",DB_SERVER,DB_BASE_NAME,ecal_id);
    pouch_request *ecaldoc_response = pr_init();
    pr_set_method(ecaldoc_response, GET);
    pr_set_url(ecaldoc_response, get_db_address);
    pr_do(ecaldoc_response);
    if (ecaldoc_response->httpresponse != 200){
      pt_printsend("Unable to connect to database. error code %d\n",(int)ecaldoc_response->httpresponse);
      running_ecal = 0;
      unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
      return;
    }
    JsonNode *ecalconfig_doc = json_decode(ecaldoc_response->resp.data);

    // get all the ecal test results for all crates/slots
    sprintf(get_db_address,"%s/%s/%s/get_ecal?startkey=\"%s\"&endkey=\"%s\"",DB_SERVER,DB_BASE_NAME,DB_VIEWDOC,ecal_id,ecal_id);
    pouch_request *ecal_response = pr_init();
    pr_set_method(ecal_response, GET);
    pr_set_url(ecal_response, get_db_address);
    pr_do(ecal_response);
    if (ecal_response->httpresponse != 200){
      pt_printsend("Unable to connect to database. error code %d\n",(int)ecal_response->httpresponse);
      running_ecal = 0;
      unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
      return;
    }
    JsonNode *ecalfull_doc = json_decode(ecal_response->resp.data);
    JsonNode *ecal_rows = json_find_member(ecalfull_doc,"rows");
    int total_rows = json_get_num_mems(ecal_rows); 
    if (total_rows == 0){
      pt_printsend("No documents for this ECAL yet! (id %s)\n",ecal_id);
      running_ecal = 0;
      unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
      return;
    }

    // loop over crates/slots, create a fec document for each
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        for (j=0;j<16;j++){
          if ((0x1<<j) & arg.slot_mask[i]){
            printf("crate %d slot %d\n",i,j);

            // lets generate the fec document
            JsonNode *doc;
            create_fec_db_doc(i,j,&doc,ecalconfig_doc,&thread_fdset);

            int k;
            for (k=0;k<total_rows;k++){
              JsonNode *ecalone_row = json_find_element(ecal_rows,k);
              JsonNode *test_doc = json_find_member(ecalone_row,"value");
              JsonNode *config = json_find_member(test_doc,"config");
              if ((json_get_number(json_find_member(config,"crate_id")) == i) && (json_get_number(json_find_member(config,"slot")) == j)){
                if (strcmp(json_get_string(json_find_member(test_doc,"type")),"find_noise") != 0){
                  printf("test type is %s\n",json_get_string(json_find_member(test_doc,"type")));
                  add_ecal_test_results(doc,test_doc);
                }
              }
            }

            post_fec_db_doc(i,j,doc);

            json_delete(doc); // only delete the head node
          }
        }
      }
    }

    json_delete(ecalfull_doc);
    pr_free(ecal_response);
    json_delete(ecalconfig_doc);
    pr_free(ecaldoc_response);
  }

  if (arg.noise_run){
    // re lock everything down
    sbc_lock = 0;
    for (i=0;i<19;i++)
      if ((0x1<<i) & arg.crate_mask)
        xl3_lock[i] = 0;

    // FIND_NOISE
    int some_crate = 0;
    do{
      sprintf(command_buffer,"find_noise -c %05x -d -E %s ",arg.crate_mask,ecal_id);
      for (i=0;i<19;i++){
        if ((0x1<<i) & arg.crate_mask){
          some_crate = i;
        }
        sprintf(command_buffer+strlen(command_buffer),"-%02d %04x ",i,arg.slot_mask[i]);
      }
      result = find_noise(command_buffer);
      if (result == -2 || result == -3){
        printf("result was %d\n",result);
        running_ecal = 0;
        unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
        return;
      }
    } while (result != 0);
    while (xl3_lock[some_crate] != 0){}
    pt_printsend("------------------------------------------\n");
  }



  // now update again with noise run stuff
  if (arg.update_hwdb){

    // re lock everything down
    sbc_lock = 0;
    for (i=0;i<19;i++)
      if ((0x1<<i) & arg.crate_mask)
        xl3_lock[i] = 0;

    pt_printsend("Updating hw db with find_noise results\n");

    // get the find noise test results
    char get_db_address[500];
    sprintf(get_db_address,"%s/%s/%s/get_ecal?startkey=\"%s\"&endkey=\"%s\"",DB_SERVER,DB_BASE_NAME,DB_VIEWDOC,ecal_id,ecal_id);
    pouch_request *ecal_response = pr_init();
    pr_set_method(ecal_response, GET);
    pr_set_url(ecal_response, get_db_address);
    pr_do(ecal_response);
    if (ecal_response->httpresponse != 200){
      pt_printsend("Unable to connect to database. error code %d\n",(int)ecal_response->httpresponse);
      running_ecal = 0;
      unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
      return;
    }
    JsonNode *ecalfull_doc = json_decode(ecal_response->resp.data);
    JsonNode *ecal_rows = json_find_member(ecalfull_doc,"rows");
    int total_rows = json_get_num_mems(ecal_rows); 
    if (total_rows == 0){
      pt_printsend("No documents for this ECAL yet! (id %s)\n",ecal_id);
      running_ecal = 0;
      unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
      return;
    }

    // loop over crates/slots
    for (i=0;i<19;i++){
      if ((0x1<<i) & arg.crate_mask){
        for (j=0;j<16;j++){
          if ((0x1<<j) & arg.slot_mask[i]){
printf("crate %d slot %d\n",i,j);
            // get the current fec document
            sprintf(get_db_address,"%s/%s/%s/get_fec?startkey=[%d,%d,\"\"]&endkey=[%d,%d]&descending=true",FECDB_SERVER,FECDB_BASE_NAME,FECDB_VIEWDOC,i,j+1,i,j);
            pouch_request *fec_response = pr_init();
            pr_set_method(fec_response, GET);
            pr_set_url(fec_response, get_db_address);
            pr_do(fec_response);
            if (fec_response->httpresponse != 200){
              pt_printsend("Unable to connect to database. error code %d\n",(int)fec_response->httpresponse);
              unthread_and_unlock(1,arg.crate_mask,arg.thread_num);
              return;
            }
            JsonNode *fecfull_doc = json_decode(fec_response->resp.data);
            JsonNode *fec_rows = json_find_member(fecfull_doc,"rows");
            int total_rows2 = json_get_num_mems(fec_rows); 
            if (total_rows2 == 0){
              pt_printsend("No FEC documents for this crate/card yet! (crate %d card %d)\n",i,j);
              unthread_and_unlock(1,arg.crate_mask,arg.thread_num);
              return;
            }
            JsonNode *fecone_row = json_find_element(fec_rows,0);
            JsonNode *fec_doc = json_find_member(fecone_row,"value");

            // now find the noise run document for this crate/slot and add it to the fec document
            int found_it = 0;
            int k;
            for (k=0;k<total_rows;k++){
              JsonNode *ecalone_row = json_find_element(ecal_rows,k);
              JsonNode *test_doc = json_find_member(ecalone_row,"value");
              JsonNode *config = json_find_member(test_doc,"config");
              if ((json_get_number(json_find_member(config,"crate_id")) == i) && (json_get_number(json_find_member(config,"slot")) == j)){
                if (strcmp(json_get_string(json_find_member(test_doc,"type")),"find_noise") == 0){
                  found_it = 1;
                  printf("test type is %s\n",json_get_string(json_find_member(test_doc,"type")));
                  add_ecal_test_results(fec_doc,test_doc);
                  break;
                }
              }
            }
            if (found_it == 0){
              pt_printsend("Couldn't find noise run results!\n");
            }else{
              // push the updated fec document
              update_fec_db_doc(fec_doc);
            }
            json_delete(fecfull_doc);
            pr_free(fec_response);
          }
        }
      }
    }

    json_delete(ecalfull_doc);
    pr_free(ecal_response);
  }


  running_ecal = 0;
  unthread_and_unlock(1,arg.crate_mask,arg.thread_num); 
}
示例#16
0
文件: exp.c 项目: bigml/emoon
int main(int argc, char **argv)
{
    mtc_init("study", 7);

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        mtc_err("sdl init error: %s", SDL_GetError());
        return 1;
    }

    if (TTF_Init() == -1) {
        mtc_err("ttf init error: %s", TTF_GetError());
        return 1;
    }
    
	SDL_Window *win = SDL_CreateWindow("Hello World!",
                                       100, 100, WIN_WIDTH, WIN_HEIGHT, SDL_WINDOW_SHOWN);
	if (!win) {
        mtc_err("SDL_CreateWindow Error: %s", SDL_GetError());
		return 1;
	}
    
	m_render = SDL_CreateRenderer(win, -1,
                                  SDL_RENDERER_ACCELERATED |
                                  SDL_RENDERER_PRESENTVSYNC);
	m_render2 = SDL_CreateRenderer(win, -1,
                                  SDL_RENDERER_ACCELERATED |
                                  SDL_RENDERER_PRESENTVSYNC);
	if (!m_render || !m_render2) {
        mtc_err("SDL_CreateRenderer Error: %s", SDL_GetError());
		return 1;
	}

    SDL_Texture *texbg = create_texture("bg.png");
    SDL_Texture *texsp = create_texture("sprite.png");

    int iw = 100, ih = 100;
    SDL_Rect clips[4];
    for (int i = 0; i < 4; i++) {
        clips[i].x = i / 2 * iw;
        clips[i].y = i % 2 * ih;
        clips[i].w = iw;
        clips[i].h = ih;
    }

    SDL_Event e;
    bool quit = false;
    int curclip = 0, count = 0;
    while (!quit) {
        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT) quit = true;
            if (e.type == SDL_KEYDOWN) {
                switch (e.key.keysym.sym) {
                case SDLK_ESCAPE:
                    quit = true;
                    break;
                case SDLK_UP:
                    curclip = 0;
                    break;
                case SDLK_DOWN:
                    curclip = 1;
                    break;
                case SDLK_LEFT:
                    curclip = 2;
                    break;
                case SDLK_RIGHT:
                    curclip = 3;
                    break;
                }
            }
        }

        SDL_Color color = {200, 200, 200};
        char msg[1024];
        snprintf(msg, sizeof(msg), "hello, bigml, ESC to quit %d", count++);
        SDL_Texture *texfont = create_texture_str(msg, color, 48);

        SDL_RenderClear(m_render);
        SDL_RenderClear(m_render2);
        rend_texture(0, 0, texbg);
        rend2_texture(20, 20, texfont);
        rend_texture_clip(WIN_WIDTH/3, WIN_HEIGHT/3, texsp, &clips[curclip]);
        SDL_RenderPresent(m_render);
        SDL_RenderPresent(m_render2);

        SDL_DestroyTexture(texfont);
    }

	//Clean up our objects and quit
	SDL_DestroyTexture(texbg);
    SDL_DestroyTexture(texsp);
	SDL_DestroyRenderer(m_render);
	SDL_DestroyRenderer(m_render2);
	SDL_DestroyWindow(win);
	SDL_Quit();

    return 0;
}
示例#17
0
void *pt_final_test(void *args)
{
  final_test_t arg = *(final_test_t *) args; 
  free(args);

  int i;
  int result;
  // once this is set we can no longer send other commands
  running_final_test = 1;
  // now we can unlock our things, since nothing else should use them
  sbc_lock = 0;
  xl3_lock[arg.crate_num] = 0;

  fd_set thread_fdset;
  FD_ZERO(&thread_fdset);
  FD_SET(rw_xl3_fd[arg.crate_num],&thread_fdset);

  char ft_ids[16][250];
  char id_string[16*250];
  JsonNode *ft_docs[16];

  char comments[1000];
  memset(comments,'\0',1000);
  char command_buffer[100];

  system("clear");
  pt_printsend("------------------------------------------\n");
  pt_printsend("Welcome to final test!\nHit enter to start\n");
  read_from_tut(comments);
  pt_printsend("------------------------------------------\n");

  do {
    sprintf(command_buffer,"crate_init -c %d -s %04x -x -v",arg.crate_num,arg.slot_mask);
    result = crate_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }
  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}
  pt_printsend("------------------------------------------\n");


  while (rw_sbc_fd <= 0){
    pt_printsend("Attempting to connecting to sbc\n");
    do {
      sprintf(command_buffer,"sbc_control");
    } while (sbc_control(command_buffer) != 0);
    while (sbc_lock != 0){}
  }
  pt_printsend("------------------------------------------\n");

  do {
    sprintf(command_buffer,"mtc_init -x");
    result = mtc_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);

  while (sbc_lock != 0 || xl3_lock[arg.crate_num] != 0){}
  pt_printsend("------------------------------------------\n");
  pt_printsend("If any boards could not initialize properly, type \"quit\" now "
      "to exit the test.\n Otherwise hit enter to continue.\n");
  read_from_tut(comments);
  if (strncmp("quit",comments,4) == 0){
    pt_printsend("Exiting final test\n");
    running_final_test = 0;
    unthread_and_unlock(1,(0x1<<arg.crate_num),arg.thread_num); 
    return;
  }

  // set up the final test documents
  for (i=0;i<16;i++){
    if ((0x1<<i) & arg.slot_mask){
      get_new_id(ft_ids[i]);
      ft_docs[i] = json_mkobject();
      sprintf(id_string+strlen(id_string),"%s ",ft_ids[i]);
      pt_printsend(".%s.\n",id_string);
    }
  }

  pt_printsend("Now starting board_id\n");
  do {
    sprintf(command_buffer,"board_id -c %d -s %04x",arg.crate_num,arg.slot_mask);
    result = board_id(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}
  pt_printsend("-------------------------------------------\n");

  if (arg.skip == 0){

    for (i=0;i<16;i++){
      if ((0x1<<i) & arg.slot_mask){
        pt_printsend("Please enter any comments for slot %i motherboard now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"fec_comments",json_mkstring(comments));
        pt_printsend("Has this slot been refurbished? (y/n)\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"refurbished",json_mkbool(comments[0] == 'y'));
        pt_printsend("Has this slot been cleaned? (y/n)\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"cleaned",json_mkbool(comments[0] == 'y'));
        pt_printsend("Time to measure resistance across analog outs and cmos address lines. For the cmos address lines"
            "it's easier if you do it during the fifo mod\n");
        read_from_tut(comments);
        json_append_member(ft_docs[i],"analog_out_res",json_mkstring(comments));
        pt_printsend("Please enter any comments for slot %i db 0 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db0_comments",json_mkstring(comments));
        pt_printsend("Please enter any comments for slot %i db 1 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db1_comments",json_mkstring(comments));
        pt_printsend("Please enter any comments for slot %i db 2 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db2_comments",json_mkstring(comments));
        pt_printsend("Please enter any comments for slot %i db 3 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db3_comments",json_mkstring(comments));
        pt_printsend("Please enter dark matter measurements for slot %i db 0 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db0_dark_matter",json_mkstring(comments));
        pt_printsend("Please enter dark matter measurements for slot %i db 1 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db1_dark_matter",json_mkstring(comments));
        pt_printsend("Please enter dark matter measurements for slot %i db 2 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db2_dark_matter",json_mkstring(comments));
        pt_printsend("Please enter dark matter measurements for slot %i db 3 now.\n",i);
        read_from_tut(comments);
        json_append_member(ft_docs[i],"db3_dark_matter",json_mkstring(comments));
      }
    }


    pt_printsend("Enter N100 DC offset\n");
    read_from_tut(comments);
    for (i=0;i<16;i++){
      if ((0x1<<i) & arg.slot_mask){
        json_append_member(ft_docs[i],"dc_offset_n100",json_mkstring(comments));
      }
    }
    pt_printsend("Enter N20 DC offset\n");
    read_from_tut(comments);
    for (i=0;i<16;i++){
      if ((0x1<<i) & arg.slot_mask){
        json_append_member(ft_docs[i],"dc_offset_n20",json_mkstring(comments));
      }
    }
    pt_printsend("Enter esum hi DC offset\n");
    read_from_tut(comments);
    for (i=0;i<16;i++){
      if ((0x1<<i) & arg.slot_mask){
        json_append_member(ft_docs[i],"dc_offset_esumhi",json_mkstring(comments));
      }
    }
    pt_printsend("Enter esum lo DC offset\n");
    read_from_tut(comments);
    for (i=0;i<16;i++){
      if ((0x1<<i) & arg.slot_mask){
        json_append_member(ft_docs[i],"dc_offset_esumlo",json_mkstring(comments));
      }
    }

    pt_printsend("Thank you. Please hit enter to continue with the rest of final test. This may take a while.\n");
    read_from_tut(comments);
  }

  // starting the tests
  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"fec_test -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = fec_test(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"vmon -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = vmon(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"cgt_test_1 -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = cgt_test(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  //////////////////////////////////////////////////////////////
  // now gotta turn pulser on and off to get rid of garbage
  //sprintf(command_buffer,"readout_add_mtc -c %d -f 0",arg.crate_num);
  //readout_add_mtc(command_buffer);
  //sprintf(command_buffer,"stop_pulser");
  //stop_pulser(command_buffer);
  //////////////////////////////////////////////////////////////

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"ped_run -c %d -s %04x -l 300 -u 1000 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = ped_run(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}


  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"crate_cbal -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = crate_cbal(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  //////////////////////////////////////////////////////////////
  // now gotta turn pulser on and off to get rid of garbage
  //sprintf(command_buffer,"readout_add_mtc -c %d -f 0",arg.crate_num);
  //readout_add_mtc(command_buffer);
  //sprintf(command_buffer,"stop_pulser");
  //stop_pulser(command_buffer);
  //////////////////////////////////////////////////////////////

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"crate_init -c %d -s %04x -B",arg.crate_num,arg.slot_mask);
    result = crate_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"ped_run -c %d -s %04x -b -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = ped_run(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"chinj_scan -c %d -s %04x -l 400 -u 5000 -w 100 -n 10 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = chinj_scan(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  if (arg.tub_tests == 1){
    pt_printsend("You should now connect the cable to ext_ped for ttot tests\nHit enter when ready\n");
    read_from_tut(comments);
    do {
      sprintf(command_buffer,"set_ttot -c %d -s %04x -t 400 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
      result = set_ttot(command_buffer);
      if (result == -2 || result == -3){
        return;
      }

    } while (result != 0);
    while (xl3_lock[arg.crate_num] != 0){}
  }




  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"crate_init -c %d -s %04x -B -D",arg.crate_num,arg.slot_mask);
    result = crate_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  if (arg.tub_tests == 1){
    do {
      sprintf(command_buffer,"get_ttot -c %d -s %04x -t 390 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
      result = get_ttot(command_buffer);
      if (result == -2 || result == -3){
        return;
      }

    } while (result != 0);
    while (xl3_lock[arg.crate_num] != 0){}
  }

  pt_printsend("-------------------------------------------\n");
  pt_printsend("You should now disconnect the cable to ext_ped\nHit enter when ready\n");
  read_from_tut(comments);
  do {
    sprintf(command_buffer,"disc_check -c %d -s %04x -n 500000 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = disc_check(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"cmos_m_gtvalid -c %d -s %04x -g 400 -n -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = cmos_m_gtvalid(command_buffer); 
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  // would put see_reflections here

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"zdisc -c %d -s %04x -o 0 -r 100 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = zdisc(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"mtc_init");
    result = mtc_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (sbc_lock != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"crate_init -c %d -s %04x -x",arg.crate_num,arg.slot_mask);
    result = crate_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do{
    sprintf(command_buffer,"mb_stability_test -c %d -s %04x -n 50 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = mb_stability_test(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"fifo_test -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = fifo_test(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"crate_init -c %d -s %04x -X",arg.crate_num,arg.slot_mask);
    result = crate_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"cald_test -c %d -s %04x -l 750 -u 3500 -n 200 -d -# %s",arg.crate_num,arg.slot_mask,id_string);
    result = cald_test(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  for (i=0;i<16;i++){
    if ((0x1<<i) & arg.slot_mask){
      do {

        pt_printsend("-------------------------------------------\n");
        do {
          sprintf(command_buffer,"crate_init -c %d -s %04x -x",arg.crate_num,arg.slot_mask);
          result = crate_init(command_buffer);
          if (result == -2 || result == -3){
            return;
          }

        } while (result != 0);
        while (xl3_lock[arg.crate_num] != 0){}

        pt_printsend("-------------------------------------------\n");

        sprintf(command_buffer,"mem_test -c %d -s %d -d -# %s",arg.crate_num,i,ft_ids[i]);
        result = mem_test(command_buffer);
        if (result == -2 || result == -3){
          return;
        }

      } while (result != 0);
      while (xl3_lock[arg.crate_num] != 0){}
    }
  }

  pt_printsend("-------------------------------------------\n");
  do {
    sprintf(command_buffer,"crate_init -c %d -s %04x -x",arg.crate_num,arg.slot_mask);
    result = crate_init(command_buffer);
    if (result == -2 || result == -3){
      return;
    }

  } while (result != 0);
  while (xl3_lock[arg.crate_num] != 0){}

  pt_printsend("-------------------------------------------\n");
  pt_printsend("Ready for see_refl test. Hit enter to begin or type \"skip\" to end the final test.\n");
  read_from_tut(comments);
  if (strncmp("skip",comments,4) != 0){
    do {
      sprintf(command_buffer,"see_refl -c %d -s %04x -d -# %s",arg.crate_num,arg.slot_mask,id_string);
      result = see_refl(command_buffer);
      if (result == -2 || result == -3){
        return;
      }

    } while (result != 0);
    while (xl3_lock[arg.crate_num] != 0){}
  }



  pt_printsend("-------------------------------------------\n");
  pt_printsend("Final test finished. Now updating the database.\n");

  // update the database
  for (i=0;i<16;i++){
    if ((0x1<<i) & arg.slot_mask){
      json_append_member(ft_docs[i],"type",json_mkstring("final_test"));
      pthread_mutex_lock(&socket_lock);
      xl3_lock[arg.crate_num] = 1; // we gotta lock this shit down before we call post_doc
      pthread_mutex_unlock(&socket_lock);
      post_debug_doc_with_id(arg.crate_num, i, ft_ids[i], ft_docs[i],&thread_fdset);
      json_delete(ft_docs[i]);
    }
  }

  pt_printsend("-------------------------------------------\n");



  running_final_test = 0;
  unthread_and_unlock(1,(0x1<<arg.crate_num),arg.thread_num); 
}