From 03fcbb15d24e2eec41bac9f5dee30bbf7dc888b8 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 27 Nov 2018 12:45:53 +0100 Subject: fs: Add struct dirent::d_type support --- testsuites/fstests/fsscandir01/init.c | 89 ++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 27 deletions(-) (limited to 'testsuites/fstests') 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 #include +#include +#include #include -#include #include -#include -#include + +#include + +#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); } -- cgit v1.2.3