Skip to content

Commit

Permalink
Regression test for incremental C++
Browse files Browse the repository at this point in the history
Summary:
This is a fully end-to-end test that indexes a base DB, an
incremental DB with some changes, and then checks queries on the
incremental DB against snapshot results. It also tests that most of
the derived predicates are working, including the manual ones.

For this to get the correct results:
* ownership must be working for the base DB
* we have to exclude the correct units
* ownership has to be working for the derived predicates, including
the manual ones (TargetUses and DeclFamilies)

Reviewed By: phlalx

Differential Revision: D51117377

fbshipit-source-id: e67e3cfe60c327702f45d32d44372099c72e04ac
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Nov 9, 2023
1 parent 6b2f6c4 commit 8948452
Show file tree
Hide file tree
Showing 16 changed files with 1,808 additions and 0 deletions.
58 changes: 58 additions & 0 deletions glean/lang/clang/tests/incremental/IncrementalTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{-
Copyright (c) Meta Platforms, Inc. and affiliates.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
-}

{-# LANGUAGE ApplicativeDo #-}
module IncrementalTest (main) where

import qualified Data.ByteString.UTF8 as UTF8
import Data.Default
import System.Directory
import System.Exit
import System.FilePath

import Glean
import Glean.Regression.Config
import Glean.Regression.Indexer
import Glean.Regression.Snapshot (testMain)
import Glean.Regression.Snapshot.Driver
import qualified Glean.Clang.Test as Clang
import qualified Glean.Clang.Test.DerivePass as DerivePass
import qualified Glean.Regression.Driver.DeriveForCodemarkup as Code

main :: IO ()
main = testMain incrementalClangDriver

incrementalClangDriver :: Driver Clang.Options
incrementalClangDriver = clangDriver { driverCreateDatabase = createDB }
where
clangDriver = DerivePass.driver Code.codemarkupDerivePasses

createDB _ backend indexer test = do
let
repo = testRepo test
base = repo { repo_name = (repo_name repo) <> "_base" }
baseTestConfig = test
{ testRepo = base
, testRoot = testRoot test </> "old"
}

fillDatabase backend base "" Nothing (die "repo already exists") $
runIndexerForTest backend indexer baseTestConfig

-- discover which files are in the new version
let isCppFile = (`elem` [".h", ".cpp"]) . takeExtension
files <- filter isCppFile <$> listDirectory (testRoot test)

let deps =
Dependencies_pruned def {
pruned_base = base,
pruned_units = map UTF8.fromString files,
pruned_exclude = True
}
fillDatabase backend repo "" (Just deps) (die "repo already exists") $
runIndexerForTest backend indexer test
6 changes: 6 additions & 0 deletions glean/lang/clang/tests/incremental/cxx1.DeclByName.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query: cxx1.DeclByName _
transform:
- sort
- - [key,name_lowercase]
- [key,kind]
- [key,ident,macro,key]
2 changes: 2 additions & 0 deletions glean/lang/clang/tests/incremental/cxx1.DeclFamily.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
query: cxx1.DeclFamily _
transform: [normord, []]
2 changes: 2 additions & 0 deletions glean/lang/clang/tests/incremental/cxx1.DeclToFamily.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
query: cxx1.DeclToFamily _
transform: [normord, []]
2 changes: 2 additions & 0 deletions glean/lang/clang/tests/incremental/cxx1.TargetUses.query
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
query: cxx1.TargetUses _
transform: [normord, []]
25 changes: 25 additions & 0 deletions glean/lang/clang/tests/incremental/src/a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

namespace test {

class C {
public:
int f();

private:
int x;
};

int a(); // defined in a.cpp

int b(); // defined in b.cpp

}
24 changes: 24 additions & 0 deletions glean/lang/clang/tests/incremental/src/b.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "a.h"

namespace test {

int b() {
return 4; // changed result
}

// Inserted comment

int bb(int x, int y) { // added parameter
C c;
return c.f() + x + y;
}

}
66 changes: 66 additions & 0 deletions glean/lang/clang/tests/incremental/src/cxx1.DeclByName.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
"@generated",
{
"key": {
"name_lowercase": "a",
"kind": 6,
"ident": { "name": { "key": "a" } }
}
},
{
"key": {
"name_lowercase": "b",
"kind": 6,
"ident": { "name": { "key": "b" } }
}
},
{
"key": {
"name_lowercase": "bb",
"kind": 6,
"ident": { "name": { "key": "bb" } }
}
},
{
"key": {
"name_lowercase": "c",
"kind": 3,
"ident": { "name": { "key": "C" } }
}
},
{
"key": {
"name_lowercase": "c",
"kind": 7,
"ident": { "name": { "key": "c" } }
}
},
{
"key": {
"name_lowercase": "f",
"kind": 6,
"ident": { "name": { "key": "f" } }
}
},
{
"key": {
"name_lowercase": "test",
"kind": 0,
"ident": { "name": { "key": "test" } }
}
},
{
"key": {
"name_lowercase": "x",
"kind": 7,
"ident": { "name": { "key": "x" } }
}
},
{
"key": {
"name_lowercase": "y",
"kind": 7,
"ident": { "name": { "key": "y" } }
}
}
]
191 changes: 191 additions & 0 deletions glean/lang/clang/tests/incremental/src/cxx1.DeclFamily.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
[
"@generated",
{
"key": [
{
"function_": {
"key": {
"method": {
"isConst": false,
"isVirtual": false,
"isVolatile": false,
"refQualifier": 0
},
"name": {
"key": {
"name": { "key": { "name": { "key": "f" } } },
"scope": {
"recordWithAccess": {
"access": 0,
"record": {
"key": {
"name": { "key": "C" },
"scope": {
"namespace_": { "key": { "name": { "key": "test" } } }
}
}
}
}
}
}
},
"signature": {
"key": { "parameters": [ ], "returns": { "key": "int" } }
},
"source": {
"columnBegin": 1,
"columnEnd": 1,
"file": { "key": "a.cpp" },
"lineBegin": 13,
"lineEnd": 15
}
}
}
},
{
"function_": {
"key": {
"method": {
"isConst": false,
"isVirtual": false,
"isVolatile": false,
"refQualifier": 0
},
"name": {
"key": {
"name": { "key": { "name": { "key": "f" } } },
"scope": {
"recordWithAccess": {
"access": 0,
"record": {
"key": {
"name": { "key": "C" },
"scope": {
"namespace_": { "key": { "name": { "key": "test" } } }
}
}
}
}
}
}
},
"signature": {
"key": { "parameters": [ ], "returns": { "key": "int" } }
},
"source": {
"columnBegin": 3,
"columnEnd": 9,
"file": { "key": "a.h" },
"lineBegin": 15,
"lineEnd": 15
}
}
}
}
]
},
{
"key": [
{
"function_": {
"key": {
"name": {
"key": {
"name": { "key": { "name": { "key": "a" } } },
"scope": {
"namespace_": { "key": { "name": { "key": "test" } } }
}
}
},
"signature": {
"key": { "parameters": [ ], "returns": { "key": "int" } }
},
"source": {
"columnBegin": 1,
"columnEnd": 1,
"file": { "key": "a.cpp" },
"lineBegin": 17,
"lineEnd": 20
}
}
}
},
{
"function_": {
"key": {
"name": {
"key": {
"name": { "key": { "name": { "key": "a" } } },
"scope": {
"namespace_": { "key": { "name": { "key": "test" } } }
}
}
},
"signature": {
"key": { "parameters": [ ], "returns": { "key": "int" } }
},
"source": {
"columnBegin": 1,
"columnEnd": 7,
"file": { "key": "a.h" },
"lineBegin": 21,
"lineEnd": 21
}
}
}
}
]
},
{
"key": [
{
"function_": {
"key": {
"name": {
"key": {
"name": { "key": { "name": { "key": "b" } } },
"scope": {
"namespace_": { "key": { "name": { "key": "test" } } }
}
}
},
"signature": {
"key": { "parameters": [ ], "returns": { "key": "int" } }
},
"source": {
"columnBegin": 1,
"columnEnd": 1,
"file": { "key": "b.cpp" },
"lineBegin": 13,
"lineEnd": 15
}
}
}
},
{
"function_": {
"key": {
"name": {
"key": {
"name": { "key": { "name": { "key": "b" } } },
"scope": {
"namespace_": { "key": { "name": { "key": "test" } } }
}
}
},
"signature": {
"key": { "parameters": [ ], "returns": { "key": "int" } }
},
"source": {
"columnBegin": 1,
"columnEnd": 7,
"file": { "key": "a.h" },
"lineBegin": 23,
"lineEnd": 23
}
}
}
}
]
}
]
Loading

0 comments on commit 8948452

Please sign in to comment.