summaryrefslogtreecommitdiff
path: root/tests/gtests/gtests.sh
blob: 4005a16a6aa4eae8688d5b4d1c92ea8afa888791 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

########################################################################
#
# similar to all.sh this file runs drives gtests.
#
# needs to work on all Unix and Windows platforms
#
# special strings
# ---------------
#   FIXME ... known problems, search for this string
#   NOTE .... unexpected behavior
#
########################################################################

############################## gtest_init ##############################
# local shell function to initialize this script
########################################################################
gtest_init()
{
  cd "$(dirname "$1")"
  pwd
  if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
      cd ../common
      . ./init.sh
  fi

  SCRIPTNAME=gtests.sh
  . "${QADIR}"/common/certsetup.sh

  if [ -z "${CLEANUP}" ] ; then   # if nobody else is responsible for
    CLEANUP="${SCRIPTNAME}"       # cleaning this script will do it
  fi

  mkdir -p "${GTESTDIR}"
  cd "${GTESTDIR}"
}

########################## gtest_start #############################
# Local function to actually start the test
####################################################################
gtest_start()
{
  echo "gtests: ${GTESTS}"
  for i in ${GTESTS}; do
    if [ ! -f "${BINDIR}/$i" ]; then
      html_unknown "Skipping $i (not built)"
      continue
    fi
    DIR="${GTESTDIR}/$i"
    html_head "$i"
    if [ ! -d "$DIR" ]; then
      mkdir -p "$DIR"
      echo "${BINDIR}/certutil" -N -d "$DIR" --empty-password 2>&1
      "${BINDIR}/certutil" -N -d "$DIR" --empty-password 2>&1

      PROFILEDIR="$DIR" make_cert dummy p256 sign
    fi
    pushd "$DIR"
    GTESTREPORT="$DIR/report.xml"
    PARSED_REPORT="$DIR/report.parsed"
    # The mozilla::pkix gtests cause an ODR violation that we ignore.
    # See bug 1588567.
    if [ "$i" = "mozpkix_gtest" ]; then
      EXTRA_ASAN_OPTIONS="detect_odr_violation=0"
    fi
    # NSS CI sets a lower max for PBE iterations, otherwise cert.sh
    # is very slow. Unset this maxiumum for softoken_gtest, as it
    # needs to check the default value.
    if [ "$i" = "softoken_gtest" ]; then
      OLD_MAX_PBE_ITERATIONS=$NSS_MAX_MP_PBE_ITERATION_COUNT
      unset NSS_MAX_MP_PBE_ITERATION_COUNT
    fi
    echo "executing $i"
    ASAN_OPTIONS="$ASAN_OPTIONS:$EXTRA_ASAN_OPTIONS" "${BINDIR}/$i" \
                 "${SOURCE_DIR}/gtests/freebl_gtest/kat/Hash_DRBG.rsp" \
                 -d "$DIR" -w --gtest_output=xml:"${GTESTREPORT}" \
                              --gtest_filter="${GTESTFILTER:-*}"
    html_msg $? 0 "$i run successfully"
    if [ "$i" = "softoken_gtest" ]; then
      export NSS_MAX_MP_PBE_ITERATION_COUNT=$OLD_MAX_PBE_ITERATIONS
    fi

    echo "test output dir: ${GTESTREPORT}"
    echo "executing sed to parse the xml report"
    sed -f "${COMMON}/parsegtestreport.sed" "$GTESTREPORT" > "$PARSED_REPORT"
    echo "processing the parsed report"
    cat "$PARSED_REPORT" | while read result name; do
      if [ "$result" = "notrun" ]; then
        echo "$name" SKIPPED
      elif [ "$result" = "run" ]; then
        html_passed_ignore_core "$name"
      else
        html_failed_ignore_core "$name"
      fi
    done
    popd
  done
}

gtest_cleanup()
{
  html "</TABLE><BR>"
  . "${QADIR}"/common/cleanup.sh
}

################## main #################################################
GTESTS="${GTESTS:-prng_gtest certhigh_gtest certdb_gtest der_gtest pk11_gtest util_gtest freebl_gtest softoken_gtest sysinit_gtest blake2b_gtest smime_gtest mozpkix_gtest}"
SOURCE_DIR="$PWD"/../..
gtest_init "$0"
gtest_start
gtest_cleanup