static void test_raw_expected(const char * uriStr,
                              const char * testBuf,
                              size_t testLen,
                              const char * expectBuf,
                              size_t expectLen,
                              lwm2m_media_type_t format,
                              const char * id)
{
    lwm2m_data_t * tlvP;
    lwm2m_uri_t uri;
    int size;
    
    if (uriStr != NULL)
    {
        lwm2m_stringToUri(uriStr, strlen(uriStr), &uri);
    }

    size = lwm2m_data_parse((uriStr != NULL) ? &uri : NULL, (uint8_t *)testBuf, testLen, format, &tlvP);
    CU_ASSERT_TRUE_FATAL(size>0);

    // Serialize to the same format and compare to the input buffer
    test_data_and_compare(uriStr, format, tlvP, size, id, (uint8_t*)expectBuf, expectLen);

    // Serialize to the other format respectivly.
    if (format == LWM2M_CONTENT_TLV)
        test_data(uriStr, LWM2M_CONTENT_JSON, tlvP, size, id);
    else if (format == LWM2M_CONTENT_JSON)
        test_data(uriStr, LWM2M_CONTENT_TLV, tlvP, size, id);
}
示例#2
0
char *test_insert_then_swim()
{
	priority_queue_p queue = priority_queue_create(sizeof(int), compare_intp);	

	priority_queue_insert(queue, test_data(10));
	priority_queue_insert(queue, test_data(20));
	mu_assert(*(int*)vector_get(queue->vector, 0) == 10, "should have set first item");	

	priority_queue_free(queue);
	return NULL;
}
TEST(fatal_debug, fieldM) {
  auto pod = test_data();
  pod.fieldM.clear();
  TEST_IMPL(pod, "<root>.fieldM");
  pod.fieldM.insert(11);
  pod.fieldM.insert(12);
  pod.fieldM.insert(13);
  pod.fieldM.insert(14);
  TEST_IMPL(pod, "<root>.fieldM.0");
  pod.fieldM = test_data().fieldM;
  TEST_IMPL(pod);
}
示例#4
0
char *test_set()
{
  vector_p vector = vector_create(sizeof(int));

  vector_add(vector, test_data(1));
  int set = vector_set(vector, 0, test_data(2));

  mu_assert(*(int*)vector_get(vector, 0) == 2, "expected 2");
  mu_assert(set, "expected to have set");

  vector_free(vector);
  return NULL;
}
示例#5
0
char *test_copy_shallow()
{
  vector_p vector = vector_create(sizeof(int));
  vector_add(vector, test_data(0));
  vector_add(vector, test_data(1));

  vector_p copy = vector_copy_shallow(vector);

  mu_assert(vector->length == copy->length, "expected same length for clone");
  mu_assert(*(int*)vector_get(copy, 1) == 1, "expected data to be copied");

  vector_free(copy);
  vector_free(vector);
  return NULL;
}
示例#6
0
char *test_insert_at_end()
{
  vector_p vector = vector_create(sizeof(int));
  vector_add(vector, test_data(0));
  vector_add(vector, test_data(1));

  int did_insert = vector_insert(vector, 2, test_data(2));

  mu_assert(vector->length == 3, "should have a length of 3");
  mu_assert(did_insert, "should have inserted");
  mu_assert(*(int*)vector_get(vector, 2) == 2, "should have added item at end");
  
  vector_free(vector);
  return NULL;
}
示例#7
0
char *test_insert_at_beginning()
{
  vector_p vector = vector_create(sizeof(int));
  vector_add(vector, test_data(1));

  int did_insert = vector_insert(vector, 0, test_data(0));

  mu_assert(vector->length == 2, "should have a length of 2");
  mu_assert(did_insert, "should have inserted");
  mu_assert(*(int*)vector_get(vector, 0) == 0, "should have added item at start");
  mu_assert(*(int*)vector_get(vector, 1) == 1, "should have moved other items");
  
  vector_free(vector);
  return NULL;
}
TEST(fatal_debug, fieldC) {
  auto pod = test_data();
  pod.fieldC = enum1::field2;
  TEST_IMPL(pod, "<root>.fieldC");
  pod.fieldC = enum1::field0;
  TEST_IMPL(pod);
}
示例#9
0
char *test_swap()
{
  vector_p vector = vector_create(sizeof(int));

  vector_add(vector, test_data(0));
  vector_add(vector, test_data(1));

  int swapped = vector_swap(vector, 0, 1);

  mu_assert(swapped, "expected to have swapped");
  mu_assert(*(int*)vector_get(vector, 0) == 1, "expected 1");
  mu_assert(*(int*)vector_get(vector, 1) == 0, "expected 0");

  vector_free(vector);
  return NULL;
}
TEST(fatal_debug, fieldG_field0) {
  auto pod = test_data();
  pod.fieldG.field0 = 12;
  TEST_IMPL(pod, "<root>.fieldG.field0");
  pod.fieldG.field0 = 98;
  TEST_IMPL(pod);
}
TEST(fatal_debug, fieldG_field1) {
  auto pod = test_data();
  pod.fieldG.field1 = "should mismatch";
  TEST_IMPL(pod, "<root>.fieldG.field1");
  pod.fieldG.field1 = "hello, world";
  TEST_IMPL(pod);
}
void
test_header (void)
{
    const gchar name[] = "X-HEADER-NAME";
    const gchar value[] = "MilterServerContext test";
    const gchar *packet;
    gsize packet_size;

    test_data();
    channel_free();

    reply_continue();

    cut_assert_true(milter_server_context_header(context, name, value));
    pump_all_events();
    milter_test_assert_state(HEADER);
    milter_test_assert_status(NOT_CHANGE);

    milter_command_encoder_encode_header(encoder,
                                         &packet, &packet_size,
                                         name, value);
    milter_test_assert_packet(channel, packet, packet_size);

    cut_assert_equal_uint(0, n_message_processed);
}
TEST(fatal_debug, fieldG_field2) {
  auto pod = test_data();
  pod.fieldG.field2 = enum1::field1;
  TEST_IMPL(pod, "<root>.fieldG.field2");
  pod.fieldG.field2 = enum1::field2;
  TEST_IMPL(pod);
}
示例#14
0
char *test_remove()
{
  vector_p vector = vector_create(sizeof(int));

  vector_add(vector, test_data(0));
  vector_add(vector, test_data(1));
  vector_add(vector, test_data(2));

  vector_remove(vector, 1);

  mu_assert(vector->length == 2, "should have a length of 2");
  mu_assert(*(int*)vector_get(vector, 1) == 2, "should have removed item");

  vector_free(vector);
  return NULL;
}
TEST(fatal_debug, fieldB) {
  auto pod = test_data();
  pod.fieldB = "should mismatch";
  TEST_IMPL(pod, "<root>.fieldB");
  pod.fieldB = "this is a test";
  TEST_IMPL(pod);
}
/**
 * @brief Parses the testBuf to an array of lwm2m_data_t objects and serializes the result
 *        to TLV and JSON and if applicable compares it to the original testBuf.
 * @param testBuf The input buffer.
 * @param testLen The length of the input buffer.
 * @param format The format of the testBuf. Maybe LWM2M_CONTENT_TLV or LWM2M_CONTENT_JSON at the moment.
 * @param id The test object id for debug out.
 */
static void test_raw(const char * uriStr,
                     const char * testBuf,
                     size_t testLen,
                     lwm2m_media_type_t format,
                     const char * id)
{
    lwm2m_data_t * tlvP;
    lwm2m_uri_t uri;
    int size;
    
    if (uriStr != NULL)
    {
        lwm2m_stringToUri(uriStr, strlen(uriStr), &uri);
    }

    size = lwm2m_data_parse((uriStr != NULL) ? &uri : NULL, (uint8_t *)testBuf, testLen, format, &tlvP);
    CU_ASSERT_TRUE_FATAL(size>0);

    // Serialize to the same format and compare to the input buffer
    test_data_and_compare(uriStr, format, tlvP, size, id, (uint8_t*)testBuf, testLen);

    // Serialize to the TLV format
    // the reverse is not possible as TLV format loses the data type information
    if (format == LWM2M_CONTENT_JSON)
    {
        test_data(uriStr, LWM2M_CONTENT_TLV, tlvP, size, id);
    }
}
TEST(fatal_debug, fieldA) {
  auto pod = test_data();
  pod.fieldA = 90;
  TEST_IMPL(pod, "<root>.fieldA");
  pod.fieldA = 141;
  TEST_IMPL(pod);
}
TEST(fatal_debug, fieldH) {
  auto pod = test_data();
  pod.fieldH.set_ui_2(3);
  TEST_IMPL(pod, "<root>.fieldH");
  pod.fieldH.__clear();
  TEST_IMPL(pod);
}
示例#19
0
int main(int argc, char **argv)
{
    test_asp_up();
    test_data();

    printf("All tests passed.\n");
    return 0;
}
示例#20
0
文件: test1.c 项目: whguan/lapalceFmm
void test_init(const int distribution, const int nparts, const int accuracy, 
	       const int s, const double beta, double **ploc, double **pcharge, 
	       double **pot, double **field, double **dxx, double **dyy, double **dzz,
	       double **dxy, double **dxz, double **dyz)
{
  // The function completes two tasks: (1) Allocate memory to hold particle locations
  // and the charges carried by them, and to hold the computed potential and field 
  // result; (2) Generate the input data as specified by the distribution variable. 

  char* datatype[] = {"", "  CUBE", "SPHERE", "OCTANT"};

  // Allocate memory to hold particle information and output results. 
  (*ploc)    = (double *)calloc(3*nparts, sizeof(double));
  (*pcharge)  = (double *)calloc(3*nparts, sizeof(double));
  (*pot)     = (double *)calloc(nparts, sizeof(double));
  
  (*field)   = (double *)calloc(3*nparts, sizeof(double));
  (*dxx) = (double *)calloc(nparts, sizeof(double));
  (*dyy) = (double *)calloc(nparts, sizeof(double));
  (*dzz) = (double *)calloc(nparts, sizeof(double));
  (*dxy) = (double *)calloc(nparts, sizeof(double));
  (*dxz) = (double *)calloc(nparts, sizeof(double));
  (*dyz) = (double *)calloc(nparts, sizeof(double));  
 
   int allocFailure = (*ploc==0) || (*pcharge==0) || (*pot==0) || (*field==0) ||
  (*dxx == 0) || (*dyy == 0) ||(*dzz == 0) ||(*dxy == 0) || (*dxz == 0) || (*dyz == 0);
  if ( allocFailure ) {
    printf("Error in %s, line %d: unable to allocate memory\n",  __FILE__, __LINE__);
    exit(-1);
  }

  // Generate input data set for the demo
  test_data(nparts, distribution, *ploc, *pcharge);

  // Print summary of the demo
  if ( beta > 0 ) {
    printf("\n\tDEMO FMM-YUKAWA RUN\n"
	   "\n\tSETUP\n\n"
	   "======================================================\n"
	   "# OF PARTICLE        | %20d\n"
	   "DISTRIBUTION         | \t\t     %s\n"
	   "S                    | %20d\n"
	   "ACCURACY             | %20d\n"
	   "======================================================\n", 
	   nparts, datatype[distribution], s, accuracy);
  } else if  ( beta == 0 ) {
    printf("\n\tDEMO FMM-LAPLACE RUN\n"
	   "\n\tSETUP\n\n"
	   "======================================================\n"
	   "# OF PARTICLE        | %20d\n"
	   "DISTRIBUTION         | \t\t     %s\n"
	   "S                    | %20d\n"
	   "ACCURACY             | %20d\n"
	   "======================================================\n", 
	   nparts, datatype[distribution], s, accuracy);
  }
  return;
}
示例#21
0
char *test_add_elements()
{
  vector_p vector = vector_create(sizeof(int));

  size_t i0 = vector_add(vector, test_data(0));
  size_t i1 = vector_add(vector, test_data(1));
  size_t i2 = vector_add(vector, test_data(2));

  mu_assert(*(int*)vector_get(vector, 0) == 0, "expected 0");
  mu_assert(*(int*)vector_get(vector, 1) == 1, "expected 1");
  mu_assert(*(int*)vector_get(vector, 2) == 2, "expected 2");
  mu_assert(i0 == 0, "should have index 0");
  mu_assert(i1 == 1, "should have index 1");
  mu_assert(i2 == 2, "should have index 2");

  vector_free(vector);
  return NULL;
}
示例#22
0
文件: test_prog_basics.c 项目: 8l/sol
int main(int argc, const char** argv) {
  SVM vm = SVM_INIT;

  test_data(&vm);
  test_arithmetic(&vm);
  test_logic_tests(&vm);
  test_control_flow(&vm);

  return 0;
}
TEST(fatal_debug, fieldG_field5) {
  auto pod = test_data();
  pod.fieldG.field5.set_ui_2(5);
  TEST_IMPL(pod, "<root>.fieldG.field5");
  pod.fieldG.field5.__clear();
  TEST_IMPL(pod, "<root>.fieldG.field5");
  pod.fieldG.field5.set_ue_2(enum1::field0);
  TEST_IMPL(pod, "<root>.fieldG.field5.ue_2");
  pod.fieldG.field5.set_ue_2(enum1::field1);
  TEST_IMPL(pod);
}
示例#24
0
char *test_get()
{
  vector_p vector = vector_create(sizeof(int));
  vector_add(vector, test_data(1));

  int data = *((int*)vector_get(vector, 0));
  mu_assert(data == 1, "expected same value");

  vector_free(vector);
  return NULL;
}
示例#25
0
char *test_set_out_of_range()
{
  vector_p vector = vector_create(sizeof(int));

  int set = vector_set(vector, 3500, test_data(2));

  mu_assert(!set, "expected to not have set");

  vector_free(vector);
  return NULL;
}
TEST(fatal_debug, fieldQ) {
  auto pod = test_data();
  pod.fieldQ.clear();
  TEST_IMPL(pod, "<root>.fieldQ");
  structA a1;
  a1.a = 1;
  a1.b = "1";
  structA a2;
  a2.a = 2;
  a2.b = "2";
  structA a3;
  a3.a = 3;
  a3.b = "3";
  pod.fieldQ["A1"] = a1;
  pod.fieldQ["A2"] = a2;
  pod.fieldQ["A3"] = a3;
  TEST_IMPL(pod, "<root>.fieldQ.0");
  pod.fieldQ = test_data().fieldQ;
  TEST_IMPL(pod);
}
示例#27
0
char *test_add()
{
  vector_p vector = vector_create(sizeof(int));
  size_t index = vector_add(vector, test_data(1));

  mu_assert(index == 0, "should have added at index 0");
  mu_assert(vector->length == 1, "expected length 1");

  vector_free(vector);
  return NULL;
}
示例#28
0
int main()
{
  vector_p vector = vector_create(sizeof(int));
  vector_add(vector, test_data(4));
  vector_add(vector, test_data(1));
  vector_add(vector, test_data(2));
  vector_add(vector, test_data(3));

  qsort(vector->data, vector->length, sizeof(void*), qscompare);
  
  for(size_t i = 0 ; i < vector->length ; i++)
  {
    int k = *(int*) vector_get(vector, i);
    printf("%d\n", k);
  }

  vector_free(vector);
  
  return 0;
}
TEST(fatal_debug, fieldE) {
  auto pod = test_data();
  pod.fieldE.set_ui(5);
  TEST_IMPL(pod, "<root>.fieldE");
  pod.fieldE.__clear();
  TEST_IMPL(pod, "<root>.fieldE");
  pod.fieldE.set_ud(4);
  TEST_IMPL(pod, "<root>.fieldE.ud");
  pod.fieldE.set_ud(5.6);
  TEST_IMPL(pod);
}
示例#30
0
文件: main.c 项目: Cai900205/test
void thread_channel_recv(void *arg)
{
    struct timeval tm_start,tm_end;
    fvl_read_rvl_t rlen;
    uint8_t i=0;
    int rvl=0;
    uint64_t total_count=0;
    gettimeofday(&tm_start,NULL);
    int fd=0;
    int *j=(int *)arg;
    printf("j:%d\n",*j);
    int cpu=*j+11;
    cpu_set_t cpuset;
    CPU_ZERO(&cpuset);
    CPU_SET(cpu,&cpuset);
    rvl = pthread_setaffinity_np(pthread_self(),sizeof(cpu_set_t),&cpuset);
    if(rvl){
	    printf("(%d)fail:pthread_setaffinity_np()\n",cpu);
	    return;
    }
    fd=fvl_srio_channel_open(channame[*j]);
    printf("##################fd:%d*****************\n",fd);
    if(fd<0)
    {
        printf("error!\n");
        return;
    }
    gettimeofday(&tm_start,NULL);
    while(1)
    {
        rlen.len=0x100000;
 	rvl=fvl_srio_read(fd,&rlen);
        if(rlen.len!=0)
        {
            test_data(i,rlen.buf_virt,10485,0);
            i++;    
//            printf("##########:%d\n",i);
            gettimeofday(&tm_end,NULL);
            total_count++;        
            double diff=(tm_end.tv_sec-tm_start.tv_sec)+(tm_end.tv_usec-tm_start.tv_usec)/1000000.0;
            if(diff>5)
            {
                double da_lu=total_count/diff;
                printf("fd: %d length(byte): %-15u time(s): %-15f  avg MB/s: %-15f total_count:%lld \n",fd,rlen.len,diff,da_lu,total_count);
                fflush(stdout);
                total_count=0;
                gettimeofday(&tm_start,NULL);
            }       
            fvl_srio_read_feedback(fd,rlen.num);
        }
    }
}