Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b1d53895
Commit
b1d53895
authored
Jul 08, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check only predicate functions in test
parent
b92eadfd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
18 deletions
+71
-18
codeinspector.go
pkg/util/codeinspector/codeinspector.go
+20
-4
predicates_test.go
plugin/pkg/scheduler/algorithm/predicates/predicates_test.go
+43
-7
priorities_test.go
plugin/pkg/scheduler/algorithm/priorities/priorities_test.go
+8
-7
No files found.
pkg/util/codeinspector/codeinspector.go
View file @
b1d53895
...
@@ -24,11 +24,27 @@ import (
...
@@ -24,11 +24,27 @@ import (
"io/ioutil"
"io/ioutil"
"strings"
"strings"
"unicode"
"unicode"
go2idlparser
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
"k8s.io/kubernetes/cmd/libs/go2idl/types"
)
)
// GetPublicFunctions lists all public functions (not methods) from a golang source file.
// GetPublicFunctions lists all public functions (not methods) from a golang source file.
func
GetPublicFunctions
(
filePath
string
)
([]
string
,
error
)
{
func
GetPublicFunctions
(
pkg
,
filePath
string
)
([]
*
types
.
Type
,
error
)
{
var
functionNames
[]
string
builder
:=
go2idlparser
.
New
()
data
,
err
:=
ioutil
.
ReadFile
(
filePath
)
if
err
!=
nil
{
return
nil
,
err
}
if
err
:=
builder
.
AddFile
(
pkg
,
filePath
,
data
);
err
!=
nil
{
return
nil
,
err
}
universe
,
err
:=
builder
.
FindTypes
()
if
err
!=
nil
{
return
nil
,
err
}
var
functions
[]
*
types
.
Type
// Create the AST by parsing src.
// Create the AST by parsing src.
fset
:=
token
.
NewFileSet
()
// positions are relative to fset
fset
:=
token
.
NewFileSet
()
// positions are relative to fset
...
@@ -45,13 +61,13 @@ func GetPublicFunctions(filePath string) ([]string, error) {
...
@@ -45,13 +61,13 @@ func GetPublicFunctions(filePath string) ([]string, error) {
s
=
x
.
Name
.
Name
s
=
x
.
Name
.
Name
// It's a function (not method), and is public, record it.
// It's a function (not method), and is public, record it.
if
x
.
Recv
==
nil
&&
isPublic
(
s
)
{
if
x
.
Recv
==
nil
&&
isPublic
(
s
)
{
function
Names
=
append
(
functionNames
,
s
)
function
s
=
append
(
functions
,
universe
[
pkg
]
.
Function
(
x
.
Name
.
Name
)
)
}
}
}
}
return
true
return
true
})
})
return
function
Name
s
,
nil
return
functions
,
nil
}
}
// isPublic checks if a given string is a public function name.
// isPublic checks if a given string is a public function name.
...
...
plugin/pkg/scheduler/algorithm/predicates/predicates_test.go
View file @
b1d53895
...
@@ -19,10 +19,13 @@ package predicates
...
@@ -19,10 +19,13 @@ package predicates
import
(
import
(
"fmt"
"fmt"
"os/exec"
"os/exec"
"path/filepath"
"reflect"
"reflect"
"strings"
"strings"
"testing"
"testing"
"k8s.io/kubernetes/cmd/libs/go2idl/parser"
"k8s.io/kubernetes/cmd/libs/go2idl/types"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/util/codeinspector"
"k8s.io/kubernetes/pkg/util/codeinspector"
...
@@ -1584,8 +1587,26 @@ func TestEBSVolumeCountConflicts(t *testing.T) {
...
@@ -1584,8 +1587,26 @@ func TestEBSVolumeCountConflicts(t *testing.T) {
}
}
}
}
func
getPredicateSignature
()
(
*
types
.
Signature
,
error
)
{
filePath
:=
"./../types.go"
pkgName
:=
filepath
.
Dir
(
filePath
)
builder
:=
parser
.
New
()
if
err
:=
builder
.
AddDir
(
pkgName
);
err
!=
nil
{
return
nil
,
err
}
universe
,
err
:=
builder
.
FindTypes
()
if
err
!=
nil
{
return
nil
,
err
}
result
,
ok
:=
universe
[
pkgName
]
.
Types
[
"FitPredicate"
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"FitPredicate type not defined"
)
}
return
result
.
Signature
,
nil
}
func
TestPredicatesRegistered
(
t
*
testing
.
T
)
{
func
TestPredicatesRegistered
(
t
*
testing
.
T
)
{
var
function
Names
[]
string
var
function
s
[]
*
types
.
Type
// Files and directories which predicates may be referenced
// Files and directories which predicates may be referenced
targetFiles
:=
[]
string
{
targetFiles
:=
[]
string
{
...
@@ -1603,27 +1624,42 @@ func TestPredicatesRegistered(t *testing.T) {
...
@@ -1603,27 +1624,42 @@ func TestPredicatesRegistered(t *testing.T) {
// Get all public predicates in files.
// Get all public predicates in files.
for
_
,
filePath
:=
range
files
{
for
_
,
filePath
:=
range
files
{
f
unctions
,
err
:=
codeinspector
.
GetPublicFunctions
(
filePath
)
f
ileFunctions
,
err
:=
codeinspector
.
GetPublicFunctions
(
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/predicates"
,
filePath
)
if
err
==
nil
{
if
err
==
nil
{
function
Names
=
append
(
functionNames
,
f
unctions
...
)
function
s
=
append
(
functions
,
fileF
unctions
...
)
}
else
{
}
else
{
t
.
Errorf
(
"unexpected error when parsing %s"
,
filePath
)
t
.
Errorf
(
"unexpected error when parsing %s"
,
filePath
)
}
}
}
}
predSignature
,
err
:=
getPredicateSignature
()
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't get predicates signature"
)
}
// Check if all public predicates are referenced in target files.
// Check if all public predicates are referenced in target files.
for
_
,
functionName
:=
range
functionNames
{
for
_
,
function
:=
range
functions
{
args
:=
[]
string
{
"-rl"
,
functionName
}
// Ignore functions that doesn't match FitPredicate signature.
signature
:=
function
.
Underlying
.
Signature
if
len
(
predSignature
.
Parameters
)
!=
len
(
signature
.
Parameters
)
{
continue
}
if
len
(
predSignature
.
Results
)
!=
len
(
signature
.
Results
)
{
continue
}
// TODO: Check exact types of parameters and results.
args
:=
[]
string
{
"-rl"
,
function
.
Name
.
Name
}
args
=
append
(
args
,
targetFiles
...
)
args
=
append
(
args
,
targetFiles
...
)
err
:=
exec
.
Command
(
"grep"
,
args
...
)
.
Run
()
err
:=
exec
.
Command
(
"grep"
,
args
...
)
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
switch
err
.
Error
()
{
switch
err
.
Error
()
{
case
"exit status 2"
:
case
"exit status 2"
:
t
.
Errorf
(
"unexpected error when checking %s"
,
functionName
)
t
.
Errorf
(
"unexpected error when checking %s"
,
function
.
Name
)
case
"exit status 1"
:
case
"exit status 1"
:
t
.
Errorf
(
"predicate %s is implemented as public but seems not registered or used in any other place"
,
t
.
Errorf
(
"predicate %s is implemented as public but seems not registered or used in any other place"
,
functionName
)
function
.
Name
)
}
}
}
}
}
}
...
...
plugin/pkg/scheduler/algorithm/priorities/priorities_test.go
View file @
b1d53895
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"strconv"
"strconv"
"testing"
"testing"
"k8s.io/kubernetes/cmd/libs/go2idl/types"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/extensions"
...
@@ -887,7 +888,7 @@ func makeImageNode(node string, status api.NodeStatus) api.Node {
...
@@ -887,7 +888,7 @@ func makeImageNode(node string, status api.NodeStatus) api.Node {
}
}
func
TestPrioritiesRegistered
(
t
*
testing
.
T
)
{
func
TestPrioritiesRegistered
(
t
*
testing
.
T
)
{
var
function
Names
[]
string
var
function
s
[]
*
types
.
Type
// Files and directories which priorities may be referenced
// Files and directories which priorities may be referenced
targetFiles
:=
[]
string
{
targetFiles
:=
[]
string
{
...
@@ -904,27 +905,27 @@ func TestPrioritiesRegistered(t *testing.T) {
...
@@ -904,27 +905,27 @@ func TestPrioritiesRegistered(t *testing.T) {
// Get all public priorities in files.
// Get all public priorities in files.
for
_
,
filePath
:=
range
files
{
for
_
,
filePath
:=
range
files
{
f
unctions
,
err
:=
codeinspector
.
GetPublicFunctions
(
filePath
)
f
ileFunctions
,
err
:=
codeinspector
.
GetPublicFunctions
(
"k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities"
,
filePath
)
if
err
==
nil
{
if
err
==
nil
{
function
Names
=
append
(
functionNames
,
f
unctions
...
)
function
s
=
append
(
functions
,
fileF
unctions
...
)
}
else
{
}
else
{
t
.
Errorf
(
"unexpected error when parsing %s"
,
filePath
)
t
.
Errorf
(
"unexpected error when parsing %s"
,
filePath
)
}
}
}
}
// Check if all public priorities are referenced in target files.
// Check if all public priorities are referenced in target files.
for
_
,
function
Name
:=
range
functionName
s
{
for
_
,
function
:=
range
function
s
{
args
:=
[]
string
{
"-rl"
,
functionName
}
args
:=
[]
string
{
"-rl"
,
function
.
Name
.
Name
}
args
=
append
(
args
,
targetFiles
...
)
args
=
append
(
args
,
targetFiles
...
)
err
:=
exec
.
Command
(
"grep"
,
args
...
)
.
Run
()
err
:=
exec
.
Command
(
"grep"
,
args
...
)
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
switch
err
.
Error
()
{
switch
err
.
Error
()
{
case
"exit status 2"
:
case
"exit status 2"
:
t
.
Errorf
(
"unexpected error when checking %s"
,
functionName
)
t
.
Errorf
(
"unexpected error when checking %s"
,
function
.
Name
)
case
"exit status 1"
:
case
"exit status 1"
:
t
.
Errorf
(
"priority %s is implemented as public but seems not registered or used in any other place"
,
t
.
Errorf
(
"priority %s is implemented as public but seems not registered or used in any other place"
,
functionName
)
function
.
Name
)
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment