Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift: prepare integration tests for internal running #16034

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion codeql-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ provide:
- "misc/suite-helpers/qlpack.yml"
- "ruby/extractor-pack/codeql-extractor.yml"
- "swift/extractor-pack/codeql-extractor.yml"
- "swift/integration-tests/qlpack.yml"
- "ql/extractor-pack/codeql-extractor.yml"
- ".github/codeql/extensions/**/codeql-pack.yml"

Expand Down
2 changes: 1 addition & 1 deletion swift/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.14
3.11
4 changes: 2 additions & 2 deletions swift/actions/run-integration-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
- name: Run integration tests
shell: bash
run: |
python swift/integration-tests/runner.py --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
python swift/ql/integration-tests/runner.py --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}"
env:
SEMMLE_DEBUG_TRACER: 10000
- name: Upload test logs
Expand All @@ -27,5 +27,5 @@ runs:
with:
name: swift-integration-tests-logs-${{ runner.os }}
path: |
swift/integration-tests/**/db/log
swift/ql/integration-tests/**/db/log
retention-days: 1

This file was deleted.

7 changes: 0 additions & 7 deletions swift/integration-tests/qlpack.yml

This file was deleted.

2 changes: 1 addition & 1 deletion swift/logging/tests/assertion-diagnostics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ py_test(
"diagnostics.expected",
":assert-false",
],
deps = ["//swift/integration-tests:integration_tests"],
deps = ["//swift/ql/integration-tests:utils"],
)
2 changes: 1 addition & 1 deletion swift/logging/tests/assertion-diagnostics/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import subprocess
# We have to use importlib due to the '-' in the path
diagnostics_test_utils = importlib.import_module("swift.integration-tests.diagnostics_test_utils")
diagnostics_test_utils = importlib.import_module("swift.ql.integration-tests.diagnostics_test_utils")

test_dir = "swift/logging/tests/assertion-diagnostics"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ xcuserdata/
DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
*.actual
db
test-db
*.swiftmodule
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
py_library(
name = "integration_tests",
name = "utils",
srcs = [
"create_database_utils.py",
"diagnostics_test_utils.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def runUnsuccessfully(cmd):
def run_codeql_database_create(cmds, lang, keep_trap=True, db=None, runFunction=runSuccessfully):
""" db parameter is here solely for compatibility with the internal test runner """
assert lang == 'swift'
codeql_root = pathlib.Path(__file__).parents[2]
shutil.rmtree("db", ignore_errors=True)
codeql_root = pathlib.Path(__file__).parents[3]
shutil.rmtree("test-db", ignore_errors=True)
cmd = [
"codeql", "database", "create",
"-s", ".", "-l", "swift", f"--search-path={codeql_root}", "--no-cleanup",
Expand All @@ -37,5 +37,5 @@ def run_codeql_database_create(cmds, lang, keep_trap=True, db=None, runFunction=
cmd.append("--keep-trap")
for c in cmds:
cmd += ["-c", c]
cmd.append("db")
cmd.append("test-db")
runFunction(cmd)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _normalize_json(data):
return "\n".join(entries)


def check_diagnostics(test_dir=".", test_db="db", actual = None):
def check_diagnostics(test_dir=".", test_db="test-db", actual = None):
test_dir = pathlib.Path(test_dir)
test_db = pathlib.Path(test_db)
if actual is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import swift

predicate relevant(Locatable loc) {
loc.getLocation().getFile().getName().matches("%/swift/ql/integration-tests/%/Sources/%")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

run_codeql_database_create([
'./build.sh',
], lang='swift')
], lang='swift',
)

with open('hashes.expected', 'w') as expected:
for f in sorted(Path().glob("*.swiftmodule")):
with open(f, 'rb') as module:
print(f.name, sha256(module.read()).hexdigest(), file=expected)

with open('hashes.actual', 'w') as actual:
hashes = [(s.name, s.resolve().name) for s in Path("db/working/swift-extraction-artifacts/store").iterdir()]
hashes = [(s.name, s.resolve().name) for s in Path("test-db/working/swift-extraction-artifacts/store").iterdir()]
hashes.sort()
for module, hash in hashes:
print(module, hash, file=actual)
Expand Down
4 changes: 4 additions & 0 deletions swift/ql/integration-tests/qlpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies:
codeql/swift-all: '*'
codeql/swift-queries: '*'
warnOnImplicitThis: true
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import platform

this_dir = pathlib.Path(__file__).parent.resolve()
codeql_root = this_dir.parents[2]

def options():
p = argparse.ArgumentParser()
Expand All @@ -30,7 +31,7 @@ def options():


def execute_test(path):
shutil.rmtree(path.parent / "db", ignore_errors=True)
shutil.rmtree(path.parent / "test-db", ignore_errors=True)
return subprocess.run([sys.executable, "-u", path.name], cwd=path.parent).returncode == 0

def skipped(test):
Expand All @@ -51,18 +52,18 @@ def main(opts):
return False

os.environ["PYTHONPATH"] = str(this_dir)
os.environ["CODEQL_CONFIG_FILE"] = "/dev/null"
failed_db_creation = []
succesful_db_creation = []
for t in tests:
(succesful_db_creation if execute_test(t) else failed_db_creation).append(t)

if succesful_db_creation:
codeql_root = this_dir.parents[1]
cmd = [
"codeql", "test", "run",
f"--additional-packs={codeql_root}",
"--keep-databases",
"--dataset=db/db-swift",
"--dataset=test-db/db-swift",
f"--threads={opts.threads}",
]
if opts.check_databases:
Expand Down
Loading