summaryrefslogtreecommitdiffstats
path: root/testsuites/fstests
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-11-27 12:45:53 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-02-05 10:17:04 +0100
commit03fcbb15d24e2eec41bac9f5dee30bbf7dc888b8 (patch)
treece9f909c5a3a4ef34dba010f9b8cfafa0fa52eb4 /testsuites/fstests
parentriscv: Fix misaligned access in context validate (diff)
downloadrtems-03fcbb15d24e2eec41bac9f5dee30bbf7dc888b8.tar.bz2
fs: Add struct dirent::d_type support
Diffstat (limited to 'testsuites/fstests')
-rw-r--r--testsuites/fstests/fsscandir01/init.c89
1 files changed, 62 insertions, 27 deletions
diff --git a/testsuites/fstests/fsscandir01/init.c b/testsuites/fstests/fsscandir01/init.c
index e92d2feceb..d7fb43c26b 100644
--- a/testsuites/fstests/fsscandir01/init.c
+++ b/testsuites/fstests/fsscandir01/init.c
@@ -8,47 +8,82 @@
*/
#ifdef HAVE_CONFIG_H
- #include "config.h"
+#include "config.h"
#endif
-#include "fstest.h"
-#include "fs_config.h"
-#include "fstest_support.h"
-#include "pmacros.h"
-
+#include <sys/stat.h>
#include <dirent.h>
+#include <fcntl.h>
+#include <limits.h>
#include <stdio.h>
-#include <string.h>
#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
+
+#include <tmacros.h>
+
+#include "fstest.h"
+#include "fs_config.h"
const char rtems_test_name[] = "FSSCANDIR " FILESYSTEM;
-/*
- * This code is from the scandir() man page.
- */
-static void test_scandir(void)
+#define FILE_NAME "aaa"
+
+#define DIR_NAME "bbb"
+
+void test(void)
{
struct dirent **namelist;
+ struct dirent *d;
+ int rv;
int n;
+ int i;
+
+ rtems_test_assert(MAXNAMLEN == NAME_MAX);
+
+ rv = mknod(FILE_NAME, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
+ rtems_test_assert(rv == 0);
+
+ rv = mkdir(DIR_NAME, S_IRWXU | S_IRWXG | S_IRWXO );
+ rtems_test_assert(rv == 0);
+
+ n = scandir(".", &namelist, NULL, alphasort);
+ rtems_test_assert(2 <= n || n == 4);
- n = scandir(".", &namelist, 0, NULL);
- if (n < 0) {
- perror("scandir");
- } else {
- while(n--) {
- printf("%s\n", namelist[n]->d_name);
- free(namelist[n]);
- }
- free(namelist);
+ i = 0;
+ d = namelist[i];
+
+ if (n >= 3) {
+ rtems_test_assert(strcmp(d->d_name, ".") == 0);
+#ifdef DT_UNKNOWN
+ rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
+#endif
+ free(d);
+ ++i;
+ d = namelist[i];
}
- rtems_test_assert(MAXNAMLEN == NAME_MAX);
-}
+ if (n == 4) {
+ rtems_test_assert(strcmp(d->d_name, "..") == 0);
+#ifdef DT_UNKNOWN
+ rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
+#endif
+ free(d);
+ ++i;
+ d = namelist[i];
+ }
+ rtems_test_assert(strcmp(d->d_name, FILE_NAME) == 0);
+#ifdef DT_UNKNOWN
+ rtems_test_assert(d->d_type == DT_REG || d->d_type == DT_UNKNOWN);
+#endif
+ free(d);
+ ++i;
+ d = namelist[i];
-void test (void)
-{
- test_scandir();
+ rtems_test_assert(strcmp(d->d_name, DIR_NAME) == 0);
+#ifdef DT_UNKNOWN
+ rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
+#endif
+ free(d);
+
+ free(namelist);
}