コード例 #1
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_erase_after_range)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());

      DataNDC::iterator i_data_1 = data.begin();
      std::advance(i_data_1, 2);

      DataNDC::iterator i_data_2 = data.begin();
      std::advance(i_data_2, 4);

      CompareDataNDC::iterator i_compare_data_1 = compare_data.begin();
      std::advance(i_compare_data_1, 2);

      CompareDataNDC::iterator i_compare_data_2 = compare_data.begin();
      std::advance(i_compare_data_2, 4);

      CompareDataNDC::iterator i_compare_result = compare_data.erase_after(i_compare_data_1, i_compare_data_2);

      DataNDC::iterator i_result = data.erase_after(i_data_1, i_data_2);

      CHECK_EQUAL(*i_compare_result, *i_result);

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
      CHECK(are_equal);
    }
コード例 #2
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_front)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());

      CHECK_EQUAL(compare_data.front(), data.front());
    }
コード例 #3
0
ファイル: replay.cpp プロジェクト: twelvedogs/Lix
void Replay::add(const Replay::Data& d)
{
    // Veraendert ist es natuerlich nicht mehr geladen, aber die Tatsache, ob
    // der Level in der Datei steckt, darf nicht verloren gehen.
    file_not_found = false;
    version_min    = gloB->version_min;

    // Daten verarbeiten
    if (data.size() == 0 || d.update > max_updates) {
        data.push_back(d);
        max_updates = d.update;
    }
    else {
        It itr = data.begin();
        while (itr != data.end()) {
            // compare_data is a static funcition defined right above this
            if (compare_data(d, *itr) == -1) {
                data.insert(itr, d);
                break;
            }
            ++itr;
        }
        if (itr == data.end()) data.push_back(d);
    }
}
コード例 #4
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_insert_after_range)
    {
      std::vector<ItemNDC> test1 = { ItemNDC("0"), ItemNDC("1"), ItemNDC("2"), ItemNDC("3"), ItemNDC("4") };
      std::vector<ItemNDC> test2 = { ItemNDC("5"), ItemNDC("6"), ItemNDC("7"), ItemNDC("8"), ItemNDC("9") };

      CompareDataNDC compare_data(test1.begin(), test1.end());
      DataNDC data(test1.begin(), test1.end());

      compare_data.insert_after(compare_data.before_begin(), test2.begin(), test2.end());
      data.insert_after(data.before_begin(), test2.begin(), test2.end());

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);

      compare_data.assign(test1.begin(), test1.end());
      data.assign(test1.begin(), test1.end());

      CompareDataNDC::iterator icd = compare_data.begin();
      DataNDC::iterator         id = data.begin();

      std::advance(icd, 3);
      std::advance(id, 3);

      compare_data.insert_after(icd, test2.begin(), test2.end());
      data.insert_after(id, test2.begin(), test2.end());

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #5
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_copy_constructor)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());
      DataNDC other_data(data);

      CHECK(std::equal(data.begin(), data.end(), other_data.begin()));
    }
コード例 #6
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_const_iterator)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(compare_data.begin(), compare_data.end());

      are_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());

      CHECK(are_equal);
    }
コード例 #7
0
ファイル: vdpow.c プロジェクト: AlbertJP/envytools
static void action_mpeg(VdpDecoder dec, VdpVideoSurface surf, VdpPictureInfoMPEG1Or2 *info, struct snap *ref,
struct fuzz *f, uint32_t oldval, uint32_t newval)
{
	VdpStatus ret;
	int debug = 1;

	struct snap *cur = f ? calloc(1, sizeof(*cur)) : ref;
	int save = 0, failed_tries = 0;

	VdpBitstreamBuffer buffer;
	buffer.struct_version = VDP_BITSTREAM_BUFFER_VERSION;
	generate_mpeg(info, 1, &buffer.bitstream, &buffer.bitstream_bytes);

	if (f)
		fprintf(stderr, "Starting %s %u -> %u\n", f->name, oldval, newval);

	if (!debug) {
		uint32_t pitches[3] = { input_width, input_width };

		void *data[3];

		data[0] = calloc(input_height, input_width);
		data[1] = calloc(input_height/2, input_width);
		data[2] = NULL;

		do {
			if (save)
				ok(vdp_video_surface_get_bits_y_cb_cr(surf, VDP_YCBCR_FORMAT_NV12, data, pitches));
			ok(vdp_decoder_render(dec, surf, (void*)info, 1, &buffer));
		} while ((save = save_data(VS_H262, cur)) == -EAGAIN || (save == -EIO && ++failed_tries < 3));

		ok(vdp_video_surface_get_bits_y_cb_cr(surf, VDP_YCBCR_FORMAT_NV12, data, pitches));
		free(data[0]);
		free(data[1]);

		if (save < 0) {
			if (!f || oldval == newval) {
				// Reference streams shouldn't be failing
				assert(!!!"WTF?");
				return;
			}
			fprintf(stderr, "Failed on %s %u->%u, stream was likely invalid\n", f->name, oldval, newval);
			free((void*)buffer.bitstream);
			free(cur);
			return;
		}
	} else
		ok(vdp_decoder_render(dec, surf, (void*)info, 1, &buffer));

	free((void*)buffer.bitstream);
	if (f) {
		compare_data(ref, cur, f, oldval, newval);
		free(cur);
	}
}
コード例 #8
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_sort)
    {
      CompareDataNDC compare_data(unsorted_data.begin(), unsorted_data.end());
      DataNDC data(unsorted_data.begin(), unsorted_data.end());

      compare_data.sort();
      data.sort();

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #9
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_reverse)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());

      compare_data.reverse();
      data.reverse();

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #10
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_unique)
    {
      CompareDataNDC compare_data(non_unique_data.begin(), non_unique_data.end());
      DataNDC data(non_unique_data.begin(), non_unique_data.end());

      compare_data.unique();
      data.unique();

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #11
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_remove_if)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());

      compare_data.remove_if(std::bind2nd(std::equal_to<ItemNDC>(), ItemNDC("7")));
      data.remove_if(std::bind2nd(std::equal_to<ItemNDC>(), ItemNDC("7")));

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #12
0
unsigned write_flash(unsigned * dst, char * src, unsigned no_of_bytes)
{

  unsigned i;

  if(no_of_bytes == FLASH_BUF_SIZE)
  {

	  for(i = 0;i<no_of_bytes;i++)
	  {
	    flash_buf[i] = *(src+i);
	  }

      find_prepare_sector(SystemCoreClock/1000, (unsigned)dst);

      if(result_table[0] != CMD_SUCCESS)
      {
    	  serial_writestr("Error: preparing to write data\n");
      }

      write_data( SystemCoreClock/1000,
                (unsigned)dst,
                (void *)flash_buf,
                FLASH_BUF_SIZE);



      if(result_table[0] != CMD_SUCCESS)
      {
    	  serial_writestr("Error: writing data\n");
      }


      compare_data( SystemCoreClock/1000,
                (unsigned)dst,
                (void *)flash_buf,
                FLASH_BUF_SIZE);


      if(result_table[0] != CMD_SUCCESS)
      {
    	  serial_writestr("Error: verifying data\n");
      }

      /* Reset flash address */
      dst = 0;
  }
  else
	  return 1;

  return(CMD_SUCCESS);
}
コード例 #13
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_assign_range)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data;

      // Do it twice. We should only get one copy.
      data.assign(compare_data.begin(), compare_data.end());
      data.assign(compare_data.begin(), compare_data.end());

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #14
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_self_assignment)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());
      DataNDC other_data(data);

      other_data = other_data;

      CHECK_EQUAL(data.size(), other_data.size());

      are_equal = std::equal(data.begin(), data.end(), other_data.begin());

      CHECK(are_equal);
    }
コード例 #15
0
ファイル: ex-doubly.c プロジェクト: sergiokas/utn
void sort_list( struct doubly_node * list ) {
	struct doubly_node *i, *j;

	for( i=list; i->next != NULL; i=i->next)
	{
		for (j=i->next; j != NULL; j=j->next )
		{
			if( compare_data((data_t *) i->data, (data_t *) j->data ) > 0)
			{
				doubly_swap(i, j);
			}
		}
	}

}
コード例 #16
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_resize_up_value)
    {
      const size_t INITIAL_SIZE = 4;
      const size_t NEW_SIZE     = 8;
      const ItemNDC VALUE("1");

      DataNDC data(INITIAL_SIZE, VALUE);
      data.resize(NEW_SIZE, VALUE);

      CompareDataNDC compare_data(INITIAL_SIZE, VALUE);
      compare_data.resize(NEW_SIZE, VALUE);

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #17
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_assign_size_value)
    {
      const size_t INITIAL_SIZE = 4;
      const ItemNDC VALUE("1");

      CompareDataNDC compare_data(INITIAL_SIZE, VALUE);
      DataNDC data;

      // Do it twice. We should only get one copy.
      data.assign(INITIAL_SIZE, VALUE);
      data.assign(INITIAL_SIZE, VALUE);

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
コード例 #18
0
ファイル: sbl_iap.c プロジェクト: bobc/R2C2_Firmware
unsigned write_flash(unsigned * dst, char * src, unsigned no_of_bytes)
{
  unsigned i;

  for(i = 0;i<no_of_bytes;i++)
  {
    flash_buf[(byte_ctr+i)] = *(src+i);
  }
  byte_ctr = byte_ctr + no_of_bytes;

  if(byte_ctr == FLASH_BUF_SIZE)
  {
    /* We have accumulated enough bytes to trigger a flash write */
    find_erase_prepare_sector(SystemCoreClock/1000, (unsigned)dst);
    if(result_table[0] != CMD_SUCCESS)
    {
      DBG("Error: prepare sectors\n");
      while(1); /* No way to recover. Just let OS report a write failure */
    }
    write_data( SystemCoreClock/1000,
                (unsigned)dst,
                (void *)flash_buf,
                FLASH_BUF_SIZE);
    if(result_table[0] != CMD_SUCCESS)
    {
      DBG("Error: writing data\n");
      while(1); /* No way to recover. Just let OS report a write failure */
    }

    compare_data( SystemCoreClock/1000,
                (unsigned)dst,
                (void *)flash_buf,
                FLASH_BUF_SIZE);
    if(result_table[0] != CMD_SUCCESS)
    {
      DBG("Error: verifying data\n");
      while(1); /* No way to recover. Just let OS report a write failure */
    }

    /* Reset byte counter and flash address */
    byte_ctr = 0;
    dst = 0;
  }
  return(CMD_SUCCESS);
}
コード例 #19
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_erase_after_range_end)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());

      DataNDC::iterator i_data = data.begin();
      std::advance(i_data, 4);

      CompareDataNDC::iterator i_compare_data = compare_data.begin();
      std::advance(i_compare_data, 4);

      DataNDC::iterator i_result = data.erase_after(i_data, data.end());

      CHECK(i_result == data.end());

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
      CHECK(are_equal);
    }
コード例 #20
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_erase_after_single)
    {
      CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
      DataNDC data(sorted_data.begin(), sorted_data.end());

      DataNDC::iterator i_data = data.begin();
      std::advance(i_data, 2);

      CompareDataNDC::iterator i_compare_data = compare_data.begin();
      std::advance(i_compare_data, 2);

      i_compare_data = compare_data.erase_after(i_compare_data);
      i_data         = data.erase_after(i_data);

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
      CHECK(*i_compare_data == *i_data);

      i_compare_data = compare_data.erase_after(compare_data.begin());
      i_data         = data.erase_after(data.begin());

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);

      are_equal = *i_data == *i_compare_data;
      CHECK(are_equal);

      // Move to the last value and erase.
      i_compare_data = compare_data.begin();
      //std::advance(i_compare_data, compare_data.size() - 1);
      i_compare_data = compare_data.erase_after(i_compare_data);

      i_data = data.begin();
      //std::advance(i_data, data.size() - 1);
      i_data = data.erase_after(i_data);

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
      are_equal = *i_data == *i_compare_data;
      CHECK(are_equal);
    }
コード例 #21
0
ファイル: libpfiflash.c プロジェクト: mobilipia/iods
static int compare_volumes(int devno, pfi_ubi_t u, FILE *fp_pfi,
		pdd_func_t pdd_f, char *err_buf, size_t err_buf_size)
{
	int rc, is_bootenv = 0;
	unsigned int i;
	ubi_lib_t ulib = NULL;
	FILE *fp_flash[u->ids_size];

	rc = ubi_open(&ulib);
	if (rc != 0) {
		rc = -PFIFLASH_ERR_UBI_OPEN;
		goto err;
	}

	for (i = 0; i < u->ids_size; i++) {
		if (u->ids[i] == EXAMPLE_BOOTENV_VOL_ID_1 ||
		    u->ids[i] == EXAMPLE_BOOTENV_VOL_ID_2)
			is_bootenv = 1;

		fp_flash[i] = ubi_vol_fopen_read(ulib, devno, u->ids[i]);
		if (fp_flash[i] == NULL) {
			rc = -PFIFLASH_ERR_UBI_OPEN;
			goto err;
		}
	}

	if (is_bootenv)
		rc = compare_bootenv(fp_pfi, fp_flash, u->ids_size,
				u->data_size, pdd_f, err_buf, err_buf_size);
	else
		rc = compare_data(fp_pfi, fp_flash, u->ids_size, u->data_size);

err:
	if (rc < 0)
		EBUF(PFIFLASH_ERRSTR[-rc]);

	for (i = 0; i < u->ids_size; i++)
		fclose(fp_flash[i]);
	if (ulib)
		ubi_close(&ulib);

	return rc;
}
コード例 #22
0
ファイル: a7201.c プロジェクト: Yuanhang123/DoSomething
UINT8 match_data(UINT8 *data_index)
{
	UINT8 Err_index = MATCH_OK;
	UINT8 Ret = FALSE;
	//UINT8 ReBufTemp[12] = {0};
	if(bDataRedly) {
		delay_ms(10);//
		bDataRedly = FALSE;
		Err_index = compare_data(&RxDataBuf[DATA0_ADDR],&RxDataBuf[DATA1_ADDR]);
		if(Err_index == MATCH_OK) {
			*data_index = DATA0_ADDR;
		} else {
			if(RxDataBuf[Err_index] == RxDataBuf[Err_index+DATA2_ADDR]) {
				*data_index = DATA0_ADDR;
			} else {
				*data_index = DATA1_ADDR;
			}
		}
		Ret = TRUE;
	}
	return Ret;
}
コード例 #23
0
    //*************************************************************************
    TEST_FIXTURE(SetupFixture, test_insert_after_position_value)
    {
      const size_t INITIAL_SIZE = 4;
      const ItemNDC VALUE("1");
      const ItemNDC INSERT_VALUE("2");

      CompareDataNDC compare_data(INITIAL_SIZE, VALUE);
      DataNDC data(INITIAL_SIZE, VALUE);

      size_t offset = 2;

      DataNDC::iterator i_data = data.begin();
      std::advance(i_data, offset);

      CompareDataNDC::iterator i_compare_data = compare_data.begin();
      std::advance(i_compare_data, offset);

      data.insert_after(i_data, INSERT_VALUE);
      compare_data.insert_after(i_compare_data, INSERT_VALUE);

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);

      offset = 0;

      i_data = data.begin();
      std::advance(i_data, offset);

      i_compare_data = compare_data.begin();
      std::advance(i_compare_data, offset);

      data.insert_after(i_data, INSERT_VALUE);
      compare_data.insert_after(i_compare_data, INSERT_VALUE);

      are_equal = std::equal(data.begin(), data.end(), compare_data.begin());

      CHECK(are_equal);
    }
// Print stats which have changed from one sorted array to the next.
static void diff_stats(struct data *old_stats, struct data *new_stats) {
    while (old_stats->name != NULL || new_stats->name != NULL) {
        int compare;
        if (old_stats->name == NULL) {
            compare = 1;
        } else if (new_stats->name == NULL) {
            compare = -1;
        } else {
            compare = compare_data(old_stats, new_stats);
        }

        if (compare < 0) {
            // old_stats no longer present
            if (old_stats->value != NULL) {
                printf("%s -\n", old_stats->name);
            }
            ++old_stats;
        } else if (compare > 0) {
            // new_stats is new
            if (new_stats->value != NULL) {
                printf("%s + %s\n", new_stats->name, new_stats->value);
            }
            ++new_stats;
        } else {
            // changed
            if (new_stats->value == NULL) {
                if (old_stats->value != NULL) {
                    printf("%s -\n", old_stats->name);
                }
            } else if (old_stats->value == NULL) {
                printf("%s + %s\n", new_stats->name, new_stats->value);
            } else if (strcmp(old_stats->value, new_stats->value)) {
                printf("%s = %s\n", new_stats->name, new_stats->value);
            }
            ++old_stats;
            ++new_stats;
        }
    }
}
コード例 #25
0
ファイル: diff_bin.c プロジェクト: Martoni/debit
static int
compare_files(const gchar *f1, const gchar *f2) {
  GError *error = NULL;
  GMappedFile *file1 = NULL, *file2 = NULL;
  int err;

  file1 = g_mapped_file_new (f1, FALSE, &error);
  if (error != NULL) {
    file1 = NULL;
    err = -1;
    goto out_err;
  }

  file2 = g_mapped_file_new (f2, FALSE, &error);
  if (error != NULL) {
    file2 = NULL;
    err = -1;
    goto out_err;
  }

  /* Then update */
  err = compare_data(g_mapped_file_get_contents (file1),
		     g_mapped_file_get_length (file1),
		     g_mapped_file_get_contents (file2),
		     g_mapped_file_get_length (file2));

  goto out;

  out_err:
    g_warning ("error opening file: %s",error->message);
    g_error_free (error);
  out:
    if (file1)
      g_mapped_file_free (file1);
    if (file2)
      g_mapped_file_free (file2);
    return err;
}
コード例 #26
0
ファイル: test_pnor_ops.c プロジェクト: DarkStarSword/skiboot
int main(int argc, char **argv)
{
	int fd, i, rc;
	struct pnor pnor;
	uint8_t data[24];
	char filename[24];

	strcpy(filename, "/tmp/pnor-XXXXXX");

	fd = mkstemp(filename);
	if (fd < 0) {
		perror("mkstemp");
		return EXIT_FAILURE;
	}
	/* So the file disappears when we exit */
	unlink(filename);

	/* E for empty */
	memset(data, 'E', sizeof(data));
	for (i = 0; i < 2; i++)
		write(fd, data, 16);

	/* Adjust this if making the file smaller */
	pnor.size = 32;

	/* This is fake. Make it smaller than the size */
	pnor.erasesize = 4;

	printf("Write: ");
	memset(data, 'A', sizeof(data));
	rc = mtd_write(&pnor, fd, data, 0, 23);
	if (rc == 23 && compare_data(fd, test_one))
		printf("PASS\n");
	else
		printf("FAIL: %d\n", rc);

	printf("Read: ");
	memset(data, '0', sizeof(data));
	rc = mtd_read(&pnor, fd, data, 7, 24);
	if (rc == 24 && !memcmp(data, &test_one[7], 24))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Write with offset: ");
	memset(data, 'M', sizeof(data));
	rc = mtd_write(&pnor, fd, data, 24, 8);
	if (rc == 8 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Write size past the end: ");
	rc = mtd_write(&pnor, fd, data, 0, 64);
	if (rc == -1 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL: %d\n", rc);

	printf("Write size past the end with offset: ");
	rc = mtd_write(&pnor, fd, data, 24, 24);
	if (rc == -1 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Write with offset past the end: ");
	rc = mtd_write(&pnor, fd, data, 64, 12);
	if (rc == -1 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Zero sized write: ");
	rc = mtd_write(&pnor, fd, data, 0, 0);
	if (rc == 0 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Zero sized write with offset: ");
	rc = mtd_write(&pnor, fd, data, 12, 0);
	if (rc == 0 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Read size past the end: ");
	rc = mtd_read(&pnor, fd, data, 0, 64);
	if (rc != 0 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");


	printf("Read size past the end with offset: ");
	rc = mtd_read(&pnor, fd, data, 24, 24);
	if (rc != 0 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Read with offset past the end: ");
	rc = mtd_read(&pnor, fd, data, 64, 12);
	if (rc != 0 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Zero sized read: ");
	rc = mtd_read(&pnor, fd, data, 0, 0);
	if (rc == 0 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	printf("Zero sized read with offset: ");
	rc = mtd_read(&pnor, fd, data, 12, 0);
	if (rc == 0 && compare_data(fd, test_three))
		printf("PASS\n");
	else
		printf("FAIL\n");

	return 0;
}
コード例 #27
0
ファイル: judge_function.c プロジェクト: nealgavin/acmjudge
void run_exe_and_check(MYSQL *conn,Submits *submit)
{
	/*****************************
	 * !!!:stdout用freopen 重定向后,定向不回去
	 * 只能先用子进程来解决下了
	 * ***************************/
	char sql[330],path[220];
	MYSQL_ROW row;
	MYSQL_RES *res;

	sprintf(sql,"select time_limit,memory_limit from problem where problem_id='%d'",submit->problem_id);
	mysql_query(conn,sql);
	res = mysql_store_result(conn);
	if((row=mysql_fetch_row(res))!=NULL)
	{
		sscanf(row[0],"%lf",&submit->time);
		sscanf(row[1],"%lf",&submit->memory);
	}
	printf("tim = %f  mem = %f\n",submit->time,submit->memory);
	mysql_free_result(res);
	fflush(stdin);
	fflush(stdout);
	puts("run_exe check");
	pid = fork();
	if(pid == 0)
	{
		puts("in pid here");
		struct rlimit t_limit,m_limit;
		getrlimit(RLIMIT_CPU,&t_limit);
		getrlimit(RLIMIT_DATA,&m_limit);
		t_limit.rlim_cur = submit->time/1000;//s
		t_limit.rlim_max = t_limit.rlim_cur;
		m_limit.rlim_cur = submit->memory*1024;//B
		m_limit.rlim_max = m_limit.rlim_cur;
		
		if(submit->language == 3)
		{
			t_limit.rlim_cur *= 3;
			t_limit.rlim_max = t_limit.rlim_cur;
			m_limit.rlim_cur *= 2;
			m_limit.rlim_max = m_limit.rlim_cur;
		}
		puts("error exits here?");
		setrlimit(RLIMIT_CPU,&t_limit);
		setrlimit(RLIMIT_DATA,&m_limit);

		puts("now runing compare");
		sprintf(path,"./data/%d/data.in",submit->problem_id);
		freopen(path,"r",stdin);
		sprintf(path,"./tmp/%d.out",submit->solution_id);
		freopen(path,"w",stdout);
		
		if(submit->language == 1)
		{
			sprintf(path,"./exe/%d",submit->solution_id);
			ptrace(PTRACE_TRACEME,pid,NULL,NULL);
			execl(path,NULL);
		}
		else if(submit->language == 3)
		{
			sprintf(path,"java ./src/java/%d",submit->solution_id);
			ptrace(PTRACE_TRACEME,pid,NULL,NULL);
			execl("/usr/java/jdk1.7/bin/java","-classpath",path,"Main",NULL);
		}

		fflush(stdin);
		fflush(stdout);
		exit(1);
	}		
		   /**************************
			*wait() 等待子进程结束
			*否则有可能子进程文件未关闭或未写入导致后
			*序的处理文件打开失败
			*************************/
			int result = 0,syscallID,insyscall,status,pstatus,returnValue,tag;
			struct rusage use;
			struct user_regs_struct reg;

		    signal(SIGALRM,TIMEOUT);
			alarm((int)submit->time*2);
			
			status = 0;
			if(setjmp(jmpbuffer))
			{
				status = 999;
				goto PTRACE_OVER;
			}
			wait4(pid,&pstatus,0,&use);
			if(WIFEXITED(pstatus))
				goto PTRACE_OVER;
			/***********************************************
			 * PEEKUSER是往USER区域中写入一个字节偏移为addr
			 * SYSCALL 重新执行
			 * 陷入内核时系统中断把调用号装入EAX寄存器
			 * 系统调用表是32位(4字节)要乘4
			 * ********************************************/
			syscallID = ptrace(PTRACE_PEEKUSER,pid,ORIG_EAX*4,NULL);
			ptrace(PTRACE_SYSCALL,pid,NULL,NULL);
			insyscall = 0;
			tag = 0;
			while(true)
			{
				wait4(pid,&pstatus,0,&use);
				if(WIFEXITED(pstatus)||WIFSIGNALED(pstatus))
					break;
				if(insyscall == 0)
				{
					errno = 0;
					/****读入寄存器信息****/
					ptrace(PTRACE_GETREGS,pid,NULL,&reg);
					insyscall = 1;
					if(submit->language == 1)
					{
						if(syscallID<0 || syscallID>_SYSCALL_NUM || !safeSysCall[syscallID])
						{
							if(syscallID<0 || syscallID>_SYSCALL_NUM)
								{status= RE;puts("RE 1");}
							else 
								status = RF;
							ptrace(PTRACE_DETACH,pid,0,0);
							kill(pid,SIGCONT);
							kill(pid,SIGKILL);
							break;
						}
					}
					else if(submit->language == 3)
					{
						if(syscallID<0 || syscallID>_SYSCALL_NUM || !JavasafeSysCall[syscallID])
						{
							if(syscallID<0 || syscallID>_SYSCALL_NUM)
								{status = RE;puts("RE 2");}
							else
								status = RF;
							ptrace(PTRACE_DETACH,pid,0,0);
							kill(pid,SIGCONT);
							kill(pid,SIGKILL);
							break;
						}
					}
				}
				else
				{
					returnValue=ptrace(PTRACE_PEEKUSER,pid,ORIG_EAX*4,NULL);
					insyscall = 0;
				}
				ptrace(PTRACE_SYSCALL,pid,NULL,NULL);
			}
PTRACE_OVER:
			alarm(0);
			
			if(status == 999)
			{
				status = TLE;
				goto JUDGE_OVER;
			}
			
			if(WIFEXITED(pstatus))
			{
				fflush(stdin);
				fflush(stdout);
				sprintf(path,"./tmp/%d.out",submit->solution_id);
				FILE *user,*std_data;
					user = fopen(path,"r");
				sprintf(path,"./data/%d/data.out",submit->problem_id);
					std_data = fopen(path,"r");
					if(std_data == NULL)
					{
						printf("\tcan't open file %d.out",submit->problem_id);
						submit->result = SYSTEM_ERR;
						update_submit_status(conn,submit);
						exit(1);
					}
				#ifdef DEBUG
					if(user == NULL)
					  puts("user open failed");
				#endif
				result = compare_data(std_data,user);
				status = result;
				puts("compare result is here");
				update_submit_status(conn,submit);
				fclose(std_data);
			}
			else if(WIFSIGNALED(pstatus))
			{
				if(WTERMSIG(pstatus)==SIGXCPU)
				{
					status = TLE;
				}
				else if(WTERMSIG(pstatus)==SIGKILL)
				{
					double passtimeS=(use.ru_stime.tv_sec+use.ru_utime.tv_sec);
					double passtimeU=(use.ru_stime.tv_usec+use.ru_utime.tv_usec)/1000000.0;
					if(passtimeS+passtimeU + 0.0002>submit->time/1000)
					{
						status = TLE;
					}
					else if(pstatus == 9||use.ru_minflt*4>=submit->memory)
					{
						status=MLE;
					}
				}
				else 
					{status = RE;puts("RE 3");}
			}
			else if(WIFSTOPPED(pstatus)&&WSTOPSIG(pstatus)!=5)
				{status = RE;puts("RE 4");}
			printf("mem = %d B pstatus=%d\n",use.ru_minflt*4,pstatus);
JUDGE_OVER:
			submit->result = status;
			if(status == AC || status == PE)
			{

					double passtimeS=(use.ru_stime.tv_sec+use.ru_utime.tv_sec);
					double passtimeU=(use.ru_stime.tv_usec+use.ru_utime.tv_usec)/1000000.0;
					printf("S=%lf U=%lf\n",passtimeS,passtimeU);
					submit->run_t = passtimeS + passtimeU;
					submit->run_m = use.ru_minflt*4/1024;
					printf("~~tm= %d mem = %lf time=%lf\n",use.ru_majflt,submit->run_m,submit->run_t);
				if(status == AC)
				{
					sprintf(sql,"update problem set accepted=accepted+1 where problem_id='%d'",submit->problem_id);
					mysql_query(conn,sql);
					sprintf(sql,"select distinct problem_id from solution where result='1' and user_id='%s' and problem_id='%d'",submit->user_id,submit->problem_id);
					mysql_query(conn,sql);
					res = mysql_store_result(conn);
					if(mysql_fetch_row(res))
					{
						mysql_free_result(res);
					}
					else
					{
						mysql_free_result(res);
						sprintf(sql,"update users set solved=solved+1 where user_id='%s'",submit->user_id);
						mysql_query(conn,sql);
					}
				}
			}
			else
			{
				submit->run_t = 0;
				submit->run_m = 0;
			}
			update_submit_status(conn,submit);
			exit(0);
			return;
}
コード例 #28
0
bool test_softmax_float_cpu_random::run() {
    bool  run_ok = true;
    test_measurement_result   run_result;
    run_result.description = "RUN SUMMARY: " + test_description;

    C_time_control  run_timer;

    std::cout << "-> Testing: " << test_description << std::endl;

    try {
        if( !init() ) throw std::runtime_error( "init() returns false so can't run test" );
        run_timer.tick();   //start time measurement
        run_result << std::string( "run test with " + current_tested_device->get_device_description() );

        NN_WORKLOAD_DATA_TYPE input_format = NN_WORKLOAD_DATA_TYPE_F32_1D_BATCH;
        NN_WORKLOAD_DATA_TYPE output_format = NN_WORKLOAD_DATA_TYPE_F32_1D_BATCH;

        const int softmax_size = 1000;
        for( auto batch : { 1, 8, 48 } ) {
            // ---------------------------------------------------------------------------------------------------------
            {   // simple sample pattern of test with time measuring:
                bool local_ok = true;
                test_measurement_result local_result;
                local_result.description = "RUN PART: (batch " + std::to_string( batch ) + ") execution of " + test_description;
                C_time_control  local_timer;
                // begin local test

                auto input = new nn::data<float>( softmax_size, batch );
                if(input == nullptr)   throw std::runtime_error("unable to create input for batch = " +std::to_string(batch));

                auto workload_output = new nn::data<float>( softmax_size, batch );
                if(workload_output == nullptr)   throw std::runtime_error("unable to create workload_output for batch = " +std::to_string(batch));

                nn_data_populate( workload_output, 0.0f );

                nn_data_populate( input, 0.0f, 20.0f );

                nn_workload_t *workload = nullptr;
                nn_data_t *input_array[1] = { input };
                nn::data<float> *output_array_cmpl[1] = { nn::data_cast<float, 0>(workload_output) };

                auto status = di->workflow_compile_function( &workload, di->device, workflow, &input_format, &output_format, batch );
                if( !workload ) throw std::runtime_error( "workload compilation failed for batch = " + std::to_string( batch )
                                                          + " status: " + std::to_string( status ) );

                di->workload_execute_function( workload, reinterpret_cast<void**>(input_array), reinterpret_cast<void**>(output_array_cmpl), &status );

                auto naive_output = cpu_layer_softmax( input );

                local_ok = compare_data(workload_output, naive_output);

                // end of local test
                // summary:
                local_timer.tock();
                local_result.time_consumed = local_timer.get_time_diff();
                local_result.clocks_consumed = local_timer.get_clocks_diff();
                local_result.passed = local_ok;
                tests_results << local_result;

                run_ok = run_ok && local_ok;

                if( input )           delete input;
                if( workload_output ) delete workload_output;
                if( naive_output )    delete naive_output;
                if( workload )        delete workload;

            } // The pattern, of complex instruction above, can be multiplied
            // END of run tests
            // ---------------------------------------------------------------------------------------------------------
        }
    } catch( std::runtime_error &error ) {
        run_result << "error: " + std::string( error.what() );
        run_ok = false;
    } catch( std::exception &error ) {
        run_result << "error: " + std::string( error.what() );
        run_ok = false;
    } catch( ... ) {
        run_result << "unknown error";
        run_ok = false;
    }

    run_timer.tock();
    run_result.time_consumed = run_timer.get_time_diff();
    run_result.clocks_consumed = run_timer.get_clocks_diff();

    run_result.passed = run_ok;
    tests_results << run_result;
    if( !done() ) run_ok = false;
    std::cout << "<- Test " << (run_ok ? "passed" : "failed") << std::endl;;
    return run_ok;
}
コード例 #29
0
ファイル: test_view.cpp プロジェクト: Yeongjae/idlf
bool test_view::run() {
    bool  run_ok = true;
    test_measurement_result   run_result;
    run_result.description = "RUN SUMMARY: " + test_description;

    C_time_control  run_timer;

    std::cout << "-> Testing: " << test_description << std::endl;
    try {
        if( !init() ) throw std::runtime_error( "init() returns false so can't run test" );
        run_timer.tick();   //start time measurement
        run_result << std::string( "run test with " + current_tested_device->get_device_description() );

        NN_WORKLOAD_DATA_TYPE input_format  = NN_WORKLOAD_DATA_TYPE_F32_3D_BATCH;
        NN_WORKLOAD_DATA_TYPE output_format = NN_WORKLOAD_DATA_TYPE_F32_3D_BATCH;

        std::mt19937 generator( 1 );
        std::uniform_int_distribution<uint32_t> distribution( 0, 56/2 );

        auto compare_data = [](nn::workload_data<nn::layout_f32>& item, nn::data<float>& ref_item) {
                float relative_error_threshold = 1e-3f,
                      absolute_error_threshold = 1e-6f,
                      absoulte_error_limit     = 1e-4f;

                uint32_t size_n = item.get_length(0),
                         size_x = item.get_length(1),
                         size_y = item.get_length(2),
                         size_z = item.get_length(3);

                for(uint32_t n = 0; n < size_n; ++n)
                    for(uint32_t z = 0; z < size_z; ++z)
                        for( uint32_t y = 0; y < size_y; ++y )
                            for( uint32_t x = 0; x < size_x; ++x ) {
                                float workload_val = item.at(n, x, y, z, 0, 0);
                                float ref_val      = ref_item.at(z, x, y, n);

                                 if( fabs(workload_val) < absoulte_error_limit) {
                                    if(fabs( workload_val - ref_val ) > absolute_error_threshold) {
                                        return false;
                                    }
                                } else
                                    if(fabs(workload_val - ref_val) / fabs(ref_val) > relative_error_threshold)
                                        return false;
                            }
            return true;
        };

        for( uint32_t batch : { 1, 8, 48 } ) {
            // simple sample pattern of test with time measuring:
            bool local_ok = true;
            test_measurement_result local_result;
            local_result.description = "RUN PART: (batch " + std::to_string( batch ) + ") execution of " + test_description;
            C_time_control  local_timer;

            for(uint32_t size_x : { 5,16,56 }) {
                for(uint32_t size_y : { 5,16,56 }) {
                    for(uint32_t size_z : { 1,8,16 }) {
                        // ---------------------------------------------------------------------------------------------------------
                        // begin local test
                        auto input = new nn::data<float>(size_z,size_x,size_y,batch);
                        if(input == nullptr)   throw std::runtime_error("unable to create input nn::data for batch = " +std::to_string(batch));

                        nn_data_populate(input,-100.0f,100.0f);
                        auto wrkld_data = new nn::workload_data<nn::layout_f32>(input->buffer,
                                                                                {batch,size_x,size_y,size_z,1,1},
                                                                                 nn::data_helper_layout_lookup_zxynpq<float>()
                                                                               );
                        if(wrkld_data == nullptr) {
                            delete input;
                            throw std::runtime_error("unable to create wrkld_data for batch = " +std::to_string(batch));
                        }

                        nn_workload_data_coords_t* view_begin_coords,*view_end_coords;
                        { // create random view
                            view_begin_coords = new nn_workload_data_coords_t{
                                distribution(generator) % batch,
                                distribution(generator) % size_x,
                                distribution(generator) % size_y,
                                distribution(generator) % size_z,
                                0,
                                0
                            };
                            if(view_begin_coords == nullptr) {
                                delete input;
                                delete wrkld_data;
                                throw std::runtime_error("unable to create view_begin_coords for batch = " +std::to_string(batch));
                            }

                            view_end_coords  = new nn_workload_data_coords_t{
                                distribution(generator) % batch,
                                distribution(generator) % size_x,
                                distribution(generator) % size_y,
                                distribution(generator) % size_z,
                                0,
                                0
                            };
                            if(view_end_coords == nullptr) {
                                delete input;
                                delete wrkld_data;
                                delete view_begin_coords;
                                throw std::runtime_error("unable to create view_end_coords for batch = " +std::to_string(batch));
                            }

                            for(int i = 0 ; i <= 4 ; ++i)
                                if(view_begin_coords->t[i] > view_end_coords->t[i]) {
                                    std::swap(view_begin_coords->t[i],view_end_coords->t[i]);
                                }
                        }

                        // create view
                        auto workload_output = new nn::workload_data<nn::layout_f32>(*wrkld_data,*view_begin_coords,*view_end_coords);
                        if(workload_output == nullptr) {
                            delete input;
                            delete wrkld_data;
                            delete view_begin_coords;
                            delete view_end_coords;
                            delete workload_output;
                            throw std::runtime_error("unable to create workload_output nn::workload_data for batch = " +std::to_string(batch));
                        }

                        // naive view
                        auto naive_output = naive_view(*input,*view_begin_coords,*view_end_coords);

                        local_ok = compare_data(*workload_output,*naive_output);

                        if(input)            delete input;
                        if(workload_output)  delete workload_output;
                        if(naive_output)     delete naive_output;
                        if(view_begin_coords)delete view_begin_coords;
                        if(view_end_coords)  delete view_end_coords;
                        if(wrkld_data)       delete wrkld_data;
                        // END of run tests
                        // ---------------------------------------------------------------------------------------------------------
                    } // The pattern, of complex instruction above, can be multiplied
                }
            }
            // end of local test
            // summary:
            local_timer.tock();
            local_result.time_consumed = local_timer.get_time_diff();
            local_result.clocks_consumed = local_timer.get_clocks_diff();
            local_result.passed = local_ok;
            tests_results << local_result;

            run_ok = run_ok && local_ok;
        }
    }
    catch(std::runtime_error &error) {
        run_result << "error: " + std::string(error.what());
        run_ok = false;
    }
    catch(std::exception &error) {
        run_result << "error: " + std::string(error.what());
        run_ok = false;
    }
    catch(...) {
        run_result << "unknown error";
        run_ok = false;
    }
    run_timer.tock();
    run_result.time_consumed = run_timer.get_time_diff();
    run_result.clocks_consumed = run_timer.get_clocks_diff();

    run_result.passed = run_ok;
    tests_results << run_result;
    if(!done()) run_ok = false;
    std::cout << "<- Test " << (run_ok ? "passed" : "failed") << std::endl;
    return run_ok;
}