aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/jittertest/JitterTest.c52
-rw-r--r--tests/jittertest/Makemodule.am6
-rwxr-xr-xtests/jittertest/filename_bounds.sh.in115
-rw-r--r--tests/jittertest/plotJittervsFill.c17
-rw-r--r--tests/mtd-tests/flash_speed.c6
-rw-r--r--tests/ubifs_tools-tests/Makemodule.am5
6 files changed, 178 insertions, 23 deletions
diff --git a/tests/jittertest/JitterTest.c b/tests/jittertest/JitterTest.c
index 2bee0b0..a3e3764 100644
--- a/tests/jittertest/JitterTest.c
+++ b/tests/jittertest/JitterTest.c
@@ -205,6 +205,7 @@ static int RunAsRTTask = FALSE; /* default action unless priority is
/********************* Local Function Prototypes **********************/
void HandleCmdLineArgs(int argc, char *argv[]);
+static void SaveFileName(char *pDest, size_t destSize, const char *pFileName);
void SetFileName(char * pFileName);
void SetInterruptPeriod(char * pASCIIInterruptPeriodMilliSec);
void SetSchedulerPriority(char * pASCIISchedulerPriority);
@@ -830,9 +831,14 @@ void HandleCmdLineArgs(
(strcmp(argv[argNum],"-r") == STRINGS_EQUAL)) {
/* Set the file to read*/
++argNum;
-
- strncpy(ReadFile, argv[argNum], sizeof(ReadFile));
- DoRead = TRUE;
+ if (argNum < argc) {
+ SaveFileName(ReadFile, sizeof(ReadFile), argv[argNum]);
+ DoRead = TRUE;
+ }
+ else {
+ printf("*** Read file name not specified. ***\n");
+ exit(0);
+ }
}
else if ((strcmp(argv[argNum],"--write_bytes") ==
@@ -858,9 +864,13 @@ void HandleCmdLineArgs(
(strcmp(argv[argNum],"-c") == STRINGS_EQUAL)) {
/* Set the file to log console log on. */
++argNum;
-
- strncpy(LogFile, argv[argNum], sizeof(LogFile) - 1);
- LogFile[sizeof(LogFile) - 1] = '\0';
+ if (argNum < argc) {
+ SaveFileName(LogFile, sizeof(LogFile), argv[argNum]);
+ }
+ else {
+ printf("*** Console log file name not specified. ***\n");
+ exit(0);
+ }
}
else if ((strcmp(argv[argNum],"--grab_kprofile") ==
@@ -913,27 +923,37 @@ void HandleCmdLineArgs(
/***********************************************************************
- * SetFileName
- * This function sets the output file name.
+ * SaveFileName
+ * This function validates and saves a file name.
* output: N/A
***********************************************************************/
-void SetFileName(
- char * pFileName) /* ptr to desired output file name */
+static void SaveFileName(
+ char *pDest, /* ptr to destination buffer */
+ size_t destSize, /* destination buffer size */
+ const char *pFileName) /* ptr to desired file name */
{
size_t fileNameLen; /* file name length (bytes) */
- /* Check file name length. */
fileNameLen = strlen(pFileName);
- if (fileNameLen > (size_t) MAX_FILE_NAME_LEN) {
+ if (fileNameLen > destSize - 1) {
printf("File name %s exceeds maximum length %d.\n",
- pFileName, MAX_FILE_NAME_LEN);
+ pFileName, (int)(destSize - 1));
exit(0);
}
- /* File name length is OK so save the file name. */
- strcpy(OutFileName, pFileName);
+ strcpy(pDest, pFileName);
+}
- return;
+
+/***********************************************************************
+ * SetFileName
+ * This function sets the output file name.
+ * output: N/A
+ ***********************************************************************/
+void SetFileName(
+ char * pFileName) /* ptr to desired output file name */
+{
+ SaveFileName(OutFileName, sizeof(OutFileName), pFileName);
}
diff --git a/tests/jittertest/Makemodule.am b/tests/jittertest/Makemodule.am
index d280192..2cb85c1 100644
--- a/tests/jittertest/Makemodule.am
+++ b/tests/jittertest/Makemodule.am
@@ -6,6 +6,8 @@ plotJittervsFill_CPPFLAGS = $(AM_CPPFLAGS)
test_PROGRAMS += JitterTest plotJittervsFill
-test_SCRIPTS += tests/jittertest/filljffs2.sh
+test_SCRIPTS += tests/jittertest/filljffs2.sh tests/jittertest/filename_bounds.sh
+TESTS += tests/jittertest/filename_bounds.sh
-EXTRA_DIST += tests/jittertest/README tests/jittertest/filljffs2.sh
+EXTRA_DIST += tests/jittertest/README tests/jittertest/filljffs2.sh \
+ tests/jittertest/filename_bounds.sh.in
diff --git a/tests/jittertest/filename_bounds.sh.in b/tests/jittertest/filename_bounds.sh.in
new file mode 100755
index 0000000..0dfba74
--- /dev/null
+++ b/tests/jittertest/filename_bounds.sh.in
@@ -0,0 +1,115 @@
+#!/bin/sh
+
+TESTBINDIR=${TESTBINDIR-@TESTBINDIR@}
+
+tmpdir=
+jt_pid=
+watchdog_pid=
+
+fatal()
+{
+ echo "Error: $1" 1>&2
+ exit 1
+}
+
+cleanup()
+{
+ if [ -n "$watchdog_pid" ]; then
+ kill "$watchdog_pid" >/dev/null 2>&1 || :
+ wait "$watchdog_pid" 2>/dev/null || :
+ fi
+
+ if [ -n "$jt_pid" ]; then
+ kill "$jt_pid" >/dev/null 2>&1 || :
+ wait "$jt_pid" 2>/dev/null || :
+ fi
+
+ if [ -n "$tmpdir" ]; then
+ rm -rf "$tmpdir"
+ fi
+}
+
+trap 'status=$?; trap - EXIT; cleanup; exit $status' EXIT
+trap 'exit 1' HUP INT QUIT TERM
+
+make_name()
+{
+ char="$1"
+ length="$2"
+ name=
+ i=0
+
+ while [ "$i" -lt "$length" ]; do
+ name="${name}${char}"
+ i=$((i + 1))
+ done
+
+ printf '%s' "$name"
+}
+
+tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/mtd-utils-jittertest.XXXXXX") ||
+ fatal "mktemp failed"
+cd "$tmpdir" || fatal "cannot change to temp dir"
+
+plot_valid=$(make_name a 249)
+: > "$plot_valid" || fatal "cannot create valid plot input"
+"$TESTBINDIR/plotJittervsFill" -f "$plot_valid" >plot-valid.out 2>plot-valid.err ||
+ fatal "plotJittervsFill rejected a 249-byte file name"
+if grep -q "exceeds maximum length" plot-valid.out plot-valid.err; then
+ fatal "plotJittervsFill reported a max-length error for a 249-byte file name"
+fi
+
+plot_invalid=$(make_name b 250)
+"$TESTBINDIR/plotJittervsFill" -f "$plot_invalid" >plot-invalid.out 2>plot-invalid.err || :
+if ! grep -q "exceeds maximum length" plot-invalid.out plot-invalid.err; then
+ fatal "plotJittervsFill did not reject a 250-byte file name"
+fi
+if grep -q "Unable to open input log file" plot-invalid.out plot-invalid.err; then
+ fatal "plotJittervsFill reached fopen() for an overlong file name"
+fi
+
+jt_read_valid=$(make_name r 32)
+"$TESTBINDIR/JitterTest" -c /dev/null -f out.dat -r "$jt_read_valid" >jt-valid.out 2>jt-valid.err &
+jt_pid=$!
+(
+ sleep 10
+ kill -TERM "$jt_pid" >/dev/null 2>&1 || :
+ sleep 1
+ kill -KILL "$jt_pid" >/dev/null 2>&1 || :
+) &
+watchdog_pid=$!
+sleep 1
+kill -INT "$jt_pid" >/dev/null 2>&1 || fatal "cannot stop JitterTest"
+wait "$jt_pid" || fatal "JitterTest failed with a 32-byte read file name"
+jt_pid=
+kill "$watchdog_pid" >/dev/null 2>&1 || :
+wait "$watchdog_pid" 2>/dev/null || :
+watchdog_pid=
+if ! grep -q "Press Ctrl+C to exit the program." jt-valid.out; then
+ fatal "JitterTest did not start normally with a 32-byte read file name"
+fi
+if ! grep -q "JitterTest exiting." jt-valid.out; then
+ fatal "JitterTest did not exit cleanly after SIGINT"
+fi
+
+jt_read_invalid=$(make_name s 33)
+"$TESTBINDIR/JitterTest" -c /dev/null -f out.dat -r "$jt_read_invalid" \
+ >jt-read-invalid.out 2>jt-read-invalid.err || :
+if ! grep -q "exceeds maximum length" jt-read-invalid.out jt-read-invalid.err; then
+ fatal "JitterTest did not reject a 33-byte read file name"
+fi
+if grep -q "Press Ctrl+C to exit the program." jt-read-invalid.out jt-read-invalid.err; then
+ fatal "JitterTest started despite an overlong read file name"
+fi
+
+jt_console_invalid=$(make_name c 33)
+"$TESTBINDIR/JitterTest" -c "$jt_console_invalid" -f out.dat \
+ >jt-console-invalid.out 2>jt-console-invalid.err || :
+if ! grep -q "exceeds maximum length" jt-console-invalid.out jt-console-invalid.err; then
+ fatal "JitterTest did not reject a 33-byte console file name"
+fi
+if grep -q "Press Ctrl+C to exit the program." jt-console-invalid.out jt-console-invalid.err; then
+ fatal "JitterTest started despite an overlong console file name"
+fi
+
+echo "SUCCESS"
diff --git a/tests/jittertest/plotJittervsFill.c b/tests/jittertest/plotJittervsFill.c
index 03929a9..8929f9a 100644
--- a/tests/jittertest/plotJittervsFill.c
+++ b/tests/jittertest/plotJittervsFill.c
@@ -75,6 +75,21 @@ static int Debug = 0; /* Debug level. Each "-d" on the cmd line increases the le
#define MIN_JITTER_THRESHOLD 1 /* ms minimum jitter threshold */
+static void SetLogFileName(
+ const char *pFileName) /* ptr to desired input file name */
+{
+ size_t fileNameLen; /* file name length (bytes) */
+
+ fileNameLen = strlen(pFileName);
+ if (fileNameLen > sizeof(LogFile) - 1) {
+ printf("File name %s exceeds maximum length %d.\n",
+ pFileName, (int)(sizeof(LogFile) - 1));
+ exit(0);
+ }
+
+ strcpy(LogFile, pFileName);
+}
+
static void PrintHelpInfo(void)
{
printf("Usage: plotJittervsFill [options] -f [--file] <input log file name> -t [--jitter_threshold] <jitter threshold in ms>\n");
@@ -122,7 +137,7 @@ static void HandleCmdLineArgs(
/* Set the name of the output file. */
++argNum;
if (argNum < argc) {
- strncpy(LogFile, argv[argNum], sizeof(LogFile));
+ SetLogFileName(argv[argNum]);
}
else {
printf("*** Input file name not specified. ***\n");
diff --git a/tests/mtd-tests/flash_speed.c b/tests/mtd-tests/flash_speed.c
index 11f396c..3319452 100644
--- a/tests/mtd-tests/flash_speed.c
+++ b/tests/mtd-tests/flash_speed.c
@@ -190,7 +190,7 @@ static int read_eraseblock(int ebnum)
{
int err = mtd_read(&mtd, fd, ebnum, 0, iobuf, mtd.eb_size);
if (err)
- fprintf(stderr, "Error writing block %d!\n", ebnum);
+ fprintf(stderr, "Error reading block %d!\n", ebnum);
return err;
}
@@ -490,7 +490,7 @@ int main(int argc, char **argv)
}
/* Multi-block erase all eraseblocks */
- if (!skip) {
+ if (flags & DESTRUCTIVE && !skip) {
for (k = 1; k < 7; ++k) {
blocks = 1 << k;
printf("Testing %dx multi-block erase speed\n", blocks);
@@ -518,7 +518,7 @@ int main(int argc, char **argv)
/* Write a page and immediately after try to read another page. Report
* the latency difference when performed on different banks (NOR only).
*/
- if (speb >= 0 && mtd.subpage_size == 1) {
+ if (flags & DESTRUCTIVE && speb >= 0 && mtd.subpage_size == 1) {
long rww_duration_w, rww_latency_end;
long rww_duration_rnw, rww_duration_r_end;
bool rww_r_end_first;
diff --git a/tests/ubifs_tools-tests/Makemodule.am b/tests/ubifs_tools-tests/Makemodule.am
index 1715757..5fe4f83 100644
--- a/tests/ubifs_tools-tests/Makemodule.am
+++ b/tests/ubifs_tools-tests/Makemodule.am
@@ -10,7 +10,7 @@ test_SCRIPTS += \
tests/ubifs_tools-tests/fsck_tests/fsck_bad_image.sh \
tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh
-test_DATA += \
+TEST_IMAGE_FILES = \
tests/ubifs_tools-tests/images/good.gz \
tests/ubifs_tools-tests/images/sb_fanout.gz \
tests/ubifs_tools-tests/images/sb_fmt_version.gz \
@@ -64,3 +64,6 @@ test_DATA += \
tests/ubifs_tools-tests/images/dir_lost_not_recover.gz \
tests/ubifs_tools-tests/images/root_dir.gz \
tests/ubifs_tools-tests/images/empty_tnc.gz
+
+test_DATA += $(TEST_IMAGE_FILES)
+EXTRA_DIST += $(TEST_IMAGE_FILES)