| 
									
										
										
										
											2016-08-09 00:55:36 +02:00
										 |  |  | // +build coverage | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package scenarios | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2017-03-31 17:12:33 +02:00
										 |  |  | 	"bytes" | 
					
						
							| 
									
										
										
										
											2016-08-09 00:55:36 +02:00
										 |  |  | 	"os" | 
					
						
							|  |  |  | 	"os/exec" | 
					
						
							| 
									
										
										
										
											2016-08-09 22:13:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-20 20:55:45 +02:00
										 |  |  | 	"v2ray.com/core/common/uuid" | 
					
						
							| 
									
										
										
										
											2016-08-09 00:55:36 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func BuildV2Ray() error { | 
					
						
							| 
									
										
										
										
											2017-03-31 17:12:33 +02:00
										 |  |  | 	genTestBinaryPath() | 
					
						
							| 
									
										
										
										
											2016-11-18 00:01:37 +01:00
										 |  |  | 	if _, err := os.Stat(testBinaryPath); err == nil { | 
					
						
							| 
									
										
										
										
											2016-08-09 00:55:36 +02:00
										 |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 23:03:29 +01:00
										 |  |  | 	cmd := exec.Command("go", "test", "-tags", "coverage coveragemain", "-coverpkg", "v2ray.com/core/...", "-c", "-o", testBinaryPath, GetSourcePath()) | 
					
						
							| 
									
										
										
										
											2016-08-09 00:55:36 +02:00
										 |  |  | 	return cmd.Run() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-16 21:39:00 +01:00
										 |  |  | func RunV2RayProtobuf(config []byte) *exec.Cmd { | 
					
						
							| 
									
										
										
										
											2017-03-31 17:12:33 +02:00
										 |  |  | 	genTestBinaryPath() | 
					
						
							| 
									
										
										
										
											2016-12-16 21:39:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-13 11:06:39 +01:00
										 |  |  | 	covDir := os.Getenv("V2RAY_COV") | 
					
						
							| 
									
										
										
										
											2016-12-16 21:39:00 +01:00
										 |  |  | 	os.MkdirAll(covDir, os.ModeDir) | 
					
						
							| 
									
										
										
										
											2018-02-16 15:29:22 +01:00
										 |  |  | 	randomID := uuid.New() | 
					
						
							|  |  |  | 	profile := randomID.String() + ".out" | 
					
						
							| 
									
										
										
										
											2016-12-16 21:39:00 +01:00
										 |  |  | 	proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb", "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir) | 
					
						
							|  |  |  | 	proc.Stdin = bytes.NewBuffer(config) | 
					
						
							|  |  |  | 	proc.Stderr = os.Stderr | 
					
						
							|  |  |  | 	proc.Stdout = os.Stdout | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return proc | 
					
						
							|  |  |  | } |