system/ramspeed: Allow read and write buffers to be allocated from the heap.

This change makes it much easier to use the ramspeed test in BUILD_KERNEL,
as one does not need to know which virtual address is safe to use.
This commit is contained in:
Stuart Ianna 2023-06-23 12:33:24 +10:00 committed by Xiang Xiao
parent 40886698fb
commit a549668439

View File

@ -92,10 +92,11 @@ struct ramspeed_s
static void show_usage(FAR const char *progname, int exitcode) static void show_usage(FAR const char *progname, int exitcode)
{ {
printf("\nUsage: %s -r <hex-address> -w <hex-address> -s <decimal-size>" printf("\nUsage: %s -a -r <hex-address> -w <hex-address> -s <decimal-size>"
" -v <hex-value>[0x00] -n <decimal-repeat number>[100] -i\n", " -v <hex-value>[0x00] -n <decimal-repeat number>[100] -i\n",
progname); progname);
printf("\nWhere:\n"); printf("\nWhere:\n");
printf(" -a allocate RW buffers on heap. Overwrites -r and -w option.\n");
printf(" -r <hex-address> read address.\n"); printf(" -r <hex-address> read address.\n");
printf(" -w <hex-address> write address.\n"); printf(" -w <hex-address> write address.\n");
printf(" -s <decimal-size> number of memory locations (in bytes).\n"); printf(" -s <decimal-size> number of memory locations (in bytes).\n");
@ -116,20 +117,24 @@ static void parse_commandline(int argc, FAR char **argv,
FAR struct ramspeed_s *info) FAR struct ramspeed_s *info)
{ {
int ch; int ch;
bool allocate_rw_address = false;
memset(info, 0, sizeof(struct ramspeed_s)); memset(info, 0, sizeof(struct ramspeed_s));
info->repeat_num = 100; info->repeat_num = 100;
if (argc < 7) if (argc < 4)
{ {
printf(RAMSPEED_PREFIX "Missing required arguments\n"); printf(RAMSPEED_PREFIX "Missing required arguments\n");
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);
} }
while ((ch = getopt(argc, argv, "r:w:s:v:n:i")) != ERROR) while ((ch = getopt(argc, argv, "r:w:s:v:n:i:a")) != ERROR)
{ {
switch (ch) switch (ch)
{ {
case 'a':
allocate_rw_address = true;
break;
case 'r': case 'r':
OPTARG_TO_VALUE(info->src, const void *, 16); OPTARG_TO_VALUE(info->src, const void *, 16);
break; break;
@ -167,6 +172,12 @@ static void parse_commandline(int argc, FAR char **argv,
} }
} }
if (allocate_rw_address)
{
info->dest = malloc(info->size);
info->src = malloc(info->size);
}
if (info->dest == NULL || info->src == NULL || info->size == 0) if (info->dest == NULL || info->src == NULL || info->size == 0)
{ {
printf(RAMSPEED_PREFIX "Missing required arguments\n"); printf(RAMSPEED_PREFIX "Missing required arguments\n");