Re: [rtems commit] untar: Make behavior similar to GNU or BSD tar

2021-12-08 Thread Christian MAUDERER

Hello Chris,

sorry that I haven't been clear enough.

1. The ticket #4552 that I created before sending the patch to the list 
and that was closed by the patch was for 5.


2. I asked as an answer to Joels review and I understood him that he is 
OK with that change:


  https://lists.rtems.org/pipermail/devel/2021-December/070092.html

and

  https://lists.rtems.org/pipermail/devel/2021-December/070093.html

Do you want me to revert that patch on 5?

Best regards

Christian

Am 09.12.21 um 08:33 schrieb Chris Johns:

Hi Christian,

I did not know this was for the 5 branch. Where was this discussed?

Functional changes to a release branch need to be treated carefully and in this
case I would not approve it. I am sorry if I did not pick up it was for 5 as 
well.

Thanks
Chris

On 9/12/21 6:21 pm, Christian Mauderer wrote:

Module:rtems
Branch:5
Commit:ff3f3490df7120c9ec039b5acd1935265c3f9262
Changeset: 
http://git.rtems.org/rtems/commit/?id=ff3f3490df7120c9ec039b5acd1935265c3f9262

Author:Christian Mauderer 
Date:  Wed Dec  1 16:39:46 2021 +0100

untar: Make behavior similar to GNU or BSD tar

RTEMS untar implementation had problems with overwriting or integrating
archives into existing directory structures. This patch adapts the
behavior to mimic that of a GNU tar or BSD tar and extends the tar01
test to check for the behavior. That is:

* If a directory structure exists, the files from the archive will be
   integrated. Existing files are overwritten.

* If a file exists and the archive contains a directory with the same
   name, the file is removed and a directory is created. In the above
   example: if l1/l2 is a file it will be overwritten with a new
   directory.

* If a directory exists and the archive contains a file with the same
   name, the directory will be replaced if it is empty. If it contains
   files, the result is an error.

* An archive also can contain only a file without the parent
   directories. If in that case one of the parent directories exists as a
   file extracting the archive results in an error. In the example: if
   l1/l2 is a file and the archive doesn't contain the directories but
   only the file l1/l2/x.txt that would be an error.

* In case of an error, it is possible that the archive has been
   partially extracted.

Closes #4552

---

  cpukit/libmisc/untar/untar.c|  57 +++
  testsuites/libtests/tar01/init.c| 199 +++-
  testsuites/libtests/tar01/tar01.doc |   1 +
  testsuites/libtests/tar01/tar01.scn |  54 --
  testsuites/libtests/tar01/tar01.tar | Bin 10240 -> 10240 bytes
  5 files changed, 282 insertions(+), 29 deletions(-)

diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index a2f09fb..ab2 100644
--- a/cpukit/libmisc/untar/untar.c
+++ b/cpukit/libmisc/untar/untar.c
@@ -126,30 +126,25 @@ Make_Path(const rtems_printer *printer, char *path)
  
  *p = '\0';

  if (p[1] == '\0') {
-  /* Speculatively unlink the last component so that it can be re-created 
*/
-  unlink(path);
return 0;
  }
  
  if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {

-  if (errno == EEXIST || errno == EISDIR) {
+  if (errno == EEXIST) {
+/* If it exists already: Check whether it is a directory */
  struct stat sb;
-
-if (stat(path, ) != 0) {
+if (lstat(path, ) != 0) {
+  Print_Error(printer, "lstat", path);
+  return -1;
+} else if (!S_ISDIR(sb.st_mode)) {
+  rtems_printf(printer,
+   "untar: mkdir: %s: exists but is not a directory\n",
+   path);
return -1;
  }
-
-if (!S_ISDIR(sb.st_mode)) {
-  if (unlink(path) != 0) {
-Print_Error(printer, "unlink", path);
-return -1;
-  }
-
-  if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
-Print_Error(printer, "mkdir (unlink)", path);
-return -1;
-  }
-}
+  } else {
+Print_Error(printer, "mkdir", path);
+return -1;
}
  }
  
@@ -206,6 +201,12 @@ Untar_ProcessHeader(
  
if (Make_Path(ctx->printer, ctx->file_path) != 0) {

  retval = UNTAR_FAIL;
+  } else {
+/*
+ * Speculatively unlink. This should unlink everything but non-empty
+ * directories or write protected stuff.
+ */
+unlink(ctx->file_path);
}
  
if (ctx->linkflag == SYMTYPE) {

@@ -225,8 +226,22 @@ Untar_ProcessHeader(
  rtems_printf(ctx->printer, "untar: dir: %s\n", ctx->file_path);
  r = mkdir(ctx->file_path, ctx->mode);
  if (r != 0) {
-  Print_Error(ctx->printer, "mkdir", ctx->file_path);
-  retval = UNTAR_FAIL;
+  if (errno == EEXIST) {
+/* If it exists already: Check whether it is a directory */
+struct stat sb;
+if (lstat(ctx->file_path, ) != 0) {
+  Print_Error(ctx->printer, "lstat", 

Re: [rtems commit] untar: Make behavior similar to GNU or BSD tar

2021-12-08 Thread Chris Johns
Hi Christian,

I did not know this was for the 5 branch. Where was this discussed?

Functional changes to a release branch need to be treated carefully and in this
case I would not approve it. I am sorry if I did not pick up it was for 5 as 
well.

Thanks
Chris

On 9/12/21 6:21 pm, Christian Mauderer wrote:
> Module:rtems
> Branch:5
> Commit:ff3f3490df7120c9ec039b5acd1935265c3f9262
> Changeset: 
> http://git.rtems.org/rtems/commit/?id=ff3f3490df7120c9ec039b5acd1935265c3f9262
> 
> Author:Christian Mauderer 
> Date:  Wed Dec  1 16:39:46 2021 +0100
> 
> untar: Make behavior similar to GNU or BSD tar
> 
> RTEMS untar implementation had problems with overwriting or integrating
> archives into existing directory structures. This patch adapts the
> behavior to mimic that of a GNU tar or BSD tar and extends the tar01
> test to check for the behavior. That is:
> 
> * If a directory structure exists, the files from the archive will be
>   integrated. Existing files are overwritten.
> 
> * If a file exists and the archive contains a directory with the same
>   name, the file is removed and a directory is created. In the above
>   example: if l1/l2 is a file it will be overwritten with a new
>   directory.
> 
> * If a directory exists and the archive contains a file with the same
>   name, the directory will be replaced if it is empty. If it contains
>   files, the result is an error.
> 
> * An archive also can contain only a file without the parent
>   directories. If in that case one of the parent directories exists as a
>   file extracting the archive results in an error. In the example: if
>   l1/l2 is a file and the archive doesn't contain the directories but
>   only the file l1/l2/x.txt that would be an error.
> 
> * In case of an error, it is possible that the archive has been
>   partially extracted.
> 
> Closes #4552
> 
> ---
> 
>  cpukit/libmisc/untar/untar.c|  57 +++
>  testsuites/libtests/tar01/init.c| 199 
> +++-
>  testsuites/libtests/tar01/tar01.doc |   1 +
>  testsuites/libtests/tar01/tar01.scn |  54 --
>  testsuites/libtests/tar01/tar01.tar | Bin 10240 -> 10240 bytes
>  5 files changed, 282 insertions(+), 29 deletions(-)
> 
> diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
> index a2f09fb..ab2 100644
> --- a/cpukit/libmisc/untar/untar.c
> +++ b/cpukit/libmisc/untar/untar.c
> @@ -126,30 +126,25 @@ Make_Path(const rtems_printer *printer, char *path)
>  
>  *p = '\0';
>  if (p[1] == '\0') {
> -  /* Speculatively unlink the last component so that it can be 
> re-created */
> -  unlink(path);
>return 0;
>  }
>  
>  if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
> -  if (errno == EEXIST || errno == EISDIR) {
> +  if (errno == EEXIST) {
> +/* If it exists already: Check whether it is a directory */
>  struct stat sb;
> -
> -if (stat(path, ) != 0) {
> +if (lstat(path, ) != 0) {
> +  Print_Error(printer, "lstat", path);
> +  return -1;
> +} else if (!S_ISDIR(sb.st_mode)) {
> +  rtems_printf(printer,
> +   "untar: mkdir: %s: exists but is not a directory\n",
> +   path);
>return -1;
>  }
> -
> -if (!S_ISDIR(sb.st_mode)) {
> -  if (unlink(path) != 0) {
> -Print_Error(printer, "unlink", path);
> -return -1;
> -  }
> -
> -  if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
> -Print_Error(printer, "mkdir (unlink)", path);
> -return -1;
> -  }
> -}
> +  } else {
> +Print_Error(printer, "mkdir", path);
> +return -1;
>}
>  }
>  
> @@ -206,6 +201,12 @@ Untar_ProcessHeader(
>  
>if (Make_Path(ctx->printer, ctx->file_path) != 0) {
>  retval = UNTAR_FAIL;
> +  } else {
> +/*
> + * Speculatively unlink. This should unlink everything but non-empty
> + * directories or write protected stuff.
> + */
> +unlink(ctx->file_path);
>}
>  
>if (ctx->linkflag == SYMTYPE) {
> @@ -225,8 +226,22 @@ Untar_ProcessHeader(
>  rtems_printf(ctx->printer, "untar: dir: %s\n", ctx->file_path);
>  r = mkdir(ctx->file_path, ctx->mode);
>  if (r != 0) {
> -  Print_Error(ctx->printer, "mkdir", ctx->file_path);
> -  retval = UNTAR_FAIL;
> +  if (errno == EEXIST) {
> +/* If it exists already: Check whether it is a directory */
> +struct stat sb;
> +if (lstat(ctx->file_path, ) != 0) {
> +  Print_Error(ctx->printer, "lstat", ctx->file_path);
> +  retval = UNTAR_FAIL;
> +} else if (!S_ISDIR(sb.st_mode)) {
> +  rtems_printf(ctx->printer,
> +   "untar: mkdir: %s: exists but is not a directory\n",
> +   ctx->file_path);
> +  retval = UNTAR_FAIL;
> +}
> +  } else {
> +

Re: [PATCH v1 3/4] ConfigFile: Convert to C++

2021-12-08 Thread Chris Johns
On 9/12/21 2:15 am, Ryan Long wrote:
> ---
>  tester/covoar/ConfigFile.cc | 79 
> +
>  tester/covoar/ConfigFile.h  |  2 +-
>  2 files changed, 31 insertions(+), 50 deletions(-)
> 
> diff --git a/tester/covoar/ConfigFile.cc b/tester/covoar/ConfigFile.cc
> index c16b64a..5c8949e 100644
> --- a/tester/covoar/ConfigFile.cc
> +++ b/tester/covoar/ConfigFile.cc
> @@ -10,6 +10,10 @@
>  #include 

Is this needed? I think reducing the C interfaces included would help the long
maintenance.

>  #include 
>  
> +#include 
> +#include 
> +#include 
> +
>  namespace Configuration {
>  
>FileReader::FileReader(
> @@ -24,43 +28,40 @@ namespace Configuration {
>}
>  
>bool FileReader::processFile(
> -const char* const file
> +const std::string& file
>)
>{
>  #define METHOD "FileReader::processFile - "
> -FILE *  in;
> -charline[256];
> -charoption[256];
> -charvalue[256];
> +#define MAX_LENGTH 256
> +std::ifstream in;
> +std::string line;
> +char option[MAX_LENGTH];
> +char value[MAX_LENGTH];
>  int line_no;
>  int i;
>  int j;
>  
> -if ( file == NULL ) {
> -  fprintf( stderr, METHOD "NULL filename\n" );
> +if ( file.empty() ) {
> +  std::cerr << METHOD << "Empty filename" << std::endl;
>return false;
>  }
>  
> -in = fopen( file, "r" );
> -if ( !in ) {
> -  fprintf( stderr, METHOD "unable to open %s\n", file );
> +in.open( file );
> +if ( !in.is_open() ) {
> +  std::cerr << METHOD << "unable to open " << file << std::endl;
>return false;
>  }
>  
>  line_no = 0;
> -while (fgets(line, sizeof(line), in) != NULL) {
> +while ( std::getline( line, MAX_LENGTH ) ) {
>int length;
>  
>line_no++;
>  
> -  length = (int) strlen( line );
> -  if ( line[length - 1] != '\n' ) {
> -fprintf(
> -  stderr,
> -  "%s: line %d is too long",
> -  file,
> -  line_no
> -);
> +  length = (int) line.length();
> +  if ( length > MAX_LENGTH ) {
> +std::cerr << file << ": line " << line_no << " is too long"
> +  << std::endl;
>  continue;
>}
>  
> @@ -96,14 +97,9 @@ namespace Configuration {
>if (line[0] == '\0')
>  continue;
>  
> -  if (sscanf(line, "%s", option) != 1) {
> -fprintf(
> -  stderr,
> -  "%s: line %d is invalid: %s\n",
> -  file,
> -  line_no,
> -  line
> -);
> +  if (sscanf(line.c_str(), "%s", option) != 1) {

I suggest you use the C++ interface ..

https://en.cppreference.com/w/cpp/io/c/fscanf

> +std::cerr << file << ": line" << line_no << " is invalid: " << line
> +  << std::endl;

Please make the repeated code a helper function with line number and line as 
args.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] spec: Update location of cadence I2C

2021-12-08 Thread Chris Johns
OK and thanks

Chris

On 9/12/21 12:08 pm, Kinsey Moore wrote:
> When the cadence I2C code was moved to a shared directory, the
> references were updated but the install locations weren't. This updates
> the install locations to match what out-of-tree applications expect.
> ---
>  spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml | 4 +++-
>  spec/build/bsps/arm/xilinx-zynq/obj.yml | 6 --
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml 
> b/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml
> index fd9d51dfa9..fa269d61ad 100644
> --- a/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml
> +++ b/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml
> @@ -9,10 +9,12 @@ enabled-by: true
>  includes: []
>  install:
>  - destination: ${BSP_INCLUDEDIR}/bsp
> +  source:
> +  - bsps/aarch64/xilinx-zynqmp/include/bsp/i2c.h
> +- destination: ${BSP_INCLUDEDIR}/dev/i2c
>source:
>- bsps/include/dev/i2c/cadence-i2c-regs.h
>- bsps/include/dev/i2c/cadence-i2c.h
> -  - bsps/aarch64/xilinx-zynqmp/include/bsp/i2c.h
>  links: []
>  source:
>  - bsps/shared/dev/i2c/cadence-i2c.c
> diff --git a/spec/build/bsps/arm/xilinx-zynq/obj.yml 
> b/spec/build/bsps/arm/xilinx-zynq/obj.yml
> index bc675cd38c..dcac09126b 100644
> --- a/spec/build/bsps/arm/xilinx-zynq/obj.yml
> +++ b/spec/build/bsps/arm/xilinx-zynq/obj.yml
> @@ -14,10 +14,12 @@ install:
>- bsps/arm/xilinx-zynq/include/tm27.h
>  - destination: ${BSP_INCLUDEDIR}/bsp
>source:
> -  - bsps/include/dev/i2c/cadence-i2c-regs.h
> -  - bsps/include/dev/i2c/cadence-i2c.h
>- bsps/arm/xilinx-zynq/include/bsp/i2c.h
>- bsps/arm/xilinx-zynq/include/bsp/irq.h
> +- destination: ${BSP_INCLUDEDIR}/dev/i2c
> +  source:
> +  - bsps/include/dev/i2c/cadence-i2c-regs.h
> +  - bsps/include/dev/i2c/cadence-i2c.h
>  links: []
>  source:
>  - bsps/arm/shared/cache/cache-l2c-310.c
> 
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] spec: Update location of cadence I2C

2021-12-08 Thread Kinsey Moore
When the cadence I2C code was moved to a shared directory, the
references were updated but the install locations weren't. This updates
the install locations to match what out-of-tree applications expect.
---
 spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml | 4 +++-
 spec/build/bsps/arm/xilinx-zynq/obj.yml | 6 --
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml 
b/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml
index fd9d51dfa9..fa269d61ad 100644
--- a/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml
+++ b/spec/build/bsps/aarch64/xilinx-zynqmp/objcadencei2c.yml
@@ -9,10 +9,12 @@ enabled-by: true
 includes: []
 install:
 - destination: ${BSP_INCLUDEDIR}/bsp
+  source:
+  - bsps/aarch64/xilinx-zynqmp/include/bsp/i2c.h
+- destination: ${BSP_INCLUDEDIR}/dev/i2c
   source:
   - bsps/include/dev/i2c/cadence-i2c-regs.h
   - bsps/include/dev/i2c/cadence-i2c.h
-  - bsps/aarch64/xilinx-zynqmp/include/bsp/i2c.h
 links: []
 source:
 - bsps/shared/dev/i2c/cadence-i2c.c
diff --git a/spec/build/bsps/arm/xilinx-zynq/obj.yml 
b/spec/build/bsps/arm/xilinx-zynq/obj.yml
index bc675cd38c..dcac09126b 100644
--- a/spec/build/bsps/arm/xilinx-zynq/obj.yml
+++ b/spec/build/bsps/arm/xilinx-zynq/obj.yml
@@ -14,10 +14,12 @@ install:
   - bsps/arm/xilinx-zynq/include/tm27.h
 - destination: ${BSP_INCLUDEDIR}/bsp
   source:
-  - bsps/include/dev/i2c/cadence-i2c-regs.h
-  - bsps/include/dev/i2c/cadence-i2c.h
   - bsps/arm/xilinx-zynq/include/bsp/i2c.h
   - bsps/arm/xilinx-zynq/include/bsp/irq.h
+- destination: ${BSP_INCLUDEDIR}/dev/i2c
+  source:
+  - bsps/include/dev/i2c/cadence-i2c-regs.h
+  - bsps/include/dev/i2c/cadence-i2c.h
 links: []
 source:
 - bsps/arm/shared/cache/cache-l2c-310.c
-- 
2.30.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [rtems-tools] tester: Update jobs configuration

2021-12-08 Thread Ryan Long

ping

On 11/1/2021 5:31 PM, Ryan Long wrote:

ping

-Original Message-
From: Ryan Long 
Sent: Wednesday, October 20, 2021 3:06 PM
To: devel@rtems.org
Cc: Ryan Long 
Subject: [rtems-tools] tester: Update jobs configuration

Allow for default_jobs and max_jobs to be specified in the BSP's configuration 
file.
---
  rtemstoolkit/options.py| 45 +-
  tester/rtems/testing/bsps/beagleboardxm.ini|  2 +-
  tester/rtems/testing/bsps/beagleboneblack.ini  |  2 +-
  tester/rtems/testing/bsps/imx7.ini |  2 +-
  tester/rtems/testing/bsps/mcf5235.ini  |  2 +-
  tester/rtems/testing/bsps/mvme2307.ini |  2 +-
  tester/rtems/testing/bsps/pc.ini   |  2 +-
  tester/rtems/testing/bsps/qoriq_e500.ini   |  2 +-
  tester/rtems/testing/bsps/qoriq_e6500_32.ini   |  2 +-
  tester/rtems/testing/bsps/qoriq_e6500_64.ini   |  2 +-
  tester/rtems/testing/bsps/raspberrypi2.ini |  2 +-
  tester/rtems/testing/bsps/xilinx_versal_vck190.ini |  2 +-  
.../rtems/testing/bsps/xilinx_zynq_a9_qemu_smp.ini |  2 +-
  tester/rtems/testing/bsps/xilinx_zynq_zc706.ini|  2 +-
  tester/rtems/testing/bsps/xilinx_zynq_zedboard.ini |  2 +-
  .../testing/bsps/xilinx_zynqmp_ilp32_zu3eg.ini |  2 +-
  .../testing/bsps/xilinx_zynqmp_lp64_zu3eg.ini  |  2 +-
  tester/rtems/testing/defaults.mc   |  2 +
  18 files changed, 45 insertions(+), 34 deletions(-)

diff --git a/rtemstoolkit/options.py b/rtemstoolkit/options.py index 
5ebe3bc..4b7a93a 100644
--- a/rtemstoolkit/options.py
+++ b/rtemstoolkit/options.py
@@ -102,7 +102,7 @@ class command_line(object):
  '--no-clean':   'Do not clean up the build tree',
  '--always-clean':   'Always clean the build tree, 
even with an error',
  '--keep-going': 'Do not stop on an error.',
-'--jobs=[0..n,none,half,full]': 'Run with specified number of 
jobs, default: num CPUs.',
+'--jobs=[0..n,none,half,full]': 'Run with specified number
+ of jobs (default: defined in configuration file)',
  '--macros file[,file]': 'Macro format files to load after 
the defaults',
  '--log file':   'Log file where all build output 
is written to',
  }
@@ -327,6 +327,11 @@ class command_line(object):
  # Handle the jobs for make
  if '_ncpus' not in self.defaults:
  raise error.general('host number of CPUs not set')
+if self.defaults['default_jobs'] != '0':
+print(
+'default_jobs is %d and the default is %d' %
+(self.defaults['default_jobs'], 0)
+)
  ncpus = self.jobs(self.defaults['_ncpus'])
  if ncpus > 1:
  self.defaults['_smp_mflags'] = '-j %d' % (ncpus) @@ -427,28 
+432,25 @@ class command_line(object):
  um += [m]
  return um if len(um) else None
  
-def jobs(self, cpus):

+def jobs(self, num_cpus):
  try:
-cpus = int(cpus)
+cpus = int(num_cpus)
  except:
  raise error.general('invalid host cpu value')
  opt_jobs = self.opts['jobs']
  if opt_jobs == 'default':
-_jobs = self.defaults.get_value('jobs')
-if _jobs is not None:
-if _jobs == 'none':
-cpus = 0
-elif _jobs == 'max':
-pass
-elif _jobs == 'half':
-cpus = cpus / 2
-else:
-try:
-cpus = int(_jobs)
-except:
-raise error.general('invalid %%{jobs} value: %s' % 
(_jobs))
+_jobs = self.defaults.get_value('default_jobs')
+if _jobs == 'none':
+cpus = 0
+elif _jobs == 'max':
+pass
+elif _jobs == 'half':
+cpus = cpus / 2
  else:
-opt_jobs = 'max'
+try:
+cpus = int(_jobs)
+except:
+raise error.general('invalid %%{jobs} value: %s' %
+ (_jobs))
  if opt_jobs != 'default':
  if opt_jobs == 'none':
  cpus = 0
@@ -474,7 +476,14 @@ class command_line(object):
  if not ok:
  raise error.internal('bad jobs option: %s' % 
(opt_jobs))
  if cpus <= 0:
-cpu = 1
+cpus = 1
+max_jobs = int(self.defaults.get_value('max_jobs'))
+if max_jobs == 0:
+max_jobs = cpus
+if cpus > max_jobs:
+raise error.internal(
+'exceeded maximum number of jobs: %d > %d' % (cpus, max_jobs)
+)
  return cpus
  
  def params(self):

diff --git 

[PATCH v1 3/4] ConfigFile: Convert to C++

2021-12-08 Thread Ryan Long
---
 tester/covoar/ConfigFile.cc | 79 +
 tester/covoar/ConfigFile.h  |  2 +-
 2 files changed, 31 insertions(+), 50 deletions(-)

diff --git a/tester/covoar/ConfigFile.cc b/tester/covoar/ConfigFile.cc
index c16b64a..5c8949e 100644
--- a/tester/covoar/ConfigFile.cc
+++ b/tester/covoar/ConfigFile.cc
@@ -10,6 +10,10 @@
 #include 
 #include 
 
+#include 
+#include 
+#include 
+
 namespace Configuration {
 
   FileReader::FileReader(
@@ -24,43 +28,40 @@ namespace Configuration {
   }
 
   bool FileReader::processFile(
-const char* const file
+const std::string& file
   )
   {
 #define METHOD "FileReader::processFile - "
-FILE *  in;
-charline[256];
-charoption[256];
-charvalue[256];
+#define MAX_LENGTH 256
+std::ifstream in;
+std::string line;
+char option[MAX_LENGTH];
+char value[MAX_LENGTH];
 int line_no;
 int i;
 int j;
 
-if ( file == NULL ) {
-  fprintf( stderr, METHOD "NULL filename\n" );
+if ( file.empty() ) {
+  std::cerr << METHOD << "Empty filename" << std::endl;
   return false;
 }
 
-in = fopen( file, "r" );
-if ( !in ) {
-  fprintf( stderr, METHOD "unable to open %s\n", file );
+in.open( file );
+if ( !in.is_open() ) {
+  std::cerr << METHOD << "unable to open " << file << std::endl;
   return false;
 }
 
 line_no = 0;
-while (fgets(line, sizeof(line), in) != NULL) {
+while ( std::getline( line, MAX_LENGTH ) ) {
   int length;
 
   line_no++;
 
-  length = (int) strlen( line );
-  if ( line[length - 1] != '\n' ) {
-fprintf(
-  stderr,
-  "%s: line %d is too long",
-  file,
-  line_no
-);
+  length = (int) line.length();
+  if ( length > MAX_LENGTH ) {
+std::cerr << file << ": line " << line_no << " is too long"
+  << std::endl;
 continue;
   }
 
@@ -96,14 +97,9 @@ namespace Configuration {
   if (line[0] == '\0')
 continue;
 
-  if (sscanf(line, "%s", option) != 1) {
-fprintf(
-  stderr,
-  "%s: line %d is invalid: %s\n",
-  file,
-  line_no,
-  line
-);
+  if (sscanf(line.c_str(), "%s", option) != 1) {
+std::cerr << file << ": line" << line_no << " is invalid: " << line
+  << std::endl;
 continue;
   }
 
@@ -111,13 +107,8 @@ namespace Configuration {
 ;
 
   if (i == length) {
-fprintf(
-  stderr,
-  "%s: line %d is invalid: %s\n",
-  file,
-  line_no,
-  line
-);
+std::cerr << file << ": line" << line_no << " is invalid: " << line
+  << std::endl;
 continue;
   }
 
@@ -129,24 +120,14 @@ namespace Configuration {
 value[j] = line[i];
   value[j] = '\0';
   if (value[0] == '\0') {
-fprintf(
-  stderr,
-  "%s: line %d is invalid: %s\n",
-  file,
-  line_no,
-  line
-);
+std::cerr << file << ": line" << line_no << " is invalid: " << line
+  << std::endl;
 continue;
   }
 
   if ( !setOption(option, value) ) {
-fprintf(
-  stderr,
-  "%s: line %d: option %s is unknown\n",
-  file,
-  line_no,
-  option
-);
+std::cerr << file << ": line" << line_no << " is invalid: " << line
+  << std::endl;
 continue;
   }
 
@@ -190,7 +171,7 @@ namespace Configuration {
 Options_t *o;
 
 for ( o=options_m ; o->option ; o++ ) {
-  fprintf( stderr, "(%s)=(%s)\n", o->option, o->value );
+  std::cerr << '(' << o->option << ")=(" << o->value << ')' << std::endl;
 }
   }
 }
diff --git a/tester/covoar/ConfigFile.h b/tester/covoar/ConfigFile.h
index 0bae7ac..f8bd9c5 100644
--- a/tester/covoar/ConfigFile.h
+++ b/tester/covoar/ConfigFile.h
@@ -54,7 +54,7 @@ namespace Configuration {
  *  @return Returns TRUE if the method succeeded and FALSE if it failed.
  */
 virtual bool processFile(
-  const char* const file
+  const std::string& file
 );
 
 bool setOption(
-- 
1.8.3.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v1 4/4] ObjdumpProcessor: Convert to C++

2021-12-08 Thread Ryan Long
---
 tester/covoar/ObjdumpProcessor.cc | 27 +++
 tester/covoar/ObjdumpProcessor.h  |  6 +++---
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/tester/covoar/ObjdumpProcessor.cc 
b/tester/covoar/ObjdumpProcessor.cc
index c910046..8c0e8dc 100644
--- a/tester/covoar/ObjdumpProcessor.cc
+++ b/tester/covoar/ObjdumpProcessor.cc
@@ -13,6 +13,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "ObjdumpProcessor.h"
 #include "CoverageMap.h"
@@ -139,8 +141,7 @@ namespace Coverage {
   )
   {
 #define METHOD "ERROR: ObjdumpProcessor::determineLoadAddress - "
-FILE*loadAddressFile = NULL;
-char*cStatus;
+std::ifstream loadAddressFile;
 uint32_t offset;
 char inputBuffer[MAX_LINE_LENGTH];
 
@@ -155,8 +156,8 @@ namespace Coverage {
 
 dlinfoName += ".dlinfo";
 // Read load address.
-loadAddressFile = ::fopen( dlinfoName.c_str(), "r" );
-if (!loadAddressFile) {
+loadAddressFile.open( dlinfoName );
+if (!loadAddressFile.is_open()) {
   std::ostringstream what;
   what << "Unable to open " << dlinfoName;
   throw rld::error( what, METHOD );
@@ -166,9 +167,9 @@ namespace Coverage {
 while ( 1 ) {
 
   // Get a line.
-  cStatus = ::fgets( inputBuffer, MAX_LINE_LENGTH, loadAddressFile );
-  if (cStatus == NULL) {
-::fclose( loadAddressFile );
+  loadAddressFile.getline( inputBuffer, MAX_LINE_LENGTH );
+  if ( loadAddressFile.fail() && loadAddressFile.is_open() ) {
+loadAddressFile.close();
 std::ostringstream what;
 what << "library " << Library << " not found in " << dlinfoName;
 throw rld::error( what, METHOD );
@@ -176,13 +177,15 @@ namespace Coverage {
   sscanf( inputBuffer, "%s %x", inLibName,  );
   std::string tmp = inLibName;
   if ( tmp.find( Library ) != tmp.npos ) {
-// fprintf( stderr, "%s - 0x%08x\n", inLibName, offset );
+// std::cerr << inLibName << " - 0x"
+//   << std::setfill( '0' ) << std::setw( 8 ) << std::hex
+//   << offset << std::endl
+//   << std::dec << std::setfill( ' ' );
 address = offset;
 break;
   }
 }
 
-::fclose( loadAddressFile );
 return address;
 
 #undef METHOD
@@ -203,7 +206,7 @@ namespace Coverage {
   }
 
   bool ObjdumpProcessor::isBranchLine(
-const char* const line
+const std::string& line
   )
   {
 if ( !targetInfo_m ) {
@@ -219,8 +222,8 @@ namespace Coverage {
   }
 
   bool ObjdumpProcessor::isNop(
-const char* const line,
-int&  size
+const std::string& line,
+int&   size
   )
   {
 if ( !targetInfo_m ){
diff --git a/tester/covoar/ObjdumpProcessor.h b/tester/covoar/ObjdumpProcessor.h
index 05a667f..0ca14b8 100644
--- a/tester/covoar/ObjdumpProcessor.h
+++ b/tester/covoar/ObjdumpProcessor.h
@@ -151,7 +151,7 @@ namespace Coverage {
  *  otherwise it returns false.
  */
 bool isBranchLine(
-  const char* const line
+  const std::string& line
 );
 
 /*!
@@ -179,8 +179,8 @@ namespace Coverage {
  *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
  */
 bool isNop(
-  const char* const line,
-  int&  size
+  const std::string& line,
+  int&   size
 );
 
 /*!
-- 
1.8.3.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH rtems-tools v1 0/4] Convert to C++ patches

2021-12-08 Thread Ryan Long
Hi,

For this series of patches, I

- Changed char * parameters and variables to a string
- Changed C functions to corresponding C++ functions
- Switched C file handling out for C++ file handling

Thanks,
Ryan

Ryan Long (4):
  TargetFactory.cc: Convert to C++
  Target: Convert to C++
  ConfigFile: Convert to C++
  ObjdumpProcessor: Convert to C++

 tester/covoar/ConfigFile.cc   | 79 +++
 tester/covoar/ConfigFile.h|  2 +-
 tester/covoar/ObjdumpProcessor.cc | 27 +++--
 tester/covoar/ObjdumpProcessor.h  |  6 +--
 tester/covoar/TargetBase.cc   | 35 -
 tester/covoar/TargetBase.h| 18 -
 tester/covoar/TargetFactory.cc|  6 +--
 tester/covoar/Target_aarch64.cc   | 18 +
 tester/covoar/Target_aarch64.h|  6 +--
 tester/covoar/Target_arm.cc   | 16 
 tester/covoar/Target_arm.h|  6 +--
 tester/covoar/Target_i386.cc  | 22 ++-
 tester/covoar/Target_i386.h   |  4 +-
 tester/covoar/Target_lm32.cc  |  6 +--
 tester/covoar/Target_lm32.h   |  4 +-
 tester/covoar/Target_m68k.cc  | 12 +++---
 tester/covoar/Target_m68k.h   |  6 +--
 tester/covoar/Target_powerpc.cc   |  8 ++--
 tester/covoar/Target_powerpc.h|  4 +-
 tester/covoar/Target_riscv.cc |  6 +--
 tester/covoar/Target_riscv.h  |  6 +--
 tester/covoar/Target_sparc.cc | 12 +++---
 tester/covoar/Target_sparc.h  |  6 +--
 23 files changed, 155 insertions(+), 160 deletions(-)

-- 
1.8.3.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v1 2/4] Target: Convert to C++

2021-12-08 Thread Ryan Long
---
 tester/covoar/TargetBase.cc | 35 ++-
 tester/covoar/TargetBase.h  | 18 +-
 tester/covoar/Target_aarch64.cc | 18 ++
 tester/covoar/Target_aarch64.h  |  6 +++---
 tester/covoar/Target_arm.cc | 16 +---
 tester/covoar/Target_arm.h  |  6 +++---
 tester/covoar/Target_i386.cc| 22 --
 tester/covoar/Target_i386.h |  4 ++--
 tester/covoar/Target_lm32.cc|  6 +++---
 tester/covoar/Target_lm32.h |  4 ++--
 tester/covoar/Target_m68k.cc| 12 +++-
 tester/covoar/Target_m68k.h |  6 +++---
 tester/covoar/Target_powerpc.cc |  8 
 tester/covoar/Target_powerpc.h  |  4 ++--
 tester/covoar/Target_riscv.cc   |  6 +++---
 tester/covoar/Target_riscv.h|  6 +++---
 tester/covoar/Target_sparc.cc   | 12 +++-
 tester/covoar/Target_sparc.h|  6 +++---
 18 files changed, 103 insertions(+), 92 deletions(-)

diff --git a/tester/covoar/TargetBase.cc b/tester/covoar/TargetBase.cc
index 7ee45b5..a62e90f 100644
--- a/tester/covoar/TargetBase.cc
+++ b/tester/covoar/TargetBase.cc
@@ -40,24 +40,24 @@ namespace Target {
   {
   }
 
-  const char* TargetBase::getAddr2line() const
+  const std::string& TargetBase::getAddr2line() const
   {
-return addr2line_m.c_str();
+return addr2line_m;
   }
 
-  const char* TargetBase::getCPU( void ) const
+  const std::string& TargetBase::getCPU() const
   {
-return cpu_m.c_str();
+return cpu_m;
   }
 
-  const char* TargetBase::getObjdump() const
+  const std::string& TargetBase::getObjdump() const
   {
-return objdump_m.c_str();
+return objdump_m;
   }
 
-  const char* TargetBase::getTarget( void ) const
+  const std::string& TargetBase::getTarget() const
   {
-return targetName_m.c_str();
+return targetName_m;
   }
 
   bool TargetBase::isBranch( const std::string& instruction )
@@ -83,12 +83,13 @@ namespace Target {
   }
 
   bool TargetBase::isBranchLine(
-const char* const line
+const std::string& line
   )
   {
-#define WARNING \
-"WARNING: TargetBase::isBranchLine - (%d) " \
-"Unable to find instruction in: %s\n"
+#define WARNING_PT1 \
+"WARNING: TargetBase::isBranchLine - ("
+#define WARNING_PT2 \
+") Unable to find instruction in: "
 const char *ch;
 char instruction[120];
 int  result;
@@ -101,7 +102,7 @@ namespace Target {
   ch++;
 }
 if (*ch != '\t') {
-  fprintf( stderr, WARNING, 1, line );
+  std::cerr << WARNING_PT1 << 1 << WARNING_PT2 << line << std::endl;
   return false;
 }
 ch++;
@@ -110,7 +111,7 @@ namespace Target {
 while ((*ch != '\t') && (*ch != '\0'))
   ch++;
 if (*ch != '\t') {
-  fprintf( stderr, WARNING, 2, line) ;
+  std::cerr << WARNING_PT1 << 2 << WARNING_PT2 << line << std::endl;
   return false;
 }
 ch++;
@@ -119,19 +120,19 @@ namespace Target {
 // after the second tab.
 result = sscanf( ch, "%s", instruction );
 if (result != 1) {
-fprintf( stderr, WARNING, 3, line );
+std::cerr << WARNING_PT1 << 3 << WARNING_PT2 << line << std::endl;
 return false;
 }
 
 return isBranch( instruction );
   }
 
-  uint8_t TargetBase::qemuTakenBit(void)
+  uint8_t TargetBase::qemuTakenBit()
   {
 return TRACE_OP_BR0;
   }
 
-  uint8_t TargetBase::qemuNotTakenBit(void)
+  uint8_t TargetBase::qemuNotTakenBit()
   {
 return TRACE_OP_BR1;
   }
diff --git a/tester/covoar/TargetBase.h b/tester/covoar/TargetBase.h
index e5c143e..0a75c85 100644
--- a/tester/covoar/TargetBase.h
+++ b/tester/covoar/TargetBase.h
@@ -42,28 +42,28 @@ namespace Target {
  *
  *  @return Returns the target specific addr2line program name
  */
-const char* getAddr2line( void ) const;
+const std::string& getAddr2line() const;
 
 /*!
  *  This method returns the CPU name.
  *
  *  @return Returns the target cpu name
  */
-const char* getCPU( void ) const;
+const std::string& getCPU() const;
 
 /*!
  *  This method returns the program name for objdump.
  *
  *  @return Returns the target specific objdump program name
  */
-const char* getObjdump( void ) const;
+const std::string& getObjdump() const;
 
 /*!
  *  This method returns the target name.
  *
  *  @return Returns the target name
  */
-const char* getTarget( void ) const;
+const std::string& getTarget() const;
 
 /*!
  *  This method determines whether the specified line from a
@@ -75,8 +75,8 @@ namespace Target {
  *  @return Returns TRUE if the instruction is a nop, FALSE otherwise.
  */
 virtual bool isNopLine(
-  const char* const line,
-  int&  size
+  const std::string& line,
+  int&   size
 ) = 0;
 
 
@@ -90,7 +90,7 @@ namespace Target {
  *  @return Returns TRUE if the instruction is a branch, FALSE otherwise.
  */

[PATCH v1 1/4] TargetFactory.cc: Convert to C++

2021-12-08 Thread Ryan Long
---
 tester/covoar/TargetFactory.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tester/covoar/TargetFactory.cc b/tester/covoar/TargetFactory.cc
index 57ba686..fa72f05 100644
--- a/tester/covoar/TargetFactory.cc
+++ b/tester/covoar/TargetFactory.cc
@@ -37,7 +37,7 @@ namespace Target {
   //!
   typedef struct {
  //! This is the string found in configuration to match.
- const char*theTarget;
+ std::string   theTarget;
  //! This is the static wrapper for the constructor.
  TargetBase *(*theCtor)(
std::string
@@ -76,10 +76,10 @@ namespace Target {
 else
   cpu = targetName.substr( 0, i );
 
-// fprintf( stderr, "%s --> %s\n", targetName.c_str(), cpu.c_str());
+// std::cerr << targetName << " --> " << cpu << std::endl;
 // Iterate over the table trying to find an entry with a matching name
 for ( i=0 ; i < sizeof(FactoryTable) / sizeof(FactoryEntry_t); i++ ) {
-  if ( !strcmp(FactoryTable[i].theTarget, cpu.c_str() ) )
+  if ( FactoryTable[i].theTarget == cpu )
 return FactoryTable[i].theCtor( targetName );
 }
 
-- 
1.8.3.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel