Add basic extractor smoke test

This exercises the extractor via 'codeql', with and without tracing.
This commit is contained in:
Chris Smowton
2021-03-29 13:08:47 +01:00
parent 23b8af3a56
commit 87d8bc8d6f
6 changed files with 52 additions and 0 deletions

View File

@@ -118,6 +118,7 @@ test: all build/testdb/check-upgrade-path
# use GOOS=linux because GOOS=darwin GOARCH=386 is no longer supported
env GOOS=linux GOARCH=386 codeql$(EXE) test run ql/test/query-tests/Security/CWE-681 --search-path . --consistency-queries ql/test/consistency
cd extractor; go test -mod=vendor ./... | grep -vF "[no test files]"
bash extractor-smoke-test/test.sh || (echo "Extractor smoke test FAILED"; exit 1)
.PHONY: build/testdb/check-upgrade-path
build/testdb/check-upgrade-path : build/testdb/go.dbscheme ql/src/go.dbscheme

4
extractor-smoke-test/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.bqrs
tracing-out.csv
notracing-out.csv
testdb

View File

@@ -0,0 +1,12 @@
"nd","col1"
"entry","skip"
"entry","skip"
"function declaration","exit"
"assignment to i","selection of Println"
"skip","skip"
"skip","function declaration"
"skip","1"
"1","assignment to i"
"call to Println","exit"
"selection of Println","i"
"i","call to Println"
1 nd col1
2 entry skip
3 entry skip
4 function declaration exit
5 assignment to i selection of Println
6 skip skip
7 skip function declaration
8 skip 1
9 1 assignment to i
10 call to Println exit
11 selection of Println i
12 i call to Println

View File

@@ -0,0 +1,3 @@
module github.com/codeql-go-extractor-smoke-test
go 1.14

View File

@@ -0,0 +1,8 @@
package main
import "fmt"
func main() {
var i int = 1
fmt.Println(i)
}

24
extractor-smoke-test/test.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd $DIR
rm -rf testdb
codeql database create --language=go testdb --search-path ..
codeql query run ../ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.ql --database=testdb --output=notracing-out.bqrs --search-path ..
codeql bqrs decode notracing-out.bqrs --format=csv --output=notracing-out.csv
diff -w -u notracing-out.csv expected.csv
# Now do it again with tracing enabled
export CODEQL_EXTRACTOR_GO_BUILD_TRACING=on
rm -rf testdb
codeql database create --language=go testdb --search-path ..
codeql query run ../ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.ql --database=testdb --output=tracing-out.bqrs --search-path ..
codeql bqrs decode tracing-out.bqrs --format=csv --output=tracing-out.csv
diff -w -u tracing-out.csv expected.csv