Tips: Generalize analyses for several architectures

This tip can only be achieved with a Committed configuration. See the Configuration files section to learn more about the different kinds of configuration.

All examples in this section can be replayed with our demo-caesar repository, used for our Introduction tutorial. Feel free to fork this repository to try it by yourself.

TrustInSoft CI Analyzer is able to simulate several architectures but only one architecture can be used at a time. It means you need to define as many analyses in your Analyses configuration as architectures you want to verify with TrustInSoft CI.

The first solution would be to copy/paste your existing analyses configuration and modifying the "machdep"value by hand. However this solution does not scale well...

Another solution would be to use the Build preparation stage to generate the Analyses configuration for all the different architecture you want.

First, move your existing .trustinsoft/config.json to another file (such as .trustinsoft/orig_config.json):

.trustinsoft/orig_config.json
[
  {
    // Test shift values 7 and -3
    "files": [ "../main.c", "../caesar.c" ],
    "cpp-extra-args": "-I .."
  },
  {
    "name": "Test from program inputs",
    "files": [ "../main.c", "../caesar.c" ],
    "cpp-extra-args": "-I ..",
    "main": "main_with_input",
    "val-program-name": "a.out",
    "val-args": "|People of Earth, your attention please|7"
  }
]

Then, create a new .trustinsoft/prepare.sh script (or adapt your existing one with the following script):

.trustinsoft/prepare.sh
#!/bin/bash

set -e

readonly INPUT_FILE="orig_config.json"
readonly MACHDEPS=(
  x86_32
  x86_64
  gcc_x86_32
  gcc_x86_64
)

test -e "$INPUT_FILE" || { echo "$INPUT_FILE not found"; exit 1; }

results=()

for machdep in "${MACHDEPS[@]}"; do
  # Use "minify --type js" to pre-process comments. Then, for each
  # object, add the "machdep" field and update the "name" field.
  res="$(minify --type js "$INPUT_FILE" | \
         jq \
           --arg mach "$machdep" \
           'map(. + { "machdep": $mach }) |
            to_entries |
            map(
              if getpath([ "value", "name" ]) != null then
                .value + { "name": (.value.name + " - " + $mach) }
              else
                .value + { "name": ("Analysis " + (.key + 1 | tostring) + " - " + $mach) } end)')"
  results+=( "$res" )
done

# Gather all configuration objects into a single one.
printf '%s\n' "${results[@]}" | jq '.[]' | jq -s '.' > config.json

Modify the MACHDEPSvariable to add the list of architectures to use for all analyses defined in .trustinsoft/orig_config.json.

Everything is now ready to be analyzed : commit these new files and run a new build to see the list of analyses for all defined architectures!

To easily identify the architecture used, the analysis name is also updated by the script to display the name of the architecture:

Last updated