summaryrefslogtreecommitdiff
path: root/.github/workflows/build.yml
blob: ff210be29d5547126fac4dce8b6700d64623eeb0 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Build

on:
  push:
    branches:
      - main
      - tmp
  pull_request:
    branches:
      - main
    types: [opened, synchronize, reopened]
  release:
    types: [created]

jobs:
  test:
    name: ${{ matrix.os }} ${{ matrix.compiler }}
    runs-on: ${{ matrix.os }}
    env:
      CMAKE_C_COMPILER: ${{ matrix.compiler }}
      CMAKE_C_FLAGS: -Werror
    strategy:
      fail-fast: true
      matrix:
        include:
          - compiler: "gcc"
            os: "ubuntu-latest"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=OFF"
            ndpid_zlib: "-DENABLE_ZLIB=ON"
            sanitizer: "-DENABLE_SANITIZER=OFF -DENABLE_SANITIZER_THREAD=OFF"
            coverage: "-DENABLE_COVERAGE=OFF"
            upload: true
            upload_suffix: ""
            ndpi_min_version: "4.8"
          - compiler: "gcc"
            os: "ubuntu-latest"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=ON"
            ndpid_zlib: "-DENABLE_ZLIB=ON"
            sanitizer: "-DENABLE_SANITIZER=OFF -DENABLE_SANITIZER_THREAD=OFF"
            coverage: "-DENABLE_COVERAGE=OFF"
            upload: true
            upload_suffix: "-host-gcrypt"
            ndpi_min_version: "4.8"
          - compiler: "clang"
            os: "ubuntu-latest"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=OFF"
            ndpid_zlib: "-DENABLE_ZLIB=OFF"
            sanitizer: "-DENABLE_SANITIZER=OFF -DENABLE_SANITIZER_THREAD=OFF"
            coverage: "-DENABLE_COVERAGE=OFF"
            upload: true
            upload_suffix: "-no-zlib"
            ndpi_min_version: "4.8"
          - compiler: "gcc"
            os: "ubuntu-latest"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=OFF"
            ndpid_zlib: "-DENABLE_ZLIB=ON"
            sanitizer: "-DENABLE_SANITIZER=ON"
            coverage: "-DENABLE_COVERAGE=ON"
            upload: false
            ndpi_min_version: "4.8"
          - compiler: "clang"
            os: "ubuntu-latest"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=OFF"
            ndpid_zlib: "-DENABLE_ZLIB=ON"
            sanitizer: "-DENABLE_SANITIZER=ON" 
            coverage: "-DENABLE_COVERAGE=ON"
            upload: false
            ndpi_min_version: "4.8"
          - compiler: "clang-12"
            os: "ubuntu-latest"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=OFF"
            ndpid_zlib: "-DENABLE_ZLIB=ON"
            sanitizer: "-DENABLE_SANITIZER_THREAD=ON"
            coverage: "-DENABLE_COVERAGE=ON"
            upload: false
            ndpi_min_version: "4.8"
          - compiler: "gcc-10"
            os: "ubuntu-latest"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=OFF"
            ndpid_zlib: "-DENABLE_ZLIB=OFF"
            sanitizer: "-DENABLE_SANITIZER=ON"
            coverage: "-DENABLE_COVERAGE=OFF"
            upload: false
            ndpi_min_version: "4.8"
          - compiler: "gcc-7"
            os: "ubuntu-20.04"
            ndpid_gcrypt: "-DNDPI_WITH_GCRYPT=OFF"
            ndpid_zlib: "-DENABLE_ZLIB=ON"
            sanitizer: "-DENABLE_SANITIZER=ON"
            coverage: "-DENABLE_COVERAGE=OFF"
            upload: false
            ndpi_min_version: "4.8"

    steps:
      - name: Print Matrix
        run: |
          echo '----------------------------------------'
          echo '| OS.......: ${{ matrix.os }}'
          echo '| CC.......: ${{ matrix.compiler }}'
          echo '|---------------------------------------'
          echo '| GCRYPT...: ${{ matrix.ndpid_gcrypt }}'
          echo '| ZLIB.....: ${{ matrix.ndpid_zlib }}'
          echo '|---------------------------------------'
          echo '| SANITIZER: ${{ matrix.sanitizer }}'
          echo '| COVERAGE.: ${{ matrix.coverage }}'
          echo '|---------------------------------------'
          echo '| UPLOAD...: ${{ matrix.upload }}'
          echo '----------------------------------------'
      - uses: actions/checkout@v3
        with:
          submodules: false
          fetch-depth: 1
      - name: Install Ubuntu Prerequisites
        if: startsWith(matrix.os, 'ubuntu')
        run: |
          sudo apt-get update
          sudo apt-get install autoconf automake cmake libtool pkg-config gettext libjson-c-dev flex bison libpcap-dev zlib1g-dev
          sudo apt-get install ${{ matrix.compiler }} lcov iproute2
      - name: Install Ubuntu Prerequisites (libgcrypt)
        if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.ndpid_gcrypt, '-DNDPI_WITH_GCRYPT=ON')
        run: |
          sudo apt-get install libgcrypt20-dev
      - name: Install Ubuntu Prerequisities (zlib)
        if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.ndpid_zlib, '-DENABLE_ZLIB=ON')
        run: |
          sudo apt-get install zlib1g-dev
      - name: Checking Network Buffer Size
        run: |
          C_VAL=$(cat config.h | sed -n 's/^#define\s\+NETWORK_BUFFER_MAX_SIZE\s\+\([0-9]\+\).*$/\1/gp')
          PY_VAL=$(cat dependencies/nDPIsrvd.py | sed -n 's/^NETWORK_BUFFER_MAX_SIZE = \([0-9]\+\).*$/\1/gp')
          test ${C_VAL} = ${PY_VAL}
      - name: Configure nDPId
        run: |
          mkdir build && cd build
          cmake .. -DENABLE_SYSTEMD=ON -DBUILD_EXAMPLES=ON -DBUILD_NDPI=ON ${{ matrix.coverage }} ${{ matrix.sanitizer }} ${{ matrix.ndpid_zlib }} ${{ matrix.ndpid_gcrypt }}
      - name: Build nDPId
        run: |
          make -C build all VERBOSE=1
      - name: Build single nDPId executable (invoke CC directly)
        if: startsWith(matrix.coverage, '-DENABLE_COVERAGE=OFF') && startsWith(matrix.sanitizer, '-DENABLE_SANITIZER=ON') && startsWith(matrix.ndpid_gcrypt, '-DNDPI_WITH_GCRYPT=OFF') && startsWith(matrix.ndpid_zlib, '-DENABLE_ZLIB=ON')
        run: |
          cc -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak nDPId.c utils.c -I./build/libnDPI/include/ndpi -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include -o /tmp/a.out -lpcap ./build/libnDPI/lib/libndpi.a -pthread -lm -lz
      - name: Test EXEC
        run: |
          ./build/nDPId-test || test $? -eq 1
          ./build/nDPId -h || test $? -eq 1
          ./build/nDPIsrvd -h || test $? -eq 1
      - name: Test DIFF
        if: startsWith(matrix.os, 'ubuntu') && startsWith(matrix.ndpid_gcrypt, '-DNDPI_WITH_GCRYPT=OFF')
        run: |
          ./test/run_tests.sh ./libnDPI ./build/nDPId-test
      - name: Daemon
        run: |
          make -C ./build daemon VERBOSE=1
          make -C ./build daemon VERBOSE=1
      - name: Coverage
        if: startsWith(matrix.coverage, '-DENABLE_COVERAGE=ON')
        run: |
          make -C ./build coverage
      - name: Dist
        if: matrix.upload == false
        run: |
          make -C ./build dist
      - name: CPack DEB
        run: |
          cd ./build && cpack -G DEB && sudo dpkg -i nDPId-*.deb && cd ..
      - name: Upload DEB
        if: matrix.upload
        uses: actions/upload-artifact@v3
        with:
          name: nDPId-debian-packages_${{ matrix.compiler }}${{ matrix.upload_suffix }}
          path: build/*.deb
      - name: systemd test
        if: startsWith(matrix.os, 'ubuntu-latest') && startsWith(matrix.compiler, 'gcc')
        run: |
          ip -c address
          sudo systemctl daemon-reload
          sudo systemctl enable ndpid@lo
          sudo systemctl start ndpid@lo
          SYSTEMCTL_RET=3; while (( $SYSTEMCTL_RET == 3 )); do systemctl is-active ndpid@lo.service; SYSTEMCTL_RET=$?; sleep 1; done
          sudo systemctl status ndpisrvd.service ndpid@lo.service
          sudo systemctl show ndpisrvd.service ndpid@lo.service -p SubState,ActiveState
      - name: Build against libnDPI-${{ matrix.ndpi_min_version }}
        if: matrix.upload == false
        run: |
          mkdir build-local-ndpi && cd build-local-ndpi
          WGET_RET=0
          wget 'https://github.com/ntop/nDPI/archive/refs/tags/${{ matrix.ndpi_min_version }}.tar.gz' || { WGET_RET=$?; true; }
          echo "wget returned: ${WGET_RET}"
          test $WGET_RET -ne 8 || echo "::warning file=nDPId.c::New libnDPI release required to build against release tarball."
          test $WGET_RET -ne 0 || { tar -xzvf ${{ matrix.ndpi_min_version }}.tar.gz && cd nDPI-${{ matrix.ndpi_min_version }} && ./autogen.sh --prefix=/usr --with-only-libndpi CC=${{ matrix.compiler }} CXX=false CFLAGS='-Werror' && sudo make install && cd .. ; }
          test $WGET_RET -ne 0 || { echo "running cmake .."; cmake .. -DBUILD_EXAMPLES=ON -DBUILD_NDPI=OFF -DENABLE_SANITIZER=OFF ${{ matrix.coverage }} ${{ matrix.ndpi_min_version }} ; }
          test $WGET_RET -ne 0 || { echo "running make .."; make all VERBOSE=1 ; }
          test $WGET_RET -eq 0 -o $WGET_RET -eq 8