예제 #1
0
// runTests runs the specified list of tests
func RunTests(conf *jsonParser.Config, tests []string,
	numSimJobs, numTestJobs int) (int, []*tester.TestResult, error) {

	if err := misc.CleanOutput(tests); err != nil {
		fmt.Println("Failed to clean up previous test results", err)
		return 0, nil, err
	}

	simJobs := make(chan *jsonParser.TestDescription, numSimJobs)
	go createSimJobs(conf.IncludeDir, tests, simJobs)

	// framework for running simulations
	simOutput := make(chan *jsonParser.TestDescription, len(tests))
	simsDone := make(chan struct{}, numSimJobs)
	for i := 0; i < numSimJobs; i++ {
		go runSimJobs(conf.McellPath, simOutput, simJobs, simsDone)
	}
	go closeSimOutput(simOutput, simsDone, numSimJobs)

	// framework for collecting simulation results and funneling them into tests
	testInput := make(chan *jsonParser.TestDescription, len(tests))
	go collectSimResults(testInput, simOutput)

	// framework for running tests
	testResults := make(chan *tester.TestResult, len(tests))
	testsDone := make(chan struct{}, numTestJobs)
	for i := 0; i < numTestJobs; i++ {
		go runTestJobs(testResults, testInput, testsDone)
	}
	numGoodTests, badTests := processResults(testResults, testsDone, numTestJobs)
	return numGoodTests, badTests, nil
}
예제 #2
0
// main routine
func main() {

	nutmegConf, err := jsonParser.ReadConfig()
	if err != nil {
		log.Fatal("Error reading nutmeg.conf: ", err)
	}

	startTime := time.Now()

	testNames, err := gatherTests(nutmegConf.TestDir)
	if err != nil {
		log.Fatal("Could not determine list of available test cases")
	}

	flag.Parse()
	if (testSelection != "") && (categorySelection != "") {
		log.Fatal("The r and R flags are mutually exclusive")
	}
	switch {
	case listTestsFlag:
		fmt.Println("Available tests:")
		fmt.Println("----------------")
		for i, t := range testNames {
			fmt.Printf("[%d] %-20s\n", i, t)
		}

	case listCategoriesFlag:
		fmt.Println("Available Categories:")
		fmt.Println("--------------------")
		categories := extractCategories(nutmegConf, testNames)
		for k := range categories {
			fmt.Println(" -", k)
		}

	case cleanTestOutput:
		testPaths := make([]string, len(testNames))
		for i, t := range testNames {
			testPaths[i] = filepath.Join(nutmegConf.TestDir, t)
		}
		if err := misc.CleanOutput(testPaths); err != nil {
			log.Fatal(err)
		}

	case descriptionSelectionShort != "":
		tests := extractTestCases(nutmegConf.TestDir, descriptionSelectionShort,
			testNames)
		engine.ShowTestDescription(nutmegConf, tests)

	case categorySelection != "":
		testSelection = strings.TrimSpace(testSelection)
		categoryMap := extractCategories(nutmegConf, testNames)
		if ts, ok := categoryMap[testSelection]; ok {
			spawnTests(nutmegConf, ts, startTime)
		}

	case testSelection != "":
		testSelection = strings.TrimSpace(testSelection)

		// check if all tests were requested
		var tests []string
		if testSelection == "all" {
			tests = extractAllTestCases(nutmegConf.TestDir, testNames)
		} else {
			tests = extractTestCases(nutmegConf.TestDir, testSelection, testNames)
		}
		spawnTests(nutmegConf, tests, startTime)

	default:
		flag.PrintDefaults()
	}
}