gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/runtimes/proctor/lib/java.go (about) 1 // Copyright 2019 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package lib 16 17 import ( 18 "fmt" 19 "os" 20 "os/exec" 21 "regexp" 22 "strings" 23 ) 24 25 // Directories to exclude from tests. 26 var javaExclDirs = regexp.MustCompile(`(^(sun\/security)|(java\/util\/stream)|(java\/time)| )`) 27 28 // Location of java tests. 29 const javaTestDir = "/root/jdk/test/jdk" 30 31 // javaRunner implements TestRunner for Java. 32 type javaRunner struct{} 33 34 var _ TestRunner = javaRunner{} 35 36 // ListTests implements TestRunner.ListTests. 37 func (javaRunner) ListTests() ([]string, error) { 38 args := []string{ 39 "-dir:" + javaTestDir, 40 "-ignore:quiet", 41 "-a", 42 "-listtests", 43 ":jdk_core", 44 ":jdk_svc", 45 ":jdk_sound", 46 ":jdk_imageio", 47 } 48 cmd := exec.Command("jtreg", args...) 49 cmd.Stderr = os.Stderr 50 out, err := cmd.Output() 51 if err != nil { 52 return nil, fmt.Errorf("jtreg -listtests : %v", err) 53 } 54 var testSlice []string 55 for _, test := range strings.Split(string(out), "\n") { 56 if !javaExclDirs.MatchString(test) { 57 testSlice = append(testSlice, test) 58 } 59 } 60 return testSlice, nil 61 } 62 63 // TestCmds implements TestRunner.TestCmds. 64 func (javaRunner) TestCmds(tests []string) []*exec.Cmd { 65 args := append( 66 []string{ 67 "-agentvm", // Execute each action using a pool of reusable JVMs. 68 "-dir:" + javaTestDir, // Base directory for test files and directories. 69 "-noreport", // Do not generate /root/JTreport/html/report.html. 70 "-timeoutFactor:5", // Extend the default timeout (2 min) of all tests by this factor. 71 "-verbose:all", // Verbose output. 72 "-tl:200", // Do not run tests which specify a timeout longer than 200s. 73 }, 74 tests..., 75 ) 76 return []*exec.Cmd{exec.Command("jtreg", args...)} 77 }