• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set -e
16
17for ARGUMENT in "$@"
18do
19case "$ARGUMENT" in
20    --binary-dir=*)
21    PANDA_BINARY_ROOT="${ARGUMENT#*=}"
22    ;;
23    --root-dir=*)
24    PANDA_ROOT="${ARGUMENT#*=}"
25    ;;
26    -build-panda)
27    BUILD_PANDA=true
28    ;;
29esac
30done
31
32if [ "$BUILD_PANDA" = true ]; then
33    cd $PANDA_BINARY_ROOT
34    make -j
35    cd -
36fi
37
38ISA=$PANDA_BINARY_ROOT/isa/isa.yaml
39IR_BUILDER_TESTS=$PANDA_ROOT/compiler/tests/ir_builder_test.cpp
40UNIT_TESTS=$PANDA_BINARY_ROOT/bin-gtests/compiler_unit_tests
41HTML=$PANDA_BINARY_ROOT/compiler/IrBuilderCoverage.html
42
43[ -e "$HTML" ] && rm $HTML
44
45all_tests=0
46all_compiled=0
47
48# Get signatures of all instructions
49all_insts=$(grep "sig:" $ISA | cut -f2 -d':' | cut -f2 -d' ')
50# Ignore repeated instructions
51pbc_instructions=$(echo $all_insts | awk '{delete seen; c=0; for (i=1;i<=NF;i++) \
52    if (!seen[$i]++) printf "%s%s", (++c>1?OFS:""), $i; print ""}')
53
54function get_test_name() {
55    # For example:
56    #    mov.64 => Mov64
57    #    fadd2.64 => Fadd2_64
58    #    call.short => CallShort
59    test_name=$(echo .${inst_name} | sed 's/\.\([a-z]\)/\U\1/g' | sed 's/\([0-9]\)\.\([0-9]\)/\1_\2/g' | sed 's/\.//g')
60}
61
62function find_test() {
63    coverage=${coverage:-0}
64    inst_status=${inst_status:-1}
65    if $(grep "TEST_F(IrBuilderTest, $1)" $IR_BUILDER_TESTS 1>/dev/null); then
66        coverage=1
67        $UNIT_TESTS --gtest_filter=IrBuilderTest.$1 1>/dev/null
68        if [ $? != 0 ]
69        then
70            inst_status=0
71        fi
72    elif $(grep "TEST_F(IrBuilderTest, DISABLED_$1)" $IR_BUILDER_TESTS 1>/dev/null); then
73        inst_status=0
74    fi
75}
76
77function calculate_ir_builder_coverage() {
78    for inst_name in $pbc_instructions
79    do
80        get_test_name
81        find_test ${test_name}
82        find_test ${test_name}Int
83        find_test ${test_name}Real
84
85        indent=$(($all_tests % 5))
86        if [ $indent -eq 0 ] ; then
87            echo "<tr>" >> $HTML
88        fi
89
90        if [ "$inst_status" == 1 ] ; then
91            if [ "$coverage" == 1 ] ; then
92                let "all_compiled+=1"
93                background="#d7e7a9"
94            else
95                background="gray"
96            fi
97        else
98            background="red"
99        fi
100        echo "<td align=\"center\" bgcolor=$background>$inst_name</td>" >> $HTML
101        let "all_tests+=1"
102    done
103}
104
105echo "<!DOCTYPE html>
106<html>
107    <head>
108        <style>table, th, td {border: 1px solid black; border-collapse: collapse;}</style>
109        <title>Benchmark coverage statistic</title>
110    </head>
111    <body>" >> $HTML
112
113echo "<header><h1>IR BUILDER TESTS</h1></header>
114        <table cellpadding=\"5\">" >> $HTML
115
116calculate_ir_builder_coverage
117
118echo "</table>" >> $HTML
119
120# Report
121ir_builder_coverage=$(($all_compiled * 100 / $all_tests))
122echo "<h3>Instructions coverage = $ir_builder_coverage%</h3>" >> $HTML
123echo "Ir_builder coverage: $ir_builder_coverage%"
124
125echo  "<h2>Legend</h2>
126        <table cellpadding=\"5\">
127            <tr><td align=\"left\">All tests for the instructions are passed</td><td bgcolor=\"#d7e7a9\"></td></tr>
128            <tr><td align=\"left\">Some tests for instructions failed or disabled</td><td bgcolor=\"red\"></td></tr>
129            <tr><td align=\"left\">The instruction is not covered by tests</td><td bgcolor=\"gray\"></td></tr>
130        </table>" >> $HTML