Skip to content

Commit 9278203

Browse files
committed
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.
1 parent 969e3a2 commit 9278203

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed

other/docker/pvs/pvs.Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
FROM ubuntu:22.04
2+
3+
RUN apt-get update && \
4+
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
5+
ca-certificates \
6+
cmake \
7+
curl \
8+
gcc \
9+
g++ \
10+
libconfig-dev \
11+
libopus-dev \
12+
libsodium-dev \
13+
libvpx-dev \
14+
ninja-build \
15+
strace \
16+
&& apt-get clean \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
RUN curl -o pvs-studio.deb https://cdn.pvs-studio.com/pvs-studio-7.29.79138.387-amd64.deb \
20+
&& dpkg -i pvs-studio.deb \
21+
&& rm pvs-studio.deb
22+
ARG LICENSE_USER="[email protected]" LICENSE_KEY=""
23+
RUN pvs-studio-analyzer credentials "$LICENSE_USER" "$LICENSE_KEY"
24+
25+
WORKDIR /work/c-toxcore
26+
COPY . /work/c-toxcore/
27+
28+
RUN cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_SHARED=OFF
29+
30+
# MISRA
31+
RUN echo 'analysis-mode=32' > pvs.cfg
32+
RUN pvs-studio-analyzer analyze --cfg pvs.cfg -f _build/compile_commands.json -j"$(nproc)" -o misra.log
33+
34+
# General Analysis
35+
RUN echo 'analysis-mode=0' > pvs.cfg
36+
RUN pvs-studio-analyzer analyze --cfg pvs.cfg -f _build/compile_commands.json -j"$(nproc)" -o pvs.log
37+
38+
# Show MISRA errors
39+
RUN plog-converter \
40+
-E "other;testing;toxav;third_party" \
41+
-d "V2501,V2511,V2514,V2516,V2519,V2520,V2537,V2547,V2568,V2571,V2572,V2575,V2578,V2594,V2611,V2614,V2620" \
42+
-a "MISRA:1,2" \
43+
-t "tasklist" \
44+
-o "misra.tasks" \
45+
"misra.log"
46+
RUN cat misra.tasks
47+
48+
# Show MISRA errors
49+
RUN plog-converter \
50+
-E "other;testing;toxav;third_party" \
51+
-d "V501,V547,V641,V802,V1037,V1042,V1051,V1086" \
52+
-a "GA:1,2,3;OP:1,2,3" \
53+
-t "tasklist" \
54+
-o "pvs.tasks" \
55+
"pvs.log"
56+
RUN cat pvs.tasks
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ===== common =====
2+
# Ignore everything ...
3+
**/*
4+
# ... except sources
5+
!**/*.[ch]
6+
!**/*.cc
7+
!**/*.hh
8+
!CHANGELOG.md
9+
!LICENSE
10+
!README.md
11+
!auto_tests/data/*
12+
!other/bootstrap_daemon/bash-completion/**
13+
!other/bootstrap_daemon/tox-bootstrapd.*
14+
!other/proxy/*.mod
15+
!other/proxy/*.sum
16+
!other/proxy/*.go
17+
# ... and CMake build files (used by most builds).
18+
!**/CMakeLists.txt
19+
!.github/scripts/flags*.sh
20+
!cmake/*.cmake
21+
!other/pkgconfig/*
22+
!other/rpm/*
23+
!so.version

other/docker/pvs/run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
DOCKERFLAGS=("--build-arg" "LICENSE_KEY=$(echo -n "$(cat "$HOME/.pvs-license")")")
4+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../sources" && pwd)/run.sh"

toxcore/crypto_core_test_util.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Random_Funcs const Random_Class::vtable = {
1313

1414
Random_Class::~Random_Class() = default;
1515

16-
void Test_Random::random_bytes(void *obj, uint8_t *bytes, size_t length)
16+
void Test_Random::random_bytes(void *obj, uint8_t bytes[], size_t length)
1717
{
1818
std::generate(bytes, &bytes[length], std::ref(lcg));
1919
}
@@ -35,7 +35,7 @@ std::ostream &operator<<(std::ostream &out, PublicKey const &pk)
3535
{
3636
out << '"';
3737
for (uint8_t byte : pk) {
38-
out << std::setw(2) << std::setfill('0') << std::hex << uint32_t(byte);
38+
out << std::setw(2) << std::setfill('0') << std::hex << static_cast<uint32_t>(byte);
3939
}
4040
out << '"';
4141
return out;

toxcore/test_util.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ template <typename T, std::size_t N>
3737
std::array<T, N> to_array(T const (&arr)[N])
3838
{
3939
std::array<T, N> stdarr;
40-
std::copy(arr, arr + N, stdarr.begin());
40+
std::copy(arr, &arr[N], stdarr.begin());
4141
return stdarr;
4242
}
4343

0 commit comments

Comments
 (0)