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

tools/ut.go: add concurrent when listing pkgs #54306

Merged
merged 1 commit into from
Jul 3, 2024
Merged
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
65 changes: 45 additions & 20 deletions tools/check/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ func cmdBuild(args ...string) bool {

// build all packages
if len(args) == 0 {
err := buildTestBinaryMulti(pkgs)
if err != nil {
if err := buildTestBinaryMulti(pkgs); err != nil {
log.Println("build package error", pkgs, err)
return false
}
Expand Down Expand Up @@ -201,28 +200,14 @@ func cmdRun(args ...string) bool {
start := time.Now()
// run all tests
if len(args) == 0 {
err := buildTestBinaryMulti(pkgs)
if err != nil {
if err := buildTestBinaryMulti(pkgs); err != nil {
log.Println("build package error", pkgs, err)
return false
}

for _, pkg := range pkgs {
exist, err := testBinaryExist(pkg)
if err != nil {
log.Println("check test binary existence error", err)
return false
}
if !exist {
fmt.Println("no test case in ", pkg)
continue
}

tasks, err = listTestCases(pkg, tasks)
if err != nil {
log.Println("list test cases error", err)
return false
}
if tasks, err = runExistingTestCases(pkgs); err != nil {
log.Println("run existing test cases error", err)
return false
}
}

Expand Down Expand Up @@ -357,6 +342,32 @@ func cmdRun(args ...string) bool {
return true
}

func runExistingTestCases(pkgs []string) (tasks []task, err error) {
wg := &sync.WaitGroup{}
tasksChannel := make(chan []task, len(pkgs))
for _, pkg := range pkgs {
exist, err := testBinaryExist(pkg)
if err != nil {
log.Println("check test binary existence error", err)
return nil, err
}
if !exist {
fmt.Println("no test case in ", pkg)
continue
}

wg.Add(1)
go listTestCasesConcurrent(wg, pkg, tasksChannel)
}

wg.Wait()
close(tasksChannel)
for t := range tasksChannel {
tasks = append(tasks, t...)
}
return tasks, nil
}

func parseCaseListFromFile(fileName string) (map[string]struct{}, error) {
ret := make(map[string]struct{})

Expand Down Expand Up @@ -651,6 +662,20 @@ func listTestCases(pkg string, tasks []task) ([]task, error) {
return tasks, nil
}

func listTestCasesConcurrent(wg *sync.WaitGroup, pkg string, tasksChannel chan<- []task) {
defer wg.Done()
newCases, err := listNewTestCases(pkg)
if err != nil {
log.Println("list test case error", pkg, err)
return
}
tasks := make([]task, 0, len(newCases))
for _, c := range newCases {
tasks = append(tasks, task{pkg, c})
}
tasksChannel <- tasks
}

func filterTestCases(tasks []task, arg1 string) ([]task, error) {
if strings.HasPrefix(arg1, "r:") {
r, err := regexp.Compile(arg1[2:])
Expand Down