github.com/tardisgo/tardisgo@v0.0.0-20161119180838-e0dd9a7e46b5/goroot/haxe/go1.4/src/tgotests.go (about) 1 // Copyright Elliott Stoneham 2015 see licence file 2 3 // Usage: go run tgotests.go 4 5 package main 6 7 import ( 8 "fmt" 9 "os/exec" 10 "runtime" 11 "sort" 12 "strings" 13 "sync" 14 "sync/atomic" 15 ) 16 17 var parallelism = 1 + runtime.NumCPU()/2 // control resource usage here 18 const groupAll = false // control grouping of tests here 19 const onlyJS = true // requires groupAll=false - control if only the JS tests are run (for quicker partial testing) 20 21 // space required before and after package names 22 23 // the allList only contains package tests that pass for all 4 targets 24 var allList = []string{ 25 // these tests do not read any files 26 // for speed of compilation, they can be grouped together (see var groupAll) into as large sets as will work 27 "bufio bytes container/heap container/list container/ring ", 28 "crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac ", 29 "crypto/md5 crypto/rand crypto/rc4 crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle ", 30 "database/sql/driver debug/gosym ", 31 "encoding/asn1 encoding/ascii85 encoding/binary encoding/base32 ", 32 "encoding/base64 encoding/csv encoding/hex encoding/pem encoding/xml ", 33 "errors flag fmt ", 34 "go/ast go/scanner go/token ", 35 "hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image/color ", 36 "index/suffixarray io log math math/cmplx math/big ", 37 "net/http/internal net/mail net/textproto net/url path ", 38 "regexp/syntax runtime sort strings sync/atomic text/scanner text/tabwriter text/template/parse ", 39 "unicode unicode/utf16 unicode/utf8 ", 40 // below are those packages that require their own testdata zip file, and so must be run individually 41 "archive/zip", 42 "compress/bzip2", "compress/flate", "compress/gzip", "compress/lzw", "compress/zlib", 43 "crypto/rsa", 44 "debug/dwarf", "debug/macho", "debug/pe", "debug/plan9obj", 45 "go/format", "go/parser", "go/printer", 46 "image", "image/draw", "image/gif", "image/jpeg", 47 "io/ioutil", 48 "mime", 49 "os", 50 "path/filepath", 51 "regexp", 52 "strconv", 53 "time", 54 } 55 56 var js1 = "" // "crypto/x509" //runtime very long at 30+ mins 57 var js = ` archive/tar 58 debug/elf go/doc 59 ` 60 61 var cs = ` 62 debug/elf 63 ` 64 65 var cpp = ` 66 archive/tar 67 go/doc 68 ` 69 70 var java = ` archive/tar debug/elf 71 ` 72 73 func pkgList(jumble string) []string { 74 pkgs := strings.Split(jumble, " ") 75 edited := []string{} 76 for _, pkg := range pkgs { 77 pkg = strings.TrimSpace(pkg) 78 if pkg != "" { 79 edited = append(edited, pkg) 80 } 81 } 82 sort.Strings(edited) 83 //println("DEBUG sorted list: ", strings.Join(edited, " ")) 84 return edited 85 } 86 87 type resChan struct { 88 output string 89 err error 90 } 91 92 var scores = make(map[string]string) 93 var passes, failures uint32 94 95 func doTarget(target string, pkg []string) { 96 //println("DEBUG ", target, pkg) 97 if onlyJS && target != "js" { 98 results <- resChan{string("Target " + target + " ignored"), nil} 99 return 100 } 101 var lastErr error 102 exe := "bash" 103 _, err := exec.LookPath(exe) 104 if err != nil { 105 switch exe { 106 default: 107 panic(" error - executable not found: " + exe) 108 } 109 } 110 out := []byte{} 111 if target == "all" { 112 prms := append([]string{"./testtgoall.sh"}, pkg...) 113 out, lastErr = exec.Command(exe, prms...).CombinedOutput() 114 } else { 115 out, lastErr = exec.Command(exe, "./testtgo.sh", target, pkg[0]).CombinedOutput() 116 } 117 layout := "%-25s %s" 118 for n := range pkg { 119 if lastErr != nil { 120 //out = append(out, []byte(lastErr.Error())...) 121 scores[fmt.Sprintf(layout, pkg[n], target)] = "Fail" 122 atomic.AddUint32(&failures, 1) 123 } else { 124 scores[fmt.Sprintf(layout, pkg[n], target)] = "Pass" 125 atomic.AddUint32(&passes, 1) 126 } 127 } 128 results <- resChan{string(out), lastErr} 129 } 130 131 type params struct { 132 tgt string 133 pkg []string 134 } 135 136 var limit = make(chan params) 137 138 var results = make(chan resChan, parallelism) 139 140 func limiter() { 141 for { 142 p := <-limit 143 doTarget(p.tgt, p.pkg) 144 } 145 } 146 147 func main() { 148 jsl := pkgList(js) 149 jsl1 := pkgList(js1) 150 csl := pkgList(cs) 151 cppl := pkgList(cpp) 152 javal := pkgList(java) 153 numPkgs := len(jsl) + len(jsl1) + len(csl) + len(cppl) + len(javal) + len(allList) 154 var wg sync.WaitGroup 155 wg.Add(numPkgs) 156 go func() { 157 for count := 0; count < numPkgs; count++ { 158 r := <-results 159 fmt.Println(r.output) 160 fmt.Printf("\n%d passes, %d failures.\n", passes, failures) 161 wg.Done() 162 } 163 }() 164 165 go limiter() // need this in case parallism == 1 166 for pll := 1; pll < parallelism/2; pll++ { // the "all" option runs 4 target tests in parallel 167 go limiter() 168 } 169 if groupAll { 170 for _, ap := range allList { 171 limit <- params{"all", pkgList(ap)} 172 } 173 } 174 for pll := parallelism / 2; pll < parallelism; pll++ { // other options run 1 test each 175 go limiter() 176 } 177 if !groupAll { 178 for _, ap := range allList { 179 pkgs := pkgList(ap) 180 numPkgs += (len(pkgs) * 4) - 1 181 wg.Add((len(pkgs) * 4) - 1) 182 for _, pkg := range pkgs { 183 limit <- params{"cpp", []string{pkg}} 184 limit <- params{"cs", []string{pkg}} 185 limit <- params{"java", []string{pkg}} 186 limit <- params{"js", []string{pkg}} 187 } 188 } 189 } 190 for _, pkg := range jsl1 { //very long js tests 1st 191 limit <- params{"js", []string{pkg}} 192 } 193 for _, pkg := range cppl { 194 limit <- params{"cpp", []string{pkg}} 195 } 196 for _, pkg := range javal { 197 limit <- params{"java", []string{pkg}} 198 } 199 for _, pkg := range csl { 200 limit <- params{"cs", []string{pkg}} 201 } 202 // normal length js tests 203 for _, pkg := range jsl { 204 limit <- params{"js", []string{pkg}} 205 } 206 207 wg.Wait() 208 joint := []string{} 209 for k := range scores { 210 joint = append(joint, k) 211 } 212 sort.Strings(joint) 213 fmt.Println("\nResults\n=======") 214 for _, k := range joint { 215 fmt.Printf("%-35s %s\n", k, scores[k]) 216 } 217 fmt.Printf("\n%d passes, %d failures.\n", passes, failures) 218 }