示例#1
0
文件: string.c 项目: Noltari/u-boot
/**
 * lib_memcpy() - unit test for memcpy()
 *
 * Test memcpy() with varied alignment and length of the copied buffer.
 *
 * @uts:	unit test state
 * Return:	0 = success, 1 = failure
 */
static int lib_memcpy(struct unit_test_state *uts)
{
	u8 buf1[BUFLEN];
	u8 buf2[BUFLEN];
	int offset1, offset2, len;
	void *ptr;

	init_buffer(buf1, MASK);

	for (offset1 = 0; offset1 <= SWEEP; ++offset1) {
		for (offset2 = 0; offset2 <= SWEEP; ++offset2) {
			for (len = 1; len < BUFLEN - SWEEP; ++len) {
				init_buffer(buf2, 0);
				ptr = memcpy(buf2 + offset2, buf1 + offset1,
					     len);
				ut_asserteq_ptr(buf2 + offset2, (u8 *)ptr);
				if (test_memmove(uts, buf2, MASK, offset1,
						 offset2, len)) {
					debug("%s: failure %d, %d, %d\n",
					      __func__, offset1, offset2, len);
					return CMD_RET_FAILURE;
				}
			}
		}
	}
	return 0;
}
示例#2
0
int main()
{
    test_memmove();

    test_memcpy();

    return 0;
}
示例#3
0
bool torture_local_replace(struct torture_context *ctx)
{
	bool ret = true;
	ret &= test_ftruncate();
	ret &= test_strlcpy();
	ret &= test_strlcat();
	ret &= test_mktime();
	ret &= test_initgroups();
	ret &= test_memmove();
	ret &= test_strdup();
	ret &= test_setlinebuf();
	ret &= test_vsyslog();
	ret &= test_timegm();
	ret &= test_setenv();
	ret &= test_strndup();
	ret &= test_strnlen();
	ret &= test_waitpid();
	ret &= test_seteuid();
	ret &= test_setegid();
	ret &= test_asprintf();
	ret &= test_snprintf();
	ret &= test_vasprintf();
	ret &= test_vsnprintf();
	ret &= test_opendir();
	ret &= test_readdir();
	ret &= test_telldir();
	ret &= test_seekdir();
	ret &= test_dlopen();
	ret &= test_chroot();
	ret &= test_bzero();
	ret &= test_strerror();
	ret &= test_errno();
	ret &= test_mkdtemp();
	ret &= test_mkstemp();
	ret &= test_pread();
	ret &= test_pwrite();
	ret &= test_getpass();
	ret &= test_inet_ntoa();
	ret &= test_strtoll();
	ret &= test_strtoull();
	ret &= test_va_copy();
	ret &= test_FUNCTION();
	ret &= test_MIN();
	ret &= test_MAX();
	ret &= test_socketpair();
	ret &= test_strptime();
	ret &= test_getifaddrs();
	ret &= test_utime();
	ret &= test_utimes();
	ret &= test_memmem();

	return ret;
}
示例#4
0
static int __init test_init (void)
{
  int status;

  /* Test strcmp first because we use it to test other things.  */
  test_strcmp ();

  /* Test strcpy next because we need it to set up other tests.  */
  test_strcpy ();

  /* strncmp.  */
  test_strncmp ();

  /* strncpy.  */
  test_strncpy ();

  /* memcmp.  */
  test_memcmp ();

  /* memchr.  */
  test_memchr ();

  /* memcpy - need not work for overlap.  */
  test_memcpy ();

  /* memmove - must work on overlap.  */
  test_memmove ();

  /* memset.  */
  test_memset ();

  if (errors == 0)
    {
      status = 0;
      printf("TEST PASS.\n");
    }
  else
    {
      status = 1;
      printf("%Zd errors.\n", errors);
      printf("TEST FAIL.\n");
    }

  return status;
}
示例#5
0
文件: main.cpp 项目: CCJY/coliru
int main()
{
    srand(time(0));

    // The counter is introduced to prevent the compiler
    // from optimizating *everything* away.
    unsigned counter = 0;

    // Print the times for the different strategies.
    print_time(test_std_copy(), counter);
    print_time(test_memmove(),  counter);
    print_time(test_memcpy(),   counter);
    print_time(test_cast(),     counter);

    // Printing the counter to stdout prevents the compiler from
    // optimizing away the inner loop of the benchmark function.
    std::cout << "(counter:  " << counter << ")" << std::endl << std::endl;

}
示例#6
0
int main(int argc, char **argv)
{
  test_memcpy();
  test_memmove();
  test_strlen();
  test_strnlen();
  test_memset();
  test_strcmp();
  test_strncmp();
  test_memcmp();
  test_strcat();
  // strncat is not tested (code from the man page)
  test_strcpy();
  test_strncpy();
  test_strchr();
  test_strrchr();
  test_memchr();
  test_memrchr();
  test_strstr();
  // strerror not tested
  // strdup not tested (uses malloc)
  // strndup not tested (uses malloc)
  return 0;
}
示例#7
0
int main(void)
{
	char *buf;
	char *buf2;

	buf = malloc(100);
	assert(test_memset(buf, 0x42, 100) == 0);
	free(buf);

	buf = malloc(128);
	assert(test_memset(buf, 0, 128) == 0);
	assert(test_memset(buf+1, 0, 127) == 0);
	free(buf);

	buf = malloc(1024);
	assert(test_memset(buf, 0, 1024) == 0);
	free(buf);

	buf = malloc(20);
	strncpy(buf, "Hello World!", 20);
	assert(test_memchr(buf, 'o', strlen(buf), buf+4));
	assert(test_memchr(buf, 'a', strlen(buf), NULL));

	assert(test_memcmp(buf, "Hello World!", strlen(buf), 0));
	assert(test_memcmp(buf, "Hfllow World", strlen(buf), -1));

	assert(test_strcmp(buf, "Hello World!",  0));
	assert(test_strcmp(buf, "Hfllow World", -1));

	assert(test_strchr(buf, 'H', buf));
	assert(test_strchr(buf, 'e', buf+1));
	assert(test_strchr(buf, 'a', NULL));
	assert(test_strchr(buf, '!', buf+11));

	assert(test_strrchr(buf, 'H', buf));
	assert(test_strrchr(buf, 'o', buf+7));
	assert(test_strrchr(buf, 'a', NULL));
	assert(test_strrchr(buf, 'l', buf+9));
	assert(test_strrchr(buf, '!', buf+11));

	assert(test_strcasecmp(buf, "Hello World!", 0));
	assert(test_strcasecmp(buf, "HELLO WORLD!", 0));
	assert(test_strcasecmp(buf, "IELLO world!", -1));
	assert(test_strcasecmp(buf, "HeLLo WOrlc!", 1));

	assert(test_strncasecmp(buf, "Hello World!", strlen(buf), 0));
	assert(test_strncasecmp(buf, "HELLO WORLD!", strlen(buf), 0));
	assert(test_strncasecmp(buf, "IELLO world!", strlen(buf), -1));
	assert(test_strncasecmp(buf, "HeLLo WOrlc!", strlen(buf), 1));

	assert(test_strncasecmp(buf, "HeLLo WOrlc!", 0, 0));
	assert(test_strncasecmp(buf, "HeLLo WOrlc!", 1, 0));
	assert(test_strncasecmp(buf, "HeLLo WOrlc!", 2, 0));
	assert(test_strncasecmp(buf, "HeLLp WOrlc!", 5, -1));

	free(buf);

	buf  = malloc(20);
	buf2 = malloc(20);
	strncpy(buf, "Hello", 20);
	strncpy(buf2, " World!", 20);

	assert(test_memmove(buf + 5, buf2, strlen(buf2), buf,
			    "Hello World!", strlen("Hello World!")));

	strncpy(buf, "HHello World!", 20);
	assert(test_memmove(buf, buf+1, strlen("Hello World!"), buf, "Hello World!", strlen("Hello World!")));

	strncpy(buf, "0123456789", 20);
	assert(test_memmove(buf+1, buf , strlen("0123456789"), buf, "00123456789", strlen("00123456789")));

	free(buf);
	free(buf2);

	return 0;
}