<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 22, 2021 at 11:06 AM Ryan Long <<a href="mailto:ryan.long@oarcorp.com">ryan.long@oarcorp.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">>> +#ifdef __sparc__<br>
>What's this for?<br>
Joel said this was a special case, and that it needed to be put in, so I'm not sure.<br></blockquote><div><br></div><div><a href="https://git.rtems.org/rtems/tree/cpukit/posix/src/sysconf.c#n57">https://git.rtems.org/rtems/tree/cpukit/posix/src/sysconf.c#n57</a></div><div><br></div><div>This was to support code in GCC which had hard-coded calls to this sysconf()</div><div>in the SPARC backend but I grep'ed for them and didn't find them on master.</div><div>Admittedly, I checked all the way back to egcs 1.1 and didn't find it there either</div><div>so I am probably not looking right.</div><div><br></div><div>If we are sure this isn't in GCC anymore, then it can be removed in a follow up</div><div>patch. </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
For the printf's in test_main(), I should take out all of the print statements saying<br>
<br>
"Testing <function>.....Success"?<br>
<br>
<br>
<br>
-----Original Message-----<br>
From: Gedare Bloom <<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>> <br>
Sent: Thursday, April 22, 2021 8:45 AM<br>
To: Ryan Long <<a href="mailto:ryan.long@oarcorp.com" target="_blank">ryan.long@oarcorp.com</a>><br>
Cc: <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
Subject: Re: [PATCH] psx13: Reworked and relicensed<br>
<br>
See below for comments. This test suite might be a good candidate for conversion to T_TEST_CASE framework. At any rate, this refactor is a marked improvement.<br>
<br>
On Wed, Apr 21, 2021 at 2:57 PM Ryan Long <<a href="mailto:ryan.long@oarcorp.com" target="_blank">ryan.long@oarcorp.com</a>> wrote:<br>
><br>
> Changed the way the tests were structured, added <br>
> rtems_test_assert()'s, updated psx13.scn and the license.<br>
<br>
relicense changes should generally Update #3899.<br>
<br>
> ---<br>
>  testsuites/psxtests/psx13/psx13.scn |  24 +-<br>
>  testsuites/psxtests/psx13/test.c    | 879 +++++++++++++-----------------------<br>
>  2 files changed, 335 insertions(+), 568 deletions(-)<br>
><br>
> diff --git a/testsuites/psxtests/psx13/psx13.scn <br>
> b/testsuites/psxtests/psx13/psx13.scn<br>
> index 428a931..ee99867 100644<br>
> --- a/testsuites/psxtests/psx13/psx13.scn<br>
> +++ b/testsuites/psxtests/psx13/psx13.scn<br>
> @@ -1,16 +1,16 @@<br>
>  *** POSIX TEST 13 ***<br>
><br>
>  Files initialized successfully.<br>
> -Testing device_lseek()... Failed!!!<br>
> -Testing dup()............ Failed!!!<br>
> -Testing dup2()........... Success.<br>
> -Testing fdatasync()...... Success.<br>
> -Testing umask().......... Success.<br>
> -Testing utime().......... Success.<br>
> -Testing utimes().......... Success.<br>
> -Testing fsync().......... Success.<br>
> -Testing pathconf()....... Success.<br>
> -Testing fpathconf()...... Success.<br>
> -Testing sync()......<br>
> +Testing lseek() on device... Success.<br>
> +Testing dup()............... Success.<br>
> +Testing dup2().............. Success.<br>
> +Testing fdatasync()......... Success.<br>
> +Testing umask()............. Success.<br>
> +Testing utime()............. Success.<br>
> +Testing utimes()............ Success.<br>
> +Testing fsync()............. Success.<br>
> +Testing pathconf().......... Success.<br>
> +Testing fpathconf()......... Success.<br>
> +Testing sync().............. Success.<br>
><br>
> -*** END OF TEST PSX13 ***<br>
> +*** END OF TEST PSX 13 ***<br>
> diff --git a/testsuites/psxtests/psx13/test.c <br>
> b/testsuites/psxtests/psx13/test.c<br>
> index 79b24c2..2d25b02 100644<br>
> --- a/testsuites/psxtests/psx13/test.c<br>
> +++ b/testsuites/psxtests/psx13/test.c<br>
> @@ -1,26 +1,49 @@<br>
> -/*<br>
> - *  Psx13<br>
> - *  Chris Bond (working under Jennifer's account)<br>
> +/**<br>
> + *  @file<br>
> + *<br>
> + *  @brief This tests various file system functions.<br>
>   *<br>
>   *  This test exercises the following routines:<br>
>   *<br>
> - *     device_lseek - test implemented<br>
> - *     dup          - test implemented<br>
> - *     dup2         - test implemented<br>
> - *     fdatasync    - test implemented<br>
> - *     fsync        - test implemented<br>
> - *     pathconf     - test implemented<br>
> - *     fpathconf    - test implemented<br>
> - *     umask        - test implemented<br>
> - *     utime        - test implemented<br>
> - *     utimes       - test implemented<br>
> + *     - lseek()<br>
> + *     - dup()<br>
> + *     - dup2()<br>
> + *     - fdatasync()<br>
> + *     - fsync()<br>
> + *     - pathconf()<br>
> + *     - fpathconf()<br>
> + *     - umask()<br>
> + *     - utime()<br>
> + *     - utimes()<br>
> + *     - sync()<br>
> + */<br>
> +<br>
<br>
While you're at it, please conform to<br>
<a href="https://docs.rtems.org/branches/master/eng/coding-file-hdr.html#c-c-header-file-template" rel="noreferrer" target="_blank">https://docs.rtems.org/branches/master/eng/coding-file-hdr.html#c-c-header-file-template</a><br>
<br>
> +/*<br>
> + *  SPDX-License-Identifier: BSD-2-Clause<br>
>   *<br>
> - *  COPYRIGHT (c) 1989-2009.<br>
> + *  COPYRIGHT (c) 1989-2009, 2021.<br>
>   *  On-Line Applications Research Corporation (OAR).<br>
>   *<br>
> - *  The license and distribution terms for this file may be<br>
> - *  found in the file LICENSE in this distribution or at<br>
> - *  <a href="http://www.rtems.org/license/LICENSE" rel="noreferrer" target="_blank">http://www.rtems.org/license/LICENSE</a>.<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + *    notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + *    notice, this list of conditions and the following disclaimer in the<br>
> + *    documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED <br>
> + TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR <br>
> + PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR <br>
> + CONTRIBUTORS BE<br>
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, <br>
> + OR<br>
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT <br>
> + OF<br>
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR <br>
> + BUSINESS<br>
> + * * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, <br>
> + WHETHER IN<br>
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR <br>
> + OTHERWISE)<br>
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF <br>
> + ADVISED OF THE<br>
> + * POSSIBILITY OF SUCH DAMAGE.<br>
>   */<br>
><br>
>  #ifdef HAVE_CONFIG_H<br>
> @@ -34,6 +57,7 @@<br>
>  #include <unistd.h><br>
>  #include <errno.h><br>
>  #include <utime.h><br>
> +#include <tmacros.h><br>
><br>
>  #include <stdio.h><br>
>  #include <unistd.h><br>
> @@ -42,685 +66,428 @@<br>
><br>
>  const char rtems_test_name[] = "PSX 13";<br>
><br>
> -int InitFiles(void);<br>
> -int DeviceLSeekTest(void);<br>
> -int DupTest(void);<br>
> -int Dup2Test(void);<br>
> -int FDataSyncTest(void);<br>
> -int UMaskTest(void);<br>
> -int UTimeTest(void);<br>
> -int UTimesTest(void);<br>
> -int PathConfTest(void);<br>
> -int FPathConfTest(void);<br>
> -int FSyncTest(void);<br>
> -<br>
> -/*-------------------------------------------------------------------<br>
> - * InitFiles function<br>
> - *<br>
> - * Initializes the three files to be used in the test.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: fopen, fprintf, fwrite, FILE are available<br>
> - * actions: creates testfile1, a text file with 'a'..'z' listed 4 times.<br>
> - *          creates testfile2, a text file with 'a'..'z' listed 4 times.<br>
> - *          creates testfile3, a binary file with 0..9 listed 4 times.<br>
> - * returns: TRUE if files opened successfully.<br>
> - *          FALSE if fail on file open for write.<br>
> - *<br>
> - * ------------------------------------------------------------------<br>
> +/**<br>
> + * @brief Initializes the three files to be used for the test.<br>
>   */<br>
> -<br>
> -int InitFiles (void)<br>
> +static void InitFiles( void )<br>
>  {<br>
>    int count;<br>
> +  int rv;<br>
>    FILE *fp1, *fp2, *fp3;<br>
>    char letter;<br>
>    int number;<br>
> -  int retval;<br>
> -<br>
> -  fp1 = fopen("testfile1.tst", "wt");<br>
> -  fp2 = fopen("testfile2.tst", "wt");<br>
> -  fp3 = fopen("testfile4.tst", "wb");<br>
><br>
> -  if ((fp1 != NULL) && (fp2 != NULL) && (fp3 !=NULL)) {<br>
> +  fp1 = fopen( "testfile1.tst", "wt" );  rtems_test_assert( fp1 != <br>
> + NULL );<br>
><br>
> -    letter = 'a';<br>
> +  fp2 = fopen( "testfile2.tst", "wt" );  rtems_test_assert( fp2 != <br>
> + NULL );<br>
><br>
> -    for (count=0 ; count<(26*4); ++count) {<br>
> -      fprintf (fp1, "%c", letter);<br>
> -      fprintf (fp2, "%c", letter);<br>
> +  fp3 = fopen( "testfile4.tst", "wb" );  rtems_test_assert( fp3 != <br>
> + NULL );<br>
><br>
> -      ++letter;<br>
> -      if (letter > 'z')<br>
> -       letter = 'a';<br>
> -    }<br>
> +  letter = 'a';<br>
><br>
> -    number = 0;<br>
> +  for( count = 0 ; count < (26*4); ++count) {<br>
> +    fprintf( fp1, "%c", letter );<br>
> +    fprintf( fp2, "%c", letter );<br>
><br>
> -    for (count = 0; count <40; ++count) {<br>
> -<br>
> -      fwrite (&number, 1, sizeof(int), fp3);<br>
> +    ++letter;<br>
> +    if( letter > 'z' )<br>
> +      letter = 'a';<br>
> +  }<br>
><br>
> -      ++number;<br>
> -      if (number > 9)<br>
> -       number = 0;<br>
> -    }<br>
> +  number = 0;<br>
><br>
> -    fclose(fp1);<br>
> -    fclose(fp2);<br>
> -    fclose(fp3);<br>
> +  for( count = 0; count < 40; ++count ) {<br>
> +    fwrite( &number, 1, sizeof(int), fp3 );<br>
><br>
> -    retval = TRUE;<br>
> +    ++number;<br>
> +    if( number > 9 )<br>
> +      number = 0;<br>
>    }<br>
><br>
> -  else<br>
> -    retval = FALSE;<br>
> +  rv = fclose( fp1 );<br>
> +  rtems_test_assert( rv != EOF );<br>
><br>
> -  /* assert (retval == TRUE);*/<br>
> +  rv = fclose( fp2 );<br>
> +  rtems_test_assert( rv != EOF );<br>
><br>
> -  return (retval);<br>
> +  rv = fclose( fp3 );<br>
> +  rtems_test_assert( rv != EOF );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * DeviceLSeekTest function<br>
> - *<br>
> - * Hits the device_lseek code by lseeking on the console.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: lseek available<br>
> - * actions: hits lseek with some dummy arguments.<br>
> - * returns: value of return from lseek.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Hits the device_lseek code by lseeking on the console.<br>
>   */<br>
> -<br>
> -int DeviceLSeekTest (void)<br>
> +static void DeviceLSeekTest( void )<br>
>  {<br>
> -  int error = -1, retval = FALSE;<br>
> +  int rv;<br>
> +  int fd;<br>
><br>
> -  int fd = open ("/dev/console", O_RDONLY);<br>
> +  fd = open( "/dev/console", O_RDONLY );  rtems_test_assert( fd != -1 <br>
> + );<br>
><br>
> -  error = lseek(fd, 5, SEEK_SET);<br>
> +  rv = lseek( fd, 5, SEEK_SET );<br>
> +  rtems_test_assert( rv == -1 );<br>
> +  rtems_test_assert( errno == ESPIPE );<br>
><br>
> -  if (error == 0)<br>
> -    retval = TRUE;<br>
> -  else<br>
> -    retval = FALSE;<br>
> -<br>
> -  close( fd );  /* assert (retval == TRUE);*/<br>
> -<br>
> -  return (retval);<br>
> +  rv = close( fd );<br>
> +  rtems_test_assert( rv == 0 );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * DupTest function<br>
> - *<br>
> - * Hits the dup code.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: dup, open, close, fcntl available.<br>
> - * actions: Gets a file descriptor(fd1) for test file1.<br>
> - *          dups fd1 to fd2.<br>
> - *          sets fd1 to append mode<br>
> - *          checks fd2 to ensure it's in append mode, also.<br>
> - * returns: success if fd2 is indeed a copy of fd1.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Exercises dup().<br>
>   */<br>
> -<br>
> -int DupTest(void)<br>
> +static void DupTest( void )<br>
>  {<br>
>    int fd1, fd2;<br>
> +  int flags;<br>
> +  int rv;<br>
><br>
> -  int flags = 0, retval = FALSE;<br>
> -<br>
> -  fd1 = open ("testfile1.tst", O_RDONLY);<br>
> -  fd2 = dup(fd1);<br>
> -<br>
> -  if (fd2 != -1) {<br>
> +  fd1 = open( "testfile1.tst", O_RDONLY );  rtems_test_assert( fd1 != <br>
> + -1 );<br>
><br>
> -    fcntl(fd1, F_SETFL, O_APPEND);<br>
> -    flags = fcntl(fd2, F_GETFL);<br>
> +  fd2 = dup( fd1 );<br>
> +  rtems_test_assert( fd2 != -1 );<br>
><br>
> -    close (fd1);<br>
> +  rv = fcntl( fd1, F_SETFL, O_APPEND );  rtems_test_assert( rv != -1 <br>
> + );<br>
><br>
> -    flags = (flags & O_APPEND);<br>
> +  flags = fcntl( fd2, F_GETFL );<br>
> +  flags = ( flags & O_APPEND );<br>
minor nit, this could be more concise<br>
flags = fcntl( fd2, F_GETFL) & O_APPEND;<br>
<br>
> +  rtems_test_assert( flags == 0 );<br>
><br>
> -    retval = (flags == O_APPEND);<br>
> -  }<br>
> -<br>
> -  else<br>
> -    retval = FALSE;<br>
> +  rv = close( fd1 );<br>
> +  rtems_test_assert( rv == 0 );<br>
><br>
Just curious, why be inconsistent how you check for the return from close? Above using != EOF, here using == 0. It doesn't matter greatly.<br>
<br>
> -  close( fd1 );<br>
> -  close( fd2 );<br>
> -  /* assert (retval == TRUE);*/<br>
> -<br>
> -  return (retval);<br>
> +  rv = close( fd2 );<br>
> +  rtems_test_assert( rv == 0 );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * Dup2Test function<br>
> - *<br>
> - * Hits the dup2 code.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: dup, dup2, open, close, fcntl available.<br>
> - * actions: Gets a file descriptor(fd1) for test file1.<br>
> - *          dups fd1 to fd2.<br>
> - *          sets fd1 to append mode<br>
> - *          checks fd2 to ensure it's in append mode, also.<br>
> - *          sets fd1 to invalid value, fd2 to valid, tries to dup2.<br>
> - *          sets fd2 to invalid value, fd1 to valid tries to dup2.<br>
> - * returns: success if fd2 is a copy of fd1, and invalid fd1 or fd2 produce errors.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Exercises dup2().<br>
>   */<br>
> -<br>
> -int Dup2Test(void)<br>
> +static void Dup2Test( void )<br>
>  {<br>
>    int fd1, fd2;<br>
> +  int flags;<br>
> +  int rv;<br>
><br>
> -  int flags = 0, retval = FALSE;<br>
> -<br>
> -  int error = 0;<br>
> +  fd1 = open( "testfile1.tst", O_RDONLY );  rtems_test_assert( fd1 != <br>
> + -1 );<br>
><br>
> -  fd1 = open ("testfile1.tst", O_RDONLY);<br>
> -  fd2 = open ("testfile2.tst", O_RDONLY);<br>
> -  error = dup2(fd1, fd2);<br>
> +  fd2 = open( "testfile2.tst", O_RDONLY );  rtems_test_assert( fd2 != <br>
> + -1 );<br>
><br>
>    /* make sure dup2 works if both fd1 and fd2 are valid file <br>
> descriptors. */<br>
> +  rv = dup2( fd1, fd2 );<br>
> +  rtems_test_assert( rv != -1 );<br>
><br>
> -  if (error != -1) {<br>
> +  rv = fcntl( fd1, F_SETFL, O_APPEND );  rtems_test_assert( rv != -1 <br>
> + );<br>
><br>
> -    fcntl(fd1, F_SETFL, O_APPEND);<br>
> -    flags = fcntl(fd1, F_GETFL);<br>
> +  flags = fcntl( fd1, F_GETFL );<br>
> +  flags = ( flags & O_APPEND );<br>
> +  rtems_test_assert( flags == O_APPEND );<br>
ditto on both conciseness and consistency here.<br>
<br>
><br>
> -    flags = (flags & O_APPEND);<br>
> -    retval = (flags == O_APPEND);<br>
> -  }<br>
> -<br>
> -  else {<br>
> -    retval = FALSE;<br>
> -    close(fd2);<br>
> -  }<br>
> -<br>
> -  if (retval == TRUE) {<br>
> +  /* make sure dup2 fails correctly if one or the other arguments are <br>
> + invalid. */<br>
> +  /* this assumes -1 is an invalid value for a file descriptor!!! <br>
> + (POSIX book, p.135) */  rv = close( fd1 );  rtems_test_assert( rv == <br>
> + 0 );<br>
><br>
> -    /* make sure dup2 fails correctly if one or the other arguments are invalid. */<br>
> -    /* this assumes -1 is an invalid value for a file descriptor!!! (POSIX book, p.135) */<br>
> +  fd1 = -1;<br>
><br>
> -    fd1 = -1;<br>
> +  rv = dup2( fd1, fd2 );<br>
> +  rtems_test_assert( rv == -1 );<br>
><br>
> -    if (dup2 (fd1, fd2) != -1)<br>
> -      retval = FALSE;<br>
> -    else {<br>
> -      fd1 = dup(fd2);<br>
> -      fd2 = -1;<br>
> +  fd1 = dup( fd2 );<br>
> +  fd2 = -1;<br>
><br>
> -      if (dup2(fd1, fd2) != -1)<br>
> -       retval = FALSE;<br>
> -    }<br>
> -  }<br>
> -<br>
> -  close (fd1);<br>
> -  close (fd2);<br>
> -  /* assert (retval == TRUE);*/<br>
> +  rv = dup2( fd1, fd2 );<br>
> +  rtems_test_assert( rv == -1 );<br>
><br>
> -  return (retval);<br>
> +  rv = close( fd1 );<br>
> +  rtems_test_assert( rv == 0 );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * FDataSyncTest function<br>
> - *<br>
> - * Hits the fdatasync code. Does NOT test the functionality of the<br>
> - * underlying fdatasync entry in the IMFS op table.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: open, close, fdatasync functions available.<br>
> - * actions: attempts to fdatasync a file descriptor flagged as read-only.<br>
> - *          attempts to fdatasync an invalid file descriptor (-1).<br>
> - *          attempts to fdatasync a perfectly valid fd opened as RDWR<br>
> - *<br>
> - * returns: TRUE if attempt to fdatasync invalid and read-only filed<br>
> - *           descriptor fail, and fdatasync succeeds on valid fd.<br>
> - *          FALSE otherwise.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Exercises fdatasync(). Does NOT test the functionality of the<br>
> + *        underlying fdatasync entry in the IMFS op table.<br>
>   */<br>
> -<br>
> -int FDataSyncTest(void)<br>
> +static void FDataSyncTest( void )<br>
>  {<br>
> -  int fd = -1;<br>
> -  int error = 0, retval = TRUE;<br>
> +  int fd;<br>
> +  int rv;<br>
><br>
>    /* Try it with a RD_ONLY file. */<br>
> +  fd = open( "testfile1.tst", O_RDONLY );  rtems_test_assert( fd != <br>
> + -1 );<br>
><br>
> -  fd = open ("testfile1.tst", O_RDONLY);<br>
> -<br>
> -  error = fdatasync(fd);<br>
> -  if ((error == -1) && (errno == EINVAL))<br>
> -    retval = TRUE;<br>
> -  else<br>
> -    retval = FALSE;<br>
> +  rv = fdatasync( fd );<br>
> +  rtems_test_assert( rv == -1 );<br>
> +  rtems_test_assert( errno == EBADF );<br>
><br>
> -  close (fd);<br>
> +  rv = close(fd);<br>
> +  rtems_test_assert( rv == 0 );<br>
><br>
> -  if (retval == TRUE) {<br>
> +  /* Try it with a bad file descriptor */  fd = -1;<br>
><br>
> -    /* Try it with a bad file descriptor */<br>
> -<br>
> -    fd = -1;<br>
> -<br>
> -    error = fdatasync(fd);<br>
> -    if ((errno == EBADF) && (error == -1))<br>
> -      retval = TRUE;<br>
> -    else<br>
> -      retval = FALSE;<br>
> -  }<br>
> +  rv = fdatasync( fd );<br>
> +  rtems_test_assert( rv == -1 );<br>
> +  rtems_test_assert( errno == EBADF );<br>
><br>
>    /* Okay - now the success case... */<br>
> +  fd = open( "testfile1.tst", O_RDWR );  rv = fdatasync( fd );  <br>
> + rtems_test_assert( rv == 0 );<br>
><br>
> -  if (retval == TRUE) {<br>
> -    fd = open ("testfile1.tst", O_RDWR);<br>
> -    error = fdatasync(fd);<br>
> -<br>
> -    if (error == 0)<br>
> -      retval = TRUE;<br>
> -    else<br>
> -      retval = FALSE;<br>
> -<br>
> -    close (fd);<br>
> -  }<br>
> -<br>
> -  /* assert (retval == TRUE);*/<br>
> -<br>
> -  return (retval);<br>
> +  rv = close( fd );<br>
> +  rtems_test_assert( rv == 0 );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * UMaskTest function<br>
> - *<br>
> - * Hits the umask code.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: umask function available.<br>
> - * actions: set umask to 0ctal 23.<br>
> - *          set umask to Octal 22, retrieve the old value.<br>
> - *<br>
> - * returns: TRUE if old value is 23,<br>
> - *          FALSE otherwise.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Hits the umask code.<br>
>   */<br>
> -<br>
> -int UMaskTest (void)<br>
> +static void UMaskTest( void )<br>
>  {<br>
> -  mode_t error = 0;<br>
> -  int    retval = FALSE;<br>
> -<br>
> -  umask(023);<br>
> -  error = umask(022);<br>
> +  mode_t rv;<br>
><br>
> -  if (error == 023)<br>
> -    retval = TRUE;<br>
> -  else<br>
> -    retval = FALSE;<br>
> +  (void)umask( 023 );<br>
nit: add a space after (void)<br>
<br>
><br>
> -  /* assert (retval == TRUE);*/<br>
> -<br>
> -  return(retval);<br>
> +  rv = umask( 022 );<br>
> +  rtems_test_assert( rv == 023 );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * UTimeTest function<br>
> - *<br>
> - * Hits the utime code. Does NOT test the functionality of the <br>
> underlying utime<br>
> - * entry in the IMFS op table.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: utime function available.<br>
> - * actions: set utime for an invalid filename.<br>
> - *          set utime for a valid filename.<br>
> - *<br>
> - * returns: TRUE if time on valid file is set correctly and utime failed on<br>
> - *          an invalid filename.<br>
> - *          FALSE otherwise.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Hits the utime code. Does not test the functionality of the<br>
> + *        underlying utime entry in the IMFS op table.<br>
>   */<br>
> -<br>
> -int UTimeTest (void)<br>
> +static void UTimeTest( void )<br>
>  {<br>
> -  int error = 0, retval = FALSE;<br>
> +  int rv;<br>
>    struct utimbuf time;<br>
>    struct stat fstat;<br>
><br>
>    /* First, an invalid filename. */<br>
> -  error = utime("!This is an =invalid p@thname!!! :)", NULL);<br>
> -<br>
> -  if (error == -1)<br>
> -    retval = TRUE;<br>
> -  else<br>
> -    retval = FALSE;<br>
> +  rv = utime( "!This is an =invalid p@thname!!! :)", NULL );  <br>
> + rtems_test_assert( rv == -1 );  rtems_test_assert( errno == ENOENT <br>
> + );<br>
><br>
>    /* Now, the success test. */<br>
> -  if (retval == TRUE) {<br>
> -<br>
> -    time.actime  = 12345;<br>
> -    time.modtime = 54321;<br>
> -<br>
> -    error = utime("testfile1.tst", &time);<br>
> +  time.actime  = 12345;<br>
> +  time.modtime = 54321;<br>
><br>
> -    if (error == 0) {<br>
> -<br>
> -      /* But, did it set the time? */<br>
> -      stat ("testfile1.tst", &fstat);<br>
> -<br>
> -      if ((fstat.st_atime == 12345) && (fstat.st_mtime == 54321 ))<br>
> -       retval = TRUE;<br>
> -      else<br>
> -       retval = FALSE;<br>
> -    }<br>
> -    else<br>
> -      retval = FALSE;<br>
> -<br>
> -    error = utime("testfile1.tst", NULL );<br>
> -    retval &= (error == 0) ? TRUE : FALSE;<br>
> -  }<br>
> +  rv = utime( "testfile1.tst", &time );  rtems_test_assert( rv == 0 <br>
> + );<br>
><br>
> -  /* assert (retval == TRUE);*/<br>
> +  /* But, did it set the time? */<br>
> +  rv = stat( "testfile1.tst", &fstat );  rtems_test_assert( rv == 0 <br>
> + );  rtems_test_assert( fstat.st_atime == 12345 );  <br>
> + rtems_test_assert( fstat.st_mtime == 54321 );<br>
><br>
> -  return (retval);<br>
> +  rv = utime( "testfile1.tst", NULL );  rtems_test_assert( rv == 0 );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * UTimesTest function<br>
> - *<br>
> - * Hits the utimes code. Does NOT test the functionality of the <br>
> underlying utime<br>
> - * entry in the IMFS op table.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: utimes function available.<br>
> - * actions: set utimes for an invalid filename.<br>
> - *          set utimes for a valid filename.<br>
> - *<br>
> - * returns: TRUE if time on valid file is set correctly and utimes failed on<br>
> - *          an invalid filename.<br>
> - *          FALSE otherwise.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Hits the utimes code. Does NOT test the functionality of the<br>
> + *        underlying utime entry in the IMFS op table.<br>
>   */<br>
> -<br>
> -int UTimesTest (void)<br>
> +static void UTimesTest( void )<br>
>  {<br>
> -  int error = 0, retval = FALSE;<br>
> +  int rv;<br>
>    struct timeval time[2];<br>
>    struct stat fstat;<br>
><br>
>    /* First, an invalid filename. */<br>
> -  error = utimes("!This is an =invalid p@thname!!! :)", NULL);<br>
> -<br>
> -  if (error == -1)<br>
> -    retval = TRUE;<br>
> -  else<br>
> -    retval = FALSE;<br>
> +  rv = utimes( "!This is an =invalid p@thname!!! : )", NULL);  <br>
> + rtems_test_assert( rv == -1 );  rtems_test_assert( errno == ENOENT <br>
> + );<br>
><br>
>    /* Now, the success test. */<br>
> -  if (retval == TRUE) {<br>
> +  time[0].tv_sec = 12345;<br>
> +  time[1].tv_sec = 54321;<br>
><br>
> -    time[0].tv_sec = 12345;<br>
> -    time[1].tv_sec = 54321;<br>
> +  rv = utimes( "testfile1.tst", (struct timeval *)&time );  <br>
> + rtems_test_assert( rv == 0 );<br>
><br>
> -    error = utimes("testfile1.tst", (struct timeval *)&time);<br>
> +  /* But, did it set the time? */<br>
> +  rv = stat( "testfile1.tst", &fstat );<br>
> +  rtems_test_assert( rv == 0 );<br>
> +  rtems_test_assert( fstat.st_atime == 12345 );<br>
> +  rtems_test_assert( fstat.st_mtime == 54321 ); }<br>
><br>
> -    if (error == 0) {<br>
> +/**<br>
> + * @brief Hits the pathconf code.<br>
> + */<br>
> +static void PathConfTest( void )<br>
> +{<br>
> +  int rv;<br>
><br>
> -      /* But, did it set the time? */<br>
> -      stat ("testfile1.tst", &fstat);<br>
> +  rv = pathconf( "thisfiledoesnotexist", _PC_LINK_MAX );  <br>
> + rtems_test_assert( rv == -1 );<br>
><br>
> -      if ((fstat.st_atime == 12345) && (fstat.st_mtime == 54321 ))<br>
> -       retval = TRUE;<br>
> -      else<br>
> -       retval = FALSE;<br>
> -    }<br>
> +  rv = pathconf( "testfile1.tst", _PC_LINK_MAX );<br>
> +  rtems_test_assert( rv != -1 );<br>
> +}<br>
><br>
> -    else<br>
> -      retval = FALSE;<br>
> -  }<br>
> +/**<br>
> + * @brief Hits the fpathconf code.<br>
> + */<br>
> +static void FPathConfTest( void )<br>
> +{<br>
> +  int rv;<br>
> +  int fd;<br>
><br>
> -  /* assert (retval == TRUE);*/<br>
> +  fd = -1;<br>
> +  rv = fpathconf( fd, _PC_LINK_MAX );  rtems_test_assert( rv == -1 );<br>
><br>
> -  return (retval);<br>
> -}<br>
> +  fd = open( "testfile1.tst", O_RDWR );  rtems_test_assert( fd != -1 <br>
> + );<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * PathConfTest function<br>
> - *<br>
> - * Hits the pathconf code.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: pathconf function available.<br>
> - * actions: Try to pathconf a bad filename.<br>
> - *          Try to pathconf a good filename.<br>
> - *<br>
> - * returns: TRUE if pathconf fails on bad file, succeeds on good file.<br>
> - *          FALSE otherwise.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> - */<br>
> +  rv = fpathconf( fd, _PC_LINK_MAX );  rtems_test_assert( rv != -1 );<br>
><br>
> -int PathConfTest (void)<br>
> -{<br>
> -  int error = 0, retval = FALSE;<br>
> +  rv = fpathconf( fd, _PC_MAX_CANON );  rtems_test_assert( rv != -1 <br>
> + );<br>
><br>
> -  error = pathconf("thisfiledoesnotexist", _PC_LINK_MAX);<br>
> +  rv = fpathconf( fd, _PC_MAX_INPUT );  rtems_test_assert( rv != -1 <br>
> + );<br>
><br>
> -  if (error == -1) {<br>
> -    error = pathconf("testfile1.tst", _PC_LINK_MAX);<br>
> +  rv = fpathconf( fd, _PC_NAME_MAX );  rtems_test_assert( rv != -1 );<br>
><br>
> -    if (error != -1)<br>
> -      retval = TRUE;<br>
> -    else<br>
> -      retval = FALSE;<br>
> -  }<br>
> +  rv = fpathconf( fd, _PC_PATH_MAX );  rtems_test_assert( rv != -1 );<br>
><br>
> -  else<br>
> -    retval = FALSE;<br>
> +  rv = fpathconf( fd, _PC_PIPE_BUF );  rtems_test_assert( rv != -1 );<br>
><br>
> -  /* assert (retval == TRUE);*/<br>
> +  rv = fpathconf( fd, _PC_CHOWN_RESTRICTED );  rtems_test_assert( rv <br>
> + != -1 );<br>
><br>
> -  return(retval);<br>
> -}<br>
> +  rv = fpathconf( fd, _PC_NO_TRUNC );  rtems_test_assert( rv != -1 );<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * FPathConfTest function<br>
> - *<br>
> - * Hits the fpathconf code.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: fpathconf function available.<br>
> - * actions: Call fpathconf with all arguments, plus an invalid.<br>
> - *<br>
> - * returns: TRUE always.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> - */<br>
> +  rv = fpathconf( fd, _PC_VDISABLE );  rtems_test_assert( rv != -1 );<br>
><br>
> -int FPathConfTest (void)<br>
> -{<br>
> -  int error = 0, retval = TRUE;<br>
> +  rv = fpathconf( fd, _PC_ASYNC_IO );  rtems_test_assert( rv != -1 );<br>
><br>
> -  int fd  = -1;<br>
> +  rv = fpathconf( fd, _PC_PRIO_IO );<br>
> +  rtems_test_assert( rv != -1 );<br>
><br>
> -  error = fpathconf(fd, _PC_LINK_MAX);<br>
> +  rv = fpathconf( fd, _PC_SYNC_IO );<br>
> +  rtems_test_assert( rv != -1 );<br>
><br>
> -  if (error == -1) {<br>
> -    fd = open("testfile1.tst", O_RDWR);<br>
> +  rv = fpathconf( fd, 255 );<br>
> +#ifdef __sparc__<br>
What's this for?<br>
<br>
> +  rtems_test_assert( rv == 0 );<br>
> +#else<br>
> +  rtems_test_assert( rv == -1 );<br>
> +#endif<br>
><br>
> -    error = fpathconf(fd, _PC_LINK_MAX);<br>
> -    error = fpathconf(fd, _PC_MAX_CANON);<br>
> -    error = fpathconf(fd, _PC_MAX_INPUT);<br>
> -    error = fpathconf(fd, _PC_NAME_MAX);<br>
> -    error = fpathconf(fd, _PC_PATH_MAX);<br>
> -    error = fpathconf(fd, _PC_PIPE_BUF);<br>
> -    error = fpathconf(fd, _PC_CHOWN_RESTRICTED);<br>
> -    error = fpathconf(fd, _PC_NO_TRUNC);<br>
> -    error = fpathconf(fd, _PC_VDISABLE);<br>
> -    error = fpathconf(fd, _PC_ASYNC_IO);<br>
> -    error = fpathconf(fd, _PC_PRIO_IO);<br>
> -    error = fpathconf(fd, _PC_SYNC_IO);<br>
> -    error = fpathconf(fd, 255);<br>
> +  rv = close( fd );<br>
> +  rtems_test_assert( rv == 0 );<br>
><br>
> -    close(fd);<br>
> +  fd = open( "testfile1.tst", O_WRONLY );  rtems_test_assert( rv != <br>
> + -1 );<br>
><br>
> -    fd = open("testfile1.tst", O_WRONLY);<br>
> +  rv = fpathconf( fd, _PC_LINK_MAX );  rtems_test_assert( rv != -1 );<br>
><br>
> -    error = fpathconf(fd, _PC_LINK_MAX);<br>
> +  rv = close( fd );<br>
> +  rtems_test_assert( rv == 0 );<br>
> +}<br>
><br>
> -    retval = TRUE;<br>
> -  }<br>
> +/**<br>
> + * @brief Hits the fsync code.<br>
> + */<br>
> +static void FSyncTest( void )<br>
> +{<br>
> +  int rv;<br>
> +  int fd;<br>
><br>
> -  else<br>
> -    retval = FALSE;<br>
> +  fd = open( "testfile1.tst", O_RDWR );  rtems_test_assert( fd != -1 <br>
> + );<br>
><br>
> -  /* assert (retval == TRUE);*/<br>
> +  rv = fsync(fd);<br>
> +  rtems_test_assert( rv != -1 );<br>
><br>
> -  return(retval);<br>
> +  rv = close( fd );<br>
> +  rtems_test_assert( rv == 0 );<br>
>  }<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * FSyncTest function<br>
> - *<br>
> - * Hits the fsync code.<br>
> - *<br>
> - * arguments: none<br>
> - * assumptions: open, fsync functions available.<br>
> - * actions: open test file,<br>
> - *          try to fsync it.<br>
> - *<br>
> - * returns: TRUE if fsync doesn't return -1,<br>
> - *          FALSE otherwise.<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> +/**<br>
> + * @brief Exercises sync().<br>
>   */<br>
> +static void SyncTest( void )<br>
> +{<br>
> +  sync();<br>
> +}<br>
><br>
> -int FSyncTest (void)<br>
> +/**<br>
> + * @brief The main entry point to the test.<br>
> + */<br>
> +int test_main( void );<br>
> +int test_main( void )<br>
>  {<br>
> -  int error = 0, retval = FALSE;<br>
> -  int fd = -1;<br>
> +  TEST_BEGIN();<br>
><br>
> -  fd = open("testfile1.tst", O_RDWR);<br>
> +  InitFiles();<br>
> +  printf( "\nFiles initialized successfully.\n" );<br>
><br>
remove the extraneous print statements. If things are working, the test output should be minimal/quiet just the start/end banners.<br>
<br>
> -  if (fd != -1) {<br>
> +  printf( "Testing lseek() on device... " );  DeviceLSeekTest();  <br>
> + printf( "Success.\n" );<br>
><br>
> -    error = fsync(fd);<br>
> +  printf( "Testing dup()............... " );  DupTest();  printf( <br>
> + "Success.\n" );<br>
><br>
> -    if (error != -1)<br>
> -      retval = TRUE;<br>
> -    else<br>
> -      retval = FALSE;<br>
> +  printf( "Testing dup2().............. " );  Dup2Test();  printf( <br>
> + "Success.\n" );<br>
><br>
> -    close(fd);<br>
> -  }<br>
> +  printf( "Testing fdatasync()......... " );  FDataSyncTest();  <br>
> + printf( "Success.\n" );<br>
><br>
> -  else<br>
> -    retval = FALSE;<br>
> +  printf( "Testing umask()............. " );  UMaskTest();  printf( <br>
> + "Success.\n" );<br>
><br>
> -  /* assert (retval == TRUE);*/<br>
> +  printf( "Testing utime()............. " );  UTimeTest();  printf( <br>
> + "Success.\n" );<br>
><br>
> -  return(retval);<br>
> -}<br>
> +  printf( "Testing utimes()............ " );  UTimesTest();  printf( <br>
> + "Success.\n" );<br>
><br>
> -/* ---------------------------------------------------------------<br>
> - * Main function<br>
> - *<br>
> - *  main entry point to the test<br>
> - *<br>
> - * ---------------------------------------------------------------<br>
> - */<br>
> +  printf( "Testing fsync()............. " );  FSyncTest();  printf( <br>
> + "Success.\n" );<br>
><br>
> -#if defined(__rtems__)<br>
> -int test_main(void);<br>
> -int test_main(void)<br>
> -#else<br>
> -int main(<br>
> -  int    argc,<br>
> -  char **argv<br>
> -)<br>
> -#endif<br>
> -{<br>
> -  TEST_BEGIN();<br>
> +  printf( "Testing pathconf().......... " );  PathConfTest();  <br>
> + printf( "Success.\n" );<br>
><br>
> -  if (InitFiles() == TRUE) {<br>
> -    printf ("\nFiles initialized successfully.\n");<br>
> -<br>
> -    printf ("Testing device_lseek()... ");<br>
> -    if (DeviceLSeekTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -    printf ("Testing dup()............ ");<br>
> -    if (DupTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -    printf ("Testing dup2()........... ");<br>
> -    if (Dup2Test() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -    printf ("Testing fdatasync()...... ");<br>
> -    if (FDataSyncTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -    printf ("Testing umask().......... ");<br>
> -    if (UMaskTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -   printf ("Testing utime().......... ");<br>
> -    if (UTimeTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -   printf ("Testing utimes().......... ");<br>
> -    if (UTimesTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -   printf ("Testing fsync().......... ");<br>
> -    if (FSyncTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -   printf ("Testing pathconf()....... ");<br>
> -    if (PathConfTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -   printf ("Testing fpathconf()...... ");<br>
> -    if (FPathConfTest() == TRUE)<br>
> -      printf ("Success.\n");<br>
> -    else<br>
> -      printf ("Failed!!!\n");<br>
> -<br>
> -    printf ("Testing sync()...... ");<br>
> -    sync();<br>
> -    printf ("Done.\n");<br>
> -<br>
> -    TEST_END();<br>
> -  }<br>
> +  printf( "Testing fpathconf()......... " );  FPathConfTest();  <br>
> + printf( "Success.\n" );<br>
> +<br>
> +  printf( "Testing sync().............. " );  SyncTest();  printf( <br>
> + "Success.\n" );<br>
> +<br>
> +  TEST_END();<br>
><br>
> -  rtems_test_exit(0);<br>
> +  rtems_test_exit( 0 );<br>
>  }<br>
> --<br>
> 1.8.3.1<br>
><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>