feat: check result status parser
This commit is contained in:
		
							parent
							
								
									c8f0fde629
								
							
						
					
					
						commit
						27972cbad1
					
				|  | @ -1,4 +1,4 @@ | ||||||
| logLevel = 0 | logLevel = 8 | ||||||
| [[stages]] | [[stages]] | ||||||
| name = "compile" | name = "compile" | ||||||
| [stages.executor] | [stages.executor] | ||||||
|  | @ -21,7 +21,7 @@ max = 4_096 | ||||||
| name = "stderr" | name = "stderr" | ||||||
| max = 4_096 | max = 4_096 | ||||||
| [stages.parser] | [stages.parser] | ||||||
| name = "dummy" | name = "result-status" | ||||||
| [stages.parser.with] | [stages.parser.with] | ||||||
| score = 100 | score = 100 | ||||||
| comment = "compile done" | comment = "compile done" | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ package parsers | ||||||
| import ( | import ( | ||||||
| 	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/diff" | 	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/diff" | ||||||
| 	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/dummy" | 	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/dummy" | ||||||
|  | 	_ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers/resultstatus" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // this file does nothing but imports to ensure all the init() functions
 | // this file does nothing but imports to ensure all the init() functions
 | ||||||
|  |  | ||||||
|  | @ -16,15 +16,15 @@ type Config struct { | ||||||
| 
 | 
 | ||||||
| type Diff struct{} | type Diff struct{} | ||||||
| 
 | 
 | ||||||
| func (e *Diff) Run(results []stage.ExecutorResult, configAny any) ( | func (*Diff) Run(results []stage.ExecutorResult, configAny any) ( | ||||||
| 	[]stage.ParserResult, error, | 	[]stage.ParserResult, bool, error, | ||||||
| ) { | ) { | ||||||
| 	config, err := stage.DecodeConfig[Config](configAny) | 	config, err := stage.DecodeConfig[Config](configAny) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, true, err | ||||||
| 	} | 	} | ||||||
| 	if len(config.Cases) != len(results) { | 	if len(config.Cases) != len(results) { | ||||||
| 		return nil, fmt.Errorf("cases number not match") | 		return nil, true, fmt.Errorf("cases number not match") | ||||||
| 	} | 	} | ||||||
| 	var res []stage.ParserResult | 	var res []stage.ParserResult | ||||||
| 	for i, caseConfig := range config.Cases { | 	for i, caseConfig := range config.Cases { | ||||||
|  | @ -32,7 +32,7 @@ func (e *Diff) Run(results []stage.ExecutorResult, configAny any) ( | ||||||
| 		score := 0 | 		score := 0 | ||||||
| 		stdout, err := os.ReadFile(caseConfig.StdoutPath) | 		stdout, err := os.ReadFile(caseConfig.StdoutPath) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			return nil, true, err | ||||||
| 		} | 		} | ||||||
| 		// TODO: more compare strategies
 | 		// TODO: more compare strategies
 | ||||||
| 		if string(stdout) == result.Files["stdout"] { | 		if string(stdout) == result.Files["stdout"] { | ||||||
|  | @ -46,5 +46,5 @@ func (e *Diff) Run(results []stage.ExecutorResult, configAny any) ( | ||||||
| 			), | 			), | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 	return res, nil | 	return res, false, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ package dummy | ||||||
| 
 | 
 | ||||||
| import "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | import "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||||
| 
 | 
 | ||||||
| var name = "dummy" | var name = "result status" | ||||||
| 
 | 
 | ||||||
| func init() { | func init() { | ||||||
| 	stage.RegisterParser(name, &Dummy{}) | 	stage.RegisterParser(name, &Dummy{}) | ||||||
|  |  | ||||||
|  | @ -13,12 +13,12 @@ type Config struct { | ||||||
| 
 | 
 | ||||||
| type Dummy struct{} | type Dummy struct{} | ||||||
| 
 | 
 | ||||||
| func (e *Dummy) Run(results []stage.ExecutorResult, configAny any) ( | func (*Dummy) Run(results []stage.ExecutorResult, configAny any) ( | ||||||
| 	[]stage.ParserResult, error, | 	[]stage.ParserResult, bool, error, | ||||||
| ) { | ) { | ||||||
| 	config, err := stage.DecodeConfig[Config](configAny) | 	config, err := stage.DecodeConfig[Config](configAny) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, true, err | ||||||
| 	} | 	} | ||||||
| 	var res []stage.ParserResult | 	var res []stage.ParserResult | ||||||
| 	for _, result := range results { | 	for _, result := range results { | ||||||
|  | @ -30,5 +30,5 @@ func (e *Dummy) Run(results []stage.ExecutorResult, configAny any) ( | ||||||
| 			), | 			), | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 	return res, nil | 	return res, false, nil | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										9
									
								
								internal/parsers/resultstatus/meta.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								internal/parsers/resultstatus/meta.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | ||||||
|  | package resultstatus | ||||||
|  | 
 | ||||||
|  | import "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||||
|  | 
 | ||||||
|  | var name = "result-status" | ||||||
|  | 
 | ||||||
|  | func init() { | ||||||
|  | 	stage.RegisterParser(name, &ResultStatus{}) | ||||||
|  | } | ||||||
							
								
								
									
										38
									
								
								internal/parsers/resultstatus/parser.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								internal/parsers/resultstatus/parser.go
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | ||||||
|  | package resultstatus | ||||||
|  | 
 | ||||||
|  | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 
 | ||||||
|  | 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||||
|  | 	"github.com/criyle/go-judge/envexec" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | type Config struct{} | ||||||
|  | 
 | ||||||
|  | type ResultStatus struct{} | ||||||
|  | 
 | ||||||
|  | func (*ResultStatus) Run(results []stage.ExecutorResult, configAny any) ( | ||||||
|  | 	[]stage.ParserResult, bool, error, | ||||||
|  | ) { | ||||||
|  | 	// TODO: more config options
 | ||||||
|  | 	_, err := stage.DecodeConfig[Config](configAny) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return nil, true, err | ||||||
|  | 	} | ||||||
|  | 	end := false | ||||||
|  | 	var res []stage.ParserResult | ||||||
|  | 	for _, result := range results { | ||||||
|  | 		comment := "" | ||||||
|  | 		if result.Status != stage.Status(envexec.StatusAccepted) { | ||||||
|  | 			end = true | ||||||
|  | 			comment = fmt.Sprintf( | ||||||
|  | 				"Unexpected executor status: %s.", result.Status, | ||||||
|  | 			) | ||||||
|  | 		} | ||||||
|  | 		res = append(res, stage.ParserResult{ | ||||||
|  | 			Score:   0, | ||||||
|  | 			Comment: comment, | ||||||
|  | 		}) | ||||||
|  | 	} | ||||||
|  | 	return res, end, nil | ||||||
|  | } | ||||||
|  | @ -3,7 +3,7 @@ package stage | ||||||
| var parserMap = map[string]Parser{} | var parserMap = map[string]Parser{} | ||||||
| 
 | 
 | ||||||
| type Parser interface { | type Parser interface { | ||||||
| 	Run([]ExecutorResult, any) ([]ParserResult, error) | 	Run([]ExecutorResult, any) ([]ParserResult, bool, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func RegisterParser(name string, parser Parser) { | func RegisterParser(name string, parser Parser) { | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ func Run(stages []Stage) []StageResult { | ||||||
| 		slog.Info("executor run done", "results", executorResults) | 		slog.Info("executor run done", "results", executorResults) | ||||||
| 		slog.Info("parser run start", "config", stage.ParserConfig) | 		slog.Info("parser run start", "config", stage.ParserConfig) | ||||||
| 		parser := parserMap[stage.ParserName] | 		parser := parserMap[stage.ParserName] | ||||||
| 		parserResults, err := parser.Run(executorResults, stage.ParserConfig) | 		parserResults, end, err := parser.Run(executorResults, stage.ParserConfig) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			slog.Error("parser run error", "name", stage.ExecutorName, "error", err) | 			slog.Error("parser run error", "name", stage.ExecutorName, "error", err) | ||||||
| 			break | 			break | ||||||
|  | @ -28,6 +28,9 @@ func Run(stages []Stage) []StageResult { | ||||||
| 			Name:          stage.Name, | 			Name:          stage.Name, | ||||||
| 			ParserResults: parserResults, | 			ParserResults: parserResults, | ||||||
| 		}) | 		}) | ||||||
|  | 		if end { | ||||||
|  | 			break | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
| 	return stageResults | 	return stageResults | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user