From 9278203546593d30c2db544062ca2d9943f81fa1 Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 9 Feb 2024 02:31:32 +0000 Subject: [PATCH] test: Add PVS studio docker run. Can't run this on github, yet. I'll add the license key later and run it as post-submit. --- other/docker/pvs/pvs.Dockerfile | 56 ++++++++++++++++++++ other/docker/pvs/pvs.Dockerfile.dockerignore | 23 ++++++++ other/docker/pvs/run | 4 ++ toxcore/crypto_core_test_util.cc | 4 +- toxcore/test_util.hh | 2 +- 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 other/docker/pvs/pvs.Dockerfile create mode 100644 other/docker/pvs/pvs.Dockerfile.dockerignore create mode 100755 other/docker/pvs/run diff --git a/other/docker/pvs/pvs.Dockerfile b/other/docker/pvs/pvs.Dockerfile new file mode 100644 index 0000000000..70321f3fba --- /dev/null +++ b/other/docker/pvs/pvs.Dockerfile @@ -0,0 +1,56 @@ +FROM ubuntu:22.04 + +RUN apt-get update && \ + DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + curl \ + gcc \ + g++ \ + libconfig-dev \ + libopus-dev \ + libsodium-dev \ + libvpx-dev \ + ninja-build \ + strace \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN curl -o pvs-studio.deb https://cdn.pvs-studio.com/pvs-studio-7.29.79138.387-amd64.deb \ + && dpkg -i pvs-studio.deb \ + && rm pvs-studio.deb +ARG LICENSE_USER="iphydf@gmail.com" LICENSE_KEY="" +RUN pvs-studio-analyzer credentials "$LICENSE_USER" "$LICENSE_KEY" + +WORKDIR /work/c-toxcore +COPY . /work/c-toxcore/ + +RUN cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_SHARED=OFF + +# MISRA +RUN echo 'analysis-mode=32' > pvs.cfg +RUN pvs-studio-analyzer analyze --cfg pvs.cfg -f _build/compile_commands.json -j"$(nproc)" -o misra.log + +# General Analysis +RUN echo 'analysis-mode=0' > pvs.cfg +RUN pvs-studio-analyzer analyze --cfg pvs.cfg -f _build/compile_commands.json -j"$(nproc)" -o pvs.log + +# Show MISRA errors +RUN plog-converter \ + -E "other;testing;toxav;third_party" \ + -d "V2501,V2511,V2514,V2516,V2519,V2520,V2537,V2547,V2568,V2571,V2572,V2575,V2578,V2594,V2611,V2614,V2620" \ + -a "MISRA:1,2" \ + -t "tasklist" \ + -o "misra.tasks" \ + "misra.log" +RUN cat misra.tasks + +# Show MISRA errors +RUN plog-converter \ + -E "other;testing;toxav;third_party" \ + -d "V501,V547,V641,V802,V1037,V1042,V1051,V1086" \ + -a "GA:1,2,3;OP:1,2,3" \ + -t "tasklist" \ + -o "pvs.tasks" \ + "pvs.log" +RUN cat pvs.tasks diff --git a/other/docker/pvs/pvs.Dockerfile.dockerignore b/other/docker/pvs/pvs.Dockerfile.dockerignore new file mode 100644 index 0000000000..3a3643cba1 --- /dev/null +++ b/other/docker/pvs/pvs.Dockerfile.dockerignore @@ -0,0 +1,23 @@ +# ===== common ===== +# Ignore everything ... +**/* +# ... except sources +!**/*.[ch] +!**/*.cc +!**/*.hh +!CHANGELOG.md +!LICENSE +!README.md +!auto_tests/data/* +!other/bootstrap_daemon/bash-completion/** +!other/bootstrap_daemon/tox-bootstrapd.* +!other/proxy/*.mod +!other/proxy/*.sum +!other/proxy/*.go +# ... and CMake build files (used by most builds). +!**/CMakeLists.txt +!.github/scripts/flags*.sh +!cmake/*.cmake +!other/pkgconfig/* +!other/rpm/* +!so.version diff --git a/other/docker/pvs/run b/other/docker/pvs/run new file mode 100755 index 0000000000..4ea4b291dc --- /dev/null +++ b/other/docker/pvs/run @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +DOCKERFLAGS=("--build-arg" "LICENSE_KEY=$(echo -n "$(cat "$HOME/.pvs-license")")") +. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh" diff --git a/toxcore/crypto_core_test_util.cc b/toxcore/crypto_core_test_util.cc index b48871a538..d3ea202b54 100644 --- a/toxcore/crypto_core_test_util.cc +++ b/toxcore/crypto_core_test_util.cc @@ -13,7 +13,7 @@ Random_Funcs const Random_Class::vtable = { Random_Class::~Random_Class() = default; -void Test_Random::random_bytes(void *obj, uint8_t *bytes, size_t length) +void Test_Random::random_bytes(void *obj, uint8_t bytes[], size_t length) { std::generate(bytes, &bytes[length], std::ref(lcg)); } @@ -35,7 +35,7 @@ std::ostream &operator<<(std::ostream &out, PublicKey const &pk) { out << '"'; for (uint8_t byte : pk) { - out << std::setw(2) << std::setfill('0') << std::hex << uint32_t(byte); + out << std::setw(2) << std::setfill('0') << std::hex << static_cast(byte); } out << '"'; return out; diff --git a/toxcore/test_util.hh b/toxcore/test_util.hh index 08bc948272..3072f2623f 100644 --- a/toxcore/test_util.hh +++ b/toxcore/test_util.hh @@ -37,7 +37,7 @@ template std::array to_array(T const (&arr)[N]) { std::array stdarr; - std::copy(arr, arr + N, stdarr.begin()); + std::copy(arr, &arr[N], stdarr.begin()); return stdarr; }