From 23a86584f0a983edcf9e0da659b904b2638cafcd Mon Sep 17 00:00:00 2001 From: Michael Trimarchi Date: Sat, 14 Dec 2024 23:41:12 +0100 Subject: [PATCH] Adding Valgrind Issues reporting Allow to use valgrindParser to report memory issues The analytic-model already has the valgrind model. Just extend the plugin to use it. recordIssues sourceCodeRetention: 'LAST_BUILD', tool: valgrind(pattern: "out/test/memcheck.xml"), qualityGates: [[threshold: 1, type: 'TOTAL', criticality: 'FAILURE']] Add Fix copy paste error in JavaDoc from Ullrich Hafner Reviewed-by: Ullrich Hafner Signed-off-by: Michael Trimarchi --- .../plugins/analysis/warnings/Valgrind.java | 41 ++ .../analysis/warnings/steps/ParsersITest.java | 6 + .../analysis/warnings/steps/valgrind.xml | 497 ++++++++++++++++++ 3 files changed, 544 insertions(+) create mode 100644 plugin/src/main/java/io/jenkins/plugins/analysis/warnings/Valgrind.java create mode 100644 plugin/src/test/resources/io/jenkins/plugins/analysis/warnings/steps/valgrind.xml diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/Valgrind.java b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/Valgrind.java new file mode 100644 index 0000000000..8ec9db8d32 --- /dev/null +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/warnings/Valgrind.java @@ -0,0 +1,41 @@ +package io.jenkins.plugins.analysis.warnings; + +import org.kohsuke.stapler.DataBoundConstructor; +import org.jenkinsci.Symbol; +import hudson.Extension; + +import io.jenkins.plugins.analysis.core.model.AnalysisModelParser; +import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider; +import io.jenkins.plugins.analysis.core.model.SymbolIconLabelProvider; + +/** + * Provides a parser and customized messages for Valgrind. + * + * @author Michael Trimarchi + */ +public class Valgrind extends AnalysisModelParser { + private static final long serialVersionUID = 1L; + private static final String ID = "valgrind"; + + /** Creates a new instance of {@link Valgrind}. */ + @DataBoundConstructor + public Valgrind() { + super(); + // empty constructor required for stapler + } + + /** Descriptor for this static analysis tool. */ + @Symbol("valgrind") + @Extension + public static class Descriptor extends AnalysisModelParserDescriptor { + /** Creates the descriptor instance. */ + public Descriptor() { + super(ID); + } + + @Override + public StaticAnalysisLabelProvider getLabelProvider() { + return new SymbolIconLabelProvider(getId(), getDisplayName(), getDescriptionProvider(), "symbol-solid/bug-slash plugin-font-awesome-api"); + } + } +} diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/ParsersITest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/ParsersITest.java index 67e8071af1..2ddb1d17a2 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/ParsersITest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/ParsersITest.java @@ -431,6 +431,12 @@ void shouldFindAllPmdIssues() { "A high number of imports can indicate a high degree of coupling within an object."); } + /** Runs the Valgrind Pipeline Issues parser on output file that contains 5 issues. */ + @Test + void shouldFindAllValgrindIssues() { + shouldFindIssuesOfTool(5, new Valgrind(), "valgrind.xml"); + } + /** Runs the CheckStyle parser on an output file that contains 6 issues. */ @Test void shouldFindAllCheckStyleIssues() { diff --git a/plugin/src/test/resources/io/jenkins/plugins/analysis/warnings/steps/valgrind.xml b/plugin/src/test/resources/io/jenkins/plugins/analysis/warnings/steps/valgrind.xml new file mode 100644 index 0000000000..fc77bb098c --- /dev/null +++ b/plugin/src/test/resources/io/jenkins/plugins/analysis/warnings/steps/valgrind.xml @@ -0,0 +1,497 @@ + + + + + 4 + memcheck + + + Memcheck, a memory error detector + Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. + Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info + Command: ./terrible_program + + + 36556 + 26175 + memcheck + + + + /usr/bin/valgrind.bin + --gen-suppressions=all + --xml=yes + --xml-file=valgrind.xml + --track-origins=yes + --leak-check=full + --show-leak-kinds=all + + + ./terrible_program + + + + + RUNNING + + + + + 0x0 + 1 + worst thread ever + UninitCondition + Conditional jump or move depends on uninitialised value(s) + + + 0x109163 + /home/some_user/terrible_program/terrible_program + main + /home/some_user/terrible_program + terrible_program.cpp + 5 + + + Uninitialised value was created by a heap allocation + + + 0x483B20F + /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so + operator new[](unsigned long) + ./coregrind/m_replacemalloc + vg_replace_malloc.c + 640 + + + 0x109151 + /home/some_user/terrible_program/terrible_program + main + /home/some_user/terrible_program + terrible_program.cpp + 3 + + + + insert_a_suppression_name_here + Memcheck:Cond + main + + + Memcheck:Cond + fun:main +} +]]> + + + + + + insert_a_suppression_name_here + Memcheck:Cond + main + + + Memcheck:Cond + fun:main +} +]]> + + + + 0x1 + 1 + InvalidWrite + Invalid write of size 4 + + + 0x109177 + /home/some_user/terrible_program/terrible_program + main + /home/some_user/terrible_program + terrible_program.cpp + 10 + + + Address 0x4dd0c90 is 0 bytes after a block of size 16 alloc'd + + + 0x483B20F + /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so + operator new[](unsigned long) + ./coregrind/m_replacemalloc + vg_replace_malloc.c + 640 + + + 0x109151 + /home/some_user/terrible_program/terrible_program + main + /home/some_user/terrible_program + terrible_program.cpp + 3 + + + + insert_a_suppression_name_here + Memcheck:Addr4 + main + + + Memcheck:Addr4 + fun:main +} +]]> + + + + + + insert_a_suppression_name_here + Memcheck:Addr4 + main + + + Memcheck:Addr4 + fun:main +} +]]> + + + + + FINISHED + + + + + 0x2 + 1 + Leak_DefinitelyLost + + 16 bytes in 1 blocks are definitely lost in loss record 1 of 1 + 16 + 1 + + + + 0x483B20F + /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so + operator new[](unsigned long) + ./coregrind/m_replacemalloc + vg_replace_malloc.c + 640 + + + 0x109151 + /home/some_user/terrible_program/terrible_program + main + /home/some_user/terrible_program + terrible_program.cpp + 3 + + + + insert_a_suppression_name_here + Memcheck:Leak + match-leak-kinds: definite + _Znam + main + + + Memcheck:Leak + match-leak-kinds: definite + fun:_Znam + fun:main +} +]]> + + + + + + insert_a_suppression_name_here + Memcheck:Leak + match-leak-kinds: definite + _Znam + main + + + Memcheck:Leak + match-leak-kinds: definite + fun:_Znam + fun:main +} +]]> + + + + 0x3 + 1 + SyscallParam + Syscall param write(buf) points to uninitialised byte(s) + + + 0x4057F73 + /lib/ld-musl-x86_64.so.1 + /home/buildozer/aports/main/musl/src/1.2.4/src/thread/x86_64 + syscall_cp.s + 29 + + + 0x40550FD + /lib/ld-musl-x86_64.so.1 + __syscall_cp_c + pthread_cancel.c + 33 + + + 0x405B67F + /lib/ld-musl-x86_64.so.1 + write + /home/buildozer/aports/main/musl/src/1.2.4/src/unistd + write.c + 6 + + + 0x109226 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 11 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x109283 + /workspace/awful project/awful_program + main + /workspace/awful project + awful_program.cpp + 14 + + + Address 0x4b31cd0 is 0 bytes inside a block of size 10 alloc'd + + + 0x48A5733 + /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so + malloc + + + 0x1091FE + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 9 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x109283 + /workspace/awful project/awful_program + main + /workspace/awful project + awful_program.cpp + 14 + + + Uninitialised value was created by a heap allocation + + + 0x48A5733 + /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so + malloc + + + 0x1091FE + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 9 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + + + 0x1091F2 + /workspace/awful project/awful_program + make_spaghetti(int) + /workspace/awful project + spaghetti.cpp + 6 + + + 0x109283 + /workspace/awful project/awful_program + main + /workspace/awful project + awful_program.cpp + 14 + + + + insert_a_suppression_name_here + Memcheck:Param + write(buf) + /lib/ld-musl-x86_64.so.1 + __syscall_cp_c + write + _Z14make_spaghettii + _Z14make_spaghettii + _Z14make_spaghettii + _Z14make_spaghettii + main + + + Memcheck:Param + write(buf) + obj:/lib/ld-musl-x86_64.so.1 + fun:__syscall_cp_c + fun:write + fun:_Z14make_spaghettii + fun:_Z14make_spaghettii + fun:_Z14make_spaghettii + fun:_Z14make_spaghettii + fun:main +} +]]> + + + + + + insert_a_suppression_name_here + Memcheck:Param + write(buf) + /lib/ld-musl-x86_64.so.1 + __syscall_cp_c + write + _Z14make_spaghettii + _Z14make_spaghettii + _Z14make_spaghettii + _Z14make_spaghettii + main + + + Memcheck:Param + write(buf) + obj:/lib/ld-musl-x86_64.so.1 + fun:__syscall_cp_c + fun:write + fun:_Z14make_spaghettii + fun:_Z14make_spaghettii + fun:_Z14make_spaghettii + fun:_Z14make_spaghettii + fun:main +} +]]> + + + + 0x4 + 1 + Not_A_Real_Error + Some type of error without a stack trace + + + + 1 + 0x4 + + + 1 + 0x3 + + + 1 + 0x2 + + + 1 + 0x1 + + + 1 + 0x0 + + + + + + +