Skip to content

Commit 036108f

Browse files
committed
csdiff: implement --filter-file option
1 parent 38aec91 commit 036108f

18 files changed

+239
-2
lines changed

src/csdiff.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ int main(int argc, char *argv[])
5050
("json-output,j", "write the result in JSON format")
5151
("html-output", "write the result in HTML format")
5252
("file-rename,s", po::value<TStringList>(),
53-
"account the file base-name change, [OLD,NEW] (*testing*)");
53+
"account the file base-name change, [OLD,NEW] (*testing*)")
54+
("filter-file,f", po::value<TStringList>(),
55+
"read custom filtering rules from a file in JSON format");
5456

5557
addColorOptions(&desc);
5658

@@ -151,6 +153,13 @@ int main(int argc, char *argv[])
151153
const bool showInternal = vm.count("show-internal");
152154
const bool silent = vm.count("quiet");
153155

156+
if (vm.count("filter-file")) {
157+
const TStringList &filterFiles = vm["filter-file"].as<TStringList>();
158+
if (!MsgFilter::inst()->setFilterFiles(filterFiles, silent))
159+
// an error message already printed out
160+
return 1;
161+
}
162+
154163
try {
155164
// open streams
156165
InStream strOld(fnOld, silent);

tests/csdiff/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2011 - 2020 Red Hat, Inc.
1+
# Copyright (C) 2011 - 2021 Red Hat, Inc.
22
#
33
# This file is part of csdiff.
44
#
@@ -77,3 +77,5 @@ test_csdiff(diff-misc 09-shellcheck-raw)
7777
test_csdiff(diff-misc 10-pylint-copr)
7878
test_csdiff(diff-misc 11-pylint-copr-json)
7979
test_csdiff(diff-misc 12-shellcheck-sc222x)
80+
81+
add_subdirectory(filter-file)

tests/csdiff/filter-file/01-basic-add-z.err

Whitespace-only changes.

tests/csdiff/filter-file/01-basic-add.err

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"msg-filter" : [
3+
{
4+
"checker" : "DIVINE|SYMBIOTIC",
5+
"regexp" : "memory"
6+
},
7+
{
8+
"checker" : "COMPILER_WARNING",
9+
"regexp" : "called on unallocated object",
10+
"replace" : "called correctly, no UB here"
11+
}
12+
]
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Error: COMPILER_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-calloc/0004-calloc-plain-leak/0004-test.c: scope_hint: In function 'main'
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-calloc/0004-calloc-plain-leak/0004-test.c:5:5: warning[-Wunused-result]: ignoring return value of 'calloc' declared with attribute 'warn_unused_result'
4+
# 5 | calloc(1, sizeof(char)); /* leak */
5+
# | ^~~~~~~~~~~~~~~~~~~~~~~
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Error: COMPILER_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-calloc/0004-calloc-plain-leak/0004-test.c: scope_hint: In function 'main'
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-calloc/0004-calloc-plain-leak/0004-test.c:5:5: warning[-Wunused-result]: ignoring return value of 'calloc' declared with attribute 'warn_unused_result'
4+
# 5 | calloc(1, sizeof(char)); /* leak */
5+
# | ^~~~~~~~~~~~~~~~~~~~~~~
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Error: COMPILER_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c: scope_hint: In function 'main'
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:6:5: warning[-Wfree-nonheap-object]: 'free' called correctly, no UB here 'a'
4+
# 6 | free(&a); /* invalid free */
5+
# | ^~~~~~~~
6+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:5:9: note: declared here
7+
# 5 | int a;
8+
# | ^
9+
10+
Error: SYMBIOTIC_WARNING:
11+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: error: memory error: memory not cleaned up
12+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: note: call stack: main ()
13+
14+
Error: DIVINE_WARNING:
15+
/home/lukas/tmp/assert-bounds.c: scope_hint: In function 'main':
16+
/home/lukas/tmp/assert-bounds.c:8: error: access of size 1 at [alloca*] is 1 bytes out of bounds
17+
/home/lukas/tmp/assert-bounds.c:8: note: memory error in userspace
18+
/opt/divine/include/dios/sys/fault.hpp:119: note: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
19+
/home/lukas/tmp/assert-bounds.c:8: note: main
20+
/opt/divine/include/dios/libc/sys/start.cpp:91: note: __dios_start
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Error: COMPILER_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c: scope_hint: In function 'main'
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:6:5: warning[-Wfree-nonheap-object]: 'free' called on unallocated object 'a'
4+
# 6 | free(&a); /* invalid free */
5+
# | ^~~~~~~~
6+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:5:9: note: declared here
7+
# 5 | int a;
8+
# | ^
9+
10+
Error: COMPILER_WARNING:
11+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-calloc/0004-calloc-plain-leak/0004-test.c: scope_hint: In function 'main'
12+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-calloc/0004-calloc-plain-leak/0004-test.c:5:5: warning[-Wunused-result]: ignoring return value of 'calloc' declared with attribute 'warn_unused_result'
13+
# 5 | calloc(1, sizeof(char)); /* leak */
14+
# | ^~~~~~~~~~~~~~~~~~~~~~~
15+
16+
Error: SYMBIOTIC_WARNING:
17+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: error: memory error: memory not cleaned up
18+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: note: call stack: main ()
19+
20+
Error: DIVINE_WARNING:
21+
/home/lukas/tmp/assert-bounds.c: scope_hint: In function 'main':
22+
/home/lukas/tmp/assert-bounds.c:8: error: access of size 1 at [alloca*] is 1 bytes out of bounds
23+
/home/lukas/tmp/assert-bounds.c:8: note: memory error in userspace
24+
/opt/divine/include/dios/sys/fault.hpp:119: note: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
25+
/home/lukas/tmp/assert-bounds.c:8: note: main
26+
/opt/divine/include/dios/libc/sys/start.cpp:91: note: __dios_start
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Error: COMPILER_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c: scope_hint: In function 'main'
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:6:5: warning[-Wfree-nonheap-object]: 'free' called correctly, no UB here 'a'
4+
# 6 | free(&a); /* invalid free */
5+
# | ^~~~~~~~
6+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:5:9: note: declared here
7+
# 5 | int a;
8+
# | ^
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Error: COMPILER_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c: scope_hint: In function 'main'
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:6:5: warning[-Wfree-nonheap-object]: 'free' called correctly, no UB here 'a'
4+
# 6 | free(&a); /* invalid free */
5+
# | ^~~~~~~~
6+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:5:9: note: declared here
7+
# 5 | int a;
8+
# | ^
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"msg-filter" : [
3+
{
4+
"checker" : "DIVINE|SYMBIOTIC",
5+
"regexp" : "memory",
6+
"replace" : "heap"
7+
}
8+
]
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Error: SYMBIOTIC_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: error: memory error: memory not cleaned up
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: note: call stack: main ()
4+
5+
Error: DIVINE_WARNING:
6+
/home/lukas/tmp/assert-bounds.c: scope_hint: In function 'main':
7+
/home/lukas/tmp/assert-bounds.c:8: error: access of size 1 at [alloca*] is 1 bytes out of bounds
8+
/home/lukas/tmp/assert-bounds.c:8: note: memory error in userspace
9+
/opt/divine/include/dios/sys/fault.hpp:119: note: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
10+
/home/lukas/tmp/assert-bounds.c:8: note: main
11+
/opt/divine/include/dios/libc/sys/start.cpp:91: note: __dios_start
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Error: SYMBIOTIC_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: error: memory error: memory not cleaned up
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: note: call stack: main ()
4+
5+
Error: DIVINE_WARNING:
6+
/home/lukas/tmp/assert-bounds.c: scope_hint: In function 'main':
7+
/home/lukas/tmp/assert-bounds.c:8: error: access of size 1 at [alloca*] is 1 bytes out of bounds
8+
/home/lukas/tmp/assert-bounds.c:8: note: memory error in userspace
9+
/opt/divine/include/dios/sys/fault.hpp:119: note: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
10+
/home/lukas/tmp/assert-bounds.c:8: note: main
11+
/opt/divine/include/dios/libc/sys/start.cpp:91: note: __dios_start
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Error: COMPILER_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c: scope_hint: In function 'main'
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:6:5: warning[-Wfree-nonheap-object]: 'free' called correctly, no UB here 'a'
4+
# 6 | free(&a); /* invalid free */
5+
# | ^~~~~~~~
6+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-free/0006-free-stack/0006-test.c:5:9: note: declared here
7+
# 5 | int a;
8+
# | ^
9+
10+
Error: SYMBIOTIC_WARNING:
11+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: error: memory error: memory not cleaned up
12+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: note: call stack: main ()
13+
14+
Error: DIVINE_WARNING:
15+
/home/lukas/tmp/assert-bounds.c: scope_hint: In function 'main':
16+
/home/lukas/tmp/assert-bounds.c:8: error: access of size 1 at [alloca*] is 1 bytes out of bounds
17+
/home/lukas/tmp/assert-bounds.c:8: note: memory error in userspace
18+
/opt/divine/include/dios/sys/fault.hpp:119: note: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
19+
/home/lukas/tmp/assert-bounds.c:8: note: main
20+
/opt/divine/include/dios/libc/sys/start.cpp:91: note: __dios_start
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Error: SYMBIOTIC_WARNING:
2+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: error: heap error: heap not cleaned up
3+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: note: call stack: main ()
4+
5+
Error: SYMBIOTIC_WARNING:
6+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: error: memory error: memory not cleaned up
7+
/home/lukas/aufover-benchmark/tests/single-c/mem-basic-malloc/0009-malloc-zerosize-leak/0009-test.c:10: note: call stack: main ()
8+
9+
Error: DIVINE_WARNING:
10+
/home/lukas/tmp/assert-bounds.c: scope_hint: In function 'main':
11+
/home/lukas/tmp/assert-bounds.c:8: error: access of size 1 at [alloca*] is 1 bytes out of bounds
12+
/home/lukas/tmp/assert-bounds.c:8: note: heap error in userspace
13+
/opt/divine/include/dios/sys/fault.hpp:119: note: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
14+
/home/lukas/tmp/assert-bounds.c:8: note: main
15+
/opt/divine/include/dios/libc/sys/start.cpp:91: note: __dios_start
16+
17+
Error: DIVINE_WARNING:
18+
/home/lukas/tmp/assert-bounds.c: scope_hint: In function 'main':
19+
/home/lukas/tmp/assert-bounds.c:8: error: access of size 1 at [alloca*] is 1 bytes out of bounds
20+
/home/lukas/tmp/assert-bounds.c:8: note: memory error in userspace
21+
/opt/divine/include/dios/sys/fault.hpp:119: note: void __dios::FaultBase::handler<__dios::Context>(_VM_Fault, _VM_Frame*, void (*)())
22+
/home/lukas/tmp/assert-bounds.c:8: note: main
23+
/opt/divine/include/dios/libc/sys/start.cpp:91: note: __dios_start
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (C) 2021 Red Hat, Inc.
2+
#
3+
# This file is part of csdiff.
4+
#
5+
# csdiff is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# any later version.
9+
#
10+
# csdiff is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with csdiff. If not, see <http://www.gnu.org/licenses/>.
17+
18+
# a generic template for a csdiff test-case
19+
macro(test_csdiff num)
20+
set(tst "${CMAKE_CURRENT_SOURCE_DIR}/${num}")
21+
22+
set(cmd "${csdiff} -cf ${tst}-filter.json ${tst}-old.err ${tst}-new.err")
23+
set(cmd "${cmd} | ${diffcmd} ${tst}-add.err -")
24+
add_test_wrap("filter-file-${num}-added" "${cmd}")
25+
26+
set(cmd "${csdiff} -xf ${tst}-filter.json ${tst}-old.err ${tst}-new.err")
27+
set(cmd "${cmd} | ${csjson} | ${csgrep}")
28+
set(cmd "${cmd} | ${diffcmd} ${tst}-fix.err -")
29+
add_test_wrap("filter-file-${num}-fixed" "${cmd}")
30+
31+
set(cmd "${csdiff} -zf ${tst}-filter.json ${tst}-old.err ${tst}-new.err")
32+
set(cmd "${cmd} | ${csjson} | ${csgrep}")
33+
set(cmd "${cmd} | ${diffcmd} ${tst}-add-z.err -")
34+
add_test_wrap("filter-file-${num}-added-with-z" "${cmd}")
35+
36+
set(cmd "${csdiff} -xzf ${tst}-filter.json ${tst}-old.err ${tst}-new.err")
37+
set(cmd "${cmd} | ${csjson} | ${csgrep}")
38+
set(cmd "${cmd} | ${diffcmd} ${tst}-fix-z.err -")
39+
add_test_wrap("filter-file-${num}-fixed-with-z" "${cmd}")
40+
41+
set(cmd "${csdiff} -cf ${tst}-filter.json ${tst}-old.err ${tst}-new.err")
42+
set(cmd "${cmd} | ${diffcmd} ${tst}-add.err -")
43+
add_test_wrap("filter-file-${num}-added-with-c" "${cmd}")
44+
45+
set(cmd "${csdiff} -jxf ${tst}-filter.json ${tst}-old.err ${tst}-new.err")
46+
set(cmd "${cmd} | ${csgrep}")
47+
set(cmd "${cmd} | ${diffcmd} ${tst}-fix.err -")
48+
add_test_wrap("filter-file-${num}-fixed-with-j" "${cmd}")
49+
endmacro()
50+
51+
test_csdiff(01-basic)
52+
test_csdiff(02-checker-regex)

tests/csdiff/sync-diff.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,18 @@ for i in diff*/; do (
1515
done
1616
echo
1717
) done
18+
19+
(
20+
cd filter-file || exit $?
21+
basename "$PWD"
22+
for j in [0-9][0-9]*-old.err; do
23+
set -x
24+
tst=${j%-old.err}
25+
"$CSDIFF" -cf ${tst}-filter.json ${tst}-old.err ${tst}-new.err > ${tst}-add.err
26+
"$CSDIFF" -czf ${tst}-filter.json ${tst}-old.err ${tst}-new.err > ${tst}-add-z.err
27+
"$CSDIFF" -cxf ${tst}-filter.json ${tst}-old.err ${tst}-new.err > ${tst}-fix.err
28+
"$CSDIFF" -cxzf ${tst}-filter.json ${tst}-old.err ${tst}-new.err > ${tst}-fix-z.err
29+
set +x
30+
done
31+
echo
32+
)

0 commit comments

Comments
 (0)