Browse Source

Run unittests

Signed-off-by: yubiuser <github@yubiuser.dev>
yubiuser 10 months ago
parent
commit
2a306508b5
2 changed files with 104 additions and 9 deletions
  1. 103 9
      .github/workflows/cibuild.yml
  2. 1 0
      .gitignore

+ 103 - 9
.github/workflows/cibuild.yml

@@ -37,6 +37,7 @@ jobs:
               ENABLE_DUKTAPE: NO
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
+              RUN_UNITTEST: 1
           
           - os: ubuntu-latest
             compiler: clang
@@ -62,6 +63,7 @@ jobs:
               ENABLE_DUKTAPE: NO
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
+              RUN_UNITTEST: 1
           
           - os: ubuntu-latest
             compiler: gcc 
@@ -139,6 +141,7 @@ jobs:
               ENABLE_DUKTAPE: NO
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
+              RUN_UNITTEST: 1
           
           - os: ubuntu-latest
             compiler: gcc
@@ -163,6 +166,7 @@ jobs:
               ENABLE_DUKTAPE: NO
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
+              RUN_UNITTEST: 1
           
           - os: ubuntu-latest
             compiler: gcc
@@ -187,6 +191,7 @@ jobs:
               ENABLE_DUKTAPE: NO
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
+              RUN_UNITTEST: 1
           
           - os: ubuntu-latest
             compiler: gcc
@@ -211,6 +216,7 @@ jobs:
               ENABLE_DUKTAPE: NO
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
+              RUN_UNITTEST: 1
           
           - os: ubuntu-latest
             compiler: gcc
@@ -235,6 +241,7 @@ jobs:
               ENABLE_DUKTAPE: NO
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
+              RUN_UNITTEST: 1
           
           - os: ubuntu-latest
             compiler: gcc
@@ -261,8 +268,9 @@ jobs:
               ALLOW_WARNINGS: YES
               RUN_UNITTEST: 1
 
-# Remove Lua build, until someone knows how to fix the CMake files
-          # - os: ubuntu-latest
+          # Disable Lua build, until someone knows how to fix the CMake files
+          # see https://github.com/civetweb/civetweb/issues/543
+          # - os: ubuntu-lastest
           #   compiler: clang
           #   env:
           #     idx: 99
@@ -286,6 +294,7 @@ jobs:
           #     ENABLE_DUKTAPE: NO
           #     NO_CACHING: YES
           #     ALLOW_WARNINGS: YES
+          #     RUN_UNITTEST: 1
 
           - os: macos-latest
             compiler: clang
@@ -313,7 +322,10 @@ jobs:
               ALLOW_WARNINGS: YES
               RUN_UNITTEST: 1
 
-          - os: macos-latest
+          # mac-os 13 is the last version of MacOS runner using x86_64 architecture
+          # mac-os 14 and later are using arm64 architecture
+          # but OpenSSL 1.0 can't compile on arm64, so we set it fixed to mac-os 13
+          - os: macos-13
             compiler: clang
             env:
               idx: 11
@@ -338,6 +350,7 @@ jobs:
               NO_CACHING: NO
               ALLOW_WARNINGS: YES
               MACOSX_PACKAGE: 1
+              RUN_UNITTEST: 1
 
 
     steps:
@@ -350,12 +363,38 @@ jobs:
             sudo apt-get install --no-install-recommends -y clang
             sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100
             sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100
+
+        - name: Install OpenSSL 1.0 on modern MacOS
+          # Needed for recent versions of MacOS as they ship with OpenSSL 1.1 by default
+          if: matrix.os == 'macos-13' && matrix.env.OPENSSL_1_0 == 'YES'
+          run: |
+            curl -O -L https://openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
+            tar -xzf openssl-1.0.2u.tar.gz
+            cd openssl-1.0.2u
+            ./Configure --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared shared darwin64-x86_64-cc
+            #make depend
+            make -j $(nproc)
+            sudo make install_sw -j $(nproc)
+
+            OPENSSL_ROOT_DIR=/usr/local/ssl
+            LDFLAGS=-L${OPENSSL_ROOT_DIR}/lib
+            CFLAGS=-I${OPENSSL_ROOT_DIR}/include
+            ADDITIONAL_CMAKE_ARGS="-DCMAKE_SHARED_LINKER_FLAGS=${LDFLAGS} -DMAKE_C_FLAGS=${CFLAGS}"
+            PKG_CONFIG_PATH=${OPENSSL_ROOT_DIR}/lib/pkgconfig
+            
+            echo "LDFLAGS=${LDFLAGS}" >> $GITHUB_ENV
+            echo "CFLAGS=${CFLAGS}" >> $GITHUB_ENV
+            echo "${OPENSSL_ROOT_DIR}/bin" >> $GITHUB_PATH
+            echo "ADDITIONAL_CMAKE_ARGS=${ADDITIONAL_CMAKE_ARGS}" >> $GITHUB_ENV
+            echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" >> $GITHUB_ENV
+            echo "DYLD_LIBRARY_PATH=${OPENSSL_ROOT_DIR}/lib" >> $GITHUB_ENV
         
-        - name: Set up OpenSSL 1.1 on MacOS
+        - name: Set up OpenSSL 1.1 on modern MacOS
+          # OpenSSL 1.1 is installed by default, so we just need to set the paths
           if: matrix.os == 'macos-latest' && matrix.env.OPENSSL_1_1 == 'YES'
           run: |
             OPENSSL_ROOT_DIR=$(brew --prefix openssl@1.1)
-            LDFLAGS=-L{$OPENSSL_ROOT_DIR}/lib
+            LDFLAGS=-L${OPENSSL_ROOT_DIR}/lib
             CFLAGS=-I${OPENSSL_ROOT_DIR}/include
             ADDITIONAL_CMAKE_ARGS="-DCMAKE_SHARED_LINKER_FLAGS=${LDFLAGS} -DMAKE_C_FLAGS=${CFLAGS}"
             PKG_CONFIG_PATH=${OPENSSL_ROOT_DIR}/lib/pkgconfig
@@ -365,6 +404,44 @@ jobs:
             echo "${OPENSSL_ROOT_DIR}/bin" >> $GITHUB_PATH
             echo "ADDITIONAL_CMAKE_ARGS=${ADDITIONAL_CMAKE_ARGS}" >> $GITHUB_ENV
             echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" >> $GITHUB_ENV
+            
+        - name: Install OpenSSL 1.0 on modern Linux
+          # Needed for recent versions of Linux as they ship with OpenSSL 3.0 by default
+          if: matrix.os == 'ubuntu-latest' && matrix.env.OPENSSL_1_0 == 'YES'
+          run: |
+            curl -O -L https://openssl.org/source/old/1.0.2/openssl-1.0.2u.tar.gz
+            tar -xzf openssl-1.0.2u.tar.gz
+            cd openssl-1.0.2u
+            ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared
+            make depend
+            make -j $(nproc)
+            sudo make install_sw -j $(nproc)
+            sudo ldconfig
+
+            OPENSSL_ROOT_DIR=/usr/local/ssl
+            LDFLAGS=-L${OPENSSL_ROOT_DIR}/lib
+            CFLAGS=-I${OPENSSL_ROOT_DIR}/include
+            ADDITIONAL_CMAKE_ARGS="-DCMAKE_SHARED_LINKER_FLAGS=${LDFLAGS} -DMAKE_C_FLAGS=${CFLAGS}"
+            PKG_CONFIG_PATH=${OPENSSL_ROOT_DIR}/lib/pkgconfig
+            
+            echo "LDFLAGS=${LDFLAGS}" >> $GITHUB_ENV
+            echo "CFLAGS=${CFLAGS}" >> $GITHUB_ENV
+            echo "${OPENSSL_ROOT_DIR}/bin" >> $GITHUB_PATH
+            echo "ADDITIONAL_CMAKE_ARGS=${ADDITIONAL_CMAKE_ARGS}" >> $GITHUB_ENV
+            echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" >> $GITHUB_ENV
+            echo "LD_LIBRARY_PATH=${OPENSSL_ROOT_DIR}/lib" >> $GITHUB_ENV
+        
+        - name: Install OpenSSL 1.1 on modern Linux
+          # Needed for recent versions of Linux as they ship  with OpenSSL 3.0 by default
+          if: matrix.os == 'ubuntu-latest' && matrix.env.OPENSSL_1_1 == 'YES'
+          run: |
+            curl -O -L https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz
+            tar -xzf openssl-1.1.1w.tar.gz
+            cd openssl-1.1.1w
+            ./config
+            make -j $(nproc)
+            sudo make install_sw -j $(nproc)
+            sudo ldconfig
         
         - name: Print tool version information
           run: |
@@ -375,7 +452,7 @@ jobs:
         
         - name: Run CMake
           run: |
-            cmake -S . -B CMakeFiles\
+            cmake -S . -B output\
               -DCMAKE_BUILD_TYPE=${{ matrix.env.BUILD_TYPE }}\
               -DBUILD_SHARED_LIBS=${{ matrix.env.BUILD_SHARED }}\
               -DCIVETWEB_THIRD_PARTY_DIR=../src/third-party\
@@ -403,12 +480,29 @@ jobs:
         - name: Build MacOS Package
           if: matrix.env.MACOSX_PACKAGE == 1
           run: |
-            make -f Makefile.osx package
+            make -f Makefile.osx package -j $(nproc)
         
         - name: Build executable
           run: |
-            cmake --build CMakeFiles -- -j $(nproc)
+            cmake --build output -- -j $(nproc)
           
         - name: Check executable
           run: |
-            ./CMakeFiles/src/civetweb -I
+            ./output/src/civetweb -I
+        
+        - name: Run unit tests
+          if: matrix.env.RUN_UNITTEST == 1
+          run: |
+            # kill processes that are using port 8084, which is used in the unit tests
+            # Currently, this affects linux only, where 'mono' is using this port
+            pid_8084=$(sudo lsof -t -i:8084 || true;)
+                
+            if [[ -n ${pid_8084} ]]; then 
+              echo "Killing process using port 8084: ${pid_8084}"     
+              sudo kill -9 ${pid_8084}
+            fi
+
+            # Run unit tests
+            gcc unittest/cgi_test.c -o output/cgi_test.cgi
+            cd output
+            CTEST_OUTPUT_ON_FAILURE=1  CK_FORK=yes  make all test -j $(nproc)

+ 1 - 0
.gitignore

@@ -27,6 +27,7 @@ log.out
 /CMakeCache.txt
 /CMakeFiles
 /mingw-builds
+/output
 
 #################
 ## Eclipse