コード例 #1
0
ファイル: file.c プロジェクト: JanDeVisser/obelix
data_t * _file_open(char *name) {
  data_t      *dummy = data_create(Bool, 0);
  array_t     *args = data_array_create(1);
  data_t      *f;

  array_push(args, data_create(String, "file.txt"));
  f = data_execute(dummy, "open", args, NULL);
  array_free(args);
  data_free(dummy);
  return f;
}
コード例 #2
0
ファイル: types.c プロジェクト: JanDeVisser/obelix
data_t * execute(data_t *self, char *name, int numargs, ...) {
  va_list  arglist;
  array_t *args;
  data_t  *ret;
  data_t  *d;
  int      ix;
  int      type;
  long     intval;
  double   dblval;
  char    *ptr;
  
  args = data_array_create(numargs);
  va_start(arglist, numargs);
  for (ix = 0; ix < numargs; ix++) {
    type = va_arg(arglist, int);
    d = NULL;
    switch (type) {
      case Int:
        intval = va_arg(arglist, long);
        d = int_to_data(intval);
        break;
      case Float:
        intval = va_arg(arglist, double);
        d = data_create(Float, dblval);
        break;
      case String:
        ptr = va_arg(arglist, char *);
        d = data_create(String, ptr);
        break;
      case Bool:
        intval = va_arg(arglist, long);
        d = data_create(Bool, intval);
        break;
      default:
        debug("Cannot do type %d. Ignored", type);
        ptr = va_arg(arglist, char *);
        break;
    }
    if (d) {
      array_push(args, d);
    }
  }
  va_end(arglist);
  ret = data_execute(self, name, args, NULL);
  if (ret && data_is_exception(ret)) {
    debug("Error executing '%s'.'%s': %s", data_tostring(self),
	  name, data_tostring(ret));
  }
  array_free(args);
  return ret;
}
コード例 #3
0
ファイル: test_list.c プロジェクト: Gratski/SD_Projecto_1
int testRemoveCabeca() {
	int result;
	struct list_t *list;
	struct entry_t *e1, *e2, *e3, *entry;
	struct data_t *data;

	printf("Módulo list -> teste remover cabeça:");

	if ((list = list_create()) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	if ((data = data_create(5)) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	e1 = entry_create("abc", data);
	e2 = entry_create("def", data);
	e3 = entry_create("ghi", data);

	if (e1 == NULL || e2 == NULL || e3 == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	memcpy(e1->value->data, "abc1", 5);
	memcpy(e2->value->data, "def1", 5);
	memcpy(e3->value->data, "ghi1", 5);

	list_add(list,e1);
	list_add(list,e2);
	list_add(list,e3);

	assert(list_remove(NULL, "abc") < 0);
	result = (list_remove(NULL, "abc") < 0);

	assert(list_remove(list, NULL) < 0);
	result = result && (list_remove(list, NULL) < 0);

	result = result &&
		 list_remove(list, "abc") == 0 &&
		 list_size(list) == 2;

	entry = list_get(list, "def");
	result = result &&
		 entry != e2 &&
		 strcmp(entry->key, e2->key) == 0;

	entry = list_get(list, "ghi");
	result = result &&
		 entry != e3 &&
		 strcmp(entry->key, e3->key) == 0;

	list_destroy(list);
	entry_destroy(e1);
	entry_destroy(e2);
	entry_destroy(e3);
	data_destroy(data);

	printf(" %s\n", result ? "passou" : "não passou");
	return result;
}
コード例 #4
0
ファイル: his_upd.cpp プロジェクト: gitgun/dLabPro
/**
 * Prepare histogram data.
 *
 * @param x  first data
 * @param wv weight data
 * @return max. index value or -1, if index empty
 */
INT32 CGEN_PROTECTED CHistogram::Prepare(CData* x, CData* wv)
{
  INT32 imax = 1, i, n;

  if (m_hist == NULL)
    m_hist = data_create("hist");

  m_nhist = data_nblock(m_hist);

  if (data_empty(m_indexlist) != TRUE)
  {
    imax = CHistogram_max_index(m_indexlist, 0) + 1;
    if (imax > m_nhist)
      m_nhist = imax;
  }

  if (data_empty(wv) != TRUE)
  {
    imax = data_ndim(wv);
    if (imax > m_nhist)
      m_nhist = imax;
  }

  if (m_nhist == 0)
    m_nhist = 1;

  if (data_empty(m_hist) != TRUE)
  {
    data_realloc (m_hist, m_nhist * m_bins);
    set_data_nrec (m_hist, m_nhist * m_bins);
    m_hdim = data_dim(m_hist);
  } else
  {
    data_reset(m_hist);
    n = data_dim(x);
    m_hdim = 0;
    for (i = 0; i < n; i++)
      if (comp_type(x,i) > 256 && i != m_icomp)
      {
        comp_def(m_hist, comp_text(x,i),T_DOUBLE);
        m_hdim++;
      }
    data_arr_alloc (m_hist, m_bins * m_nhist);
  }

  set_data_descr(m_hist, DESCR1, (FLOAT64)m_hmode);
  set_data_descr(m_hist, DESCR2, (FLOAT64)m_bins);

  set_data_nblock(m_hist, m_nhist);

  return (m_nhist);
}
コード例 #5
0
int testCreate() {
    int result;
    struct data_t *data = data_create(1024);

    memcpy(data->data,"1234567890a",strlen("1234567890a")+1);

    result = (strcmp(data->data,"1234567890a") == 0) && (data->datasize == 1024);

    data_destroy(data);

    printf("Modulo data -> teste data_create: %s\n",result?"passou":"nao passou");
    return result;
}
コード例 #6
0
ファイル: test_list.c プロジェクト: Gratski/SD_Projecto_1
int testGetKeys() {
	int result;
	struct list_t *list;
	struct entry_t *e1, *e2, *e3;
	struct data_t *data;
	char **keys;

	printf("Módulo list -> teste busca chaves:");

	if ((list = list_create()) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	if ((data = data_create(5)) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	assert(list_get_keys(NULL) == NULL);
	result = (list_get_keys(NULL) == NULL);

	e1 = entry_create("abc", data);
	e2 = entry_create("def", data);
	e3 = entry_create("ghi", data);

	if (e1 == NULL || e2 == NULL || e3 == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	memcpy(e1->value->data, "abc1", 5);
	memcpy(e2->value->data, "def1", 5);
	memcpy(e3->value->data, "ghi1", 5);

	list_add(list,e1);
	list_add(list,e2);
	list_add(list,e3);

	if ((keys = list_get_keys(list)) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	result = strcmp(keys[0], e1->key) == 0 && keys[0] != e1->key &&
                 strcmp(keys[1], e2->key) == 0 && keys[1] != e2->key && 
                 strcmp(keys[2], e3->key) == 0 && keys[2] != e3->key && 
                 keys[3] == NULL;

	list_free_keys(keys);
	list_destroy(list);
	entry_destroy(e1);
	entry_destroy(e2);
	entry_destroy(e3);
	data_destroy(data);

	printf(" %s\n", result ? "passou" : "não passou");
	return result;
}
コード例 #7
0
ファイル: data.c プロジェクト: Gratski/SD_Projecto_2
struct data_t *data_create2(int size, void * data){
	if (size < 0 || data == NULL)
		return NULL;

	struct data_t *d = data_create(size);

	// se nao tem memoria suficiente
	if ( d == NULL )
		return NULL;

	memcpy(d->data, data, d->datasize);
	return d;

}
コード例 #8
0
int data_append(data_t **list, char *buffer, int size)
{
    if(NULL==buffer || 0==size)
    {
        return NUMBER_FALSE;
    }
    data_t *t = data_create(buffer, size);
    if(NULL==t)
    {
        return NUMBER_FALSE;
    }
    data_insert(list, t);
    return NUMBER_TRUE;
}
コード例 #9
0
ファイル: data.c プロジェクト: GNsunghokim/IoTGateway
Data* data_json_create(json_object* jso) {
	char name[64] = {0, };
	uint64_t size = 10;

	//TODO add new value
	json_object_object_foreach(jso, key, child_object) { 
		if(!strcmp(key, "name")) {
			strcpy(name, json_object_to_json_string(child_object));
			remove_blank(name);
		} else if(!strcmp(key, "size")) {
			size = json_object_get_int64(child_object);
		}
	}

	return data_create(name, size);
}
コード例 #10
0
ファイル: tdatalist.c プロジェクト: JanDeVisser/obelix
void setup(void) {
  array_t *a = array_create(0);

  list_null = datalist_create(NULL);
  check_list(list_null, 0);

  array_push(a, str_wrap("test"));
  array_push(a, data_true());
  array_push(a, data_null());
  array_push(a, int_to_data(42));
  list_array = datalist_create(a);
  check_list(list_array, array_size(a));

  list_valist = (datalist_t *) data_create(List, 2, str_wrap("test"), int_to_data(42));
  check_list(list_valist, 2);
}
コード例 #11
0
ファイル: test_list.c プロジェクト: Gratski/SD_Projecto_1
int testAddVarios() {
	int result,i,keysize;
	struct list_t *list;
	struct entry_t *entry[1024];
	struct entry_t *aux;
	struct data_t *data;
	char key[16];

	printf("Módulo list -> teste adicionar vários:");

	if ((list = list_create()) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	for(i=0; i<1024; i++) {
		sprintf(key, "keyabc-%d",i);
		keysize = strlen(key) + 1;

		if ((data = data_create(keysize)) == NULL)
			error(1, errno, "  O teste não pode prosseguir");

		memcpy(data->data, key, keysize);
		if ((entry[i] = entry_create(key, data)) == NULL)
			error(1, errno, "  O teste não pode prosseguir");

		data_destroy(data);
		list_add(list, entry[i]);
	}

	assert(list_size(list) == 1024);
	result = (list_size(list) == 1024);

	for(i=0; i<1024; i++) {
		assert(list_get(list, entry[i]->key) != entry[i]);
		aux = list_get(list, entry[i]->key);
		result = result &&
			 (aux != entry[i]) &&
			 strcmp(aux->key, entry[i]->key) == 0;
		entry_destroy(entry[i]);
	}

	list_destroy(list);

	printf(" %s\n", result ? "passou" : "não passou");
	return result;
}
コード例 #12
0
ファイル: test_list.c プロジェクト: Gratski/SD_Projecto_1
int testAddCabeca() {
	int result;
	struct list_t *list;

	struct entry_t *entry;
	struct entry_t *entry2;
	struct data_t *data;

	printf("Módulo list -> teste adicionar cabeça:");

	if ((list = list_create()) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	if ((data = data_create(5)) == NULL)
		error(1, errno, "  O teste não pode prosseguir");

	if ((entry = entry_create("abc", data)) == NULL)
		error(1, errno, "  O teste não pode prosseguir");


	memcpy(entry->value->data, "abc1", 5);

	assert(list_add(NULL, entry) < 0);
	result = (list_add(NULL, entry) < 0);

	assert(list_add(list, NULL) < 0);
	result = result && (list_add(list, NULL) < 0);

	result = result && (list_add(list, entry) == 0);

	entry2 = list_get(list, "abc");

	result = result &&
		 entry2 != entry && 
                 list_size(list) == 1 &&
		 strcmp(entry->key, entry2->key) == 0;

	entry_destroy(entry);
	data_destroy(data);
	list_destroy(list);

	printf(" %s\n",result ? "passou" : "não passou");
	return result;
}
コード例 #13
0
ファイル: ofp_role_test.c プロジェクト: JackieXie168/lagopus
void
test_ofp_role_mp_check(void) {
  data_create(ofp_role_mp_check_wrap,
              "00 00 00 00 00 00 00 00");
}
コード例 #14
0
ファイル: utils.c プロジェクト: nowl/semblis
DLL_INFO data_t *reader_to_data(reader_node_t *code, bool in_pair, bool is_gc)
{
    int fn_index = code->filename_index;
    int line_num = code->line_num;
    uint8 type;
    void *arg1, *arg2, *arg3;
    data_t *result;

    arg1 = arg2 = arg3 = NULL;

    switch(code->token_type) {
    case SRT_PAIR:
        arg1 = reader_to_data(code->child, true, is_gc);
        if(code->next)
            arg2 = reader_to_data(code->next, true, is_gc);
        else
            arg2 = DataNIL;
        type = DT_PAIR;
        break;
    case SRT_STRING: 
    {
        String str = util_to_wcs(code->data);
        int len = wcslen(str);
        
        if(str[len-1] == L'"')
            str[len-1] = 0;

        arg1 = &str[1];          /* skip the '"' chars on each end */
        type = DT_STRING;
        break;
    }
    case SRT_SYMBOL:
    {
        String str = util_to_wcs(code->data);
        arg1 = &str[1]; /* skip the '\'' char */
        type = DT_SYMBOL;
        break;
    }
    case SRT_VARIABLE:
        arg1 = util_to_wcs(code->data);
        type = DT_VARIABLE;
        break;
    case SRT_NUMBER:
        arg1 = code->data;
        type = DT_NUMBER;
        break;
    default:
        assert(false);
    }

    /* special case of ")" */
    if(type == DT_VARIABLE && util_wcs_eq(arg1, L")"))
        return DataNIL;

    if(is_gc)
        result = data_create(fn_index, line_num, type, arg1, arg2, arg3);
    else
        result = data_create_no_gc(fn_index, line_num, type, arg1, arg2, arg3);

    if(result->type != DT_PAIR && in_pair) {
        data_t *data_next;
        if(code->next)
            data_next = reader_to_data(code->next, true, is_gc);
        else
            data_next = DataNIL;
        
        if(is_gc)
            result = data_create(result->filename,
                                 result->line_num,
                                 DT_PAIR,
                                 result,
                                 data_next,
                                 result);
        else
            result = data_create_no_gc(result->filename,
                                       result->line_num,
                                       DT_PAIR,
                                       result,
                                       data_next,
                                       result);
        
    }

    return result;
}
コード例 #15
0
/* 
 * Executar uma função (indicada pelo opcode na msg) e retorna o resultado na
 * própria struct msg.
 * Retorna 0 (OK) ou -1 (erro, por exemplo, tabela nao inicializada).
 */
int invoke(struct message_t *msg) {

    int retVal = 0;
    char *key;
    struct entry_t *entry;

    if(sharedPtable && msg) {
        switch (msg->opcode) {
            case OP_RT_GET:
                // table_get: (struct table_t* char*) -> (struct data_t*)
                if(msg->content.key) {
                    key = msg->content.key;
                    if(!(msg->content.value = ptable_get(sharedPtable, key))) {
                        if(!(msg->content.value = data_create(0))) {
                            msg->opcode = OP_RT_ERROR;
                            msg->c_type = CT_RESULT;
                            msg->content.result = -1;
                        }
                    }
                    if(msg->content.value) {
                        msg->opcode ++; // Incrementa para dizer que esta mensagem contem o resultado
                        msg->c_type = CT_VALUE;
                        free(key);
                    }
                }
                else {
                    msg->opcode = OP_RT_ERROR;
                    msg->c_type = CT_RESULT;
                    msg->content.result = -1;
                }
            break;

            case OP_RT_PUT:
                // table_put: (struct table_t* char* struct data_t*) -> (int)
                if(msg->content.entry) {
                    entry = msg->content.entry;
                    if((retVal = ptable_put(sharedPtable, entry->key, entry->value)) != -1) {
                        msg->content.result = retVal;
                        msg->opcode ++;
                        msg->c_type = CT_RESULT;
                    }
                    else {
						// Deu erro pq ficamos sem espaço de log.
						//cria um ficheiro temporário com o estado da tabela
						if(pmanager_store_table(sharedPtable->pmanager, sharedPtable->table) < 0) {
							ERROR("persistent_table: pmanager_store_table");
							msg->opcode = OP_RT_ERROR;
							msg->c_type = CT_RESULT;
							msg->content.result = -1;
						}
						
						//cria um ficheiro temporário com o estado da tabela
						if(pmanager_rotate_log(sharedPtable->pmanager) != 0) {
							ERROR("persistent_table: pmanager_rotate_log");
							msg->opcode = OP_RT_ERROR;
							msg->c_type = CT_RESULT;
							msg->content.result = -1;
						}
						if((retVal = ptable_put(sharedPtable, entry->key, entry->value)) != -1) {
							msg->content.result = retVal;
							msg->opcode ++;
							msg->c_type = CT_RESULT;
						} else {
							msg->opcode = OP_RT_ERROR;
							msg->c_type = CT_RESULT;
							msg->content.result = -1;
						}
                    }
                    entry_destroy(entry);
                }
                else {
                    msg->opcode = OP_RT_ERROR;
                    msg->c_type = CT_RESULT;
                    msg->content.result = -1;
                }
            break;

            case OP_RT_SIZE:
                // table_size: (struct table_t*) -> (int)
                msg->content.result = ptable_size(sharedPtable);
                msg->opcode ++;
                msg->c_type = CT_RESULT;
                // Nao temos nada para libertar...
            break;
	
            case OP_RT_DEL:
                // table_del: (struct table_t* char*) -> (int)
                if(msg->content.key) {
                    key = msg->content.key;
                    msg->content.key = NULL;
                    retVal = ptable_del(sharedPtable, key);
                    msg->content.result = retVal;
                    msg->opcode ++;
                    msg->c_type = CT_RESULT;
                    free(key);
                }
                else {
                    msg->opcode = OP_RT_ERROR;
                    msg->c_type = CT_RESULT;
                    msg->content.result = -1;
                }
            break;

            case OP_RT_GETKEYS:
                // table_get_keys: (struct table_t*) -> (char**)
                if((msg->content.keys = ptable_get_keys(sharedPtable))) {
                    msg->opcode ++;
                    msg->c_type = CT_KEYS;
                }
                else {
                    msg->opcode = OP_RT_ERROR;
                    msg->c_type = CT_RESULT;
                    msg->content.result = -1;
                }
                // Não temos nada para libertar...
            break;

            case OP_RT_GETTS:
                // table_get: (struct table_t* char*) -> (int)
                if(msg->content.key) {
                    key = strdup(msg->content.key);
					free(msg->content.key);

                    // Verifica a validade da resposta
                    if((msg->content.timestamp = ptable_get_ts(sharedPtable, key)) < 0) {
                            msg->opcode = OP_RT_ERROR;
							msg->c_type = CT_RESULT;
                            msg->content.result = -1;
                    } else if(msg->content.timestamp >= 0) {
                        msg->opcode ++; // Incrementa para dizer que esta mensagem contem o resultado
                        msg->c_type = CT_TIMESTAMP;
                    }
                }
                else {
                    msg->opcode = OP_RT_ERROR;
                    msg->c_type = CT_RESULT;
                    msg->content.result = -1;
                }
				free(key);
            break;

            default:
                ERROR("opcode");
                msg->opcode = OP_RT_ERROR;
                msg->c_type = CT_RESULT;
                msg->content.result = -1;
            break;
        }
    }
    else {
        ERROR("NULL sharedPtable");
        retVal = -1;
    }
    return retVal;
}
コード例 #16
0
ファイル: his_mod.cpp プロジェクト: gitgun/dLabPro
/**
 * Reorganize histogram.
 *
 * <p>Remarks</p>
 * <ul>
 *   <li>If (exist == NULL), the number of histogram blocks is set to nind,
 *       by adding empty blocks or removing blocks from the end.</li>
 *   <li>If (exist != NULL), histogram blocks may selected as follows:
 *       exist(i,0) == 0: block i is deleted;
 *       exist(i,0) >  0: block i is preserved</li>
 *   <li> Only preserved blocks will be available after reorganization! The
 *        index correspondence may be changed by this operation!nind is not used
 *        in this case.</li>
 * </ul>
 *
 * @param exist  -  index existing flag sequence (may be NULL)
 * @param nind   -  index number
 * @return O_K if ok, NOT_EXEC if not executed
 */
INT16 CGEN_PUBLIC CHistogram::ReorgEx(CData* exist, INT32 nind)
  {
  INT32 n, ifree, i, imax, rl;
  CData* h;

  if (CheckHisto() != O_K)
    return (NOT_EXEC);

  /* --- change only histogram number */
  if (exist == NULL)
  {
    if (nind > 0 && nind != data_nblock(m_hist))
    {
      data_realloc (m_hist, nind * m_bins);
      set_data_nblock(m_hist, nind);
      set_data_nrec (m_hist, nind * m_bins);
      return (O_K);
    } else
      return (NOT_EXEC);
  }

  /* --- reorganize according to exist */
  if (exist != NULL)
  {
    imax = data_nrec(exist);

    n = 0;
    for (i = 0; i < imax; i++)
    {
      if (dfetch (exist,i,0) > 0.0)
        n++;
    }

    if (n == imax)
      return (O_K);

    h = data_create("h");
    data_copy (m_hist,h);

    rl = BytesPerBlock();
    data_realloc (m_hist, n * m_bins);

    ifree = 0;

    for (i = 0; i < imax; i++)
    {
      if (dfetch (exist,i,0) > 0.0)
      {
        dl_memmove ( xaddr(m_hist,ifree,0),xaddr(h,i*m_bins,0), rl);
        ifree += m_bins;
      }
    }

    if (m_hmode == 3)
    {
      data_copy (m_hist,h);
      rl = 2 * data_reclen(m_minmax);
      data_realloc (m_minmax, n * 2);

      ifree = 0;

      for (i = 0; i < imax; i++)
      {
        if (dfetch (exist,i,0) > 0.0)
        {
          dl_memmove ( xaddr(m_minmax,ifree,0),xaddr(h,2*i,0), rl);
          ifree += 2;
        }
      }
    }

    data_destroy(h);

    set_data_nblock(m_hist, n);
    return (O_K);
  }

  return (O_K);
}
コード例 #17
0
ファイル: test.c プロジェクト: MasterGG/GIT
int main()
{
        int N;
        int i;
        FILE *fp = NULL;
        clock_t start,end;
        char temp;
	
        printf("input the length of string:\n");
        scanf("%d",&N);
	i = 0;
	char *ch1 = (char *)malloc(sizeof(char)*N);
	char *ch2 = (char *)malloc(sizeof(char)*N);
	/*get deferent address*/
	char *src1 = ch1 + 1;
	char *src2 = ch1 + 2;
	char *src3 = ch1 + 3;		
	char *src4 = ch1 + 4;		
	char *src5 = ch1 + 5;		
	char *src6 = ch1 + 6;		
	char *src7 = ch1 + 7;		
	
	data_create(N);
	fp = fopen("input_data.txt","r+");
	if(!fp)
	{
		printf("open file failed!\n");
		exit(1);
	}
	temp = fgetc(fp);
	while(temp != EOF)
	{
		
		ch1[i++] = temp;
		temp = fgetc(fp);
	}

	start = clock();
	memcpy_unloop(ch1,ch2,N);
	end = clock();

	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(ch1[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}
	printf("memcpy_unloop is correct!\n");
	printf("0偏移:source address=%p	des address=%p\n", ch1, ch2);
	printf("0偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));
	memcpy(src1, ch1,N);
	start = clock();
	memcpy_unloop(src1,ch2,N);
	end = clock();

	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(src1[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}
	printf("memcpy_unloop is correct!\n");

	printf("1偏移:source address=%p	des address=%p\n", src1, ch2);
	printf("1偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));
	memcpy(src2, ch1,N);
	start = clock();
	memcpy_unloop(src2,ch2,N);
	end = clock();
	
	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(src2[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}
	int len1, len2;
	printf("memcpy_unloop is correct!\n");
	printf("2偏移:source address=%p	des address=%p\n", src2, ch2);

	 printf("2偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));
	memcpy(src3, ch1,N);
	start = clock();
	memcpy_unloop(src3,ch2,N);
	end = clock();

	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(src3[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}
	printf("memcpy_unloop is correct!\n");
	printf("3偏移:source address=%p	des address=%p\n", src3, ch2);

	printf("3偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));
	memcpy(src4, ch1,N);
	start = clock();
	memcpy_unloop(src4,ch2,N);
	end = clock();

	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(src4[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}
	printf("memcpy_unloop is correct!\n");
	printf("4偏移:source address=%p	des address=%p\n", src4, ch2);
	printf("4偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));
	memcpy(src5, ch1,N);
	start = clock();
	memcpy_unloop(src5,ch2,N);
	end = clock();

	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(src5[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}

	printf("memcpy_unloop is correct!\n");
	printf("5偏移:source address=%p	des address=%p\n", src5, ch2);
	printf("5偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));
	memcpy(src6, ch1,N);
	start = clock();
	memcpy_unloop(src6,ch2,N);
	end = clock();

	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(src6[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}
	printf("memcpy_unloop is correct!\n");
	printf("6偏移:source address=%p	des address=%p\n", src6, ch2);
	printf("6偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));
	memcpy(src7, ch1,N);
	start = clock();
	memcpy_unloop(src7,ch2,N);
	end = clock();

	/*judge the copyed data is correct*/
	for(i = 0;i < N;i++)
	{
		if(src7[i] != ch2[i])
		{
			printf("memcpy_unloop is fault!\n");
			exit(1);
		}
	}
	printf("memcpy_unloop is correct!\n");
	printf("7偏移:source address=%p	des address=%p\n", src7, ch2);
	printf("7偏移:memcpy_unloop cost:%d us!\n\n",(int)(end-start));

//	free(ch1);
//	free(ch2);
	fclose(fp);
	fp = NULL;
//	ch1 = NULL;
//	ch2 = NULL;
        return 0;
}
コード例 #18
0
ファイル: ofp_role_test.c プロジェクト: JackieXie168/lagopus
void
test_role_mp_null_check(void) {
  data_create(ofp_role_mp_check_null_wrap, "");
}
コード例 #19
0
ファイル: ofp_role_test.c プロジェクト: JackieXie168/lagopus
void
test_ofp_role_check_null(void) {
  data_create(ofp_role_check_null_wrap, "");
}