Example #1
0
/**
 * \internal
 * \brief Test drawing a filled rectangle to the every other page of the
 * display
 *
 * This test draws a filled rectangle to every other page of a display and
 * checks that every other page is filled and the rest are empty.
 *
 * \param test Current test case.
 */
static void run_draw_rectangles_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_set[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill expected page buffers
	set_buffer(expected_set, 0xFF);
	set_buffer(expected_empty, 0x00);

	// Fill every other page
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		if (page % 2 == 0) {
			gfx_mono_draw_filled_rect(0, LCD_PAGE_HEIGHT * page,
					GFX_MONO_LCD_WIDTH, LCD_PAGE_HEIGHT, GFX_PIXEL_SET);
		}
	}

	// Get all pages from display and check that every other is filled
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page % 2 == 0) {
			test_assert_true(test, is_page_correct(actual, expected_set),
					"Set page %d not matching expected page", page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #2
0
/**
 * Test nvm_user_sig_write_buffer().
 *
 * Test procedure:
 * - Erase and write to user signature row with some known values
 * - Write other values to user signature row with automatic erasing disabled
 * - Verify contents is NOT equal to buffer
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_write_no_erase(void)
{
	// Clear memory buffer
	set_buffer(buffer, FLASH_ERASED);

	// Set some test values
	buffer[0] = 0xAA;
	buffer[1] = 0xEE;
	buffer[2] = 0xAA;
	buffer[3] = 0xEE;

	// Erase and write data to user signature row:
	nvm_user_sig_write_buffer(TEST_ADDR, &buffer, BUFFER_SIZE, true);

	// Clear memory buffer
	set_buffer(buffer, FLASH_ERASED);

	// Set some other test values
	buffer[0] = 0xCA;
	buffer[1] = 0xFE;
	buffer[2] = 0xBA;
	buffer[3] = 0xBE;

	// Write test values to user signature row without erasing:
	nvm_user_sig_write_buffer(TEST_ADDR, &buffer, BUFFER_SIZE, false);

	// Verify that contents is not equal:
	if (is_user_sig_equal_to_buffer(TEST_ADDR, buffer, BUFFER_SIZE)) {
		return ERR_BAD_DATA;
	}

	return STATUS_OK;
}
Example #3
0
/**
 * \brief Test AES decryption function.
 *
 * This test decrypts the pre-encrypted data and checks
 * whether it is correct.
 *
 * \param test Current test case.
 */
static void run_aes_decryption_test(const struct test_case *test)
{
	t_key decrypted_data;
	bool  success;

	set_buffer(decrypted_data, 0x00);
	set_buffer(lastsubkey, 0x00);

	/* Call helper function to generate a last subkey for decryption */
	if (!aes_lastsubkey_generate(encryption_key, lastsubkey)) {
		success = false;
		test_assert_true(test, !success,
				"Could not generate last subkey");
	} else {
		/* Configure module for manual decryption */
		aes_software_reset();
		aes_set_key(lastsubkey);
		aes_configure(AES_DECRYPT, AES_MANUAL, AES_XOR_OFF);
		aes_write_inputdata(pre_encrypted_data);

		aes_start();

		do {
			/* Wait until AES is finished or an error occurs. */
		} while (aes_is_busy());

		aes_read_outputdata(decrypted_data);

		/* Verify that the decrypted data is correct */
		success = compare_data_block(decrypted_data, encryption_data);

		test_assert_true(test, success,
				"Decrypted values do not match excepted values");
	}
}
Example #4
0
/**
 * \internal
 * \brief Test drawing the outline of a rectangle spanning two pages
 *
 * This test draws the outline of a rectangle spanning two pages and checks
 * that this is done.
 *
 * \param test Current test case.
 */
static void run_draw_rectangle_outline_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page1[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page2[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;
	uint8_t i;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill page buffer holding first part of rectangle
	set_buffer(expected_page1, 0x00);
	expected_page1[5] = 0xE0;
	for (i = 1; i < 99; i++) {
		expected_page1[i + 5] = 0x20;
	}
	expected_page1[99 + 5] = 0xE0;

	// Fill page buffer holding second part of rectangle
	set_buffer(expected_page2, 0x00);
	expected_page2[5] = 0x7F;
	for (i = 1; i < 99; i++) {
		expected_page2[i + 5] = 0x40;
	}
	expected_page2[99 + 5] = 0x7F;

	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Draw the outline of a 100x10 rectangle at position 5, 5
	gfx_mono_draw_rect(5, 5, 100, 10, GFX_PIXEL_SET);

	// Get all pages from display and check that the rectangle is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 0) {
			test_assert_true(test, is_page_correct(actual, expected_page1),
					"Page %d with rectangle not matching expected page",
					page);
		} else if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page2),
					"Page %d with rectangle not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #5
0
/**
 * Each thread initializes the buffers in the local NUMA node for memory copy
 * in the next phase.
 */
void *buf_init_func(void *arg)
{
	int i, j;
	struct buf_init_data *data = (struct buf_init_data *) arg;

	bind2node_id(data->node_id);
	for (i = 0; i < NUM_NODES; i++) {
		for (j = 0; j < NUM_THREADS; j++) {
			/*
			 * For remote memory access, NUM_NODES * NUM_THREADS pieces of
			 * memory are allocated, even though only (NUM_NODES - 1) * NUM_THREADS
			 * pieces of memory are actually used.
			 * For local memory access, only NUM_THREADS pieces of memory
			 * are allocated.
			 */
			if (/*(i == data->node_id && use_remote)
					||*/ (i != data->node_id && !use_remote)) {
				init_buffer(&data->src_bufs[i][j]);
				init_buffer(&data->local_bufs[i][j]);
			}
			if ((/*i != data->node_id && */use_remote)
					|| (i == data->node_id && !use_remote)) {
				char *buf;
				
				if (data->mode == MEMCPY_PULL || data->mode == MEMCPY_PUSH
						|| data->mode == MEMCPY_R2R || data->mode == MEMREAD) {
					buf = (char *) numa_alloc_onnode(data->buf_size,
							data->node_id);
					materialize_buf(buf, data->buf_size);
					set_buffer(&data->src_bufs[i][j], buf, data->buf_size,
							data->node_id);
				}
				else
					init_buffer(&data->src_bufs[i][j]);

				if (data->mode == MEMCPY_PULL || data->mode == MEMCPY_PUSH
						|| data->mode == MEMCPY_R2R || data->mode == MEMWRITE) {
					buf = (char *) numa_alloc_onnode(data->buf_size,
							data->node_id);
					materialize_buf(buf, data->buf_size);
					set_buffer(&data->local_bufs[i][j], buf, data->buf_size,
							data->node_id);
				}
				else
					init_buffer(&data->local_bufs[i][j]);
			}
		}
	}
	return NULL;
}
Example #6
0
void cell_syncproc_z( struct Cell *** theCells , struct Sim *theSim,struct MPIsetup * theMPIsetup){
  if (sim_N_global(theSim,Z_DIR)>1){
    //set indices for convenience
    int kNm2g = sim_N(theSim,Z_DIR)-2*sim_Nghost_max(theSim,Z_DIR);
    int kNmg  = sim_N(theSim,Z_DIR)-sim_Nghost_max(theSim,Z_DIR);
    int kN    = sim_N(theSim,Z_DIR);
    int k0  = 0;
    int kg  = sim_Nghost_min(theSim,Z_DIR);
    int k2g = 2*sim_Nghost_min(theSim,Z_DIR);
    int i0 = 0;
    int iN = sim_N(theSim,R_DIR);

    // find buffer sizes
    int buffersize_z_hi_send = get_buffersize(i0,iN, kNm2g,kNmg,theSim);
    int buffersize_z_hi_recv = get_buffersize(i0,iN,kNmg,kN,theSim);
    // allocate memory for buffers
    double * buffer_z_hi_send = malloc(sizeof(double)*buffersize_z_hi_send);
    double * buffer_z_hi_recv = malloc(sizeof(double)*buffersize_z_hi_recv);
    // set buffer with data from upper edge of this processor
    set_buffer(i0,iN, kNm2g,kNmg,theSim,theCells,buffer_z_hi_send);

    // find buffer sizes
    int buffersize_z_low_send = get_buffersize(i0,iN,kg, k2g,theSim);
    int buffersize_z_low_recv = get_buffersize(i0,iN,k0,kg,theSim);
    // allocate memory for buffers
    double * buffer_z_low_send = malloc(sizeof(double)*buffersize_z_low_send);
    double * buffer_z_low_recv = malloc(sizeof(double)*buffersize_z_low_recv);
    // set buffer with data from lower edge of this processor
    set_buffer(i0,iN,kg,k2g,theSim,theCells,buffer_z_low_send);

    MPI_Status status;
    // send your lower buffer to the downward proc. recieve your upper buffer from the upward proc.
    MPI_Sendrecv(buffer_z_low_send,buffersize_z_low_send,MPI_DOUBLE,mpisetup_left_Proc(theMPIsetup,Z_DIR),14,
        buffer_z_hi_recv,buffersize_z_hi_recv,MPI_DOUBLE,mpisetup_right_Proc(theMPIsetup,Z_DIR),14,sim_comm,&status);
    // send your upper buffer to the upward proc. recieve your lower buffer from the downward proc.
    MPI_Sendrecv(buffer_z_hi_send,buffersize_z_hi_send,MPI_DOUBLE,mpisetup_right_Proc(theMPIsetup,Z_DIR),15,
        buffer_z_low_recv,buffersize_z_low_recv,MPI_DOUBLE,mpisetup_left_Proc(theMPIsetup,Z_DIR),15,sim_comm,&status);

    // fill your upper ghost zones with the buffer you recieved
    set_cells(i0,iN,kNmg,kN,theSim,theCells,buffer_z_hi_recv);
    // fill your lower ghost zones with the buffer you recieved
    set_cells(i0,iN,k0,kg,theSim,theCells,buffer_z_low_recv);

    //cleanup
    free(buffer_z_low_send);
    free(buffer_z_low_recv);    
    free(buffer_z_hi_send);
    free(buffer_z_hi_recv);
  }
}
Example #7
0
/**
 * \internal
 * \brief Test drawing a filled rectangle spanning two pages
 *
 * This test draws a filled rectangle spanning two pages and checks that this
 * is done.
 *
 * \param test Current test case.
 */
static void run_draw_rectangle_two_pages_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page1[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page2[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;
	uint8_t i;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill page buffer holding first part of rectangle
	set_buffer(expected_page1, 0x00);
	for (i = 0; i < 10; i++) {
		expected_page1[i + 48] = 0x80;
	}

	// Fill page buffer holding second part of rectangle
	set_buffer(expected_page2, 0x00);
	for (i = 0; i < 10; i++) {
		expected_page2[i + 48] = 0x7F;
	}

	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Draw a 10x8 filled rectangle at position 48, 15
	gfx_mono_draw_filled_rect(48, 15, 10, 8, GFX_PIXEL_SET);

	// Get all pages from display and check that the rectangle is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page1),
					"First page %d with rectangle not matching expected page",
					page);
		} else if (page == 2) {
			test_assert_true(test, is_page_correct(actual, expected_page2),
					"Second page %d with rectangle not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #8
0
/**
 * Test nvm_user_sig_read_buffer().
 *
 * Test procedure:
 * - Write to user signature row
 * - Read back with nvm_user_sig_read_buffer().
 * - Verify contents
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_read(void)
{
	uint8_t i;
	uint8_t mybuffer[BUFFER_SIZE];

	// Clear memory buffer
	set_buffer(buffer, FLASH_ERASED);

	// Set some test values
	buffer[0] = 0xB0;
	buffer[1] = 0x0B;
	buffer[2] = 0xB0;
	buffer[3] = 0x0B;
	buffer[4] = 0xB0;
	buffer[5] = 0x0B;

	// Erase and write test values to user signature row
	nvm_user_sig_write_buffer(TEST_ADDR, &buffer, BUFFER_SIZE, true);

	// Read back
	nvm_user_sig_read_buffer(TEST_ADDR, mybuffer, BUFFER_SIZE);

	// Verify
	for (i=0; i < BUFFER_SIZE; i++) {
		if (buffer[i] != mybuffer[i]) {
			return ERR_BAD_DATA;
		}
	}

	return STATUS_OK;
}
Example #9
0
File: cd.c Project: ExPl0siF/42sh
t_cmd	*cd(t_cmd  *cmd)
{
  char	*home;
  char  buffer[8192];
  int	ok;

  set_buffer(buffer, &ok, cmd);
  if ((size_wordtab(cmd->tabx)) > 1)
    if ((my_strcmp(cmd->tabx[1], "-")) == 0)
      cmd = cd_oldpwd(cmd);
    else
      ok = chdir(cmd->tabx[1]);
  else
    {
      if ((home = get_info("HOME", cmd->lenv)) == NULL)
	{
	  cmd->retour = 1;
	  my_fdputstr("bash: cd: HOME not set\n", cmd->fdout);
	  return (cmd);
	}
      ok = chdir(home);
    }
  if (ok < 0)
    error_cd(cmd->tabx, home, cmd);
  else if (ok >= 0 && cmd->retour == 0)
    set_oldpwd(cmd, buffer);
  return (cmd);
}
Example #10
0
/**
 * \brief Test EEPROM write buffer
 *
 * This test erases test page \ref TEST_WRITE_BUFFER_PAGE then writes a buffer
 * to the test page, and then overwrites this with the another buffer and checks
 * that the last buffer written is what the page is containing.
 *
 * \param test Current test case.
 */
static void run_eeprom_write_buffer_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0x11;
	buffer[1] = 0xaa;
	buffer[2] = 0xee;
	buffer[3] = 0x22;

	// Erase page
	nvm_eeprom_erase_bytes_in_page(TEST_WRITE_BUFFER_PAGE);
	// Write buffer to EEPROM
	nvm_eeprom_erase_and_write_buffer(TEST_WRITE_BUFFER_PAGE *
			EEPROM_PAGE_SIZE, &buffer, EEPROM_PAGE_SIZE);
	/* Write another buffer to EEPROM to make sure EEPROM is deleted before
	 * written to.
	*/
	buffer[0] = 0x33;
	buffer[1] = 0x11;
	buffer[2] = 0xee;
	buffer[3] = 0xaa;
	nvm_eeprom_erase_and_write_buffer(TEST_WRITE_BUFFER_PAGE *
			EEPROM_PAGE_SIZE, &buffer, EEPROM_PAGE_SIZE);

	// Check that what we have written is in EEPROM.
	success = is_eeprom_page_equal_to_buffer(TEST_WRITE_BUFFER_PAGE, buffer);

	test_assert_true(test, success, "Write buffer failed");
}
Example #11
0
/**
 * \brief Test EEPROM read buffer
 *
 * This test erases test page \ref TEST_READ_BUFFER_PAGE then writes four bytes
 * to the test page and tries to read the entire page using
 * nvm_eeprom_read_buffer.
 * It then compares the read page with what's actually in the EEPROM page.
 *
 * \param test Current test case.
 */
static void run_eeprom_read_buffer_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	uint8_t buffer_read[EEPROM_PAGE_SIZE];
	bool    success;

	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0x11;
	buffer[1] = 0xaa;
	buffer[2] = 0xee;
	buffer[3] = 0x22;

	// Erase page
	nvm_eeprom_erase_bytes_in_page(TEST_READ_BUFFER_PAGE);

	// Write 4 bytes into page:
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 0,
			buffer[0]);
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 1,
			buffer[1]);
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 2,
			buffer[2]);
	nvm_eeprom_write_byte(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE + 3,
			buffer[3]);

	nvm_eeprom_read_buffer(TEST_READ_BUFFER_PAGE * EEPROM_PAGE_SIZE,
			&buffer_read, EEPROM_PAGE_SIZE);

	// Check that what we have read is actually what's in EEPROM.
	success = is_eeprom_page_equal_to_buffer(TEST_READ_BUFFER_PAGE,
			buffer_read);

	test_assert_true(test, success, "Read buffer failed");
}
Example #12
0
/**
 * \brief Test EEPROM atomic write
 *
 * This test erases test page \ref TEST_ATOMIC_WRITE_PAGE, then writes the first
 * byte in the page buffer before flushing it -- this byte should then not be
 * written to the EEPROM -- and writing different values to the two successive
 * bytes. An atomic write is then executed before the write of the latter two
 * bytes is verified.
 *
 * \param test Current test case.
 */
static void run_eeprom_atomic_write_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	nvm_eeprom_erase_page(TEST_ATOMIC_WRITE_PAGE);

	/* Load a dummy byte and then flush the buffer to remove the byte from
	 * the buffer. The byte should not be written to the EEPROM.
	 */
	nvm_eeprom_load_byte_to_buffer(0, 55);
	nvm_eeprom_flush_buffer();

	/* Load some additional bytes */
	set_buffer(buffer, EEPROM_ERASED);
	buffer[1] = 0xaa;
	buffer[2] = 0x19;
	nvm_eeprom_load_byte_to_buffer(1, buffer[1]);
	nvm_eeprom_load_byte_to_buffer(2, buffer[2]);
	/* Erase and then write page */
	nvm_eeprom_atomic_write_page(TEST_ATOMIC_WRITE_PAGE);

	success = is_eeprom_page_equal_to_buffer(TEST_ATOMIC_WRITE_PAGE, buffer);
	test_assert_true(test, success,
			"Page buffer flush, byte load or atomic write failed");
}
Example #13
0
/**
 * Test nvm_eeprom_erase_bytes_in_page() and
 * nvm_eeprom_erase_bytes_in_all_pages()
 *
 * Test procedure:
 * - Write two bytes into page TEST_ERASE_BYTES_PAGE_1 and
 *   TEST_ERASE_BYTES_PAGE_2
 * - Load value to page buffer in the address of the first byte
 * - Erase first byte of TEST_ERASE_BYTES_PAGE_1
 * - Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_1
 * - Load value to page buffer in the address of the first byte
 * - Erase first byte of all pages
 * - Verify that first byte is deleted in TEST_ERASE_BYTES_PAGE_2
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_erase_bytes(void)
{
	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0xaa;
	buffer[1] = 0xaf;

	/* Write two bytes into first page */
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 0, buffer[0]);
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_1 * EEPROM_PAGE_SIZE + 1, buffer[1]);

	/* Write two bytes into second page */
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 0, buffer[0]);
	nvm_eeprom_write_byte(TEST_ERASE_BYTES_PAGE_2 * EEPROM_PAGE_SIZE + 1, buffer[1]);

	/* Erase first byte of the first page */
	nvm_eeprom_load_byte_to_buffer(0, 0xff);
	nvm_eeprom_erase_bytes_in_page(TEST_ERASE_BYTES_PAGE_1);
	buffer[0] = EEPROM_ERASED;

	if (is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_1, buffer)) {
		/* Erase first byte of all pages */
		nvm_eeprom_load_byte_to_buffer(0, 0xff);
		nvm_eeprom_erase_bytes_in_all_pages();

		if (is_eeprom_page_equal_to_buffer(TEST_ERASE_BYTES_PAGE_2, buffer)) {
			return STATUS_OK;
		}
	}

	return ERR_BAD_DATA;
}
Example #14
0
/**
 * Test nvm_eeprom_load_byte_to_buffer(), nvm_eeprom_flush_buffer() and
 * nvm_eeprom_atomic_write_page()
 *
 * Test procedure:
 * - Erase the TEST_ATOMIC_WRITE_PAGE page.
 * - Load byte and then flush the buffer at one location.
 * - Load two more bytes at a different location.
 * - Write the page.
 * - Verify that only two bytes are written and the rest of the page is erased.
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_atomic_write(void)
{
	nvm_eeprom_erase_page(TEST_ATOMIC_WRITE_PAGE);

	/* Load a dummy byte and then flush the buffer to remove the byte from
	 * the buffer. The byte should not be written to the EEPROM.
	 */
	nvm_eeprom_load_byte_to_buffer(0, 55);
	nvm_eeprom_flush_buffer();

	/* Load some additional bytes */
	set_buffer(buffer, EEPROM_ERASED);
	buffer[1] = 0xaa;
	buffer[2] = 0x19;
	nvm_eeprom_load_byte_to_buffer(1, buffer[1]);
	nvm_eeprom_load_byte_to_buffer(2, buffer[2]);
	/* Erase and then write page */
	nvm_eeprom_atomic_write_page(TEST_ATOMIC_WRITE_PAGE);

	if (is_eeprom_page_equal_to_buffer(TEST_ATOMIC_WRITE_PAGE, buffer)) {
		return STATUS_OK;
	}

	return ERR_BAD_DATA;
}
Example #15
0
/**
 * \internal
 * \brief Test drawing a line between to points
 *
 * This test draws a line between two points and checks that this is done.
 *
 * \param test Current test case.
 */
static void run_draw_diagonal_line_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page1[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page2[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill first page buffer holding the line
	set_buffer(expected_page1, 0x00);
	expected_page1[0] = 0x03;
	expected_page1[1] = 0x0C;
	expected_page1[2] = 0x30;
	expected_page1[3] = 0xC0;

	// Fill second page buffer holding the line
	set_buffer(expected_page2, 0x00);
	expected_page2[4] = 0x01;
	
	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Draw a line between 0,0 and 4, 8
	gfx_mono_draw_line(0, 0, 4, 8, GFX_PIXEL_SET);

	// Get all pages from display and check that the line is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 0) {
			test_assert_true(test, is_page_correct(actual, expected_page1),
					"Page %d with line not matching expected page",
					page);
		} else if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page2),
					"Page %d with line not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #16
0
static CURLcode init_environment(struct Curl_easy *data,
                                 gsk_handle *envir, const char *appid,
                                 const char *file, const char *label,
                                 const char *password)
{
  int rc;
  CURLcode result;
  gsk_handle h;

  /* Creates the GSKit environment. */

  rc = gsk_environment_open(&h);
  switch (rc) {
  case GSK_OK:
    break;
  case GSK_INSUFFICIENT_STORAGE:
    return CURLE_OUT_OF_MEMORY;
  default:
    failf(data, "gsk_environment_open(): %s", gsk_strerror(rc));
    return CURLE_SSL_CONNECT_ERROR;
  }

  result = set_enum(data, h, GSK_SESSION_TYPE, GSK_CLIENT_SESSION, FALSE);
  if(!result && appid)
    result = set_buffer(data, h, GSK_OS400_APPLICATION_ID, appid, FALSE);
  if(!result && file)
    result = set_buffer(data, h, GSK_KEYRING_FILE, file, FALSE);
  if(!result && label)
    result = set_buffer(data, h, GSK_KEYRING_LABEL, label, FALSE);
  if(!result && password)
    result = set_buffer(data, h, GSK_KEYRING_PW, password, FALSE);

  if(!result) {
    /* Locate CAs, Client certificate and key according to our settings.
       Note: this call may be blocking for some tenths of seconds. */
    result = gskit_status(data, gsk_environment_init(h),
                          "gsk_environment_init()", CURLE_SSL_CERTPROBLEM);
    if(!result) {
      *envir = h;
      return result;
    }
  }
  /* Error: rollback. */
  gsk_environment_close(&h);
  return result;
}
Example #17
0
static void
dispose (GObject *gobject)
{
  GeglSampler *sampler = GEGL_SAMPLER (gobject);

  /* This call handles unreffing the buffer and disconnecting signals */
  set_buffer (sampler, NULL);

  G_OBJECT_CLASS (gegl_sampler_parent_class)->dispose (gobject);
}
Example #18
0
/**
 * \internal
 * \brief Test drawing a vertical line
 *
 * This test draws a vertical line and checks that this is done.
 *
 * \param test Current test case.
 */
static void run_draw_vertical_line_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page1[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page2[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill page buffer holding the top of the line
	set_buffer(expected_page1, 0x00);
	expected_page1[4] = 0xFC;

	// Fill page buffer holding the bottom of the line
	set_buffer(expected_page2, 0x00);
	expected_page2[4] = 0x1F;

	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Draw a vertical line at position 4, 2 with length 11
	gfx_mono_draw_vertical_line(4, 2, 11, GFX_PIXEL_SET);

	// Get all pages from display and check that the line is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 0) {
			test_assert_true(test, is_page_correct(actual, expected_page1),
					"Page %d with line not matching expected page",
					page);
		} else if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page2),
					"Page %d with line not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #19
0
/**
 * \brief Run encryption, then decryption. Announce end by interrupt.
 *
 * This test encrypts a data block, decrypts it, and checks if it's
 * correct with respect to the input data block. Utilizes interrupts
 * to let the software know when a encryption/decryption is done.
 * AUTO mode will be used in this test.
 *
 * \param test Current test case.
 */
static void run_aes_encrypt_and_decrypt_test(const struct test_case *test)
{
	bool success = true;

	set_buffer(output_data, 0x00);
	set_buffer(lastsubkey, 0x00);

	aes_software_reset();

	/* Configure AES for automatic mode, with XOR, and interrupt. */
	aes_configure(AES_ENCRYPT, AES_AUTO, AES_XOR_ON);
	aes_isr_configure(AES_INTLVL_LO);
	aes_set_key(encryption_key);
	aes_write_inputdata(encryption_data);

	/*
	 * Wait for it to end, since we actually don't have
	 * anything better to do
	 */
	while (!aes_is_finished) {
		/* Intentionally left empty */
	}

	/* output_data should now contain encrypted data */

	/* Configure AES for automatic mode, XOR off. Last subkey
	 * is already in the module, so we don't need to load it
	 */
	aes_is_finished = false;
	aes_configure(AES_DECRYPT, AES_AUTO, AES_XOR_OFF);
	aes_write_inputdata(output_data);

	while (!aes_is_finished) {
		/* Intentionally left empty */
	}

	/* The AES module should be finished now, and output_data
	 * should contain our initial data. */
	success = compare_data_block(output_data, encryption_data);

	test_assert_true(test, success,
			"End values do not match start values");
}
Example #20
0
	//-----------------------------------------------------------------//
	void audio_io::test_stream(const char* filename)
	{
		static const int numbuff = 16;
		static const int bufsize = 4096;

		utils::fileio fin;
		if(!fin.open(filename, "rb")) {
			return;
		}
		wavio wav;
		audio_info info;
		wav.open_stream(fin, bufsize, info);
		const i_audio* aif = wav.get_stream();
		if(aif == 0) {
			wav.close_stream();
			fin.close();
			return;
		}

		int cnt = 0;

		ALuint source;
		alGenSources(1, &source);
		size_t pos = 0;
		while(pos < info.samples) {
			ALint n;
			alGetSourcei(source, AL_BUFFERS_QUEUED, &n);
			ALuint buffer;
			if(n < numbuff) {
				alGenBuffers(1, &buffer);
				++cnt;
			} else {
				ALint state;
				alGetSourcei(source, AL_SOURCE_STATE, &state);
				if(state != AL_PLAYING) {
					alSourcePlay(source);
				}
				while(alGetSourcei(source, AL_BUFFERS_PROCESSED, &n), n == 0) {
					useconds_t usec = 1000 * 10;	//[ms]
					usleep(usec);
				}
				alSourceUnqueueBuffers(source, 1, &buffer);
			}
			pos += wav.read_stream(fin, pos, bufsize);
			set_buffer(buffer, aif);
			alSourceQueueBuffers(source, 1, &buffer);
		}
		alDeleteSources(1, &source);

		wav.close_stream();
		fin.close();

		std::cout << boost::format("buffer: %d\n") % cnt;
	}
Example #21
0
/**
 * \brief Test EEPROM erase
 *
 * This test writes a single byte to test page \ref TEST_ERASE_PAGE, then erases
 * _all_ pages and checks that the test page contains only \ref EEPROM_ERASED.
 *
 * \param test Current test case.
 */
static void run_eeprom_erase_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	nvm_eeprom_write_byte(TEST_ERASE_PAGE * EEPROM_PAGE_SIZE, 42);
	nvm_eeprom_erase_all();
	set_buffer(buffer, EEPROM_ERASED);

	success = is_eeprom_page_equal_to_buffer(TEST_ERASE_PAGE, buffer);
	test_assert_true(test, success, "Page was not erased");
}
Example #22
0
/**
 * Test nvm_eeprom_erase_all().
 *
 * Test procedure:
 * - Write one byte to the TEST_ERASE_PAGE page.
 * - Erase all memory locations
 * - Verify that the EEPROM is erased by a spot test on the
 *   TEST_ERASE_PAGE page.
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_erase(void)
{
	nvm_eeprom_write_byte(TEST_ERASE_PAGE * EEPROM_PAGE_SIZE, 42);
	nvm_eeprom_erase_all();
	set_buffer(buffer, EEPROM_ERASED);

	if (is_eeprom_page_equal_to_buffer(TEST_ERASE_PAGE, buffer)) {
		return STATUS_OK;
	}

	return ERR_BAD_DATA;
}
Example #23
0
/**
 * \internal
 * \brief Test drawing the outline of a circle on a page
 *
 * This test draws the outline of a circle and checks that this is done.
 *
 * \param test Current test case.
 */
static void run_draw_circle_outline_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill page buffer holding the outlined circle
	set_buffer(expected_page, 0x00);
	expected_page[47] = 0x1C;
	expected_page[48] = 0x22;
	expected_page[49] = 0x41;
	expected_page[50] = 0x41;
	expected_page[51] = 0x41;
	expected_page[52] = 0x22;
	expected_page[53] = 0x1C;

	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Draw the outline of a circle with radius 3 and centre at position 50, 11
	gfx_mono_draw_circle(50, 11, 3, GFX_PIXEL_SET, GFX_WHOLE);

	// Get all pages from display and check that the circle is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page),
					"Page %d with outlined circle not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #24
0
/**
 * \brief Test EEPROM write
 *
 * This test erases test page \ref TEST_WRITE_PAGE, then writes a single byte to
 * it and verifies that the write succeeded.
 *
 * \param test Current test case.
 */
static void run_eeprom_write_test(const struct test_case *test)
{
	uint8_t buffer[EEPROM_PAGE_SIZE];
	bool    success;

	nvm_eeprom_erase_page(TEST_WRITE_PAGE);
	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0xaa;
	nvm_eeprom_write_byte(TEST_WRITE_PAGE * EEPROM_PAGE_SIZE, buffer[0]);

	success = is_eeprom_page_equal_to_buffer(TEST_WRITE_PAGE, buffer);
	test_assert_true(test, success, "Byte write failed");
}
Example #25
0
/**
 * \internal
 * \brief Test drawing a horizontal line
 *
 * This test draws a horizontal line and checks that this is done.
 *
 * \param test Current test case.
 */
static void run_draw_horizontal_line_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;
	uint8_t i;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill page buffer holding the line
	set_buffer(expected_page, 0x00);
	for (i = 0; i < 50; i++) {
		expected_page[i + 10] = 0x10;
	}

	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Draw a horizontal line at postition 10, 20 with length 50
	gfx_mono_draw_horizontal_line(10, 20, 50, GFX_PIXEL_SET);

	// Get all pages from display and check that the line is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 2) {
			test_assert_true(test, is_page_correct(actual, expected_page),
					"Page %d with line not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #26
0
/**
 * \internal
 * \brief Test drawing a filled rectangle inside a page
 *
 * This test draws a filled rectangle inside a page and checks that this
 * is done.
 *
 * \param test Current test case.
 */
static void run_draw_filled_rectangle_test(const struct test_case *test)
{
	uint8_t actual[GFX_MONO_LCD_WIDTH];
	uint8_t expected_page[GFX_MONO_LCD_WIDTH];
	uint8_t expected_empty[GFX_MONO_LCD_WIDTH];
	uint8_t page;
	uint8_t i;

	// Clear entire display
	gfx_mono_draw_filled_rect(0, 0, GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT,
			GFX_PIXEL_CLR);

	// Fill page buffer holding rectangle
	set_buffer(expected_page, 0x00);
	for (i = 0; i < 10; i++) {
		expected_page[i + 50] = 0x7C;
	}
	
	// Fill empty page buffer
	set_buffer(expected_empty, 0x00);

	// Draw a 10x5 filled rectangle at position 50, 10
	gfx_mono_draw_filled_rect(50, 10, 10, 5, GFX_PIXEL_SET);

	// Get all pages from display and check that the rectangle is drawn
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		gfx_mono_get_page(actual, page, 0, GFX_MONO_LCD_WIDTH);
		if (page == 1) {
			test_assert_true(test, is_page_correct(actual, expected_page),
					"Page with rectangle %d not matching expected page",
					page);
		} else {
			test_assert_true(test, is_page_correct(actual, expected_empty),
					"Empty page %d not matching expected page", page);
		}
	}
}
Example #27
0
void FastaParser::init() {
    std::string s;
    is.seekg(init_pos);
    while (getline(is, s)) {
        s = trim(s);
        if (s.empty()) continue;
        if (s[0] == '>') {
            set_buffer(s);
            return;
        } else {
            // something wrong
            // raise exception 
        }
    }
}
Example #28
0
/**
 * Test nvm_eeprom_erase_page() and nvm_eeprom_write_byte().
 *
 * Test procedure:
 * - Erase TEST_WRITE_PAGE
 * - Write one byte
 * - Verify that the byte is written and that all other bytes are erased.
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_write(void)
{
	// Test write
	nvm_eeprom_erase_page(TEST_WRITE_PAGE);

	set_buffer(buffer, EEPROM_ERASED);
	buffer[0] = 0xaa;
	nvm_eeprom_write_byte(TEST_WRITE_PAGE*EEPROM_PAGE_SIZE, buffer[0]);

	if (is_eeprom_page_equal_to_buffer(TEST_WRITE_PAGE, buffer)) {
		return STATUS_OK;
	}

	return ERR_BAD_DATA;
}
Example #29
0
/**
 * Test nvm_flash_load_word_to_buffer() and nvm_flash_atomic_write_boot_page().
 *
 * Test procedure:
 * - Fill page buffer.
 * - Erase and write page to bootloader section
 * - Verify each byte written correctly by comparing each word in flash
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_atomic_write_boot(void)
{
	flash_addr_t page_addr;

	page_addr = BOOT_SECTION_START + 1 * FLASH_PAGE_SIZE;

	set_buffer(buffer, FLASH_ERASED);
	fill_flash_page_buffer(buffer, 0xC1BA);

	nvm_flash_atomic_write_boot_page(page_addr);
	if (!is_flash_page_equal_to_buffer(page_addr, buffer)) {
		return ERR_BAD_DATA;
	}

	return STATUS_OK;
}
Example #30
0
/**
 * Test nvm_flash_load_word_to_buffer() and nvm_flash_atomic_write_app_page().
 *
 * Test procedure:
 * - Fill page buffer.
 * - Erase and write page to application table section
 * - Verify each byte written correctly by comparing each word in flash
 *
 * \return STATUS_OK if test succeeded, otherwise ERR_BAD_DATA
 */
static status_code_t test_atomic_write_app_table(void)
{
	flash_addr_t page_addr;

	page_addr = APPTABLE_SECTION_START + 2 * FLASH_PAGE_SIZE;

	set_buffer(buffer, FLASH_ERASED);
	fill_flash_page_buffer(buffer, 0xA37A);

	nvm_flash_atomic_write_app_page(page_addr);
	if (!is_flash_page_equal_to_buffer(page_addr, buffer)) {
		return ERR_BAD_DATA;
	}

	return STATUS_OK;
}