2013-05-01 16:09:20 +02:00
|
|
|
/****************************************************************************
|
2021-06-10 07:51:27 +02:00
|
|
|
* apps/testing/smart_test/smart_test.c
|
2013-05-01 16:09:20 +02:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-05-01 16:09:20 +02:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-05-01 16:09:20 +02:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-05-01 16:09:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2018-10-19 19:44:41 +02:00
|
|
|
#include <sys/stat.h>
|
2013-05-01 16:09:20 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
static int *g_line_pos;
|
|
|
|
static int *g_line_len;
|
|
|
|
static int g_seek_count = 0;
|
|
|
|
static int g_write_count = 0;
|
|
|
|
static int g_circ_count = 0;
|
2015-11-23 00:22:05 +01:00
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
static int g_line_count = 2000;
|
|
|
|
static int g_record_len = 64;
|
|
|
|
static int g_erase_count = 32;
|
|
|
|
static int g_totalz_records = 40000;
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_create_test_file
|
|
|
|
*
|
|
|
|
* Description: Creates the test file with test data that we will use
|
|
|
|
* to conduct the test.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_create_test_file(char *filename)
|
|
|
|
{
|
2015-11-19 01:20:42 +01:00
|
|
|
FILE *fd;
|
2013-05-01 16:09:20 +02:00
|
|
|
int x;
|
|
|
|
char string[80];
|
|
|
|
|
|
|
|
/* Try to open the file */
|
|
|
|
|
|
|
|
printf("Creating file %s for write mode\n", filename);
|
|
|
|
|
|
|
|
fd = fopen(filename, "w+");
|
|
|
|
|
|
|
|
if (fd == NULL)
|
|
|
|
{
|
|
|
|
printf("Unable to create file %s\n", filename);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write data to the file. The data consists of a bunch of
|
|
|
|
* lines, each with a line number and the offset within the
|
|
|
|
* file where that file starts.
|
|
|
|
*/
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
printf("Writing test data. %d lines to write\n", g_line_count);
|
|
|
|
for (x = 0; x < g_line_count; x++)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
g_line_pos[x] = ftell(fd);
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
sprintf(string, "This is line %d at offset %d\n", x, g_line_pos[x]);
|
|
|
|
g_line_len[x] = strlen(string);
|
2014-04-14 00:24:28 +02:00
|
|
|
fprintf(fd, "%s", string);
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
printf("\r%d", x);
|
|
|
|
fflush(stdout);
|
2014-04-14 00:24:28 +02:00
|
|
|
}
|
|
|
|
|
2013-05-01 16:09:20 +02:00
|
|
|
/* Close the file */
|
|
|
|
|
|
|
|
printf("\r\nDone.\n");
|
|
|
|
|
|
|
|
fclose(fd);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_seek_test
|
|
|
|
*
|
|
|
|
* Description: Conducts a seek test on the file.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_seek_test(char *filename)
|
|
|
|
{
|
2022-10-08 10:31:21 +02:00
|
|
|
FILE *fd;
|
|
|
|
char readstring[80];
|
|
|
|
char cmpstring[80];
|
|
|
|
int index;
|
|
|
|
int x;
|
|
|
|
int ret = OK;
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
fd = fopen(filename, "r");
|
|
|
|
if (fd == NULL)
|
|
|
|
{
|
|
|
|
printf("Unable to open file %s\n", filename);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
printf("Performing %d random seek tests\n", g_seek_count);
|
2015-11-19 01:20:42 +01:00
|
|
|
|
2013-05-01 16:09:20 +02:00
|
|
|
srand(23);
|
2021-06-10 12:29:20 +02:00
|
|
|
for (x = 0; x < g_seek_count; x++)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
|
|
|
/* Get random line to seek to */
|
|
|
|
|
|
|
|
index = rand();
|
2021-06-10 12:29:20 +02:00
|
|
|
while (index >= g_line_count)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
index -= g_line_count;
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
fseek(fd, g_line_pos[index], SEEK_SET);
|
|
|
|
fread(readstring, 1, g_line_len[index], fd);
|
|
|
|
readstring[g_line_len[index]] = '\0';
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
sprintf(cmpstring, "This is line %d at offset %d\n",
|
2021-06-10 12:29:20 +02:00
|
|
|
index, g_line_pos[index]);
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
if (strcmp(readstring, cmpstring) != 0)
|
|
|
|
{
|
|
|
|
printf("\nSeek error on line %d\n", index);
|
2015-11-19 01:20:42 +01:00
|
|
|
printf ("\t Expected \"%s\"\n", cmpstring);
|
|
|
|
printf ("\t Received \"%s\"\n", readstring);
|
|
|
|
ret = -1;
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\r%d", x);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2015-11-19 01:20:42 +01:00
|
|
|
printf("\r%d", x);
|
|
|
|
fflush(stdout);
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2015-11-19 01:20:42 +01:00
|
|
|
fclose(fd);
|
|
|
|
return ret;
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_append_test
|
|
|
|
*
|
|
|
|
* Description: Conducts an append test on the file.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_append_test(char *filename)
|
|
|
|
{
|
2015-11-19 01:20:42 +01:00
|
|
|
FILE *fd;
|
2013-05-01 16:09:20 +02:00
|
|
|
int pos;
|
|
|
|
char readstring[80];
|
|
|
|
|
|
|
|
fd = fopen(filename, "a+");
|
|
|
|
if (fd == NULL)
|
|
|
|
{
|
|
|
|
printf("Unable to open file %s\n", filename);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now write some data to the end of the file */
|
|
|
|
|
|
|
|
fprintf(fd, "This is a test of the append.\n");
|
|
|
|
pos = ftell(fd);
|
|
|
|
|
|
|
|
/* Now seek to the end of the file and ensure that is where
|
|
|
|
* pos is.
|
|
|
|
*/
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2013-05-01 16:09:20 +02:00
|
|
|
fseek(fd, 0, SEEK_END);
|
|
|
|
if (ftell(fd) != pos)
|
|
|
|
{
|
|
|
|
printf("Error opening for append ... data not at EOF\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now seek to that position and read the data back */
|
|
|
|
|
|
|
|
fseek(fd, 30, SEEK_END);
|
|
|
|
fread(readstring, 1, 30, fd);
|
|
|
|
readstring[30] = '\0';
|
|
|
|
if (strcmp(readstring, "This is a test of the append.\n") != 0)
|
|
|
|
{
|
2015-11-19 01:20:42 +01:00
|
|
|
printf("\nAppend test failed\n");
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-19 01:20:42 +01:00
|
|
|
printf("\nAppend test passed\n");
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fd);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_seek_with_write_test
|
|
|
|
*
|
|
|
|
* Description: Conducts an append test on the file.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_seek_with_write_test(char *filename)
|
|
|
|
{
|
2015-11-19 01:20:42 +01:00
|
|
|
FILE *fd;
|
2013-05-01 16:09:20 +02:00
|
|
|
char temp;
|
|
|
|
char readstring[80];
|
|
|
|
char cmpstring[80];
|
2015-11-19 01:20:42 +01:00
|
|
|
int c;
|
|
|
|
int s1;
|
|
|
|
int s2;
|
|
|
|
int len;
|
|
|
|
int x;
|
|
|
|
int index;
|
|
|
|
int pass = TRUE;
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
fd = fopen(filename, "r+");
|
|
|
|
if (fd == NULL)
|
|
|
|
{
|
|
|
|
printf("Unable to open file %s\n", filename);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2015-11-19 01:20:42 +01:00
|
|
|
printf("Performing %d random seek with write tests\n",
|
2021-06-10 12:29:20 +02:00
|
|
|
g_write_count);
|
2015-11-19 01:20:42 +01:00
|
|
|
|
2013-05-01 16:09:20 +02:00
|
|
|
index = 0;
|
2021-06-10 12:29:20 +02:00
|
|
|
for (x = 0; x < g_write_count; x++)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* Get a random value */
|
|
|
|
|
|
|
|
index = rand();
|
2021-06-10 12:29:20 +02:00
|
|
|
while (index >= g_line_count)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
index -= g_line_count;
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
#endif
|
2021-06-10 12:29:20 +02:00
|
|
|
|
2013-05-01 16:09:20 +02:00
|
|
|
/* Read the data into the buffer */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
fseek(fd, g_line_pos[index], SEEK_SET);
|
|
|
|
fread(readstring, 1, g_line_len[index], fd);
|
|
|
|
readstring[g_line_len[index]] = '\0';
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
/* Scramble the data in the line */
|
|
|
|
|
|
|
|
len = strlen(readstring);
|
|
|
|
for (c = 0; c < 100; c++)
|
|
|
|
{
|
|
|
|
s1 = rand() % len;
|
|
|
|
s2 = rand() % len;
|
|
|
|
|
|
|
|
temp = readstring[s1];
|
|
|
|
readstring[s1] = readstring[s2];
|
|
|
|
readstring[s2] = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now write the data back to the file */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
fseek(fd, g_line_pos[index], SEEK_SET);
|
|
|
|
fwrite(readstring, 1, g_line_len[index], fd);
|
2013-05-01 16:09:20 +02:00
|
|
|
fflush(fd);
|
|
|
|
|
|
|
|
/* Now read the data back and compare it */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
fseek(fd, g_line_pos[index], SEEK_SET);
|
|
|
|
fread(cmpstring, 1, g_line_len[index], fd);
|
|
|
|
cmpstring[g_line_len[index]] = '\0';
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
if (strcmp(readstring, cmpstring) != 0)
|
|
|
|
{
|
2015-11-19 01:20:42 +01:00
|
|
|
printf("\nCompare failure on line %d, offset %d\n",
|
2021-06-10 12:29:20 +02:00
|
|
|
index, g_line_pos[index]);
|
2015-11-19 01:20:42 +01:00
|
|
|
printf("\tExpected \"%s\"", cmpstring);
|
|
|
|
printf("\rReceived \"%s\"", readstring);
|
2021-06-10 12:29:20 +02:00
|
|
|
fseek(fd, g_line_pos[index], SEEK_SET);
|
|
|
|
fread(cmpstring, 1, g_line_len[index], fd);
|
2015-11-19 01:20:42 +01:00
|
|
|
pass = FALSE;
|
2013-05-01 16:09:20 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\r%d", x);
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
/* On to next line */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
if (++index >= g_line_count)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-19 01:20:42 +01:00
|
|
|
if (pass)
|
|
|
|
{
|
|
|
|
printf("\nPass\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("\nFail\n");
|
|
|
|
}
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
fclose(fd);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_circular_log_test
|
|
|
|
*
|
|
|
|
* Description: Conducts a record based circular log seek / update test
|
|
|
|
*
|
|
|
|
* NOTE!!!
|
|
|
|
* In the test below, we use open / write, not fopen / fwrite. If the
|
|
|
|
* fopen / fwrite routines were used instead, they would provide us with
|
|
|
|
* stream buffer management which we DO NOT WANT. This will throw off
|
|
|
|
* the SMARTFS write sizes which will not generate the optimized wear
|
|
|
|
* operations.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_circular_log_test(char *filename)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char *buffer;
|
|
|
|
char *cmpbuf;
|
|
|
|
int s1;
|
|
|
|
int x;
|
2021-06-10 12:29:20 +02:00
|
|
|
int record_no;
|
|
|
|
int buf_size;
|
2015-11-23 00:22:05 +01:00
|
|
|
int pass = TRUE;
|
|
|
|
|
|
|
|
/* Calculate the size of our granular "erase record" writes */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
buf_size = g_record_len * g_erase_count;
|
|
|
|
if (buf_size == 0)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
|
|
|
printf("Invalid record parameters\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory for the record */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
buffer = malloc(buf_size);
|
2015-11-23 00:22:05 +01:00
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
|
|
|
printf("Unable to allocate memory for record storage\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory for the compare buffer */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
cmpbuf = malloc(g_record_len);
|
2015-11-23 00:22:05 +01:00
|
|
|
if (cmpbuf == NULL)
|
|
|
|
{
|
|
|
|
printf("Unable to allocate memory for record storage\n");
|
|
|
|
free(buffer);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the circular log file */
|
|
|
|
|
|
|
|
fd = open(filename, O_RDWR | O_CREAT);
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
printf("Unable to create file %s\n", filename);
|
|
|
|
free(buffer);
|
|
|
|
free(cmpbuf);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now fill the circular log with dummy 0xFF data */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
printf("Creating circular log with %d records\n", g_totalz_records);
|
|
|
|
memset(buffer, 0xff, g_record_len);
|
|
|
|
for (x = 0; x < g_totalz_records; x++)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
write(fd, buffer, g_record_len);
|
2015-11-23 00:22:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
/* Now reopen the file for read/write mode */
|
|
|
|
|
|
|
|
fd = open(filename, O_RDWR);
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
printf("Unable to open file %s\n", filename);
|
|
|
|
free(buffer);
|
|
|
|
free(cmpbuf);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Performing %d circular log record update tests\n",
|
2021-06-10 12:29:20 +02:00
|
|
|
g_circ_count);
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
/* Start at record number zero and start updating log entries */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
record_no = 0;
|
|
|
|
for (x = 0; x < g_circ_count; x++)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
|
|
|
/* Fill a new record with random data */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
for (s1 = 0; s1 < g_record_len; s1++)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
buffer[s1] = rand() & 0xff;
|
2015-11-23 00:22:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the first byte of the record (flag byte) to 0xFF */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
buffer[0] = 0xff;
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
/* Seek to the record location in the file */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
lseek(fd, g_record_len * record_no, SEEK_SET);
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
/* Write the new record to the file */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
if ((record_no & (g_erase_count - 1)) == 0)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
/* Every g_erase_count records we will write a larger
|
2015-11-23 00:22:05 +01:00
|
|
|
* buffer with our record and padded with 0xFF to
|
|
|
|
* the end of our larger buffer.
|
|
|
|
*/
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
memset(&buffer[g_record_len], 0xff, buf_size - g_record_len);
|
|
|
|
write(fd, buffer, buf_size);
|
2015-11-23 00:22:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Just write a single record */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
write(fd, buffer, g_record_len);
|
2015-11-23 00:22:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now perform a couple of simulated flag updates */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
lseek(fd, g_record_len * record_no, SEEK_SET);
|
|
|
|
buffer[0] = 0xfe;
|
2015-11-23 00:22:05 +01:00
|
|
|
write(fd, buffer, 1);
|
2021-06-10 12:29:20 +02:00
|
|
|
lseek(fd, g_record_len * record_no, SEEK_SET);
|
|
|
|
buffer[0] = 0xfc;
|
2015-11-23 00:22:05 +01:00
|
|
|
write(fd, buffer, 1);
|
|
|
|
|
|
|
|
/* Now read the data back and compare it */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
lseek(fd, g_record_len * record_no, SEEK_SET);
|
|
|
|
read(fd, cmpbuf, g_record_len);
|
2015-11-23 00:22:05 +01:00
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
for (s1 = 0; s1 < g_record_len; s1++)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
|
|
|
if (buffer[s1] != cmpbuf[s1])
|
|
|
|
{
|
|
|
|
printf("\nCompare failure in record %d, offset %d\n",
|
2021-06-10 12:29:20 +02:00
|
|
|
record_no, record_no * g_record_len + s1);
|
2015-11-23 00:22:05 +01:00
|
|
|
printf("\tExpected \"%02x\"", cmpbuf[s1]);
|
|
|
|
printf("\rReceived \"%02x\"", buffer[s1]);
|
|
|
|
pass = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\r%d", x);
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
/* Increment to the next record */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
if (++record_no >= g_totalz_records)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
record_no = 0;
|
2015-11-23 00:22:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pass)
|
|
|
|
{
|
|
|
|
printf("\nPass\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("\nFail\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
free(buffer);
|
|
|
|
free(cmpbuf);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_usage
|
|
|
|
*
|
|
|
|
* Description: Displays usage information for the command.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2019-01-24 21:44:54 +01:00
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
static void smart_usage(void)
|
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, "usage: smart_test "
|
|
|
|
"[-c COUNT] [-s SEEKCOUNT] [-w WRITECOUNT] smart_mounted_filename\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "DESCRIPTION\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
" Conducts various stress tests to validate SMARTFS operation.\n");
|
|
|
|
fprintf(stderr,
|
|
|
|
" Please choose one or more of -c, -s, or -w to conduct tests.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "OPTIONS\n");
|
|
|
|
fprintf(stderr, " -c COUNT\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " "
|
|
|
|
"Performs a circular log style test where a fixed number of fixed\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"length records are written and then overwritten with new data.\n");
|
|
|
|
fprintf(stderr, " "
|
2021-12-26 23:10:48 +01:00
|
|
|
"Uses the -r, -e and -t options to specify the parameters of the\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " "
|
|
|
|
"record geometry and update operation. The COUNT parameter sets\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"the number of record updates to perform.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, " -s SEEKCOUNT\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " "
|
|
|
|
"Performs a simple seek test where to validate the SMARTFS seek\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"operation. Uses the -l option to specify the number of test\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"lines to write to the test file. The SEEKCOUNT parameter sets\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"the number of seek/read operations to perform.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, " -w WRITECOUNT\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " "
|
|
|
|
"Performs a seek/write/seek/read test where to validate the SMARTFS\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"seek/write operation. Uses the -l option to specify the number of\n");
|
|
|
|
fprintf(stderr, " test lines "
|
|
|
|
"to write to the test file. The WRITECOUNT parameter sets\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"the number of seek/write operations to perform.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, " -l LINECOUNT\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " "
|
|
|
|
"Sets the number of lines of test data to write to the test file\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"during seek and seek/write tests.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, " -r RECORDLEN\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " "
|
|
|
|
"Sets the length of each log record during circular log tests.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, " -e ERASECOUNT\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " Sets the erase granularity"
|
|
|
|
" for overwriting old circular log entries.\n");
|
|
|
|
fprintf(stderr, " Setting this value to 16, "
|
|
|
|
"for instance, would cause every 16th record\n");
|
|
|
|
fprintf(stderr, " update "
|
|
|
|
"to write a single record followed by 15 records with all 0xFF\n");
|
|
|
|
fprintf(stderr, " content. "
|
|
|
|
"This helps SMARTFS perform better wear leveling and reduces\n");
|
|
|
|
fprintf(stderr, " "
|
|
|
|
"the number of FLASH block erases significantly.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
|
|
|
|
fprintf(stderr, " -t TOTALRECORDS\n");
|
2021-06-10 12:29:20 +02:00
|
|
|
fprintf(stderr, " "
|
|
|
|
"Sets the total number of records in the circular log test file.\n\n");
|
2015-11-23 00:22:05 +01:00
|
|
|
}
|
|
|
|
|
2013-05-01 16:09:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
int ret;
|
|
|
|
int opt;
|
2013-05-01 16:09:20 +02:00
|
|
|
|
|
|
|
/* Argument given? */
|
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
while ((opt = getopt(argc, argv, "c:e:l:r:s:t:w:")) != -1)
|
2021-06-10 12:29:20 +02:00
|
|
|
{
|
|
|
|
switch (opt)
|
|
|
|
{
|
|
|
|
case 'c':
|
|
|
|
g_circ_count = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e':
|
|
|
|
g_erase_count = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
g_line_count = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
g_record_len = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
g_seek_count = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
g_totalz_records = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
g_write_count = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* '?' */
|
|
|
|
smart_usage();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-11-19 01:20:42 +01:00
|
|
|
}
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
if (argc < 2 || (g_seek_count + g_write_count + g_circ_count == 0))
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
2015-11-23 00:22:05 +01:00
|
|
|
smart_usage();
|
2015-11-19 01:20:42 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory for the test */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
g_line_pos = malloc(g_line_count * sizeof(int));
|
|
|
|
if (g_line_pos == NULL)
|
2015-11-19 01:20:42 +01:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
g_line_len = malloc(g_line_count * sizeof(int));
|
|
|
|
if (g_line_len == NULL)
|
2015-11-19 01:20:42 +01:00
|
|
|
{
|
2021-06-10 12:29:20 +02:00
|
|
|
free(g_line_pos);
|
2013-05-01 16:09:20 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
/* Test if performing seek test or write test */
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
if (g_seek_count > 0 || g_write_count > 0)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
2015-11-23 00:22:05 +01:00
|
|
|
/* Create a test file */
|
|
|
|
|
|
|
|
if ((ret = smart_create_test_file(argv[optind])) < 0)
|
|
|
|
{
|
|
|
|
goto err_out_with_mem;
|
|
|
|
}
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
/* Conduct a seek test? */
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
if (g_seek_count > 0)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
|
|
|
if ((ret = smart_seek_test(argv[optind])) < 0)
|
|
|
|
{
|
|
|
|
goto err_out_with_mem;
|
|
|
|
}
|
|
|
|
}
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
/* Conduct an append test */
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
if ((ret = smart_append_test(argv[optind])) < 0)
|
|
|
|
{
|
|
|
|
goto err_out_with_mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Conduct a seek with write test? */
|
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
if (g_write_count > 0)
|
2015-11-23 00:22:05 +01:00
|
|
|
{
|
|
|
|
if ((ret = smart_seek_with_write_test(argv[optind])) < 0)
|
|
|
|
{
|
|
|
|
goto err_out_with_mem;
|
|
|
|
}
|
|
|
|
}
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
/* Perform a "circular log" test */
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2015-11-23 00:22:05 +01:00
|
|
|
if ((ret = smart_circular_log_test(argv[optind])) < 0)
|
2013-05-01 16:09:20 +02:00
|
|
|
{
|
2015-11-19 01:20:42 +01:00
|
|
|
goto err_out_with_mem;
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|
|
|
|
|
2015-11-19 01:20:42 +01:00
|
|
|
err_out_with_mem:
|
|
|
|
|
|
|
|
/* Free the memory */
|
2013-05-01 16:09:20 +02:00
|
|
|
|
2021-06-10 12:29:20 +02:00
|
|
|
free(g_line_pos);
|
|
|
|
free(g_line_len);
|
2015-11-19 01:20:42 +01:00
|
|
|
return ret;
|
2013-05-01 16:09:20 +02:00
|
|
|
}
|