コード例 #1
0
ファイル: test_fvec.c プロジェクト: MLDroid/malheur
/* 
 * A simple load and save test case
 */
int test_load_save()
{
    int i, j, err = 0;
    fvec_t *f, *g;
    gzFile *z;

    test_printf("Loading and saving of feature vectors");

    fvec_reset_delim();
    config_set_string(&cfg, "features.ngram_delim", " ");
    config_set_int(&cfg, "features.ngram_len", 2);

    /* Create and save feature vectors */
    z = gzopen(TEST_FILE, "wb9");
    if (!z) {
        printf("Could not create file (ignoring)\n");
        return FALSE;
    }

    for (i = 0; tests[i].str; i++) {
        f = fvec_extract(tests[i].str, strlen(tests[i].str), "test");
        fvec_save(f, z);
        fvec_destroy(f);
    }
    gzclose(z);


    /* Load and compare feature vectors */
    z = gzopen(TEST_FILE, "r");

    for (i = 0; tests[i].str; i++) {
        f = fvec_extract(tests[i].str, strlen(tests[i].str), "test");
        g = fvec_load(z);

        /* Check dimensions and values */
        for (j = 0; j < f->len && j < g->len; j++) {
            if (f->dim[j] != g->dim[j]) {
                test_error("(%d) f->dim[%d] != g->dim[%d]", i, j, j);
                break;
            }
            if (fabs(f->val[j] - g->val[j]) > 10e-10) {
                test_error("(%d) f->val[%d] != g->val[%d]", i, j, j);
                break;
            }
        }
        err += (j < f->len || j < g->len);

        fvec_destroy(f);
        fvec_destroy(g);
    }

    gzclose(z);
    unlink(TEST_FILE);

    test_return(err, i);
    return err;
}
コード例 #2
0
ファイル: igreplua.cpp プロジェクト: omghaxzs/qgrep
// arg is a table with the following elements
// project  - string name of the project
// callback - function(filename, linenumber, linestring)
// regex    - regex to search for
// caseSensitive  - optional
// regexIsLiteral - optional
int C_executeSearch(lua_State* L)
{
    const int arg_table = 1;
    lua_getfield(L, arg_table, "project");            /* idx:2 */
    test_error(lua_isstring(L, -1), "execute_search needs a key of 'project' which must be a string");
    const char* project = luaL_checkstring(L, 2);

    char projectFile[1024];
    GetProjectFileName(projectFile, project);
    if (FileExists(projectFile))
    {
        // unpack the rest of the table
        lua_getfield(L, arg_table, "regex");          /* idx:3 */
        test_error(lua_isstring(L, -1), "execute_search needs a key of 'regex' which must be a string");
        lua_getfield(L, arg_table, "caseSensitive");  /* idx:4 */
        lua_getfield(L, arg_table, "regexIsLiteral"); /* idx:5 */
        lua_getfield(L, arg_table, "ignoreTrigrams"); /* idx:6 */
        // MUST leave the callback on the top of the stack
        lua_getfield(L, arg_table, "callback");       /* idx:7 */
        test_error(lua_isfunction(L, -1), "execute_search needs a key of 'callback' which must be a lua function");
    
        // marshal into C data
        const char* regex   = luaL_checkstring(L, 3);
        bool caseSensitive  = lua_isnil(L, 4) || lua_toboolean(L, 4);
        bool regexIsLiteral = lua_toboolean(L, 5);
        bool ignoreTrigrams = lua_toboolean(L, 6);
    
        GrepParams params;
        memset(&params, 0, sizeof(params));
        // standard parms
        params.streamBlockSize = 1 * 1024 * 1024;
        params.streamBlockCount = 10;
        params.searchFilenames = false;
        // custom parms
        params.sourceArchiveName = projectFile;
        params.callbackFunction = luaHitCallback;
        params.caseSensitive = caseSensitive;
        params.regexIsLiteral = regexIsLiteral;
        params.ignoreTrigrams = ignoreTrigrams;
        params.searchPattern = regex;
        params.callbackContext = (void*)L;
        ExecuteSearch(&params);
    }
    else
    {
        lua_ProjectExistsOrDie(project);
        printf("Project is registered, but archive does not exist.\n");
        printf("Run 'qgrep build %s' to generate archive\n", project);
    }
    return 0;
}
コード例 #3
0
ファイル: pcitest.c プロジェクト: ariavie/bcm
int
pci_test(int u, args_t *a, void *pa)
/*
 * Function: 	pci_test
 * Purpose:	Test basic PCI stuff on StrataSwitch.
 * Parameters:	u - unit #.
 *		a - pointer to arguments.
 *		pa - ignored cookie.
 * Returns:	0
 */
{
    int		i;

    COMPILER_REFERENCE(a);
    COMPILER_REFERENCE(pa);

    setup_pca_table(u);


    for (i = 0; i < pca_cnt; i++) {
	pca_t *p = &pca_table[i];
	uint32	read_val;

	/* If write - do write first */

	if (p->pca_flags & WR) {
	    LOG_VERBOSE(BSL_LS_APPL_TESTS,
                        (BSL_META_U(u,
                                    "Writing PCI Config 0x%x <--- 0x%x\n"),
                         p->pca_addr, p->pca_write));
	    if (bde->pci_conf_write(u, p->pca_addr, p->pca_write)){
		test_error(u, "PCI config write failed to address: 0x%x\n",
			   p->pca_addr);
		continue;		/* If test error returns */
	    }
	}
	read_val = bde->pci_conf_read(u, p->pca_addr);
	read_val &= p->pca_read_mask;
	LOG_VERBOSE(BSL_LS_APPL_TESTS,
                    (BSL_META_U(u,
                                "Reading PCI Config (Masked) 0x%x --> 0x%x\n"), 
                     p->pca_addr, read_val));
	if (read_val != p->pca_read) {
	    test_error(u, "PCI Config @0x%x Read 0x%x expected 0x%x\n",
		       p->pca_addr, read_val, p->pca_read);
	}
    }

    return(0);
}
コード例 #4
0
ファイル: mock-server.c プロジェクト: Machyne/mongo-c-driver
void
mock_server_replies_to_find (request_t           *request,
                             mongoc_query_flags_t flags,
                             int64_t              cursor_id,
                             int32_t              number_returned,
                             const char          *ns,
                             const char          *reply_json,
                             bool                 is_command)
{
   char *find_reply;
   char db[MONGOC_NAMESPACE_MAX];

   _mongoc_get_db_name (ns, db);

   /* minimal validation, we're not testing query / find cmd here */
   if (request->is_command && !is_command) {
      test_error ("expected query, got command");
      abort ();
   }

   if (!request->is_command && is_command) {
      test_error ("expected command, got query");
      abort ();
   }

   if (!request_matches_flags (request, flags)) {
      abort ();
   }

   if (is_command) {
      find_reply = bson_strdup_printf (
         "{'ok': 1,"
            " 'cursor': {"
            "    'id': {'$numberLong': '%" PRId64 "'},"
            "    'ns': '%s',"
            "    'firstBatch': [%s]}}",
         cursor_id,
         ns,
         reply_json);

      mock_server_replies_simple (request, find_reply);
      bson_free (find_reply);
   } else {
      mock_server_replies (request, MONGOC_REPLY_NONE, cursor_id, 0,
                           number_returned, reply_json);

   }
}
コード例 #5
0
ファイル: ces.c プロジェクト: Reedgarden/bcm-sdk-xgs
int
ces_test_done(int u, void *p)
{
    int			rv = 0;

    /*
     * Clear ge0 loopback
     */
#if 0
    ces_test_ge0_loopback_set(u, FALSE);
#else
    printk("<<<< GE0 LOOPBACK STILL ON >>>>\n");
#endif

#if 0
    /*
     * Reset CES
     */
    bcm_ces_services_init(u);
#else
    printk("<<<< CES NOT CLEANED UP >>>>\n");
#endif
    if (p != NULL)
        sal_free(p);

    if (rv < 0) {
        test_error(u, "Post-CES reset failed: %s\n", soc_errmsg(rv));
        return -1;
    }

    return 0;
}
コード例 #6
0
ファイル: test.c プロジェクト: ariavie/bcm
void
test_done(int u, test_t *test, int status)
/*
 * Function:    test_done
 * Purpose:     Process the completion of a test
 * Parameters:  u - unit number.
 *              test - pointer to test completed.
 *              status - exit status of test.
 * Returns:     Nothing.
 */
{
    if (status || (test->t_flags & T_F_ERROR)) {
        last_test_status[u] = -1;
        test->t_fail++;
        soc_cm_debug(DK_TESTS, "Test %d (%s) Completed with error (%d)\n", 
                     test->t_test, test->t_name, status);
        /*
         * If Stop-on-error not processed yet, give user a chance
         * now.
         */
        if ((status == TEST_ABORT) || (status == TEST_STOP)) {
            printk("Test %d (%s) Aborted\n", test->t_test, test->t_name);
        } else if ((test_options & TEST_O_SOE) && 
                   !(test->t_flags & T_F_STOP)) {
            test_error(u, 
                       "Stop-on-error: Test %d (%s) completed with error\n",
                       test->t_test, test->t_name);
        }
    } else {
        last_test_status[u] = 0;
        test->t_success++;
        soc_cm_debug(DK_TESTS, "Test %d (%s) Completed successfully\n", 
                     test->t_test, test->t_name);
    }
}
コード例 #7
0
ファイル: test_fvec.c プロジェクト: MLDroid/malheur
/* 
 * A simple static test for the feature vectors
 */
int test_static()
{
    int i, err = 0;
    fvec_t *f;

    test_printf("Extraction of feature vectors");

    for (i = 0; tests[i].str; i++) {
        fvec_reset_delim();
        config_set_string(&cfg, "features.ngram_delim", tests[i].dlm);
        config_set_int(&cfg, "features.ngram_len", tests[i].nlen);

        /* Extract features */
        f = fvec_extract(tests[i].str, strlen(tests[i].str), "test");

        /* Check for correct number of dimensions */
        if (f->len != tests[i].len) {
            test_error("(%d) len %d != %d", i, f->len, tests[i].len);
            err++;
        }

        fvec_destroy(f);
    }

    test_return(err, i);
    return err;
}
コード例 #8
0
ファイル: test_embed.c プロジェクト: rieck/sally
/* 
 * A simple test for the binary embedding
 */
int test_embed_tfidf()
{
    int i, j, n, err = 0;
    string_t strs[10];

    config_set_string(&cfg, "features.vect_norm", "none");
    config_set_string(&cfg, "features.tfidf_file", TEST_TFIDF);

    unlink(TEST_TFIDF);
    char *test_file = getenv("TEST_FILE");
    idf_create(test_file);
    test_printf("Testing TFIDF embedding");

    input_config("lines");
    n = input_open(test_file);
    input_read(strs, n);

    /* Compute IDF manually */
    config_set_string(&cfg, "features.vect_embed", "bin");
    fvec_t *w = fvec_zero();
    for (i = 0, err = 0; i < n; i++) {
        fvec_t *fv = fvec_extract(strs[i].str, strs[i].len);
        fvec_add(w, fv);
        fvec_destroy(fv);
    }
    fvec_invert(w);
    fvec_mul(w, n);
    fvec_log2(w);

    if (!idf_check(w)) {
        err++;
        test_error("(%d) internal idf values seem to be wrong", i);
    }

    /* Invert w for multiplying out IDFs */
    fvec_invert(w);

    config_set_string(&cfg, "features.vect_embed", "tfidf");
    for (i = 0, err = 0; i < n; i++) {
        fvec_t *fv = fvec_extract(strs[i].str, strs[i].len);
        fvec_times(fv, w);

        /* Check if rest tf */
        double d = 0;
        for (j = 0; j < fv->len; j++)
            d += fv->val[j];
        err += fabs(d - 1.0) > 1e-6;
        fvec_destroy(fv);
    }
    test_return(err, n);

    fvec_destroy(w);
    input_free(strs, n);
    input_close();

    idf_destroy();
    unlink(TEST_TFIDF);

    return err;
}
コード例 #9
0
ファイル: test_packet.c プロジェクト: quinoacomputing/HDF5
static int test_packet_table(hid_t fid)
{

    if( test_create_close(fid) < 0 )
        return -1;

    if( test_open(fid) < 0 )
        return -1;

    /* test_append must be run before test_count and test_read, as it */
    /* creates the packet table they use. */
    if( test_append(fid) < 0 )
        return -1;

    /* These tests will not necessarily cause failures in each other,
           so we don't abort the other tests if one fails. */
    test_read(fid);
    test_get_next(fid);
    test_big_table(fid);
    test_rw_nonnative_dt(fid);
#ifdef VLPT_REMOVED
    test_varlen(fid);
#endif /* VLPT_REMOVED */
    test_opaque(fid);
    test_compress();
    test_error(fid);

    return 0;
}
コード例 #10
0
ファイル: tests.c プロジェクト: benoit-canet/packetgraph
int main(int argc, char **argv)
{
	int ret;
	uint64_t test_flags;
	struct pg_error *error = NULL;
	/* tests in the same order as the header function declarations */
	g_test_init(&argc, &argv, NULL);

	/* initialize packetgraph */
	ret = pg_start(argc, argv, &error);
	g_assert(ret >= 0);
	g_assert(!error);

	/* accounting program name */
	ret += + 1;
	argc -= ret;
	argv += ret;
	test_flags = parse_args(argc, argv);
	if (test_flags & PRINT_USAGE)
		print_usage();
	g_assert(!(test_flags & FAIL));

	test_error();
	test_brick_core();
	test_brick_flow();
	test_pkts_count();
	test_brick_graph();

	return g_test_run();
}
コード例 #11
0
ファイル: pcitest.c プロジェクト: ariavie/bcm
int
pci_test_init(int u, args_t *a, void **pa)
/*
 * Function: 	pci_test_init
 * Purpose:	Save all the current PCI Config registers to write
 *		on completion.
 * Parameters:	u - unit #
 *		a - pointer to args
 *		pa - Pointer to cookie
 * Returns:	0 - success, -1 - failed.
 */
{
    pt_t	*pt = &pt_config[u];
    int		i;

    if (ARG_CNT(a)) {
	test_error(u, "Arguments not supported\n");
	return -1;
    }

    for (i = 0; i < PT_REGS; i++) {
	pt->pt_config[i] = bde->pci_conf_read(u, i * 4);
    }
    *pa = pt;
    return(0);
}
コード例 #12
0
ファイル: tt3_checkpoint.c プロジェクト: fengzw/sqlite
static void checkpoint_starvation_2(int nMs){
  Error err = {0};
  CheckpointStarvationCtx ctx = { SQLITE_CHECKPOINT_RESTART, 0 };
  checkpoint_starvation_main(nMs, &ctx);
  if( ctx.nMaxFrame>CHECKPOINT_STARVATION_FRAMELIMIT+10 ){
    test_error(&err, "WAL grew too large - %d frames", ctx.nMaxFrame);
  }
  print_and_free_err(&err);
}
コード例 #13
0
ファイル: tt3_checkpoint.c プロジェクト: fengzw/sqlite
static void checkpoint_starvation_1(int nMs){
  Error err = {0};
  CheckpointStarvationCtx ctx = { SQLITE_CHECKPOINT_PASSIVE, 0 };
  checkpoint_starvation_main(nMs, &ctx);
  if( ctx.nMaxFrame<(CHECKPOINT_STARVATION_FRAMELIMIT*10) ){
    test_error(&err, "WAL failed to grow - %d frames", ctx.nMaxFrame);
  }
  print_and_free_err(&err);
}
コード例 #14
0
ファイル: test-bus-error.c プロジェクト: arthur-c/systemd
int main(int argc, char *argv[]) {
        dump_mapping_table();

        test_error();
        test_errno_mapping_standard();
        test_errno_mapping_custom();

        return 0;
}
コード例 #15
0
ファイル: logcontext.c プロジェクト: je-so/js-projekt
int unittest_io_log_logcontext()
{
   if (test_error())          goto ONERR;
   if (test_initfree())       goto ONERR;
   if (test_query())          goto ONERR;

   return 0;
ONERR:
   return EINVAL;
}
コード例 #16
0
int main(void) {
  uint32_t i;

  yices_init();
  for (i=0; i<NUM_CODES; i++) {
    test_error(all_codes[i], all_names[i]);
  }
  yices_exit();

  return 0;
}
コード例 #17
0
int main(int argc, char **argv)
{
  test_simple();
  test_error();
  test_record();
  test_no_ascii();
  test_copy();
  test_encode_char();
  printf("DONE.\n");
  return 0;
}
コード例 #18
0
ファイル: test.cpp プロジェクト: yczhangsjtu/Cpp-libcrypt
void test_unmatch_q(FILE *stream, const char *where, mpq_srcptr a, mpq_srcptr b)
{
	char buf[MAX_INFO_SIZE+1];
	char stra[MAX_INFO_SIZE+1],strb[MAX_INFO_SIZE+1];
	mpq_get_str(stra,10,a);
	mpq_get_str(strb,10,b);
	strcpy(buf,"Expected is ");
	strncat(buf,stra,MAX_INFO_SIZE-strlen(buf));
	strcat(buf,", but got ");
	strncat(buf,strb,MAX_INFO_SIZE-strlen(buf));
	test_error(stream,where,buf);
}
コード例 #19
0
int main(void)
{
	osmo_init_logging(&log_info);
	log_set_log_level(osmo_stderr_target, LOGL_INFO);

	test_error();
	test_auth_not_avail();
	test_auth_then_ciph1();
	test_auth_then_ciph2();
	test_auth_reuse();
	test_auth_reuse_key_seq_mismatch();
	return 0;
}
コード例 #20
0
ファイル: main.c プロジェクト: alueger/dAISy
void test_packet_handler(const char* message)
{
	// send/receive fake AIS message
	test_ph_send_packet(message);

	// verify packet handler operation
	if (ph_get_last_error() != PH_ERROR_NONE)
		test_error();

	// verify if a new packet showed up in FIFO
	uint16_t packet_size = fifo_get_packet();
	if (packet_size == 0)
		test_error();

	// verify if new packet is identical with sent message
	if (!test_nmea_verify_packet(message))
		test_error();

	nmea_process_packet();

	// remove packet from FIFO
	fifo_remove_packet();
}
コード例 #21
0
ファイル: sched.c プロジェクト: rohsaini/mkunity
int
get_quantum(struct policy_state *ps)
{
	switch(ps->policy) {
	case POLICY_TIMESHARE:
		return(-1);
	case POLICY_RR:
		return(ps->base.rr_base.quantum);
	case POLICY_FIFO:
		return(-1);
	default:
		test_error("get_quantum", "invalid policy");
	}
}
コード例 #22
0
int remote_thumbnail::close()
{
	cmd.cmd = thumbnail_cmd_close_file;
	cmd.data_size = 0;
	if (!WriteFile(m_pipe, &cmd, sizeof(cmd), &byteWritten, NULL ) || byteWritten != sizeof(cmd))
		error_exit(error_fail);

	if (!ReadFile(m_pipe, &cmd, sizeof(cmd), &byteWritten, NULL) || byteWritten != sizeof(cmd))
		error_exit(error_fail);

	test_error(cmd.cmd);

	return 0;
}
コード例 #23
0
ファイル: sched.c プロジェクト: rohsaini/mkunity
int
get_max_pri(struct policy_state *ps)
{
	switch(ps->policy) {
	case POLICY_TIMESHARE:
		return(ps->limit.tr_limit.max_priority);
	case POLICY_RR:
		return(ps->limit.rr_limit.max_priority);
	case POLICY_FIFO:
		return(ps->limit.ff_limit.max_priority);
	default:
		test_error("get_max_pri", "invalid policy");
	}
}
コード例 #24
0
ファイル: sched.c プロジェクト: rohsaini/mkunity
void
set_quantum(struct policy_state *ps, int quantum)
{
	switch(ps->policy) {
	case POLICY_TIMESHARE:
		return;
	case POLICY_RR:
		ps->base.rr_base.quantum = quantum;
		return;
	case POLICY_FIFO:
		return;
	default:
		test_error("set_quantum", "invalid policy");
	}
}
コード例 #25
0
ファイル: test_main.c プロジェクト: secXsQuared/secX
void *talloc(uint32 size)
{
    if (!gat_full())
    {
        void *result = malloc(size);
        gat_push(result);
        return result;
    }
    else
    {
        test_error();
        printf("GAT full, rejecting further allocations.\n");
    }
    return NULL;
}
コード例 #26
0
int remote_thumbnail::seek(__int64 position)
{
	cmd.cmd = thumbnail_cmd_seek;
	cmd.data_size = sizeof(position);
	if (!WriteFile(m_pipe, &cmd, sizeof(cmd), &byteWritten, NULL ) || byteWritten != sizeof(cmd))
		error_exit(error_fail);
	if (!WriteFile(m_pipe, &position, sizeof(position), &byteWritten, NULL ) || byteWritten != sizeof(position))
		error_exit(error_fail);

	if (!ReadFile(m_pipe, &cmd, sizeof(cmd), &byteWritten, NULL) || byteWritten != sizeof(cmd))
		error_exit(error_fail);

	test_error(cmd.cmd);

	return 0;
}
コード例 #27
0
ファイル: sched.c プロジェクト: rohsaini/mkunity
void
set_base_pri(struct policy_state *ps, int base_pri)
{
	switch(ps->policy) {
	case POLICY_TIMESHARE:
		ps->base.tr_base.base_priority = base_pri;
		return;
	case POLICY_RR:
		ps->base.rr_base.base_priority = base_pri;
		return;
	case POLICY_FIFO:
		ps->base.ff_base.base_priority = base_pri;
		return;
	default:
		test_error("set_base_pri", "invalid policy");
	}
}
コード例 #28
0
ファイル: sched.c プロジェクト: rohsaini/mkunity
void
set_max_pri(struct policy_state *ps, int max_pri)
{
	switch(ps->policy) {
	case POLICY_TIMESHARE:
		ps->limit.tr_limit.max_priority = max_pri;
		return;
	case POLICY_RR:
		ps->limit.rr_limit.max_priority = max_pri;
		return;
	case POLICY_FIFO:
		ps->limit.ff_limit.max_priority = max_pri;
		return;
	default:
		test_error("set_max_pri", "invalid policy");
	}
}
コード例 #29
0
ファイル: api-dijkstra.c プロジェクト: dooglus/ccan
int main(void)
{
	plan_tests(6 + 23
		   + FULL_LEN * (FULL_LEN*4 - 1)
		   + CHAIN_LEN * (1 + CHAIN_LEN*2)
		   + 12 + 32 + 7 + 2);

	test_trivial();
	test_parallel();
	test_full();
	test_chain();
	test_error();
	test_traversal1();
	test_shortcut1();
	test_shortcut2();
	
	return exit_status();
}
コード例 #30
0
ファイル: test_ngrams.c プロジェクト: rieck/sally
int test_pos_ngrams()
{
    int i, err = 0;
    fvec_t *f;

    /* Test for positional n-grams */
    test_t t[] = {
        {"b b b b b", 3, 0, 1},
        {"b b b b b", 3, 1, 3},
        {"b b b b b", 2, 0, 1},
        {"b b b b b", 2, 1, 4},
        {NULL, 0, 0, 0}
    };

    test_printf("Testing positional n-grams");

    /* Hack to set delimiters */
    config_set_string(&cfg, "features.granularity", "tokens");
    config_set_string(&cfg, "features.token_delim", " ");
    fvec_delim_set(" ");

    for (i = 0; t[i].str; i++) {

        config_set_int(&cfg, "features.ngram_len", t[i].nlen);
        config_set_bool(&cfg, "features.ngram_pos", t[i].flag);
        config_set_int(&cfg, "features.pos_shift", 0);

        /* Extract features */
        f = fvec_extract(t[i].str, strlen(t[i].str));

        /* Check for correct number of dimensions */
        if (f->len != t[i].len) {
            test_error("(%d) len %d != %d", i, f->len, t[i].len);
            err++;
        }

        fvec_destroy(f);
    }

    config_set_bool(&cfg, "features.ngram_pos", 0);

    test_return(err, i);
    return err;
}