[PATCH v2] Test suite for FTW.H methods

Eshan Dhawan eshandhawan51 at gmail.com
Tue Feb 9 19:23:02 UTC 2021


ping !!


On Thu, Feb 4, 2021 at 3:04 AM Eshan Dhawan <eshandhawan51 at gmail.com> wrote:

> From: Eshan dhawan <eshandhawan51 at gmail.com>
>
> Signed-off-by: Eshan Dhawan <eshandhawan51 at gmail.com>
> ---
>  spec/build/testsuites/psxtests/grp.yml      |   2 +
>  spec/build/testsuites/psxtests/psxftw01.yml |  34 ++++
>  testsuites/psxtests/Makefile.am             |  26 +++
>  testsuites/psxtests/configure.ac            |   1 +
>  testsuites/psxtests/psxftw01/init.c         | 204 ++++++++++++++++++++
>  testsuites/psxtests/psxftw01/psxftw01.doc   |  18 ++
>  testsuites/psxtests/psxftw01/psxftw01.scn   |  10 +
>  testsuites/psxtests/psxftw01/psxftw01.tar   | Bin 0 -> 3584 bytes
>  8 files changed, 295 insertions(+)
>  create mode 100644 spec/build/testsuites/psxtests/psxftw01.yml
>  create mode 100644 testsuites/psxtests/psxftw01/init.c
>  create mode 100644 testsuites/psxtests/psxftw01/psxftw01.doc
>  create mode 100644 testsuites/psxtests/psxftw01/psxftw01.scn
>  create mode 100644 testsuites/psxtests/psxftw01/psxftw01.tar
>
> diff --git a/spec/build/testsuites/psxtests/grp.yml
> b/spec/build/testsuites/psxtests/grp.yml
> index 47dedac275..fb7ce465ae 100644
> --- a/spec/build/testsuites/psxtests/grp.yml
> +++ b/spec/build/testsuites/psxtests/grp.yml
> @@ -109,6 +109,8 @@ links:
>    uid: psxfile02
>  - role: build-dependency
>    uid: psxfilelock01
> +- role: build-dependency
> +  uid: psxftw01
>  - role: build-dependency
>    uid: psxgetattrnp01
>  - role: build-dependency
> diff --git a/spec/build/testsuites/psxtests/psxftw01.yml
> b/spec/build/testsuites/psxtests/psxftw01.yml
> new file mode 100644
> index 0000000000..c8b2a4fb59
> --- /dev/null
> +++ b/spec/build/testsuites/psxtests/psxftw01.yml
> @@ -0,0 +1,34 @@
> +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
> +build-type: script
> +cflags: []
> +copyrights:
> +- Copyright (C) 2020 Eshan Dhawan
> +cppflags: []
> +do-build: |
> +  path = "testsuites/psxtests/psxftw01/"
> +  tar = path + "psxftw01.tar"
> +  tar_gz = self.gzip(bld, tar)
> +  tar_xz = self.xz(bld, tar)
> +  tar_c, tar_h = self.bin2c(bld, tar)
> +  tar_gz_c, tar_gz_h = self.bin2c(bld, tar_gz)
> +  tar_xz_c, tar_xz_h = self.bin2c(bld, tar_xz)
> +  objs = []
> +  objs.append(self.cc(bld, bic, tar_c))
> +  objs.append(self.cc(bld, bic, tar_gz_c))
> +  objs.append(self.cc(bld, bic, tar_xz_c))
> +  objs.append(self.cc(bld, bic, path + "init.c", deps=[tar_h, tar_gz_h,
> tar_xz_h], cppflags=bld.env.TEST_psxftw01_CPPFLAGS))
> +  objs.append(self.cc(bld, bic,
> "testsuites/psxtests/psxfile01/test_cat.c", target=path + "test_cat.o"))
> +  self.link_cc(bld, bic, objs, "testsuites/psxtests/psxftw01.exe")
> +do-configure: null
> +enabled-by: true
> +includes:
> +- testsuites/psxtests/psxftw01
> +ldflags: []
> +links: []
> +prepare-build: null
> +prepare-configure: null
> +stlib: []
> +type: build
> +use-after:
> +- z
> +use-before: []
> diff --git a/testsuites/psxtests/Makefile.am
> b/testsuites/psxtests/Makefile.am
> index d89bcd8801..a35f00b665 100755
> --- a/testsuites/psxtests/Makefile.am
> +++ b/testsuites/psxtests/Makefile.am
> @@ -453,6 +453,32 @@ psxfilelock01_CPPFLAGS = $(AM_CPPFLAGS)
> $(TEST_FLAGS_psxfilelock01) \
>         $(support_includes)
>  endif
>
> +if TEST_psxftw01
> +psx_tests += psxftw01
> +psx_screens += psxftw01/psxftw01.scn
> +psx_docs += psxftw01/psxftw01.doc
> +psxftw01_SOURCES = psxftw01/init.c psxfile01/test_cat.c \
> +       psxftw01-tar.c psxftw01-tar.h psxftw01-tar-gz.c psxftw01-tar-gz.h
> +
> +psxftw01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxftw01) \
> +       $(support_includes) $(test_includes) -I$(top_srcdir)/include
> +psxftw01_LDADD = $(RTEMS_ROOT)cpukit/librtemscpu.a
> $(RTEMS_ROOT)cpukit/libz.a $(LDADD)
> +psxftw01-tar.c: psxftw01/psxftw01.tar
> +       $(AM_V_GEN)$(BIN2C) -C $< $@
> +psxftw01-tar.h: psxftw01/psxftw01.tar
> +       $(AM_V_GEN)$(BIN2C) -H $< $@
> +psxftw01-tar.o: psxftw01-tar.c psxftw01-tar.h
> +psxftw01.tar.gz: psxftw01/psxftw01.tar
> +       $(AM_V_GEN)$(GZIP) < $< > $@
> +psxftw01-tar-gz.c: psxftw01.tar.gz
> +       $(AM_V_GEN)$(BIN2C) -C $< $@
> +psxftw01-tar-gz.h: psxftw01.tar.gz
> +       $(AM_V_GEN)$(BIN2C) -H $< $@
> +CLEANFILES += psxftw01.tar psxftw01-tar.c psxftw01-tar.h \
> +       psxftw01.tar.gz psxftw01-tar-gz.c psxftw01-tar-gz.h
> +psxftw01/init.c: psxftw01-tar.h psxftw01-tar-gz.h $(TAR01_XZ_H)
> +endif
> +
>  if TEST_psxgetattrnp01
>  psx_tests += psxgetattrnp01
>  psx_screens += psxgetattrnp01/psxgetattrnp01.scn
> diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/
> configure.ac
> index 139787cccb..3f95010cd3 100644
> --- a/testsuites/psxtests/configure.ac
> +++ b/testsuites/psxtests/configure.ac
> @@ -90,6 +90,7 @@ RTEMS_TEST_CHECK([psxfenv01])
>  RTEMS_TEST_CHECK([psxfile01])
>  RTEMS_TEST_CHECK([psxfile02])
>  RTEMS_TEST_CHECK([psxfilelock01])
> +RTEMS_TEST_CHECK([psxftw01])
>  RTEMS_TEST_CHECK([psxgetattrnp01])
>  RTEMS_TEST_CHECK([psxgetrusage01])
>  RTEMS_TEST_CHECK([psxglobalcon01])
> diff --git a/testsuites/psxtests/psxftw01/init.c
> b/testsuites/psxtests/psxftw01/init.c
> new file mode 100644
> index 0000000000..bc3858395f
> --- /dev/null
> +++ b/testsuites/psxtests/psxftw01/init.c
> @@ -0,0 +1,204 @@
> +/*
> + *  @file
> + *  @brief Test suite for ftw.h methods
> + */
> +
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Copyright (C) 2020 Eshan Dhawan, embedded brains GmbH, Joel Sherrill
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
> "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
> BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +/* Header files */
> +#include <bsp.h> /* for device driver prototypes */
> +#include "tmacros.h"
> +#include <rtems.h>
> +#include <rtems/bspIo.h>
> +#include <rtems/untar.h>
> +#include <rtems/error.h>
> +#include <ftw.h>
> +#include <dirent.h>
> +#include <sys/stat.h>
> +#include <errno.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <rtems/test.h>
> +
> +#include "psxftw01-tar.h"
> +#include "psxftw01-tar-gz.h"
> +
> +#define TARFILE_START    psxftw01_tar
> +#define TARFILE_SIZE     psxftw01_tar_size
> +#define TARFILE_GZ_START psxftw01_tar_gz
> +#define TARFILE_GZ_SIZE  psxftw01_tar_gz_size
> +
> +const char rtems_test_name[] = "psxftw01";
> +/* Function decleration to avoid warning */
> +void *POSIX_Init (void * argument);
> +
> +static char  file_traverse_order[6][20];
> +static int file_order;
> +
> +static char buffer[512];
> +
> +static const T_action actions[] = {
> +  T_report_hash_sha256,
> +  T_check_task_context,
> +  T_check_file_descriptors,
> +  T_check_rtems_barriers,
> +  T_check_rtems_extensions,
> +  T_check_rtems_message_queues,
> +  T_check_rtems_partitions,
> +  T_check_rtems_periods,
> +  T_check_rtems_regions,
> +  T_check_rtems_semaphores,
> +  T_check_rtems_tasks,
> +  T_check_rtems_timers,
> +  T_check_posix_keys
> +};
> +
> +static const T_config config = {
> +  .name = "psxftw01",
> +  .buf = buffer,
> +  .buf_size = sizeof(buffer),
> +  .putchar = rtems_put_char,
> +  .verbosity = T_VERBOSE,
> +  .now = T_now_clock,
> +  .action_count = T_ARRAY_SIZE(actions),
> +  .actions = actions
> +};
> +
> +
> +static int fn_function (const char *fpath, const struct stat *sb,
> +int tflag, struct FTW *ftwbuf)
> +{
> +  strcpy(file_traverse_order [file_order], fpath + ftwbuf->base) ;
> +  file_order = file_order + 1;
> +  return 0; /* to make nftw run further */
> +}
> +
> +
> +T_TEST_CASE(ftw)
> +{
> +
> +  /* VARIABLE DECLEARATION */
> +  int r;
> +  char *files_path;
> +  int flags;
> +  int i;
> +  /* setting up filesystem */
> +  rtems_status_code sc;
> +
> +  /*Untaring from memory */
> +  sc = Untar_FromMemory_Print(
> +   (void *)TARFILE_START,
> +   TARFILE_SIZE,
> +   &rtems_test_printer
> +   );
> +  if (sc != RTEMS_SUCCESSFUL) {
> +     printf ("error: untar failed: %s\n", rtems_status_text (sc));
> +   }
> +
> +  /* Array with expected file order */
> +  char arr_ftw_depth[5][20] = { "test_file", "test_script", "def", "abc",
> "home" };
> +  char arr_ftw_phys[5][20] = { "home", "test_file", "abc", "def",
> "test_script" };
> +  /* defining the path to run nftw*/
> +  files_path = "/home";
> +  /* nftw test with FTW_DEPTH flag*/
> +  flags = 0;
> +  file_order = 0;
> +  flags |= FTW_DEPTH;
> +  r = nftw( files_path, fn_function, 5, flags );
> +
> +  T_quiet_psx_success(r);
> +
> +  /*comparing the nftw file tree to the expexted file tree traversal */
> +  for (i = 0; i < file_order; i++){
> +    r = strcmp( arr_ftw_depth[i], file_traverse_order[i]);
> +    if (r){
> +      printf( "Incorrect Order " );
> +    }
> +    T_quiet_psx_success(r);
> +  }
> +    /*----------------Test Block 2--------------------*/
> +  flags = 0;
> +  file_order = 0;
> +  flags |= FTW_PHYS;
> +  r = nftw( files_path, fn_function, 5, flags );
> +  T_quiet_psx_success(r);
> +
> +  /*comparing the nftw file tree to the expected file tree traversal*/
> +  for (i = 0; i < file_order; i++){
> +    r = strcmp( arr_ftw_phys[i], file_traverse_order[i]);
> +    if (r){
> +      printf( "Incorrect Order " );
> +    }
> +    T_quiet_psx_success(r);
> +  }
> +
> +}
> +
> +void *POSIX_Init (void * argument)
> +{
> +  int exit_code;
> +
> +  TEST_BEGIN();
> +
> +  T_register();
> +  exit_code = T_main(&config);
> +  if (exit_code == 0) {
> +    TEST_END();
> +  }
> +
> + rtems_test_exit(exit_code);
> +
> +}
> +
> +/* NOTICE: the clock driver is explicitly disabled */
> +
> +#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
> +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> +
> +#define CONFIGURE_MAXIMUM_TASKS                  1
> +
> +#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 6
> +
> +#define CONFIGURE_MAXIMUM_POSIX_THREADS  2
> +
> +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
> +
> +#define CONFIGURE_POSIX_INIT_THREAD_TABLE
> +
> +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
> +
> +
> +#define CONFIGURE_INIT
> +#include <rtems/confdefs.h>
> +/* end of file */
> diff --git a/testsuites/psxtests/psxftw01/psxftw01.doc
> b/testsuites/psxtests/psxftw01/psxftw01.doc
> new file mode 100644
> index 0000000000..7b2863a2da
> --- /dev/null
> +++ b/testsuites/psxtests/psxftw01/psxftw01.doc
> @@ -0,0 +1,18 @@
> +#  COPYRIGHT (c) 2019
> +#  On-Line Applications Research Corporation (OAR).
> +#
> +# SPDX-License-Identifier: BSD-2-Clause
> +#
> +
> +This file describes the directives and concepts tested by this test set.
> +
> +test set name:  psxftw01
> +
> +Directives:
> +nftw
> +
> +Concepts:
> +
> ++ This test exercises the ftw.h methods.
> +
> +
> diff --git a/testsuites/psxtests/psxftw01/psxftw01.scn
> b/testsuites/psxtests/psxftw01/psxftw01.scn
> new file mode 100644
> index 0000000000..650d365033
> --- /dev/null
> +++ b/testsuites/psxtests/psxftw01/psxftw01.scn
> @@ -0,0 +1,10 @@
> +*** BEGIN OF TEST psxftw01 ***
> +
> +untar: memory at 0x12608c (10240)
> +untar: file: home/test_file (s:73,m:0644)
> +untar: file: home/abc/def/test_script (s:21,m:0755)
> +untar: symlink: home/test_file -> symlink
> +
> +*** END OF TEST psxftw01 ***
> +
> +
> diff --git a/testsuites/psxtests/psxftw01/psxftw01.tar
> b/testsuites/psxtests/psxftw01/psxftw01.tar
> new file mode 100644
> index
> 0000000000000000000000000000000000000000..e45d10793a9fbcadc7d1ee84d42d13ff8eb2655e
> GIT binary patch
> literal 3584
> zcmeHJ!EVAZ4DFe(@U-)WlQ!uW?6}Lu9R)~fM4C=@nZ)1Eq3gsD8sbnuTCGY}>(?ZH
> z$+J_|m7TVh+Iiu;O$ISU)L8}z$~2RB;5iUY2mvD1LQAC(Q$V4$zyxrR)f^4FrPeeF
> zBH4wZ)|oIbj}YDKs;-O+uqE5jDL|JBC$~2^1-Zv>v(gdpV;~*^s0;A5S-G$V6X0$3
> z^7;<(V9<_QTS3v(6$d6RIHt-2QwOdxYx_L8$K=K}on at em`ZtT^bY+XK4$!i3AMM#6
> zF95J2a;2g)M6RO#e|#qvlo~|FMM7yQ8Nm8amAtb4L+xGhM*%z+?{(k%3;4Mu^zi{K
> zl`Lsb at Z=2vAB4|Q%(vW<tIkck%Db=`bk3;%JU{6B{XO7Y{_KADe~DZN5|I1iH1Or*
> TpZEVkH+~#^WME|At{M0OLN<HT
>
> literal 0
> HcmV?d00001
>
> --
> 2.27.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20210210/de1d94b7/attachment-0001.html>


More information about the devel mailing list